@@ -18,7 +18,6 @@ public class NpcAttackAction : AttackAction
18
18
private GameObject _losCheckTarget ;
19
19
20
20
private static int LosCheckInterval => Properties . CHECK_LOS_DURING_RANGED_ATTACK_MINIMUM_INTERVAL ;
21
- private bool HasLosOnCurrentTarget => _losCheckTarget == _target && _hasLos ;
22
21
private bool IsGuardArcherOrImmobile => _npcOwner is GuardArcher || _npcOwner . MaxSpeedBase == 0 ;
23
22
24
23
public NpcAttackAction ( GameNPC owner ) : base ( owner )
@@ -82,9 +81,20 @@ protected override bool PrepareMeleeAttack()
82
81
_npcOwner . Inventory ? . GetItem ( eInventorySlot . DistanceWeapon ) != null &&
83
82
! _npcOwner . IsWithinRadius ( _target , offsetMeleeAttackRange ) )
84
83
{
85
- // But only if there is no timer running or if it has LoS.
84
+ // But only if there is no timer running or if it has LoS on its current target .
86
85
// If the timer is running, it'll check for LoS continuously.
87
- if ( _checkLosTimer == null || ! _checkLosTimer . IsAlive || HasLosOnCurrentTarget )
86
+ if ( ! Properties . CHECK_LOS_BEFORE_NPC_RANGED_ATTACK || _checkLosTimer == null || ! _checkLosTimer . IsAlive )
87
+ {
88
+ SwitchToRangedAndTick ( ) ;
89
+ return false ;
90
+ }
91
+
92
+ if ( _losCheckTarget != _target )
93
+ {
94
+ _hasLos = false ;
95
+ _checkLosTimer . ChangeTarget ( _target ) ;
96
+ }
97
+ else if ( _hasLos )
88
98
{
89
99
SwitchToRangedAndTick ( ) ;
90
100
return false ;
@@ -119,10 +129,12 @@ protected override bool PrepareRangedAttack()
119
129
{
120
130
if ( _checkLosTimer == null )
121
131
_checkLosTimer = new CheckLosTimer ( _npcOwner , _target , LosCheckCallback ) ;
122
- else
132
+ else if ( _losCheckTarget != _target )
133
+ {
134
+ _hasLos = false ;
123
135
_checkLosTimer . ChangeTarget ( _target ) ;
124
-
125
- if ( ! HasLosOnCurrentTarget )
136
+ }
137
+ else if ( ! _hasLos )
126
138
{
127
139
_interval = TICK_INTERVAL_FOR_NON_ATTACK ;
128
140
return false ;
0 commit comments