Check for IsReloading in HasAnyValidWeapons
For Attack*.CanAttack(). Allows us to drop the additional check for armaments with ammo.
This commit is contained in:
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!target.IsValidFor(self))
|
if (!target.IsValidFor(self))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!HasAnyValidWeapons(target))
|
if (!HasAnyValidWeapons(target, reloadingIsInvalid: true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// PERF: Mobile implements IPositionable, so we can use 'as' to save a trait look-up here.
|
// PERF: Mobile implements IPositionable, so we can use 'as' to save a trait look-up here.
|
||||||
@@ -157,9 +157,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (mobile != null && !mobile.CanInteractWithGroundLayer(self))
|
if (mobile != null && !mobile.CanInteractWithGroundLayer(self))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Armaments.All(a => a.IsReloading))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public abstract Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
|
public abstract Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
|
||||||
|
|
||||||
public bool HasAnyValidWeapons(in Target t, bool checkForCenterTargetingWeapons = false)
|
public bool HasAnyValidWeapons(in Target t, bool checkForCenterTargetingWeapons = false, bool reloadingIsInvalid = false)
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return false;
|
return false;
|
||||||
@@ -241,7 +238,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
foreach (var armament in Armaments)
|
foreach (var armament in Armaments)
|
||||||
{
|
{
|
||||||
var checkIsValid = checkForCenterTargetingWeapons ? armament.Weapon.TargetActorCenter : !armament.IsTraitPaused;
|
var checkIsValid = checkForCenterTargetingWeapons ? armament.Weapon.TargetActorCenter : !armament.IsTraitPaused;
|
||||||
if (checkIsValid && !armament.IsTraitDisabled && armament.Weapon.IsValidAgainst(t, self.World, self))
|
var reloadingStateIsValid = !reloadingIsInvalid || !armament.IsReloading;
|
||||||
|
if (checkIsValid && reloadingStateIsValid && !armament.IsTraitDisabled && armament.Weapon.IsValidAgainst(t, self.World, self))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user