add a "capturing" condition for ExternalCapture

This commit is contained in:
gwenzek
2017-09-05 21:52:37 +02:00
committed by abcdefg30
parent 8027bed6b2
commit 7721d0b328
3 changed files with 28 additions and 9 deletions

View File

@@ -22,6 +22,8 @@ namespace OpenRA.Mods.Common.Activities
readonly ExternalCapturesInfo capturesInfo; readonly ExternalCapturesInfo capturesInfo;
readonly Mobile mobile; readonly Mobile mobile;
readonly Target target; readonly Target target;
readonly ConditionManager conditionManager;
int capturingToken = ConditionManager.InvalidConditionToken;
public ExternalCaptureActor(Actor self, Target target) public ExternalCaptureActor(Actor self, Target target)
{ {
@@ -29,18 +31,14 @@ namespace OpenRA.Mods.Common.Activities
capturable = target.Actor.Trait<ExternalCapturable>(); capturable = target.Actor.Trait<ExternalCapturable>();
capturesInfo = self.Info.TraitInfo<ExternalCapturesInfo>(); capturesInfo = self.Info.TraitInfo<ExternalCapturesInfo>();
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
conditionManager = self.TraitOrDefault<ConditionManager>();
} }
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (target.Type != TargetType.Actor) if (IsCanceled || !self.IsInWorld || self.IsDead || target.Type != TargetType.Actor || !target.IsValidFor(self))
return NextActivity;
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
{ {
if (capturable.CaptureInProgress) EndCapture(self);
capturable.EndCapture();
return NextActivity; return NextActivity;
} }
@@ -50,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
return ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this); return ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this);
if (!capturable.CaptureInProgress) if (!capturable.CaptureInProgress)
capturable.BeginCapture(self); BeginCapture(self);
else else
{ {
if (capturable.Captor != self) return NextActivity; if (capturable.Captor != self) return NextActivity;
@@ -75,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in target.Actor.TraitsImplementing<INotifyCapture>()) foreach (var t in target.Actor.TraitsImplementing<INotifyCapture>())
t.OnCapture(target.Actor, self, oldOwner, self.Owner); t.OnCapture(target.Actor, self, oldOwner, self.Owner);
capturable.EndCapture(); EndCapture(self);
if (self.Owner.Stances[oldOwner].HasStance(capturesInfo.PlayerExperienceStances)) if (self.Owner.Stances[oldOwner].HasStance(capturesInfo.PlayerExperienceStances))
{ {
@@ -92,5 +90,20 @@ namespace OpenRA.Mods.Common.Activities
return this; 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);
}
} }
} }

View File

@@ -173,6 +173,8 @@ namespace OpenRA.Mods.Common.Traits
firstTick = false; firstTick = false;
} }
protected override void TraitDisabled(Actor self) { Uncloak(); }
public bool IsVisible(Actor self, Player viewer) public bool IsVisible(Actor self, Player viewer)
{ {
if (!Cloaked || self.Owner.IsAlliedWith(viewer)) if (!Cloaked || self.Owner.IsAlliedWith(viewer))

View File

@@ -34,6 +34,10 @@ namespace OpenRA.Mods.Common.Traits
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
[GrantedConditionReference]
[Desc("Condition granted when capturing.")]
public readonly string CapturingCondition = null;
public readonly string CaptureCursor = "ability"; public readonly string CaptureCursor = "ability";
public readonly string CaptureBlockedCursor = "move-blocked"; public readonly string CaptureBlockedCursor = "move-blocked";