Health System

This commit is contained in:
ThomasCharester committed 2026-11-17 18:44:54 +03:00
1 parent 329cc98ade
commit cb05da5e89
87 files changed
+568550 -155362

No files matched your search

@@ -103,8 +103,9 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
private void OnEnemyHit(Collider attacker, Collider enemyCollider)
{
var originEntityId = enemyCollider.GetComponentInParent<EntityProperties>().GetEntityId();
var defenderId = enemyCollider.GetComponentInParent<EntityProperties>().GetEntityId();
var attackerId = attacker.GetComponentInParent<EntityProperties>().GetEntityId();
Vector3 attackerDirection = attacker.transform.TransformDirection(_attackData.LocalKnockbackDirection);
attackerDirection.y = 0f;
attackerDirection.Normalize();
@@ -119,7 +120,16 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
};
var decisionResult = new AsIsBattleActionDeciderResult { ActionType = BattleActionType.Stugger };
battleTimeline.ForceDecideAction(originEntityId, actionData, decisionResult);
EntityAttackedData attackedData = new()
{
ForcedActionData = actionData,
ForcedDecisionResult = decisionResult,
Damage = _attackData.Damage
};
battleTimeline.AttackRequest(attackerId, defenderId, attackedData);
//battleTimeline.ForceDecideAction(originEntityId, actionData, decisionResult);
_particleService.EmitOneShot(
new ParticlePartitionIDPair(ParticlePartition.HitParticles, 0),
@@ -74,6 +74,15 @@ namespace Code.OfficeGame.BattleMode.Actions
stuggerActionData.KnockbackSpeed * tickDelta,
stuggerActionData.KnockbackDistance);
// Поворот противоположно направлению атаки за время отталкивания
Quaternion targetRotation = Quaternion.LookRotation(-stuggerActionData.KnockbackDirection, Vector3.up);
float t = stepDistance / stuggerActionData.KnockbackDistance;
Quaternion nextRotation = Quaternion.Slerp(
entity.KinematicCharacterMotor.TransientRotation,
targetRotation,
t);
entity.KinematicCharacterMotor.SetRotation(nextRotation);
stuggerActionData.KnockbackDistance -= stepDistance;
Vector3 step = stuggerActionData.KnockbackDirection * stepDistance;
@@ -1,6 +1,10 @@
using System.Collections.Generic;
using Code.Game.Gameplay.Player;
using Code.OfficeGame.BattleMode.Effects;
using Code.OfficeGame.BattleMode.Health;
using Code.OfficeGame.BattleMode.HitBoxes;
using KinematicCharacterController;
using Unity.VisualScripting;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
@@ -14,5 +18,10 @@ namespace Code.OfficeGame.BattleMode.Actions
public KinematicCharacterMotor KinematicCharacterMotor;
public EntityHitBoxes EntityHitBoxes;
public EntityPreviewVisuals EntityPreviewVisuals;
public EntityHealth EntityHealth;
[DoNotSerialize]
public List<Effect> Effects = new();
}
}
@@ -1,4 +1,5 @@
using Code.Game.Gameplay.Player;
using Code.OfficeGame.BattleMode.Health;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
@@ -11,6 +12,7 @@ namespace Code.OfficeGame.BattleMode.Actions
public AnimatorSnapshot AnimatorSnapshot;
public MovementControllerSnapshot ControllerSnapshot;
public EntityHealthSnapshot HealthSnapshot;
public static EntitySnapshot GetSnapshot(EntityProperties entityProperties)
{
@@ -20,12 +22,15 @@ namespace Code.OfficeGame.BattleMode.Actions
Position = entityProperties.KinematicCharacterMotor.TransientPosition,
Rotation = entityProperties.KinematicCharacterMotor.TransientRotation,
AnimatorSnapshot = AnimatorSnapshot.GetSnapshot(entityProperties.animator),
ControllerSnapshot = MovementControllerSnapshot.GetSnapshot(entityProperties.MovementController)
ControllerSnapshot = MovementControllerSnapshot.GetSnapshot(entityProperties.MovementController),
HealthSnapshot = EntityHealthSnapshot.GetSnapshot(entityProperties.EntityHealth)
};
}
public static void RestoreSnapshot(EntityProperties entityProperties, EntitySnapshot snapshot)
{
snapshot.HealthSnapshot.RestoreSnapshot(entityProperties.EntityHealth);
// 1. Возвращаем капсулу KCC
entityProperties.KinematicCharacterMotor.SetPositionAndRotation(snapshot.Position, snapshot.Rotation);
entityProperties.KinematicCharacterMotor.BaseVelocity = snapshot.BaseVelocity;
@@ -93,6 +98,8 @@ namespace Code.OfficeGame.BattleMode.Actions
NormalizedTime = stateInfo.normalizedTime,
LayerWeight = animator.GetLayerWeight(i)
};
Debug.Log($"Saved animator state {stateInfo.shortNameHash}");
}
int paramCount = animator.parameterCount;
@@ -199,4 +206,22 @@ namespace Code.OfficeGame.BattleMode.Actions
movementController.LookInputVector = LookInput;
}
}
public struct EntityHealthSnapshot
{
public HealthData HealthData;
public static EntityHealthSnapshot GetSnapshot(EntityHealth entityHealth)
{
return new()
{
HealthData = entityHealth.HealthData.CurrentValue
};
}
public void RestoreSnapshot(EntityHealth entityHealth)
{
entityHealth.SetHealthData(HealthData);
}
}
}