Fix conditional traits that incorrectly override INotifyCreated.

This commit is contained in:
Paul Chote
2019-07-13 13:02:24 +01:00
committed by teinarss
parent 37325dbfc7
commit 6eaf615798
10 changed files with 34 additions and 23 deletions

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public class AutoTarget : ConditionalTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync, INotifyCreated, INotifyOwnerChanged
public class AutoTarget : ConditionalTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync, INotifyOwnerChanged
{
public readonly IEnumerable<AttackBase> ActiveAttackBases;
[Sync]
@@ -189,19 +189,21 @@ namespace OpenRA.Mods.Common.Traits
PredictedStance = stance;
}
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
// AutoTargetPriority and their Priorities are fixed - so we can safely cache them with ToArray.
// IsTraitEnabled can change over time, and so must appear after the ToArray so it gets re-evaluated each time.
activeTargetPriorities =
self.TraitsImplementing<AutoTargetPriority>()
.OrderByDescending(ati => ati.Info.Priority).ToArray()
.Where(Exts.IsTraitEnabled).Select(atp => atp.Info);
.OrderByDescending(ati => ati.Info.Priority).ToArray()
.Where(Exts.IsTraitEnabled).Select(atp => atp.Info);
conditionManager = self.TraitOrDefault<ConditionManager>();
disableAutoTarget = self.TraitsImplementing<IDisableAutoTarget>().ToArray();
notifyStanceChanged = self.TraitsImplementing<INotifyStanceChanged>().ToArray();
ApplyStanceCondition(self);
base.Created(self);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new PrimaryBuilding(init.Self, this); }
}
public class PrimaryBuilding : ConditionalTrait<PrimaryBuildingInfo>, INotifyCreated, IIssueOrder, IResolveOrder
public class PrimaryBuilding : ConditionalTrait<PrimaryBuildingInfo>, IIssueOrder, IResolveOrder
{
const string OrderID = "PrimaryProducer";
@@ -55,9 +55,10 @@ namespace OpenRA.Mods.Common.Traits
public PrimaryBuilding(Actor self, PrimaryBuildingInfo info)
: base(info) { }
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
base.Created(self);
}
IEnumerable<IOrderTargeter> IIssueOrder.Orders

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
public enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
public class GrantConditionOnDeploy : PausableConditionalTrait<GrantConditionOnDeployInfo>, IResolveOrder, IIssueOrder, INotifyCreated,
public class GrantConditionOnDeploy : PausableConditionalTrait<GrantConditionOnDeployInfo>, IResolveOrder, IIssueOrder,
INotifyDeployComplete, IIssueDeployOrder, IOrderVoice, IWrapMove
{
readonly Actor self;
@@ -93,10 +93,11 @@ namespace OpenRA.Mods.Common.Traits
deployState = init.Get<DeployStateInit, DeployState>();
}
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
notify = self.TraitsImplementing<INotifyDeployTriggered>().ToArray();
base.Created(self);
switch (deployState)
{

View File

@@ -26,16 +26,17 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new DetectCloaked(this); }
}
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>, INotifyCreated
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>
{
IDetectCloakedModifier[] rangeModifiers;
public DetectCloaked(DetectCloakedInfo info)
: base(info) { }
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
rangeModifiers = self.TraitsImplementing<IDetectCloakedModifier>().ToArray();
base.Created(self);
}
public WDist Range

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public class Explodes : ConditionalTrait<ExplodesInfo>, INotifyKilled, INotifyDamage, INotifyCreated
public class Explodes : ConditionalTrait<ExplodesInfo>, INotifyKilled, INotifyDamage
{
readonly IHealth health;
BuildingInfo buildingInfo;
@@ -91,9 +91,10 @@ namespace OpenRA.Mods.Common.Traits
health = self.Trait<IHealth>();
}
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
base.Created(self);
}
void INotifyKilled.Killed(Actor self, AttackInfo e)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
}
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyCreated, INotifyAddedToWorld, ITick
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld, ITick
{
int lifetime;
ConditionManager conditionManager;
@@ -51,9 +51,10 @@ namespace OpenRA.Mods.Common.Traits
Kill(self);
}
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
base.Created(self);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public class ReloadAmmoPool : PausableConditionalTrait<ReloadAmmoPoolInfo>, ITick, INotifyCreated, INotifyAttack, ISync
public class ReloadAmmoPool : PausableConditionalTrait<ReloadAmmoPoolInfo>, ITick, INotifyAttack, ISync
{
AmmoPool ammoPool;
IReloadAmmoModifier[] modifiers;
@@ -54,11 +54,12 @@ namespace OpenRA.Mods.Common.Traits
public ReloadAmmoPool(ReloadAmmoPoolInfo info)
: base(info) { }
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
ammoPool = self.TraitsImplementing<AmmoPool>().Single(ap => ap.Info.Name == Info.AmmoPool);
modifiers = self.TraitsImplementing<IReloadAmmoModifier>().ToArray();
remainingTicks = Info.Delay;
base.Created(self);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new ActorSpawnManager(init.Self, this); }
}
public class ActorSpawnManager : ConditionalTrait<ActorSpawnManagerInfo>, ITick, INotifyCreated
public class ActorSpawnManager : ConditionalTrait<ActorSpawnManagerInfo>, ITick
{
readonly ActorSpawnManagerInfo info;
@@ -55,9 +55,10 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
}
void INotifyCreated.Created(Actor self)
protected override void Created(Actor self)
{
enabled = self.Trait<MapCreeps>().Enabled;
base.Created(self);
}
void ITick.Tick(Actor self)