Add support for enabling prone state permanently

Negative ProneTime now activates prone state
permanently as soon as the trait is enabled.
This commit is contained in:
reaperrr
2019-10-21 19:32:08 +02:00
committed by abcdefg30
parent d6436858a9
commit a9eca2cf54

View File

@@ -19,14 +19,15 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Make the unit go prone when under attack, in an attempt to reduce damage.")]
public class TakeCoverInfo : TurretedInfo
{
[Desc("How long (in ticks) the actor remains prone.")]
[Desc("How long (in ticks) the actor remains prone.",
"Negative values mean actor remains prone permanently.")]
public readonly int Duration = 100;
[Desc("Prone movement speed as a percentage of the normal speed.")]
public readonly int SpeedModifier = 50;
[FieldLoader.Require]
[Desc("Damage types that trigger prone state. Defined on the warheads.")]
[Desc("Damage types that trigger prone state. Defined on the warheads.",
"If Duration is negative (permanent), you can leave this empty to trigger prone state immediately.")]
public readonly BitSet<DamageType> DamageTriggers = default(BitSet<DamageType>);
[Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")]
@@ -40,6 +41,14 @@ namespace OpenRA.Mods.Common.Traits
public readonly string ProneSequencePrefix = "prone-";
public override object Create(ActorInitializer init) { return new TakeCover(init, this); }
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
if (Duration > -1 && DamageTriggers.IsEmpty)
throw new YamlException("TakeCover: If Duration isn't negative (permanent), DamageTriggers is required.");
base.RulesetLoaded(rules, ai);
}
}
public class TakeCover : Turreted, INotifyDamage, IDamageModifier, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
@@ -49,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
[Sync]
int remainingDuration = 0;
bool IsProne { get { return !IsTraitDisabled && remainingDuration > 0; } }
bool IsProne { get { return !IsTraitDisabled && remainingDuration != 0; } }
bool IRenderInfantrySequenceModifier.IsModifyingSequence { get { return IsProne; } }
string IRenderInfantrySequenceModifier.SequencePrefix { get { return info.ProneSequencePrefix; } }
@@ -58,6 +67,8 @@ namespace OpenRA.Mods.Common.Traits
: base(init, info)
{
this.info = info;
if (info.Duration < 0 && info.DamageTriggers.IsEmpty)
remainingDuration = info.Duration;
}
void INotifyDamage.Damaged(Actor self, AttackInfo e)
@@ -111,5 +122,14 @@ namespace OpenRA.Mods.Common.Traits
{
remainingDuration = 0;
}
protected override void TraitEnabled(Actor self)
{
if (info.Duration < 0 && info.DamageTriggers.IsEmpty)
{
remainingDuration = info.Duration;
localOffset = info.ProneOffset;
}
}
}
}