add a "capturing" condition for ExternalCapture
This commit is contained in:
@@ -22,6 +22,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly ExternalCapturesInfo capturesInfo;
|
||||
readonly Mobile mobile;
|
||||
readonly Target target;
|
||||
readonly ConditionManager conditionManager;
|
||||
int capturingToken = ConditionManager.InvalidConditionToken;
|
||||
|
||||
public ExternalCaptureActor(Actor self, Target target)
|
||||
{
|
||||
@@ -29,18 +31,14 @@ namespace OpenRA.Mods.Common.Activities
|
||||
capturable = target.Actor.Trait<ExternalCapturable>();
|
||||
capturesInfo = self.Info.TraitInfo<ExternalCapturesInfo>();
|
||||
mobile = self.Trait<Mobile>();
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (target.Type != TargetType.Actor)
|
||||
return NextActivity;
|
||||
|
||||
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
|
||||
if (IsCanceled || !self.IsInWorld || self.IsDead || target.Type != TargetType.Actor || !target.IsValidFor(self))
|
||||
{
|
||||
if (capturable.CaptureInProgress)
|
||||
capturable.EndCapture();
|
||||
|
||||
EndCapture(self);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -50,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this);
|
||||
|
||||
if (!capturable.CaptureInProgress)
|
||||
capturable.BeginCapture(self);
|
||||
BeginCapture(self);
|
||||
else
|
||||
{
|
||||
if (capturable.Captor != self) return NextActivity;
|
||||
@@ -75,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
foreach (var t in target.Actor.TraitsImplementing<INotifyCapture>())
|
||||
t.OnCapture(target.Actor, self, oldOwner, self.Owner);
|
||||
|
||||
capturable.EndCapture();
|
||||
EndCapture(self);
|
||||
|
||||
if (self.Owner.Stances[oldOwner].HasStance(capturesInfo.PlayerExperienceStances))
|
||||
{
|
||||
@@ -92,5 +90,20 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void BeginCapture(Actor self)
|
||||
{
|
||||
capturable.BeginCapture(self);
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(capturesInfo.CapturingCondition) && capturingToken == ConditionManager.InvalidConditionToken)
|
||||
capturingToken = conditionManager.GrantCondition(self, capturesInfo.CapturingCondition);
|
||||
}
|
||||
|
||||
void EndCapture(Actor self)
|
||||
{
|
||||
if (capturable.CaptureInProgress)
|
||||
capturable.EndCapture();
|
||||
if (capturingToken != ConditionManager.InvalidConditionToken)
|
||||
capturingToken = conditionManager.RevokeCondition(self, capturingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user