Merge pull request #11816 from reaperrr/fix-UpgradeOnDamage
Fix UpgradeOnDamage to apply if initial DamageState is valid
This commit is contained in:
@@ -507,7 +507,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\UpgradeActorsNear.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeActorsNear.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnDamage.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnDamageState.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||||
<Compile Include="Traits\Valued.cs" />
|
<Compile Include="Traits\Valued.cs" />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ 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 UpgradeOnDamageInfo : ITraitInfo, Requires<UpgradeManagerInfo>
|
public class UpgradeOnDamageStateInfo : ITraitInfo, Requires<UpgradeManagerInfo>, Requires<HealthInfo>
|
||||||
{
|
{
|
||||||
[UpgradeGrantedReference, FieldLoader.Require]
|
[UpgradeGrantedReference, FieldLoader.Require]
|
||||||
[Desc("The upgrades to grant.")]
|
[Desc("The upgrades to grant.")]
|
||||||
@@ -32,41 +32,52 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Are upgrades irrevocable once the conditions have been met?")]
|
[Desc("Are upgrades irrevocable once the conditions have been met?")]
|
||||||
public readonly bool GrantPermanently = false;
|
public readonly bool GrantPermanently = false;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new UpgradeOnDamage(init.Self, this); }
|
public object Create(ActorInitializer init) { return new UpgradeOnDamageState(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpgradeOnDamage : INotifyDamageStateChanged
|
public class UpgradeOnDamageState : INotifyDamageStateChanged, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly UpgradeOnDamageInfo info;
|
readonly UpgradeOnDamageStateInfo info;
|
||||||
readonly UpgradeManager um;
|
readonly UpgradeManager um;
|
||||||
|
readonly Health health;
|
||||||
bool granted;
|
bool granted;
|
||||||
|
|
||||||
public UpgradeOnDamage(Actor self, UpgradeOnDamageInfo info)
|
public UpgradeOnDamageState(Actor self, UpgradeOnDamageStateInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
um = self.TraitOrDefault<UpgradeManager>();
|
um = self.Trait<UpgradeManager>();
|
||||||
|
health = self.Trait<Health>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
if (um == null)
|
GrantUpgradeOnValidDamageState(self, health.DamageState);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
|
||||||
|
{
|
||||||
|
if (!info.ValidDamageStates.HasFlag(state))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (granted && info.GrantPermanently)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var rand = Game.CosmeticRandom;
|
|
||||||
if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
|
||||||
{
|
|
||||||
granted = true;
|
granted = true;
|
||||||
|
var rand = Game.CosmeticRandom;
|
||||||
var sound = info.EnabledSounds.RandomOrDefault(rand);
|
var sound = info.EnabledSounds.RandomOrDefault(rand);
|
||||||
Game.Sound.Play(sound, self.CenterPosition);
|
Game.Sound.Play(sound, self.CenterPosition);
|
||||||
foreach (var u in info.Upgrades)
|
foreach (var u in info.Upgrades)
|
||||||
um.GrantUpgrade(self, u, this);
|
um.GrantUpgrade(self, u, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
||||||
|
{
|
||||||
|
if (granted && info.GrantPermanently)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
||||||
|
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;
|
granted = false;
|
||||||
|
var rand = Game.CosmeticRandom;
|
||||||
var sound = info.DisabledSounds.RandomOrDefault(rand);
|
var sound = info.DisabledSounds.RandomOrDefault(rand);
|
||||||
Game.Sound.Play(sound, self.CenterPosition);
|
Game.Sound.Play(sound, self.CenterPosition);
|
||||||
foreach (var u in info.Upgrades)
|
foreach (var u in info.Upgrades)
|
||||||
@@ -280,6 +280,17 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (engineVersion < 20160818)
|
||||||
|
{
|
||||||
|
if (depth == 1 && node.Key.StartsWith("UpgradeOnDamage"))
|
||||||
|
{
|
||||||
|
var parts = node.Key.Split('@');
|
||||||
|
node.Key = "UpgradeOnDamageState";
|
||||||
|
if (parts.Length > 1)
|
||||||
|
node.Key += "@" + parts[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -397,7 +397,7 @@
|
|||||||
WithInfantryBody:
|
WithInfantryBody:
|
||||||
AttackSequence: attack
|
AttackSequence: attack
|
||||||
IdleSequences: idle1,idle2
|
IdleSequences: idle1,idle2
|
||||||
UpgradeOnDamage@CRITICAL:
|
UpgradeOnDamageState@CRITICAL:
|
||||||
Upgrades: criticalspeed
|
Upgrades: criticalspeed
|
||||||
ValidDamageStates: Critical
|
ValidDamageStates: Critical
|
||||||
GrantPermanently: true
|
GrantPermanently: true
|
||||||
@@ -476,10 +476,10 @@
|
|||||||
Weapons: SmallDebris
|
Weapons: SmallDebris
|
||||||
Pieces: 3, 7
|
Pieces: 3, 7
|
||||||
Range: 2c0, 5c0
|
Range: 2c0, 5c0
|
||||||
UpgradeOnDamage@DAMAGED:
|
UpgradeOnDamageState@DAMAGED:
|
||||||
Upgrades: damagedspeed
|
Upgrades: damagedspeed
|
||||||
ValidDamageStates: Heavy
|
ValidDamageStates: Heavy
|
||||||
UpgradeOnDamage@CRITICAL:
|
UpgradeOnDamageState@CRITICAL:
|
||||||
Upgrades: criticalspeed
|
Upgrades: criticalspeed
|
||||||
ValidDamageStates: Critical
|
ValidDamageStates: Critical
|
||||||
SpeedMultiplier@DAMAGED:
|
SpeedMultiplier@DAMAGED:
|
||||||
|
|||||||
Reference in New Issue
Block a user