Add ReloadingCondition to Armament
Allows to grant condition while reloading.
This commit is contained in:
@@ -61,6 +61,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Use multiple muzzle images if non-zero")]
|
[Desc("Use multiple muzzle images if non-zero")]
|
||||||
public readonly int MuzzleSplitFacings = 0;
|
public readonly int MuzzleSplitFacings = 0;
|
||||||
|
|
||||||
|
[GrantedConditionReference]
|
||||||
|
[Desc("Condition to grant while reloading.")]
|
||||||
|
public readonly string ReloadingCondition = null;
|
||||||
|
|
||||||
public WeaponInfo WeaponInfo { get; private set; }
|
public WeaponInfo WeaponInfo { get; private set; }
|
||||||
public WDist ModifiedRange { get; private set; }
|
public WDist ModifiedRange { get; private set; }
|
||||||
|
|
||||||
@@ -108,6 +112,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
INotifyBurstComplete[] notifyBurstComplete;
|
INotifyBurstComplete[] notifyBurstComplete;
|
||||||
INotifyAttack[] notifyAttacks;
|
INotifyAttack[] notifyAttacks;
|
||||||
|
|
||||||
|
ConditionManager conditionManager;
|
||||||
|
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||||
|
|
||||||
IEnumerable<int> rangeModifiers;
|
IEnumerable<int> rangeModifiers;
|
||||||
IEnumerable<int> reloadModifiers;
|
IEnumerable<int> reloadModifiers;
|
||||||
IEnumerable<int> damageModifiers;
|
IEnumerable<int> damageModifiers;
|
||||||
@@ -160,6 +167,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
coords = self.Trait<BodyOrientation>();
|
coords = self.Trait<BodyOrientation>();
|
||||||
notifyBurstComplete = self.TraitsImplementing<INotifyBurstComplete>().ToArray();
|
notifyBurstComplete = self.TraitsImplementing<INotifyBurstComplete>().ToArray();
|
||||||
notifyAttacks = self.TraitsImplementing<INotifyAttack>().ToArray();
|
notifyAttacks = self.TraitsImplementing<INotifyAttack>().ToArray();
|
||||||
|
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||||
|
|
||||||
rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
|
rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
|
||||||
reloadModifiers = self.TraitsImplementing<IReloadModifier>().ToArray().Select(m => m.GetReloadModifier());
|
reloadModifiers = self.TraitsImplementing<IReloadModifier>().ToArray().Select(m => m.GetReloadModifier());
|
||||||
@@ -169,8 +177,24 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateCondition(Actor self)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Info.ReloadingCondition) || conditionManager == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var enabled = !IsTraitDisabled && IsReloading;
|
||||||
|
|
||||||
|
if (enabled && conditionToken == ConditionManager.InvalidConditionToken)
|
||||||
|
conditionToken = conditionManager.GrantCondition(self, Info.ReloadingCondition);
|
||||||
|
else if (!enabled && conditionToken != ConditionManager.InvalidConditionToken)
|
||||||
|
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Tick(Actor self)
|
protected virtual void Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// We need to disable conditions if IsTraitDisabled is true, so we have to update conditions before the return below.
|
||||||
|
UpdateCondition(self);
|
||||||
|
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user