cache the trait lookup
This commit is contained in:
@@ -27,15 +27,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new Guard(this); }
|
public object Create(ActorInitializer init) { return new Guard(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Guard : IResolveOrder, IOrderVoice
|
public class Guard : IResolveOrder, IOrderVoice, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly GuardInfo info;
|
readonly GuardInfo info;
|
||||||
|
IMove move;
|
||||||
|
|
||||||
public Guard(GuardInfo info)
|
public Guard(GuardInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Created(Actor self)
|
||||||
|
{
|
||||||
|
move = self.Trait<IMove>();
|
||||||
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "Guard")
|
if (order.OrderString == "Guard")
|
||||||
@@ -51,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.SetTargetLine(target, Color.Yellow);
|
self.SetTargetLine(target, Color.Yellow);
|
||||||
|
|
||||||
var range = target.Actor.Info.TraitInfo<GuardableInfo>().Range;
|
var range = target.Actor.Info.TraitInfo<GuardableInfo>().Range;
|
||||||
self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WDist.Zero, range)));
|
self.QueueActivity(false, new AttackMoveActivity(self, move.MoveFollow(self, target, WDist.Zero, range)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
|||||||
Reference in New Issue
Block a user