Actor.traits is implementation detail

This commit is contained in:
Bob
2010-08-14 15:19:30 +12:00
committed by alzeih
parent f6c6255f64
commit ae703d50b2
165 changed files with 586 additions and 561 deletions

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA
new FacingInit( Util.GetFacing(order.TargetLocation - startPos, 0) ),
new AltitudeInit( Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude ),
});
a.traits.Get<CarpetBomb>().SetTarget(order.TargetLocation);
a.Trait<CarpetBomb>().SetTarget(order.TargetLocation);
a.CancelActivity();
a.QueueActivity(new Fly(order.TargetLocation));

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
self.World.CancelInputMode();
// Ensure the target cell is valid for the unit
var movement = order.TargetActor.traits.GetOrDefault<IMove>();
var movement = order.TargetActor.TraitOrDefault<IMove>();
if (!movement.CanEnterCell(order.TargetLocation))
return;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
.WithTrait<Chronosphere>()
.Select(x => x.Actor).FirstOrDefault();
chronosphere.traits.Get<Chronosphere>().Teleport(order.TargetActor, order.TargetLocation);
chronosphere.Trait<Chronosphere>().Teleport(order.TargetActor, order.TargetLocation);
FinishActivate();
}
@@ -71,8 +71,8 @@ namespace OpenRA.Mods.RA
if (mi.Button == MouseButton.Left)
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Owner != null && a.traits.Contains<Chronoshiftable>()
&& a.traits.Contains<Selectable>()).FirstOrDefault();
.Where(a => a.Owner != null && a.HasTrait<Chronoshiftable>()
&& a.HasTrait<Selectable>()).FirstOrDefault();
if (underCursor != null)
yield return new Order("ChronosphereSelect", world.LocalPlayer.PlayerActor, underCursor);
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA
if (!world.LocalPlayer.Shroud.IsExplored(xy))
return "move-blocked";
var movement = self.traits.GetOrDefault<IMove>();
var movement = self.TraitOrDefault<IMove>();
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
}
}
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.RA
public void Teleport(Actor targetActor, int2 targetLocation)
{
var info = self.Info.Traits.Get<ChronosphereInfo>();
bool success = targetActor.traits.Get<Chronoshiftable>().Activate(targetActor, targetLocation, info.Duration * 25, info.KillCargo, self);
bool success = targetActor.Trait<Chronoshiftable>().Activate(targetActor, targetLocation, info.Duration * 25, info.KillCargo, self);
if (success)
{
@@ -182,7 +182,7 @@ namespace OpenRA.Mods.RA
foreach (var a in self.World.Queries.WithTrait<ChronoshiftPaletteEffect>())
a.Trait.Enable();
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
protected override void OnFinishCharging()
{
var launchSite = Owner.World.Queries.OwnedBy[Owner]
.FirstOrDefault(a => a.traits.Contains<GpsLaunchSite>());
.FirstOrDefault(a => a.HasTrait<GpsLaunchSite>());
if (launchSite == null)
return;

View File

@@ -46,11 +46,11 @@ namespace OpenRA.Mods.RA
.Where(a => a.Actor.Owner != null)
.FirstOrDefault().Actor;
if (curtain != null)
curtain.traits.Get<RenderBuilding>().PlayCustomAnim(curtain, "active");
curtain.Trait<RenderBuilding>().PlayCustomAnim(curtain, "active");
Sound.Play("ironcur9.aud", order.TargetActor.CenterLocation);
order.TargetActor.traits.Get<IronCurtainable>().Activate(order.TargetActor,
order.TargetActor.Trait<IronCurtainable>().Activate(order.TargetActor,
(int)((Info as IronCurtainPowerInfo).Duration * 25 * 60));
FinishActivate();
@@ -75,8 +75,8 @@ namespace OpenRA.Mods.RA
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Owner != null
&& a.traits.Contains<IronCurtainable>()
&& a.traits.Contains<Selectable>()).FirstOrDefault();
&& a.HasTrait<IronCurtainable>()
&& a.HasTrait<Selectable>()).FirstOrDefault();
if (underCursor != null)
yield return new Order("IronCurtain", underCursor.Owner.PlayerActor, underCursor);

View File

@@ -38,16 +38,16 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "NuclearMissile")
{
var silo = self.World.Queries.OwnedBy[self.Owner]
.Where(a => a.traits.Contains<NukeSilo>())
.Where(a => a.HasTrait<NukeSilo>())
.FirstOrDefault();
if (silo != null)
silo.traits.Get<RenderBuilding>().PlayCustomAnim(silo, "active");
silo.Trait<RenderBuilding>().PlayCustomAnim(silo, "active");
// Play to everyone but the current player
if (Owner != Owner.World.LocalPlayer)
Sound.Play(Info.LaunchSound);
silo.traits.Get<NukeSilo>().Attack(order.TargetLocation);
silo.Trait<NukeSilo>().Attack(order.TargetLocation);
self.World.CancelInputMode();
FinishActivate();
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
public void Attack(int2 targetLocation)
{
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
self.World.AddFrameEndTask(w =>
{

View File

@@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA
a.CancelActivity();
a.QueueActivity(new FlyCircle(p));
a.traits.Get<ParaDrop>().SetLZ(p, flare);
a.Trait<ParaDrop>().SetLZ(p, flare);
var cargo = a.traits.Get<Cargo>();
var cargo = a.Trait<Cargo>();
foreach (var i in items)
cargo.Load(a, owner.World.CreateActor(false, i.ToLowerInvariant(), new TypeDictionary { new OwnerInit( a.Owner ) }));
});