Add PreventsAutoTarget.
This commit is contained in:
@@ -36,10 +36,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Condition granted when being captured by another actor.")]
|
[Desc("Condition granted when being captured by another actor.")]
|
||||||
public readonly string BeingCapturedCondition = null;
|
public readonly string BeingCapturedCondition = null;
|
||||||
|
|
||||||
|
[Desc("Should units friendly to the capturing actor auto-target this actor while it is being captured?")]
|
||||||
|
public readonly bool PreventsAutoTarget = true;
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new CaptureManager(this); }
|
public virtual object Create(ActorInitializer init) { return new CaptureManager(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CaptureManager : INotifyCreated, INotifyCapture, ITick
|
public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IPreventsAutoTarget
|
||||||
{
|
{
|
||||||
readonly CaptureManagerInfo info;
|
readonly CaptureManagerInfo info;
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
@@ -63,6 +66,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int beingCapturedToken = ConditionManager.InvalidConditionToken;
|
int beingCapturedToken = ConditionManager.InvalidConditionToken;
|
||||||
bool enteringCurrentTarget;
|
bool enteringCurrentTarget;
|
||||||
|
|
||||||
|
HashSet<Actor> currentCaptors = new HashSet<Actor>();
|
||||||
|
|
||||||
public bool BeingCaptured { get; private set; }
|
public bool BeingCaptured { get; private set; }
|
||||||
|
|
||||||
public CaptureManager(CaptureManagerInfo info)
|
public CaptureManager(CaptureManagerInfo info)
|
||||||
@@ -176,6 +181,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (currentTarget != null)
|
if (currentTarget != null)
|
||||||
CancelCapture(self, currentTarget, currentTargetManager);
|
CancelCapture(self, currentTarget, currentTargetManager);
|
||||||
|
|
||||||
|
targetManager.currentCaptors.Add(self);
|
||||||
currentTarget = target;
|
currentTarget = target;
|
||||||
currentTargetManager = targetManager;
|
currentTargetManager = targetManager;
|
||||||
currentTargetDelay = 0;
|
currentTargetDelay = 0;
|
||||||
@@ -244,6 +250,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
currentTargetManager = null;
|
currentTargetManager = null;
|
||||||
currentTargetDelay = 0;
|
currentTargetDelay = 0;
|
||||||
enteringCurrentTarget = false;
|
enteringCurrentTarget = false;
|
||||||
|
targetManager.currentCaptors.Remove(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
@@ -262,5 +269,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
foreach (var w in currentTargetManager.progressWatchers)
|
foreach (var w in currentTargetManager.progressWatchers)
|
||||||
w.Update(currentTarget, self, currentTarget, currentTargetDelay, currentTargetTotal);
|
w.Update(currentTarget, self, currentTarget, currentTargetDelay, currentTargetTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IPreventsAutoTarget.PreventsAutoTarget(Actor self, Actor attacker)
|
||||||
|
{
|
||||||
|
return info.PreventsAutoTarget && currentCaptors.Any(c => attacker.AppearsFriendlyTo(c));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user