Make PortableChrono PausableConditional.

This commit is contained in:
Mustafa Alperen Seki
2022-03-13 15:47:47 +03:00
committed by abcdefg30
parent 9de8d8854d
commit 62e7c7a318

View File

@@ -21,7 +21,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits namespace OpenRA.Mods.Cnc.Traits
{ {
class PortableChronoInfo : TraitInfo, Requires<IMoveInfo> class PortableChronoInfo : PausableConditionalTraitInfo, Requires<IMoveInfo>
{ {
[Desc("Cooldown in ticks until the unit can teleport.")] [Desc("Cooldown in ticks until the unit can teleport.")]
public readonly int ChargeDelay = 500; public readonly int ChargeDelay = 500;
@@ -78,21 +78,23 @@ namespace OpenRA.Mods.Cnc.Traits
public override object Create(ActorInitializer init) { return new PortableChrono(init.Self, this); } public override object Create(ActorInitializer init) { return new PortableChrono(init.Self, this); }
} }
class PortableChrono : IIssueOrder, IResolveOrder, ITick, ISelectionBar, IOrderVoice, ISync class PortableChrono : PausableConditionalTrait<PortableChronoInfo>, IIssueOrder, IResolveOrder, ITick, ISelectionBar, IOrderVoice, ISync
{ {
public readonly PortableChronoInfo Info;
readonly IMove move; readonly IMove move;
[Sync] [Sync]
int chargeTick = 0; int chargeTick = 0;
public PortableChrono(Actor self, PortableChronoInfo info) public PortableChrono(Actor self, PortableChronoInfo info)
: base(info)
{ {
Info = info;
move = self.Trait<IMove>(); move = self.Trait<IMove>();
} }
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled || IsTraitPaused)
return;
if (chargeTick > 0) if (chargeTick > 0)
chargeTick--; chargeTick--;
} }
@@ -101,6 +103,9 @@ namespace OpenRA.Mods.Cnc.Traits
{ {
get get
{ {
if (IsTraitDisabled)
yield break;
yield return new PortableChronoOrderTargeter(Info.TargetCursor); yield return new PortableChronoOrderTargeter(Info.TargetCursor);
yield return new DeployOrderTargeter("PortableChronoDeploy", 5, yield return new DeployOrderTargeter("PortableChronoDeploy", 5,
() => CanTeleport ? Info.DeployCursor : Info.DeployBlockedCursor); () => CanTeleport ? Info.DeployCursor : Info.DeployBlockedCursor);
@@ -153,15 +158,23 @@ namespace OpenRA.Mods.Cnc.Traits
chargeTick = Info.ChargeDelay; chargeTick = Info.ChargeDelay;
} }
public bool CanTeleport => chargeTick <= 0; public bool CanTeleport => !IsTraitDisabled && !IsTraitPaused && chargeTick <= 0;
float ISelectionBar.GetValue() float ISelectionBar.GetValue()
{ {
if (IsTraitDisabled)
return 0f;
return (float)(Info.ChargeDelay - chargeTick) / Info.ChargeDelay; return (float)(Info.ChargeDelay - chargeTick) / Info.ChargeDelay;
} }
Color ISelectionBar.GetColor() { return Color.Magenta; } Color ISelectionBar.GetColor() { return Color.Magenta; }
bool ISelectionBar.DisplayWhenEmpty => false; bool ISelectionBar.DisplayWhenEmpty => false;
protected override void TraitDisabled(Actor self)
{
chargeTick = 0;
}
} }
class PortableChronoOrderTargeter : IOrderTargeter class PortableChronoOrderTargeter : IOrderTargeter
@@ -234,6 +247,15 @@ namespace OpenRA.Mods.Cnc.Traits
world.CancelInputMode(); world.CancelInputMode();
} }
protected override void Tick(World world)
{
if (portableChrono.IsTraitDisabled || portableChrono.IsTraitPaused)
{
world.CancelInputMode();
return;
}
}
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; } protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; } protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }