Convert Pluggable to conditions.
This commit is contained in:
@@ -14,13 +14,15 @@ using OpenRA.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.")]
|
||||
public readonly CVec Offset = CVec.Zero;
|
||||
|
||||
[FieldLoader.Require, Desc("Upgrades to grant for each accepted plug type.")]
|
||||
public readonly Dictionary<string, string[]> Upgrades = null;
|
||||
[FieldLoader.Require]
|
||||
[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); }
|
||||
}
|
||||
@@ -30,14 +32,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly PluggableInfo Info;
|
||||
|
||||
readonly string initialPlug;
|
||||
readonly UpgradeManager upgradeManager;
|
||||
UpgradeManager upgradeManager;
|
||||
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||
|
||||
string active;
|
||||
|
||||
public Pluggable(ActorInitializer init, PluggableInfo info)
|
||||
{
|
||||
Info = info;
|
||||
upgradeManager = init.Self.Trait<UpgradeManager>();
|
||||
|
||||
var plugInit = init.Contains<PlugsInit>() ? init.Get<PlugsInit, Dictionary<CVec, string>>() : new Dictionary<CVec, string>();
|
||||
if (plugInit.ContainsKey(Info.Offset))
|
||||
@@ -46,24 +48,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Created(Actor self)
|
||||
{
|
||||
upgradeManager = self.TraitOrDefault<UpgradeManager>();
|
||||
|
||||
if (!string.IsNullOrEmpty(initialPlug))
|
||||
EnablePlug(self, initialPlug);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
string[] upgrades;
|
||||
if (!Info.Upgrades.TryGetValue(type, out upgrades))
|
||||
string condition;
|
||||
if (!Info.Conditions.TryGetValue(type, out condition))
|
||||
return;
|
||||
|
||||
foreach (var u in upgrades)
|
||||
upgradeManager.GrantUpgrade(self, u, this);
|
||||
|
||||
conditionToken = upgradeManager.GrantCondition(self, condition);
|
||||
active = type;
|
||||
}
|
||||
|
||||
@@ -72,8 +74,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (type != active)
|
||||
return;
|
||||
|
||||
foreach (var u in Info.Upgrades[type])
|
||||
upgradeManager.RevokeUpgrade(self, u, this);
|
||||
if (conditionToken != UpgradeManager.InvalidConditionToken)
|
||||
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"))
|
||||
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);
|
||||
|
||||
@@ -38,7 +38,7 @@ GAPOWR:
|
||||
DisabledOverlay:
|
||||
Pluggable@pluga:
|
||||
Offset: 0,1
|
||||
Upgrades:
|
||||
Conditions:
|
||||
powrup: powrup.a
|
||||
Power@pluga:
|
||||
RequiresCondition: powrup.a
|
||||
@@ -48,7 +48,7 @@ GAPOWR:
|
||||
Sequence: idle-powrupa
|
||||
Pluggable@plugb:
|
||||
Offset: 1,1
|
||||
Upgrades:
|
||||
Conditions:
|
||||
powrup: powrup.b
|
||||
WithIdleOverlay@plugb:
|
||||
RequiresCondition: powrup.b
|
||||
@@ -438,7 +438,7 @@ GAPLUG:
|
||||
Amount: -50
|
||||
Pluggable@pluga:
|
||||
Offset: 0,2
|
||||
Upgrades:
|
||||
Conditions:
|
||||
plug.ioncannon: plug.ioncannona
|
||||
plug.hunterseeker: plug.hunterseekera
|
||||
WithIdleOverlay@ioncannona:
|
||||
@@ -449,7 +449,7 @@ GAPLUG:
|
||||
Sequence: idle-hunterseekera
|
||||
Pluggable@plugb:
|
||||
Offset: 1,2
|
||||
Upgrades:
|
||||
Conditions:
|
||||
plug.ioncannon: plug.ioncannonb
|
||||
plug.hunterseeker: plug.hunterseekerb
|
||||
WithIdleOverlay@ioncannonb:
|
||||
|
||||
@@ -126,7 +126,7 @@ GACTWR:
|
||||
RequiresCondition: tower.sam
|
||||
Amount: -10
|
||||
Pluggable:
|
||||
Upgrades:
|
||||
Conditions:
|
||||
tower.vulcan: tower.vulcan
|
||||
tower.rocket: tower.rocket
|
||||
tower.sam: tower.sam
|
||||
|
||||
Reference in New Issue
Block a user