Damage source and effect fix

This commit is contained in:
Фёдор Веселов 2024-10-06 19:55:42 +05:00
commit c89d93cf24
15 changed files with 52 additions and 34 deletions

View file

@ -4,7 +4,7 @@ namespace Newlon.Components.Zombies;
public partial class AudioDamage : AudioStreamPlayer2D
{
public void OnDamaged(int amount)
public void OnDamaged(int amount, Node origin)
{
Play();
}

View file

@ -15,7 +15,7 @@ public partial class EatBox : Area2D
public void Bite()
{
plant.TakeDamage(_damage);
plant?.TakeDamage(_damage,GetParent());
}
public void OnAreaEntered(Area2D area)

View file

@ -7,7 +7,7 @@ namespace Newlon.Components.Zombies;
public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffectHandler
{
[Signal]
public delegate void OnHPChangedEventHandler(int deltaHP);
public delegate void OnHPChangedEventHandler(int deltaHP, Node origin);
[Signal]
public delegate void OnLocalTimescaleChangedEventHandler(int currentTimescale);
@ -45,14 +45,15 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
var timer = new Timer() {Autostart = false, OneShot = true};
_effectSlotTimers[i] = timer;
AddChild(timer);
timer.Timeout += () => {EndEffectAtSlot(i);};
int current_index = i;
timer.Timeout += () => {EndEffectAtSlot(current_index);};
}
}
public void Heal(int amount)
public void Heal(int amount,Node origin)
{
_hp += amount;
EmitSignal(SignalName.OnHPChanged,amount);
EmitSignal(SignalName.OnHPChanged,amount,origin);
if (MaxHp > 0)
{
@ -60,10 +61,10 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
}
}
public void TakeDamage(int amount)
public void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
{
_hp -= amount;
EmitSignal(SignalName.OnHPChanged,-amount);
EmitSignal(SignalName.OnHPChanged,-amount, origin);
if (_hp <= 0)
{
@ -101,7 +102,7 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
public void ProcessEffects()
{
for(int i = 0; i < Utility.EffectSlotCount; i++)
_activeEffectSlots[i].Process(this);
_activeEffectSlots[i]?.Process(this);
}
private void EndEffectAtSlot(int slot)