引入属性、伤害管线

This commit is contained in:
2026-09-18 21:43:22 +08:00
parent 92e1ea0d55
commit ba25ec1926
108 changed files with 2920 additions and 720 deletions
@@ -1,4 +1,5 @@
using SepCore.Components;
using SepCore.Battle;
using SepCore.Components;
using SepCore.Definition;
using SepCore.CustomUtility;
using UnityEngine;
@@ -18,22 +19,54 @@ namespace SepCore.Entity
public abstract ImpactData GetImpactData();
public void ApplyDamage(EntityBase attacker, int damageHP)
public void ApplyDamage(EntityBase attacker, in DamageResult damageResult, Vector3? hitPosition = null)
{
if (damageResult.IsDodge)
{
_healthComponent.TakeDamage(0, false, true, hitPosition);
return;
}
float fromHPRatio = _healthComponent.HealthRatio;
_healthComponent.TakeDamage(damageHP);
_healthComponent.TakeDamage(damageResult.Damage, damageResult.IsCrit, false, hitPosition);
float toHPRatio = _healthComponent.HealthRatio;
if (fromHPRatio > toHPRatio)
{
GameEntry.HPBar.ShowHPBar(this, fromHPRatio, toHPRatio);
}
if (damageResult.IsLifeSteal && attacker != null)
{
HealthComponent attackerHealth = attacker.GetComponent<HealthComponent>();
if (attackerHealth == null && attacker is WeaponBase weapon)
{
attackerHealth = weapon.GetComponentInParent<HealthComponent>();
}
if (attackerHealth != null)
{
attackerHealth.TryTriggerLifeSteal(damageResult.LifeStealAmount);
}
}
if (_healthComponent.CurrentHealth <= 0)
{
OnDead(attacker);
}
}
public void ApplyDamage(EntityBase attacker, int damageHP)
{
ApplyDamage(attacker, new DamageResult
{
Damage = damageHP,
IsDodge = false,
IsCrit = false,
IsLifeSteal = false,
LifeStealAmount = 0
});
}
protected override void OnInit(object userData)
{
base.OnInit(userData);