Merge pull request #4189 from pchote/health-lookups
Move HealthExts.IsDead and Kill to Actor.
This commit is contained in:
@@ -28,6 +28,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
Lazy<IOccupySpace> occupySpace;
|
Lazy<IOccupySpace> occupySpace;
|
||||||
Lazy<IFacing> facing;
|
Lazy<IFacing> facing;
|
||||||
|
Lazy<Health> health;
|
||||||
|
|
||||||
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
|
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
|
|
||||||
facing = Lazy.New(() => TraitOrDefault<IFacing>());
|
facing = Lazy.New(() => TraitOrDefault<IFacing>());
|
||||||
|
health = Lazy.New(() => TraitOrDefault<Health>());
|
||||||
|
|
||||||
applyIRender = (x, wr) => x.Render(this, wr);
|
applyIRender = (x, wr) => x.Render(this, wr);
|
||||||
applyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
|
applyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
|
||||||
@@ -210,5 +212,21 @@ namespace OpenRA
|
|||||||
t.OnOwnerChanged(this, oldOwner, newOwner);
|
t.OnOwnerChanged(this, oldOwner, newOwner);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDead()
|
||||||
|
{
|
||||||
|
if (Destroyed)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return (health.Value == null) ? false : health.Value.IsDead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kill(Actor attacker)
|
||||||
|
{
|
||||||
|
if (health.Value == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
health.Value.InflictDamage(this, attacker, health.Value.MaxHP, null, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,15 +168,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public static class HealthExts
|
public static class HealthExts
|
||||||
{
|
{
|
||||||
public static bool IsDead(this Actor self)
|
|
||||||
{
|
|
||||||
if (self.Destroyed)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var health = self.TraitOrDefault<Health>();
|
|
||||||
return (health == null) ? false : health.IsDead;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DamageState GetDamageState(this Actor self)
|
public static DamageState GetDamageState(this Actor self)
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Destroyed)
|
||||||
@@ -193,12 +184,5 @@ namespace OpenRA.Traits
|
|||||||
if (health == null) return;
|
if (health == null) return;
|
||||||
health.InflictDamage(self, attacker, damage, warhead, false);
|
health.InflictDamage(self, attacker, damage, warhead, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Kill(this Actor self, Actor attacker)
|
|
||||||
{
|
|
||||||
var health = self.TraitOrDefault<Health>();
|
|
||||||
if (health == null) return;
|
|
||||||
health.InflictDamage(self, attacker, health.MaxHP, null, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user