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)