Skip to content

Commit

Permalink
Make PortableChrono PausableConditional.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR authored and abcdefg30 committed Apr 17, 2022
1 parent 9de8d88 commit 62e7c7a
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions OpenRA.Mods.Cnc/Traits/PortableChrono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenRA.Mods.Cnc.Traits
{
class PortableChronoInfo : TraitInfo, Requires<IMoveInfo>
class PortableChronoInfo : PausableConditionalTraitInfo, Requires<IMoveInfo>
{
[Desc("Cooldown in ticks until the unit can teleport.")]
public readonly int ChargeDelay = 500;
Expand Down Expand Up @@ -78,21 +78,23 @@ class PortableChronoInfo : TraitInfo, Requires<IMoveInfo>
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;
[Sync]
int chargeTick = 0;

public PortableChrono(Actor self, PortableChronoInfo info)
: base(info)
{
Info = info;
move = self.Trait<IMove>();
}

void ITick.Tick(Actor self)
{
if (IsTraitDisabled || IsTraitPaused)
return;

if (chargeTick > 0)
chargeTick--;
}
Expand All @@ -101,6 +103,9 @@ public IEnumerable<IOrderTargeter> Orders
{
get
{
if (IsTraitDisabled)
yield break;

yield return new PortableChronoOrderTargeter(Info.TargetCursor);
yield return new DeployOrderTargeter("PortableChronoDeploy", 5,
() => CanTeleport ? Info.DeployCursor : Info.DeployBlockedCursor);
Expand Down Expand Up @@ -153,15 +158,23 @@ public void ResetChargeTime()
chargeTick = Info.ChargeDelay;
}

public bool CanTeleport => chargeTick <= 0;
public bool CanTeleport => !IsTraitDisabled && !IsTraitPaused && chargeTick <= 0;

float ISelectionBar.GetValue()
{
if (IsTraitDisabled)
return 0f;

return (float)(Info.ChargeDelay - chargeTick) / Info.ChargeDelay;
}

Color ISelectionBar.GetColor() { return Color.Magenta; }
bool ISelectionBar.DisplayWhenEmpty => false;

protected override void TraitDisabled(Actor self)
{
chargeTick = 0;
}
}

class PortableChronoOrderTargeter : IOrderTargeter
Expand Down Expand Up @@ -234,6 +247,15 @@ protected override void SelectionChanged(World world, IEnumerable<Actor> selecte
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> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
Expand Down

0 comments on commit 62e7c7a

Please sign in to comment.