93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenRa.Mods.Aftermath.Orders;
|
|
using OpenRa.Traits;
|
|
using OpenRa.Traits.Activities;
|
|
|
|
namespace OpenRa.Mods.Aftermath
|
|
{
|
|
class ChronoshiftDeployInfo : ITraitInfo
|
|
{
|
|
public readonly int ChargeTime = 120; // Seconds
|
|
public object Create(Actor self) { return new ChronoshiftDeploy(self); }
|
|
}
|
|
|
|
class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips
|
|
{
|
|
// Recharge logic
|
|
[Sync]
|
|
int chargeTick = 0; // How long until we can chronoshift again?
|
|
|
|
public ChronoshiftDeploy(Actor self) { }
|
|
|
|
public void Tick(Actor self)
|
|
{
|
|
if (chargeTick > 0)
|
|
chargeTick--;
|
|
}
|
|
|
|
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
|
{
|
|
if (mi.Button == MouseButton.Right && xy == self.Location && chargeTick <= 0)
|
|
return new Order("Deploy", self);
|
|
|
|
return null;
|
|
}
|
|
|
|
public void ResolveOrder(Actor self, Order order)
|
|
{
|
|
if (order.OrderString == "Deploy")
|
|
{
|
|
Game.controller.orderGenerator = new SetChronoTankDestination(self);
|
|
return;
|
|
}
|
|
|
|
var movement = self.traits.GetOrDefault<IMovement>();
|
|
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
|
|
{
|
|
// Cannot chronoshift into unexplored location
|
|
if (!self.Owner.Shroud.IsExplored(order.TargetLocation))
|
|
return;
|
|
|
|
Game.controller.CancelInputMode();
|
|
self.CancelActivity();
|
|
self.QueueActivity(new Teleport(order.TargetLocation));
|
|
Sound.Play("chrotnk1.aud");
|
|
chargeTick = 25 * self.Info.Traits.Get<ChronoshiftDeployInfo>().ChargeTime;
|
|
|
|
foreach (var a in self.World.Queries.WithTrait<ChronoshiftPaletteEffect>())
|
|
a.Trait.DoChronoshift();
|
|
}
|
|
}
|
|
|
|
// Display 5 pips indicating the current charge status
|
|
public IEnumerable<PipType> GetPips(Actor self)
|
|
{
|
|
const int numPips = 5;
|
|
for (int i = 0; i < numPips; i++)
|
|
{
|
|
if ((1 - chargeTick * 1.0f / (25 * self.Info.Traits.Get<ChronoshiftDeployInfo>().ChargeTime)) * numPips < i + 1)
|
|
{
|
|
yield return PipType.Transparent;
|
|
continue;
|
|
}
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
case 1:
|
|
yield return PipType.Red;
|
|
break;
|
|
case 2:
|
|
case 3:
|
|
yield return PipType.Yellow;
|
|
break;
|
|
case 4:
|
|
yield return PipType.Green;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|