Convert Pluggable to conditions.
This commit is contained in:
@@ -14,13 +14,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public class PluggableInfo : ITraitInfo, Requires<UpgradeManagerInfo>, UsesInit<PlugsInit>
|
public class PluggableInfo : ITraitInfo, UsesInit<PlugsInit>
|
||||||
{
|
{
|
||||||
[Desc("Footprint cell offset where a plug can be placed.")]
|
[Desc("Footprint cell offset where a plug can be placed.")]
|
||||||
public readonly CVec Offset = CVec.Zero;
|
public readonly CVec Offset = CVec.Zero;
|
||||||
|
|
||||||
[FieldLoader.Require, Desc("Upgrades to grant for each accepted plug type.")]
|
[FieldLoader.Require]
|
||||||
public readonly Dictionary<string, string[]> Upgrades = null;
|
[UpgradeGrantedReference]
|
||||||
|
[Desc("Conditions to grant for each accepted plug type.")]
|
||||||
|
public readonly Dictionary<string, string> Conditions = null;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Pluggable(init, this); }
|
public object Create(ActorInitializer init) { return new Pluggable(init, this); }
|
||||||
}
|
}
|
||||||
@@ -30,14 +32,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly PluggableInfo Info;
|
public readonly PluggableInfo Info;
|
||||||
|
|
||||||
readonly string initialPlug;
|
readonly string initialPlug;
|
||||||
readonly UpgradeManager upgradeManager;
|
UpgradeManager upgradeManager;
|
||||||
|
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
|
||||||
string active;
|
string active;
|
||||||
|
|
||||||
public Pluggable(ActorInitializer init, PluggableInfo info)
|
public Pluggable(ActorInitializer init, PluggableInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
upgradeManager = init.Self.Trait<UpgradeManager>();
|
|
||||||
|
|
||||||
var plugInit = init.Contains<PlugsInit>() ? init.Get<PlugsInit, Dictionary<CVec, string>>() : new Dictionary<CVec, string>();
|
var plugInit = init.Contains<PlugsInit>() ? init.Get<PlugsInit, Dictionary<CVec, string>>() : new Dictionary<CVec, string>();
|
||||||
if (plugInit.ContainsKey(Info.Offset))
|
if (plugInit.ContainsKey(Info.Offset))
|
||||||
@@ -46,24 +48,24 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void Created(Actor self)
|
public void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
upgradeManager = self.TraitOrDefault<UpgradeManager>();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(initialPlug))
|
if (!string.IsNullOrEmpty(initialPlug))
|
||||||
EnablePlug(self, initialPlug);
|
EnablePlug(self, initialPlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AcceptsPlug(Actor self, string type)
|
public bool AcceptsPlug(Actor self, string type)
|
||||||
{
|
{
|
||||||
return active == null && Info.Upgrades.ContainsKey(type);
|
return active == null && Info.Conditions.ContainsKey(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnablePlug(Actor self, string type)
|
public void EnablePlug(Actor self, string type)
|
||||||
{
|
{
|
||||||
string[] upgrades;
|
string condition;
|
||||||
if (!Info.Upgrades.TryGetValue(type, out upgrades))
|
if (!Info.Conditions.TryGetValue(type, out condition))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var u in upgrades)
|
conditionToken = upgradeManager.GrantCondition(self, condition);
|
||||||
upgradeManager.GrantUpgrade(self, u, this);
|
|
||||||
|
|
||||||
active = type;
|
active = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +74,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (type != active)
|
if (type != active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var u in Info.Upgrades[type])
|
if (conditionToken != UpgradeManager.InvalidConditionToken)
|
||||||
upgradeManager.RevokeUpgrade(self, u, this);
|
conditionToken = upgradeManager.RevokeCondition(self, conditionToken);
|
||||||
|
|
||||||
|
active = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -644,6 +644,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
if (!node.Value.Nodes.Any(n => n.Key == "AttackingCondition"))
|
if (!node.Value.Nodes.Any(n => n.Key == "AttackingCondition"))
|
||||||
node.Value.Nodes.Add(new MiniYamlNode("AttackingCondition", "attacking"));
|
node.Value.Nodes.Add(new MiniYamlNode("AttackingCondition", "attacking"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.Key.StartsWith("Pluggable", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
var upgrades = node.Value.Nodes.FirstOrDefault(n => n.Key == "Upgrades");
|
||||||
|
if (upgrades != null)
|
||||||
|
{
|
||||||
|
upgrades.Key = "Conditions";
|
||||||
|
foreach (var n in upgrades.Value.Nodes)
|
||||||
|
{
|
||||||
|
var conditions = FieldLoader.GetValue<string[]>("", n.Value.Value);
|
||||||
|
if (conditions.Length > 1)
|
||||||
|
Console.WriteLine("Unable to automatically migrate multiple Pluggable upgrades to a condition. This must be corrected manually");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ GAPOWR:
|
|||||||
DisabledOverlay:
|
DisabledOverlay:
|
||||||
Pluggable@pluga:
|
Pluggable@pluga:
|
||||||
Offset: 0,1
|
Offset: 0,1
|
||||||
Upgrades:
|
Conditions:
|
||||||
powrup: powrup.a
|
powrup: powrup.a
|
||||||
Power@pluga:
|
Power@pluga:
|
||||||
RequiresCondition: powrup.a
|
RequiresCondition: powrup.a
|
||||||
@@ -48,7 +48,7 @@ GAPOWR:
|
|||||||
Sequence: idle-powrupa
|
Sequence: idle-powrupa
|
||||||
Pluggable@plugb:
|
Pluggable@plugb:
|
||||||
Offset: 1,1
|
Offset: 1,1
|
||||||
Upgrades:
|
Conditions:
|
||||||
powrup: powrup.b
|
powrup: powrup.b
|
||||||
WithIdleOverlay@plugb:
|
WithIdleOverlay@plugb:
|
||||||
RequiresCondition: powrup.b
|
RequiresCondition: powrup.b
|
||||||
@@ -438,7 +438,7 @@ GAPLUG:
|
|||||||
Amount: -50
|
Amount: -50
|
||||||
Pluggable@pluga:
|
Pluggable@pluga:
|
||||||
Offset: 0,2
|
Offset: 0,2
|
||||||
Upgrades:
|
Conditions:
|
||||||
plug.ioncannon: plug.ioncannona
|
plug.ioncannon: plug.ioncannona
|
||||||
plug.hunterseeker: plug.hunterseekera
|
plug.hunterseeker: plug.hunterseekera
|
||||||
WithIdleOverlay@ioncannona:
|
WithIdleOverlay@ioncannona:
|
||||||
@@ -449,7 +449,7 @@ GAPLUG:
|
|||||||
Sequence: idle-hunterseekera
|
Sequence: idle-hunterseekera
|
||||||
Pluggable@plugb:
|
Pluggable@plugb:
|
||||||
Offset: 1,2
|
Offset: 1,2
|
||||||
Upgrades:
|
Conditions:
|
||||||
plug.ioncannon: plug.ioncannonb
|
plug.ioncannon: plug.ioncannonb
|
||||||
plug.hunterseeker: plug.hunterseekerb
|
plug.hunterseeker: plug.hunterseekerb
|
||||||
WithIdleOverlay@ioncannonb:
|
WithIdleOverlay@ioncannonb:
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ GACTWR:
|
|||||||
RequiresCondition: tower.sam
|
RequiresCondition: tower.sam
|
||||||
Amount: -10
|
Amount: -10
|
||||||
Pluggable:
|
Pluggable:
|
||||||
Upgrades:
|
Conditions:
|
||||||
tower.vulcan: tower.vulcan
|
tower.vulcan: tower.vulcan
|
||||||
tower.rocket: tower.rocket
|
tower.rocket: tower.rocket
|
||||||
tower.sam: tower.sam
|
tower.sam: tower.sam
|
||||||
|
|||||||
Reference in New Issue
Block a user