Merge ConditionManager trait directly into Actor
This commit is contained in:
@@ -34,8 +34,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
readonly AttackLeapInfo info;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
int leapToken = ConditionManager.InvalidConditionToken;
|
||||
int leapToken = Actor.InvalidConditionToken;
|
||||
|
||||
public AttackLeap(Actor self, AttackLeapInfo info)
|
||||
: base(self, info)
|
||||
@@ -43,12 +42,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
protected override bool CanAttack(Actor self, Target target)
|
||||
{
|
||||
if (target.Type != TargetType.Actor)
|
||||
@@ -62,14 +55,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public void GrantLeapCondition(Actor self)
|
||||
{
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(info.LeapCondition))
|
||||
leapToken = conditionManager.GrantCondition(self, info.LeapCondition);
|
||||
if (!string.IsNullOrEmpty(info.LeapCondition))
|
||||
leapToken = self.GrantCondition(info.LeapCondition);
|
||||
}
|
||||
|
||||
public void RevokeLeapCondition(Actor self)
|
||||
{
|
||||
if (leapToken != ConditionManager.InvalidConditionToken)
|
||||
leapToken = conditionManager.RevokeCondition(self, leapToken);
|
||||
if (leapToken != Actor.InvalidConditionToken)
|
||||
leapToken = self.RevokeCondition(leapToken);
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public object Create(ActorInitializer init) { return new ConyardChronoReturn(init, this); }
|
||||
}
|
||||
|
||||
public class ConyardChronoReturn : INotifyCreated, ITick, ISync, IObservesVariables, ISelectionBar, INotifySold,
|
||||
public class ConyardChronoReturn : ITick, ISync, IObservesVariables, ISelectionBar, INotifySold,
|
||||
IDeathActorInitModifier, ITransformActorInitModifier
|
||||
{
|
||||
readonly ConyardChronoReturnInfo info;
|
||||
@@ -70,8 +70,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
readonly Actor self;
|
||||
readonly string faction;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||
int conditionToken = Actor.InvalidConditionToken;
|
||||
|
||||
Actor chronosphere;
|
||||
int duration;
|
||||
@@ -110,11 +109,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
chronosphere = init.Get<ChronoshiftChronosphereInit, Actor>();
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||
{
|
||||
if (info.ReturnOriginalActorOnCondition != null)
|
||||
@@ -128,8 +122,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
void TriggerVortex()
|
||||
{
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition) && conditionToken == ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.GrantCondition(self, info.Condition);
|
||||
if (!string.IsNullOrEmpty(info.Condition) && conditionToken == Actor.InvalidConditionToken)
|
||||
conditionToken = self.GrantCondition(info.Condition);
|
||||
|
||||
triggered = true;
|
||||
|
||||
@@ -140,8 +134,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
wsb.PlayCustomAnimation(self, info.Sequence, () =>
|
||||
{
|
||||
triggered = false;
|
||||
if (conditionToken != ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
conditionToken = self.RevokeCondition(conditionToken);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public object Create(ActorInitializer init) { return new Disguise(init.Self, this); }
|
||||
}
|
||||
|
||||
class Disguise : INotifyCreated, IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack,
|
||||
class Disguise : IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack,
|
||||
INotifyDamage, INotifyUnload, INotifyDemolition, INotifyInfiltration, ITick
|
||||
{
|
||||
public ActorInfo AsActor { get; private set; }
|
||||
@@ -112,9 +112,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
readonly Actor self;
|
||||
readonly DisguiseInfo info;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
int disguisedToken = ConditionManager.InvalidConditionToken;
|
||||
int disguisedAsToken = ConditionManager.InvalidConditionToken;
|
||||
int disguisedToken = Actor.InvalidConditionToken;
|
||||
int disguisedAsToken = Actor.InvalidConditionToken;
|
||||
CPos? lastPos;
|
||||
|
||||
public Disguise(Actor self, DisguiseInfo info)
|
||||
@@ -125,11 +124,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
AsActor = self.Info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
||||
{
|
||||
get
|
||||
@@ -225,25 +219,22 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
|
||||
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
|
||||
|
||||
if (conditionManager != null)
|
||||
if (Disguised != oldDisguiseSetting)
|
||||
{
|
||||
if (Disguised != oldDisguiseSetting)
|
||||
{
|
||||
if (Disguised && disguisedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
|
||||
disguisedToken = conditionManager.GrantCondition(self, info.DisguisedCondition);
|
||||
else if (!Disguised && disguisedToken != ConditionManager.InvalidConditionToken)
|
||||
disguisedToken = conditionManager.RevokeCondition(self, disguisedToken);
|
||||
}
|
||||
if (Disguised && disguisedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
|
||||
disguisedToken = self.GrantCondition(info.DisguisedCondition);
|
||||
else if (!Disguised && disguisedToken != Actor.InvalidConditionToken)
|
||||
disguisedToken = self.RevokeCondition(disguisedToken);
|
||||
}
|
||||
|
||||
if (AsActor != oldEffectiveActor)
|
||||
{
|
||||
if (disguisedAsToken != ConditionManager.InvalidConditionToken)
|
||||
disguisedAsToken = conditionManager.RevokeCondition(self, disguisedAsToken);
|
||||
if (AsActor != oldEffectiveActor)
|
||||
{
|
||||
if (disguisedAsToken != Actor.InvalidConditionToken)
|
||||
disguisedAsToken = self.RevokeCondition(disguisedAsToken);
|
||||
|
||||
string disguisedAsCondition;
|
||||
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
|
||||
disguisedAsToken = conditionManager.GrantCondition(self, disguisedAsCondition);
|
||||
}
|
||||
string disguisedAsCondition;
|
||||
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
|
||||
disguisedAsToken = self.GrantCondition(disguisedAsCondition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,22 +83,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
}
|
||||
}
|
||||
|
||||
class MadTank : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, IIssueDeployOrder
|
||||
class MadTank : IIssueOrder, IResolveOrder, IOrderVoice, IIssueDeployOrder
|
||||
{
|
||||
readonly MadTankInfo info;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
|
||||
public MadTank(Actor self, MadTankInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
@@ -195,8 +188,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (target.Type == TargetType.Invalid)
|
||||
return true;
|
||||
|
||||
if (mad.conditionManager != null && !string.IsNullOrEmpty(mad.info.DeployedCondition))
|
||||
mad.conditionManager.GrantCondition(self, mad.info.DeployedCondition);
|
||||
if (!string.IsNullOrEmpty(mad.info.DeployedCondition))
|
||||
self.GrantCondition(mad.info.DeployedCondition);
|
||||
|
||||
self.World.AddFrameEndTask(w => EjectDriver());
|
||||
if (mad.info.ThumpSequence != null)
|
||||
|
||||
Reference in New Issue
Block a user