Skip to content

Commit a07f0d5

Browse files
committed
Fix ranged NPCs not updating their LoS checker correctly in some cases
1 parent 3ef3759 commit a07f0d5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

GameServer/ECS-Components/Actions/NpcAttackAction.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class NpcAttackAction : AttackAction
1818
private GameObject _losCheckTarget;
1919

2020
private static int LosCheckInterval => Properties.CHECK_LOS_DURING_RANGED_ATTACK_MINIMUM_INTERVAL;
21-
private bool HasLosOnCurrentTarget => _losCheckTarget == _target && _hasLos;
2221
private bool IsGuardArcherOrImmobile => _npcOwner is GuardArcher || _npcOwner.MaxSpeedBase == 0;
2322

2423
public NpcAttackAction(GameNPC owner) : base(owner)
@@ -82,9 +81,20 @@ protected override bool PrepareMeleeAttack()
8281
_npcOwner.Inventory?.GetItem(eInventorySlot.DistanceWeapon) != null &&
8382
!_npcOwner.IsWithinRadius(_target, offsetMeleeAttackRange))
8483
{
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.
8685
// 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)
8898
{
8999
SwitchToRangedAndTick();
90100
return false;
@@ -119,10 +129,12 @@ protected override bool PrepareRangedAttack()
119129
{
120130
if (_checkLosTimer == null)
121131
_checkLosTimer = new CheckLosTimer(_npcOwner, _target, LosCheckCallback);
122-
else
132+
else if (_losCheckTarget != _target)
133+
{
134+
_hasLos = false;
123135
_checkLosTimer.ChangeTarget(_target);
124-
125-
if (!HasLosOnCurrentTarget)
136+
}
137+
else if (!_hasLos)
126138
{
127139
_interval = TICK_INTERVAL_FOR_NON_ATTACK;
128140
return false;

0 commit comments

Comments
 (0)