Allow UpgradeOnDamage to grant permanent upgrades
Needed to properly implement things like permanently crippled weapons or limbs.
This commit is contained in:
@@ -29,6 +29,9 @@ 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?")]
|
||||||
|
public readonly bool GrantPermanently = false;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new UpgradeOnDamage(init.Self, this); }
|
public object Create(ActorInitializer init) { return new UpgradeOnDamage(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly UpgradeOnDamageInfo info;
|
readonly UpgradeOnDamageInfo info;
|
||||||
readonly UpgradeManager um;
|
readonly UpgradeManager um;
|
||||||
|
bool granted;
|
||||||
|
|
||||||
public UpgradeOnDamage(Actor self, UpgradeOnDamageInfo info)
|
public UpgradeOnDamage(Actor self, UpgradeOnDamageInfo info)
|
||||||
{
|
{
|
||||||
@@ -43,12 +47,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
um = self.TraitOrDefault<UpgradeManager>();
|
um = self.TraitOrDefault<UpgradeManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool granted;
|
|
||||||
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (um == null)
|
if (um == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (granted && info.GrantPermanently)
|
||||||
|
return;
|
||||||
|
|
||||||
var rand = Game.CosmeticRandom;
|
var rand = Game.CosmeticRandom;
|
||||||
if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user