Fix conditional traits that incorrectly override INotifyCreated.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
}
|
||||
|
||||
public class Chronoshiftable : ConditionalTrait<ChronoshiftableInfo>, ITick, ISync, ISelectionBar,
|
||||
IDeathActorInitModifier, ITransformActorInitModifier, INotifyCreated
|
||||
IDeathActorInitModifier, ITransformActorInitModifier
|
||||
{
|
||||
readonly Actor self;
|
||||
Actor chronosphere;
|
||||
@@ -100,9 +100,10 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
iPositionable = self.TraitOrDefault<IPositionable>();
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
// Can't be used in synced code, except with ignoreVis.
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public override object Create(ActorInitializer init) { return new ResourcePurifier(init.Self, this); }
|
||||
}
|
||||
|
||||
public class ResourcePurifier : ConditionalTrait<ResourcePurifierInfo>, INotifyCreated, INotifyResourceAccepted, ITick, INotifyOwnerChanged
|
||||
public class ResourcePurifier : ConditionalTrait<ResourcePurifierInfo>, INotifyResourceAccepted, ITick, INotifyOwnerChanged
|
||||
{
|
||||
readonly int[] modifier;
|
||||
|
||||
@@ -50,15 +50,16 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
currentDisplayTick = Info.TickRate;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
// Special case handling is required for the Player actor.
|
||||
// Created is called before Player.PlayerActor is assigned,
|
||||
// so we must query other player traits from self, knowing that
|
||||
// it refers to the same actor as self.Owner.PlayerActor
|
||||
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
|
||||
|
||||
playerResources = playerActor.Trait<PlayerResources>();
|
||||
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
void INotifyResourceAccepted.OnResourceAccepted(Actor self, Actor refinery, int amount)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user