Merge pull request #8563 from matija-hustic/tesla_boost
Tesla boost for RA2 mod
This commit is contained in:
@@ -13,23 +13,24 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Needs power to operate.")]
|
||||
class RequiresPowerInfo : ITraitInfo
|
||||
class RequiresPowerInfo : UpgradableTraitInfo, ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new RequiresPower(init.Self); }
|
||||
public override object Create(ActorInitializer init) { return new RequiresPower(init.Self, this); }
|
||||
}
|
||||
|
||||
class RequiresPower : IDisable, INotifyOwnerChanged
|
||||
class RequiresPower : UpgradableTrait<RequiresPowerInfo>, IDisable, INotifyOwnerChanged
|
||||
{
|
||||
PowerManager playerPower;
|
||||
|
||||
public RequiresPower(Actor self)
|
||||
public RequiresPower(Actor self, RequiresPowerInfo info)
|
||||
: base(info)
|
||||
{
|
||||
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get { return playerPower.PowerProvided < playerPower.PowerDrained; }
|
||||
get { return playerPower.PowerProvided < playerPower.PowerDrained && !IsTraitDisabled; }
|
||||
}
|
||||
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
|
||||
@@ -85,13 +85,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Upgrade level increments are limited to one per source, i.e., if a single source
|
||||
/// attempts granting multiple upgrades, they will not accumulate. They will replace each other
|
||||
/// instead, leaving only the last granted upgrade active. An upgrade from each new distinct
|
||||
/// source will increment the upgrade's level until AcceptsUpgrade starts returning false. Then,
|
||||
/// when no new levels are accepted, the upgrade source with the shortest remaining upgrade
|
||||
/// duration will be replaced by the new source.</summary>
|
||||
public void GrantTimedUpgrade(Actor self, string upgrade, int duration, object source = null)
|
||||
/// <summary>Upgrade level increments are limited to dupesAllowed per source, i.e., if a single
|
||||
/// source attempts granting more upgrades than dupesAllowed, they will not accumulate. They will
|
||||
/// replace each other instead, leaving only the most recently granted upgrade active. Each new
|
||||
/// upgrade granting request will increment the upgrade's level until AcceptsUpgrade starts
|
||||
/// returning false. Then, when no new levels are accepted, the upgrade source with the shortest
|
||||
/// remaining upgrade duration will be replaced by the new source.</summary>
|
||||
public void GrantTimedUpgrade(Actor self, string upgrade, int duration, object source = null, int dupesAllowed = 1)
|
||||
{
|
||||
var timed = timedUpgrades.FirstOrDefault(u => u.Upgrade == upgrade);
|
||||
if (timed == null)
|
||||
@@ -102,17 +102,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
}
|
||||
|
||||
var src = timed.Sources.FirstOrDefault(s => s.Source == source);
|
||||
if (src == null)
|
||||
var srcs = timed.Sources.Where(s => s.Source == source);
|
||||
if (srcs.Count() < dupesAllowed)
|
||||
{
|
||||
timed.Sources.Add(new TimedUpgrade.UpgradeSource(duration, source));
|
||||
if (AcceptsUpgrade(self, upgrade))
|
||||
GrantUpgrade(self, upgrade, timed);
|
||||
else
|
||||
timed.Sources.Remove(timed.Sources.OrderByDescending(s => s.Remaining).Last());
|
||||
timed.Sources.Remove(timed.Sources.MinBy(s => s.Remaining));
|
||||
}
|
||||
else
|
||||
src.Remaining = duration;
|
||||
srcs.MinBy(s => s.Remaining).Remaining = duration;
|
||||
|
||||
timed.Remaining = Math.Max(duration, timed.Remaining);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
if (Duration > 0)
|
||||
{
|
||||
if (um.AcknowledgesUpgrade(a, u))
|
||||
um.GrantTimedUpgrade(a, u, Duration, firedBy);
|
||||
um.GrantTimedUpgrade(a, u, Duration, firedBy, Upgrades.Count(upg => upg == u));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user