Add support for custom SupportPowerInstances.

This commit is contained in:
Paul Chote
2018-10-07 15:02:04 +00:00
committed by reaperrr
parent 61c56dcb00
commit e03abdc0da
2 changed files with 35 additions and 30 deletions

View File

@@ -125,6 +125,11 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
} }
public virtual SupportPowerInstance CreateInstance(string key, SupportPowerManager manager)
{
return new SupportPowerInstance(key, info, manager);
}
public virtual void Charging(Actor self, string key) public virtual void Charging(Actor self, string key)
{ {
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.BeginChargeSound); Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.BeginChargeSound);

View File

@@ -60,12 +60,7 @@ namespace OpenRA.Mods.Common.Traits
if (!Powers.ContainsKey(key)) if (!Powers.ContainsKey(key))
{ {
Powers.Add(key, new SupportPowerInstance(key, this) Powers.Add(key, t.CreateInstance(key, this));
{
Instances = new List<SupportPower>(),
RemainingTime = t.Info.StartFullyCharged ? 0 : t.Info.ChargeInterval,
TotalTime = t.Info.ChargeInterval,
});
if (t.Info.Prerequisites.Any()) if (t.Info.Prerequisites.Any())
{ {
@@ -145,7 +140,6 @@ namespace OpenRA.Mods.Common.Traits
return; return;
sp.PrerequisitesAvailable(false); sp.PrerequisitesAvailable(false);
sp.RemainingTime = sp.TotalTime;
} }
public void PrerequisitesItemHidden(string key) { } public void PrerequisitesItemHidden(string key) { }
@@ -154,15 +148,15 @@ namespace OpenRA.Mods.Common.Traits
public class SupportPowerInstance public class SupportPowerInstance
{ {
readonly SupportPowerManager manager; protected readonly SupportPowerManager Manager;
public readonly string Key; public readonly string Key;
public List<SupportPower> Instances; public readonly List<SupportPower> Instances = new List<SupportPower>();
public int RemainingTime; public readonly int TotalTime;
public int TotalTime; public int RemainingTime { get; private set; }
public bool Active { get; private set; } public bool Active { get; private set; }
public bool Disabled { get { return (!prereqsAvailable && !manager.DevMode.AllTech) || !instancesEnabled || oneShotFired; } } public bool Disabled { get { return (!prereqsAvailable && !Manager.DevMode.AllTech) || !instancesEnabled || oneShotFired; } }
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
public bool Ready { get { return Active && RemainingTime == 0; } } public bool Ready { get { return Active && RemainingTime == 0; } }
@@ -170,21 +164,27 @@ namespace OpenRA.Mods.Common.Traits
bool instancesEnabled; bool instancesEnabled;
bool prereqsAvailable = true; bool prereqsAvailable = true;
bool oneShotFired; bool oneShotFired;
public SupportPowerInstance(string key, SupportPowerManager manager)
{
this.manager = manager;
Key = key;
}
public void PrerequisitesAvailable(bool available)
{
prereqsAvailable = available;
}
bool notifiedCharging; bool notifiedCharging;
bool notifiedReady; bool notifiedReady;
public void Tick()
public SupportPowerInstance(string key, SupportPowerInfo info, SupportPowerManager manager)
{
Key = key;
TotalTime = info.ChargeInterval;
RemainingTime = info.StartFullyCharged ? 0 : info.ChargeInterval;
Manager = manager;
}
public virtual void PrerequisitesAvailable(bool available)
{
prereqsAvailable = available;
if (!available)
RemainingTime = TotalTime;
}
public virtual void Tick()
{ {
instancesEnabled = Instances.Any(i => !i.IsTraitDisabled); instancesEnabled = Instances.Any(i => !i.IsTraitDisabled);
if (!instancesEnabled) if (!instancesEnabled)
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Traits
if (Active) if (Active)
{ {
var power = Instances.First(); var power = Instances.First();
if (manager.DevMode.FastCharge && RemainingTime > 25) if (Manager.DevMode.FastCharge && RemainingTime > 25)
RemainingTime = 25; RemainingTime = 25;
if (RemainingTime > 0) if (RemainingTime > 0)
@@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void Target() public virtual void Target()
{ {
if (!Ready) if (!Ready)
return; return;
@@ -226,10 +226,10 @@ namespace OpenRA.Mods.Common.Traits
if (power == null) if (power == null)
return; return;
power.SelectTarget(power.Self, Key, manager); power.SelectTarget(power.Self, Key, Manager);
} }
public void Activate(Order order) public virtual void Activate(Order order)
{ {
if (!Ready) if (!Ready)
return; return;
@@ -247,7 +247,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
// Note: order.Subject is the *player* actor // Note: order.Subject is the *player* actor
power.Activate(power.Self, order, manager); power.Activate(power.Self, order, Manager);
RemainingTime = TotalTime; RemainingTime = TotalTime;
notifiedCharging = notifiedReady = false; notifiedCharging = notifiedReady = false;