Merge pull request #4189 from pchote/health-lookups

Move HealthExts.IsDead and Kill to Actor.
This commit is contained in:
Matthias Mailänder
2013-11-30 07:18:47 -08:00
2 changed files with 18 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ namespace OpenRA
Lazy<IOccupySpace> occupySpace;
Lazy<IFacing> facing;
Lazy<Health> health;
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
@@ -72,6 +73,7 @@ namespace OpenRA
}
facing = Lazy.New(() => TraitOrDefault<IFacing>());
health = Lazy.New(() => TraitOrDefault<Health>());
applyIRender = (x, wr) => x.Render(this, wr);
applyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
@@ -210,5 +212,21 @@ namespace OpenRA
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);
}
}
}

View File

@@ -168,15 +168,6 @@ namespace OpenRA.Traits
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)
{
if (self.Destroyed)
@@ -193,12 +184,5 @@ namespace OpenRA.Traits
if (health == null) return;
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);
}
}
}