tidy up SpawnViceroid

This commit is contained in:
Chris Forbes
2011-09-25 15:09:43 +13:00
parent 7cbd2cb9b6
commit 6b602d5262

View File

@@ -16,8 +16,7 @@ namespace OpenRA.Mods.Cnc
{ {
class SpawnViceroidInfo : ITraitInfo class SpawnViceroidInfo : ITraitInfo
{ {
[ActorReference] [ActorReference] public readonly string ViceroidActor = "vice";
public readonly string ViceroidActor = "vice";
public readonly int Probability = 10; public readonly int Probability = 10;
public readonly string Owner = "Creeps"; public readonly string Owner = "Creeps";
public readonly int InfDeath = 5; public readonly int InfDeath = 5;
@@ -29,15 +28,13 @@ namespace OpenRA.Mods.Cnc
{ {
readonly SpawnViceroidInfo Info; readonly SpawnViceroidInfo Info;
public SpawnViceroid(SpawnViceroidInfo info) public SpawnViceroid(SpawnViceroidInfo info) { Info = info; }
{
Info = info;
}
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
if (e.Warhead != null && e.Warhead.InfDeath == Info.InfDeath if (e.Warhead == null || e.Warhead.InfDeath != Info.InfDeath) return;
&& self.World.SharedRandom.Next(100) <= Info.Probability) if (self.World.SharedRandom.Next(100) > Info.Probability) return;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var td = new TypeDictionary var td = new TypeDictionary
@@ -46,8 +43,10 @@ namespace OpenRA.Mods.Cnc
new OwnerInit( self.World.Players.First(p => p.InternalName == Info.Owner) ) new OwnerInit( self.World.Players.First(p => p.InternalName == Info.Owner) )
}; };
if (self.HasTrait<IFacing>()) var facing = self.TraitOrDefault<IFacing>();
td.Add(new FacingInit( self.Trait<IFacing>().Facing )); if (facing != null)
td.Add(new FacingInit( facing.Facing ));
w.CreateActor(Info.ViceroidActor, td); w.CreateActor(Info.ViceroidActor, td);
}); });
} }