fix: Fixes guard infinite loop, and streamlines call methods (#2175)

This commit is contained in:
Kamron Batman 2025-05-06 23:54:13 -07:00 • committed by GitHub
parent f02403a374
commit 990e86b983
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 46 deletions

View file

@ -108,7 +108,7 @@ public partial class ArcherGuard : BaseGuard
if (_focus != null) if (_focus != null)
{ {
AttackTimer = new GuardAttackTimer(this); AttackTimer = new GuardAttackTimer(this);
AttackTimer.DoOnTick(); AttackTimer.Start();
} }
else else
{ {

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.CompilerServices;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Items; using Server.Items;
@ -13,33 +14,34 @@ public abstract partial class BaseGuard : Mobile
GuardsInstantKill = ServerConfiguration.GetSetting("guards.instantKill", true); GuardsInstantKill = ServerConfiguration.GetSetting("guards.instantKill", true);
} }
public static void Spawn(Mobile caller, Mobile target, int amount = 1, bool onlyAdditional = false) [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Spawn(Mobile caller, Mobile target, int amount = 1, bool onlyAdditional = false) =>
Spawn(caller.Region, target, amount, onlyAdditional);
public static void Spawn(Region region, Mobile target, int amount = 1, bool onlyAdditional = false)
{ {
if (target?.Deleted != false) if (target?.Deleted != false)
{ {
return; return;
} }
foreach (var m in target.GetMobilesInRange(15)) foreach (var g in target.GetMobilesInRange<BaseGuard>(15))
{ {
if (m is BaseGuard g) if (g.Focus == null) // idling
{ {
if (g.Focus == null) // idling g.Focus = target;
{
g.Focus = target;
--amount; --amount;
} }
else if (g.Focus == target && !onlyAdditional) else if (g.Focus == target && !onlyAdditional)
{ {
--amount; --amount;
}
} }
} }
while (amount-- > 0) while (amount-- > 0)
{ {
caller.Region.MakeGuard(target); region.MakeGuard(target);
} }
} }
@ -242,13 +244,6 @@ public class GuardAttackTimer : Timer
return; return;
} }
if (_owner.Weapon is Fists)
{
_owner.Kill();
Stop();
return;
}
if (target != null && _owner.Combatant != target) if (target != null && _owner.Combatant != target)
{ {
_owner.Combatant = target; _owner.Combatant = target;

View file

@ -124,7 +124,7 @@ public partial class WarriorGuard : BaseGuard
if (_focus != null) if (_focus != null)
{ {
AttackTimer = new GuardAttackTimer(this); AttackTimer = new GuardAttackTimer(this);
AttackTimer.DoOnTick(); AttackTimer.Start();
} }
else else
{ {

View file

@ -152,32 +152,15 @@ public class GuardedRegion : BaseRegion
public override void MakeGuard(Mobile focus) public override void MakeGuard(Mobile focus)
{ {
BaseGuard useGuard = null; m_GuardParams[0] = focus;
foreach (var m in focus.GetMobilesInRange<BaseGuard>(8))
{
if (m.Focus == null)
{
useGuard = m;
break;
}
}
if (useGuard == null) try
{ {
m_GuardParams[0] = focus; GuardType.CreateInstance<object>(m_GuardParams);
try
{
GuardType.CreateInstance<object>(m_GuardParams);
}
catch
{
// ignored
}
} }
else catch
{ {
useGuard.Focus = focus; // ignored
} }
} }
@ -296,7 +279,7 @@ public class GuardedRegion : BaseRegion
{ {
fakeCall.Say(Utility.Random(1013037, 16)); fakeCall.Say(Utility.Random(1013037, 16));
MakeGuard(m); BaseGuard.Spawn(fakeCall, m);
timer.Stop(); timer.Stop();
m_GuardCandidates.Remove(m); m_GuardCandidates.Remove(m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you. m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
@ -332,7 +315,7 @@ public class GuardedRegion : BaseRegion
while (queue.Count > 0) while (queue.Count > 0)
{ {
var m = queue.Dequeue(); var m = queue.Dequeue();
MakeGuard(m); BaseGuard.Spawn(this, m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you. m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
} }
} }