Optimise TakeCover to have clear states
This commit is contained in:
@@ -58,17 +58,32 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Sync]
|
[Sync]
|
||||||
int remainingDuration = 0;
|
int remainingDuration = 0;
|
||||||
|
|
||||||
bool IsProne => !IsTraitDisabled && remainingDuration != 0;
|
bool isProne = false;
|
||||||
|
void SetProneState(bool state)
|
||||||
|
{
|
||||||
|
localOffset = state ? info.ProneOffset : WVec.Zero;
|
||||||
|
isProne = state;
|
||||||
|
}
|
||||||
|
|
||||||
bool IRenderInfantrySequenceModifier.IsModifyingSequence => IsProne;
|
bool IRenderInfantrySequenceModifier.IsModifyingSequence => isProne;
|
||||||
string IRenderInfantrySequenceModifier.SequencePrefix => info.ProneSequencePrefix;
|
string IRenderInfantrySequenceModifier.SequencePrefix => info.ProneSequencePrefix;
|
||||||
|
|
||||||
public TakeCover(ActorInitializer init, TakeCoverInfo info)
|
public TakeCover(ActorInitializer init, TakeCoverInfo info)
|
||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
if (info.Duration < 0 && info.DamageTriggers.IsEmpty)
|
}
|
||||||
|
|
||||||
|
protected override void Created(Actor self)
|
||||||
|
{
|
||||||
|
base.Created(self);
|
||||||
|
|
||||||
|
if (info.DamageTriggers.IsEmpty)
|
||||||
|
{
|
||||||
remainingDuration = info.Duration;
|
remainingDuration = info.Duration;
|
||||||
|
if (!IsTraitDisabled)
|
||||||
|
SetProneState(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyDamage.Damaged(Actor self, AttackInfo e)
|
void INotifyDamage.Damaged(Actor self, AttackInfo e)
|
||||||
@@ -79,8 +94,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (e.Damage.Value <= 0 || !e.Damage.DamageTypes.Overlaps(info.DamageTriggers))
|
if (e.Damage.Value <= 0 || !e.Damage.DamageTypes.Overlaps(info.DamageTriggers))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsProne)
|
if (!isProne)
|
||||||
localOffset = info.ProneOffset;
|
SetProneState(true);
|
||||||
|
|
||||||
remainingDuration = info.Duration;
|
remainingDuration = info.Duration;
|
||||||
}
|
}
|
||||||
@@ -89,18 +104,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
base.Tick(self);
|
base.Tick(self);
|
||||||
|
|
||||||
|
if (IsTraitDisabled || info.Duration < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!IsTraitPaused && remainingDuration > 0)
|
if (!IsTraitPaused && remainingDuration > 0)
|
||||||
remainingDuration--;
|
remainingDuration--;
|
||||||
|
|
||||||
if (remainingDuration == 0)
|
if (isProne && remainingDuration == 0)
|
||||||
localOffset = WVec.Zero;
|
SetProneState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HasAchievedDesiredFacing => true;
|
public override bool HasAchievedDesiredFacing => true;
|
||||||
|
|
||||||
int IDamageModifier.GetDamageModifier(Actor attacker, Damage damage)
|
int IDamageModifier.GetDamageModifier(Actor attacker, Damage damage)
|
||||||
{
|
{
|
||||||
if (!IsProne)
|
if (!isProne)
|
||||||
return 100;
|
return 100;
|
||||||
|
|
||||||
if (damage == null || damage.DamageTypes.IsEmpty)
|
if (damage == null || damage.DamageTypes.IsEmpty)
|
||||||
@@ -112,20 +130,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
int ISpeedModifier.GetSpeedModifier()
|
int ISpeedModifier.GetSpeedModifier()
|
||||||
{
|
{
|
||||||
return IsProne ? info.SpeedModifier : 100;
|
return isProne ? info.SpeedModifier : 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitDisabled(Actor self)
|
protected override void TraitDisabled(Actor self)
|
||||||
{
|
{
|
||||||
remainingDuration = 0;
|
remainingDuration = 0;
|
||||||
|
SetProneState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
{
|
{
|
||||||
if (info.Duration < 0 && info.DamageTriggers.IsEmpty)
|
if (info.DamageTriggers.IsEmpty)
|
||||||
{
|
{
|
||||||
remainingDuration = info.Duration;
|
remainingDuration = info.Duration;
|
||||||
localOffset = info.ProneOffset;
|
SetProneState(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user