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,27 +28,27 @@ 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 =>
{
var td = new TypeDictionary
{
new LocationInit( self.Location ),
new OwnerInit( self.World.Players.First(p => p.InternalName == Info.Owner) )
};
if (self.HasTrait<IFacing>()) self.World.AddFrameEndTask(w =>
td.Add(new FacingInit( self.Trait<IFacing>().Facing )); {
w.CreateActor(Info.ViceroidActor, td); var td = new TypeDictionary
}); {
new LocationInit( self.Location ),
new OwnerInit( self.World.Players.First(p => p.InternalName == Info.Owner) )
};
var facing = self.TraitOrDefault<IFacing>();
if (facing != null)
td.Add(new FacingInit( facing.Facing ));
w.CreateActor(Info.ViceroidActor, td);
});
} }
} }
} }