Convert UpgradeOnDamageState to conditions.
This commit is contained in:
@@ -494,7 +494,7 @@
|
|||||||
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||||
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnDamageState.cs" />
|
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnMovement.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnMovement.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Applies an upgrade to the actor at specified damage states.")]
|
[Desc("Applies an upgrade to the actor at specified damage states.")]
|
||||||
public class UpgradeOnDamageStateInfo : ITraitInfo, Requires<UpgradeManagerInfo>, Requires<HealthInfo>
|
public class GrantConditionOnDamageStateInfo : ITraitInfo, Requires<HealthInfo>
|
||||||
{
|
{
|
||||||
[UpgradeGrantedReference, FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
[Desc("The upgrades to grant.")]
|
[UpgradeGrantedReference]
|
||||||
public readonly string[] Upgrades = { };
|
[Desc("Condition to grant.")]
|
||||||
|
public readonly string Condition = null;
|
||||||
|
|
||||||
[Desc("Play a random sound from this list when enabled.")]
|
[Desc("Play a random sound from this list when enabled.")]
|
||||||
public readonly string[] EnabledSounds = { };
|
public readonly string[] EnabledSounds = { };
|
||||||
@@ -29,59 +30,57 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Levels of damage at which to grant upgrades.")]
|
[Desc("Levels of damage at which to grant upgrades.")]
|
||||||
public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical;
|
public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical;
|
||||||
|
|
||||||
[Desc("Are upgrades irrevocable once the conditions have been met?")]
|
[Desc("Is the condition irrevocable once it has been activated?")]
|
||||||
public readonly bool GrantPermanently = false;
|
public readonly bool GrantPermanently = false;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new UpgradeOnDamageState(init.Self, this); }
|
public object Create(ActorInitializer init) { return new GrantConditionOnDamageState(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpgradeOnDamageState : INotifyDamageStateChanged, INotifyCreated
|
public class GrantConditionOnDamageState : INotifyDamageStateChanged, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly UpgradeOnDamageStateInfo info;
|
readonly GrantConditionOnDamageStateInfo info;
|
||||||
readonly UpgradeManager um;
|
|
||||||
readonly Health health;
|
readonly Health health;
|
||||||
bool granted;
|
|
||||||
|
|
||||||
public UpgradeOnDamageState(Actor self, UpgradeOnDamageStateInfo info)
|
UpgradeManager manager;
|
||||||
|
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
|
||||||
|
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
um = self.Trait<UpgradeManager>();
|
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<Health>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
|
manager = self.TraitOrDefault<UpgradeManager>();
|
||||||
GrantUpgradeOnValidDamageState(self, health.DamageState);
|
GrantUpgradeOnValidDamageState(self, health.DamageState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
|
void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
|
||||||
{
|
{
|
||||||
if (!info.ValidDamageStates.HasFlag(state))
|
if (!info.ValidDamageStates.HasFlag(state) || conditionToken != UpgradeManager.InvalidConditionToken)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
granted = true;
|
conditionToken = manager.GrantCondition(self, info.Condition);
|
||||||
var rand = Game.CosmeticRandom;
|
|
||||||
var sound = info.EnabledSounds.RandomOrDefault(rand);
|
var sound = info.EnabledSounds.RandomOrDefault(Game.CosmeticRandom);
|
||||||
Game.Sound.Play(sound, self.CenterPosition);
|
Game.Sound.Play(sound, self.CenterPosition);
|
||||||
foreach (var u in info.Upgrades)
|
|
||||||
um.GrantUpgrade(self, u, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (granted && info.GrantPermanently)
|
var granted = conditionToken != UpgradeManager.InvalidConditionToken;
|
||||||
|
if ((granted && info.GrantPermanently) || manager == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
||||||
GrantUpgradeOnValidDamageState(self, health.DamageState);
|
GrantUpgradeOnValidDamageState(self, health.DamageState);
|
||||||
else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
||||||
{
|
{
|
||||||
granted = false;
|
conditionToken = manager.RevokeCondition(self, conditionToken);
|
||||||
var rand = Game.CosmeticRandom;
|
|
||||||
var sound = info.DisabledSounds.RandomOrDefault(rand);
|
var sound = info.DisabledSounds.RandomOrDefault(Game.CosmeticRandom);
|
||||||
Game.Sound.Play(sound, self.CenterPosition);
|
Game.Sound.Play(sound, self.CenterPosition);
|
||||||
foreach (var u in info.Upgrades)
|
|
||||||
um.RevokeUpgrade(self, u, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,6 +617,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
if (!node.Value.Nodes.Any(n => n.Key == "PrimaryCondition"))
|
if (!node.Value.Nodes.Any(n => n.Key == "PrimaryCondition"))
|
||||||
node.Value.Nodes.Add(new MiniYamlNode("PrimaryCondition", "primary"));
|
node.Value.Nodes.Add(new MiniYamlNode("PrimaryCondition", "primary"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.Key.StartsWith("UpgradeOnDamageState", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
RenameNodeKey(node, "GrantConditionOnDamageState");
|
||||||
|
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -418,8 +418,8 @@
|
|||||||
WithInfantryBody:
|
WithInfantryBody:
|
||||||
DefaultAttackSequence: attack
|
DefaultAttackSequence: attack
|
||||||
IdleSequences: idle1,idle2
|
IdleSequences: idle1,idle2
|
||||||
UpgradeOnDamageState@CRITICAL:
|
GrantConditionOnDamageState@CRITICAL:
|
||||||
Upgrades: criticalspeed
|
Condition: criticalspeed
|
||||||
ValidDamageStates: Critical
|
ValidDamageStates: Critical
|
||||||
GrantPermanently: true
|
GrantPermanently: true
|
||||||
SpeedMultiplier@CRITICAL:
|
SpeedMultiplier@CRITICAL:
|
||||||
@@ -498,11 +498,11 @@
|
|||||||
Weapons: SmallDebris
|
Weapons: SmallDebris
|
||||||
Pieces: 3, 7
|
Pieces: 3, 7
|
||||||
Range: 2c0, 5c0
|
Range: 2c0, 5c0
|
||||||
UpgradeOnDamageState@DAMAGED:
|
GrantConditionOnDamageState@DAMAGED:
|
||||||
Upgrades: damagedspeed
|
Condition: damagedspeed
|
||||||
ValidDamageStates: Heavy
|
ValidDamageStates: Heavy
|
||||||
UpgradeOnDamageState@CRITICAL:
|
GrantConditionOnDamageState@CRITICAL:
|
||||||
Upgrades: criticalspeed
|
Condition: criticalspeed
|
||||||
ValidDamageStates: Critical
|
ValidDamageStates: Critical
|
||||||
SpeedMultiplier@DAMAGED:
|
SpeedMultiplier@DAMAGED:
|
||||||
RequiresCondition: damagedspeed
|
RequiresCondition: damagedspeed
|
||||||
|
|||||||
Reference in New Issue
Block a user