Convert Cloak to conditions.
This commit is contained in:
@@ -54,8 +54,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" };
|
public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" };
|
||||||
|
|
||||||
[UpgradeGrantedReference]
|
[UpgradeGrantedReference]
|
||||||
[Desc("The upgrades to grant to self while cloaked.")]
|
[Desc("The condition to grant to self while cloaked.")]
|
||||||
public readonly string[] WhileCloakedUpgrades = { };
|
public readonly string CloakedCondition = null;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new Cloak(this); }
|
public override object Create(ActorInitializer init) { return new Cloak(this); }
|
||||||
}
|
}
|
||||||
@@ -70,6 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
CPos? lastPos;
|
CPos? lastPos;
|
||||||
bool wasCloaked = false;
|
bool wasCloaked = false;
|
||||||
|
int cloakedToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
|
||||||
public Cloak(CloakInfo info)
|
public Cloak(CloakInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
@@ -81,12 +82,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
upgradeManager = self.TraitOrDefault<UpgradeManager>();
|
upgradeManager = self.TraitOrDefault<UpgradeManager>();
|
||||||
|
|
||||||
// The upgrade manager exists, but may not have finished being created yet.
|
|
||||||
// We'll defer the upgrades until the end of the tick, at which point it will be ready.
|
|
||||||
if (Cloaked)
|
if (Cloaked)
|
||||||
{
|
{
|
||||||
wasCloaked = true;
|
wasCloaked = true;
|
||||||
self.World.AddFrameEndTask(_ => GrantUpgrades(self));
|
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
|
||||||
|
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,13 +144,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var isCloaked = Cloaked;
|
var isCloaked = Cloaked;
|
||||||
if (isCloaked && !wasCloaked)
|
if (isCloaked && !wasCloaked)
|
||||||
{
|
{
|
||||||
GrantUpgrades(self);
|
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
|
||||||
|
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
|
||||||
|
|
||||||
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
|
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
|
||||||
Game.Sound.Play(Info.CloakSound, self.CenterPosition);
|
Game.Sound.Play(Info.CloakSound, self.CenterPosition);
|
||||||
}
|
}
|
||||||
else if (!isCloaked && wasCloaked)
|
else if (!isCloaked && wasCloaked)
|
||||||
{
|
{
|
||||||
RevokeUpgrades(self);
|
if (cloakedToken != UpgradeManager.InvalidConditionToken)
|
||||||
|
cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken);
|
||||||
|
|
||||||
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
|
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
|
||||||
Game.Sound.Play(Info.UncloakSound, self.CenterPosition);
|
Game.Sound.Play(Info.UncloakSound, self.CenterPosition);
|
||||||
}
|
}
|
||||||
@@ -176,20 +180,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrantUpgrades(Actor self)
|
|
||||||
{
|
|
||||||
if (upgradeManager != null)
|
|
||||||
foreach (var u in Info.WhileCloakedUpgrades)
|
|
||||||
upgradeManager.GrantUpgrade(self, u, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RevokeUpgrades(Actor self)
|
|
||||||
{
|
|
||||||
if (upgradeManager != null)
|
|
||||||
foreach (var u in Info.WhileCloakedUpgrades)
|
|
||||||
upgradeManager.RevokeUpgrade(self, u, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell, Activity next) { }
|
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell, Activity next) { }
|
||||||
|
|
||||||
void INotifyHarvesterAction.MovingToRefinery(Actor self, CPos targetCell, Activity next) { }
|
void INotifyHarvesterAction.MovingToRefinery(Actor self, CPos targetCell, Activity next) { }
|
||||||
|
|||||||
@@ -593,6 +593,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
ConvertUpgradesToCondition(parent, node, "AirborneUpgrades", "AirborneCondition");
|
ConvertUpgradesToCondition(parent, node, "AirborneUpgrades", "AirborneCondition");
|
||||||
ConvertUpgradesToCondition(parent, node, "CruisingUpgrades", "CruisingCondition");
|
ConvertUpgradesToCondition(parent, node, "CruisingUpgrades", "CruisingCondition");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.Key.StartsWith("Cloak", StringComparison.Ordinal))
|
||||||
|
ConvertUpgradesToCondition(parent, node, "WhileCloakedUpgrades", "CloakedCondition");
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ SS:
|
|||||||
CloakDelay: 50
|
CloakDelay: 50
|
||||||
CloakSound: subshow1.aud
|
CloakSound: subshow1.aud
|
||||||
UncloakSound: subshow1.aud
|
UncloakSound: subshow1.aud
|
||||||
WhileCloakedUpgrades: underwater
|
CloakedCondition: underwater
|
||||||
Palette: submerged
|
Palette: submerged
|
||||||
Armament:
|
Armament:
|
||||||
Weapon: TorpTube
|
Weapon: TorpTube
|
||||||
@@ -85,7 +85,7 @@ MSUB:
|
|||||||
CloakDelay: 100
|
CloakDelay: 100
|
||||||
CloakSound: subshow1.aud
|
CloakSound: subshow1.aud
|
||||||
UncloakSound: subshow1.aud
|
UncloakSound: subshow1.aud
|
||||||
WhileCloakedUpgrades: underwater
|
CloakedCondition: underwater
|
||||||
Palette: submerged
|
Palette: submerged
|
||||||
Armament@PRIMARY:
|
Armament@PRIMARY:
|
||||||
Weapon: SubMissile
|
Weapon: SubMissile
|
||||||
|
|||||||
Reference in New Issue
Block a user