death now cancels effects
This commit is contained in:
parent
9be6a3a169
commit
5c33aacf7f
5 changed files with 66 additions and 34 deletions
|
|
@ -13,12 +13,14 @@ public partial class Entity : Node2D
|
|||
[Export]public float HP;
|
||||
[Signal] public delegate void OnHPChangedEventHandler(EntitySignalContext context);
|
||||
[Signal] public delegate void OnDamagedEventHandler();
|
||||
[Signal] public delegate void HasBeenKilledEventHandler(Entity who);
|
||||
|
||||
|
||||
public virtual void TakeDamage(float amount, Node origin)
|
||||
{
|
||||
if(amount > 0)
|
||||
if (amount > 0)
|
||||
EmitSignal(SignalName.OnDamaged);
|
||||
|
||||
|
||||
var context = new EntitySignalContext()
|
||||
{
|
||||
target = this,
|
||||
|
|
@ -62,8 +64,13 @@ public partial class Entity : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
public bool Killed = false;
|
||||
public virtual void KillByDamage()
|
||||
{
|
||||
if (Killed) return;
|
||||
Killed = true;
|
||||
EmitSignal(SignalName.HasBeenKilled,this);
|
||||
ClearEffects();
|
||||
Kill();
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +123,7 @@ public partial class Entity : Node2D
|
|||
|
||||
public virtual void GiveEffect(Effect what)
|
||||
{
|
||||
if (Killed) return;
|
||||
if (_effectImmunities.Contains(what) || completeInvulnerability)
|
||||
{
|
||||
return;
|
||||
|
|
@ -166,8 +174,21 @@ public partial class Entity : Node2D
|
|||
EndEffectAtSlot(what.Slot);
|
||||
}
|
||||
|
||||
protected void ClearEffects()
|
||||
{
|
||||
foreach (var slot in _activeEffectSlots.Keys)
|
||||
{
|
||||
if (_activeEffectSlots[slot] != null)
|
||||
{
|
||||
_activeEffectSlots[slot].Exit(this);
|
||||
_activeEffectSlots[slot] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessEffects()
|
||||
{
|
||||
if (Killed) return;
|
||||
foreach (string key in _activeEffectSlots.Keys)
|
||||
_activeEffectSlots[key]?.Process(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ public partial class RuntimeZombieData : Entity
|
|||
{
|
||||
[Export]
|
||||
private Armor _armor;
|
||||
[Signal] public delegate void HasBeenKilledEventHandler(RuntimeZombieData who);
|
||||
[Signal] public delegate void HPChangedMixedEventHandler(EntitySignalContext context);
|
||||
public bool AbleToEat = true;
|
||||
|
||||
|
|
@ -102,12 +101,12 @@ public partial class RuntimeZombieData : Entity
|
|||
return HP;
|
||||
}
|
||||
#region Death sequence
|
||||
private bool _killed = false;
|
||||
public override void KillByDamage()
|
||||
{
|
||||
if (_killed) return;
|
||||
_killed = true;
|
||||
if (Killed) return;
|
||||
Killed = true;
|
||||
AbleToEat = false;
|
||||
ClearEffects();
|
||||
EmitSignal(SignalName.HasBeenKilled,this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public partial class LevelRunner : Node
|
|||
zombie.HasBeenKilled += OnLastZombieKilled;
|
||||
}
|
||||
}
|
||||
private void OnLastZombieKilled(RuntimeZombieData who)
|
||||
private void OnLastZombieKilled(Entity who)
|
||||
{
|
||||
aliveZombies -= 1;
|
||||
if (aliveZombies > 0) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue