Make Capture related traits conditional.
This commit is contained in:
committed by
reaperrr
parent
35ad33e8be
commit
556774804f
@@ -17,22 +17,19 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Visualize capture progress.")]
|
||||
class CapturableProgressBarInfo : ITraitInfo, Requires<CapturableInfo>
|
||||
class CapturableProgressBarInfo : ConditionalTraitInfo, Requires<CapturableInfo>
|
||||
{
|
||||
public readonly Color Color = Color.Orange;
|
||||
|
||||
public object Create(ActorInitializer init) { return new CapturableProgressBar(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new CapturableProgressBar(init.Self, this); }
|
||||
}
|
||||
|
||||
class CapturableProgressBar : ISelectionBar, ICaptureProgressWatcher
|
||||
class CapturableProgressBar : ConditionalTrait<CapturableProgressBarInfo>, ISelectionBar, ICaptureProgressWatcher
|
||||
{
|
||||
readonly CapturableProgressBarInfo info;
|
||||
Dictionary<Actor, Pair<int, int>> progress = new Dictionary<Actor, Pair<int, int>>();
|
||||
|
||||
public CapturableProgressBar(Actor self, CapturableProgressBarInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
: base(info) { }
|
||||
|
||||
void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total)
|
||||
{
|
||||
@@ -47,13 +44,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
float ISelectionBar.GetValue()
|
||||
{
|
||||
if (!progress.Any())
|
||||
if (IsTraitDisabled || !progress.Any())
|
||||
return 0f;
|
||||
|
||||
return progress.Values.Max(p => (float)p.First / p.Second);
|
||||
}
|
||||
|
||||
Color ISelectionBar.GetColor() { return info.Color; }
|
||||
Color ISelectionBar.GetColor() { return Info.Color; }
|
||||
bool ISelectionBar.DisplayWhenEmpty { get { return false; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,22 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Blinks the actor and captor when it is being captured.")]
|
||||
class CapturableProgressBlinkInfo : ITraitInfo, Requires<CapturableInfo>
|
||||
class CapturableProgressBlinkInfo : ConditionalTraitInfo, Requires<CapturableInfo>
|
||||
{
|
||||
[Desc("Number of ticks to wait between repeating blinks.")]
|
||||
public readonly int Interval = 50;
|
||||
|
||||
public object Create(ActorInitializer init) { return new CapturableProgressBlink(this); }
|
||||
public override object Create(ActorInitializer init) { return new CapturableProgressBlink(this); }
|
||||
}
|
||||
|
||||
class CapturableProgressBlink : ITick, ICaptureProgressWatcher
|
||||
class CapturableProgressBlink : ConditionalTrait<CapturableProgressBlinkInfo>, ITick, ICaptureProgressWatcher
|
||||
{
|
||||
readonly CapturableProgressBlinkInfo info;
|
||||
List<Player> captorOwners = new List<Player>();
|
||||
HashSet<Actor> captors = new HashSet<Actor>();
|
||||
int tick = 0;
|
||||
|
||||
public CapturableProgressBlink(CapturableProgressBlinkInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
: base(info) { }
|
||||
|
||||
void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total)
|
||||
{
|
||||
@@ -54,6 +51,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (!captorOwners.Any())
|
||||
{
|
||||
tick = 0;
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.Add(new FlashTarget(captor, captorOwner));
|
||||
}
|
||||
|
||||
if (++tick >= info.Interval)
|
||||
if (++tick >= Info.Interval)
|
||||
tick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,23 +15,20 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Visualize the progress of this actor being captured.")]
|
||||
class CaptureProgressBarInfo : ITraitInfo, Requires<CapturesInfo>
|
||||
class CaptureProgressBarInfo : ConditionalTraitInfo, Requires<CapturesInfo>
|
||||
{
|
||||
public readonly Color Color = Color.Orange;
|
||||
|
||||
public object Create(ActorInitializer init) { return new CaptureProgressBar(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new CaptureProgressBar(init.Self, this); }
|
||||
}
|
||||
|
||||
class CaptureProgressBar : ISelectionBar, ICaptureProgressWatcher
|
||||
class CaptureProgressBar : ConditionalTrait<CaptureProgressBarInfo>, ISelectionBar, ICaptureProgressWatcher
|
||||
{
|
||||
readonly CaptureProgressBarInfo info;
|
||||
int current;
|
||||
int total;
|
||||
|
||||
public CaptureProgressBar(Actor self, CaptureProgressBarInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
: base(info) { }
|
||||
|
||||
void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total)
|
||||
{
|
||||
@@ -44,13 +41,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
float ISelectionBar.GetValue()
|
||||
{
|
||||
if (total == 0)
|
||||
if (IsTraitDisabled || total == 0)
|
||||
return 0f;
|
||||
|
||||
return (float)current / total;
|
||||
}
|
||||
|
||||
Color ISelectionBar.GetColor() { return info.Color; }
|
||||
Color ISelectionBar.GetColor() { return Info.Color; }
|
||||
bool ISelectionBar.DisplayWhenEmpty { get { return false; } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user