fix: Fixes guard infinite loop, and streamlines call methods (#2175)
This commit is contained in:
parent
f02403a374
commit
990e86b983
4 changed files with 24 additions and 46 deletions
|
|
@ -108,7 +108,7 @@ public partial class ArcherGuard : BaseGuard
|
|||
if (_focus != null)
|
||||
{
|
||||
AttackTimer = new GuardAttackTimer(this);
|
||||
AttackTimer.DoOnTick();
|
||||
AttackTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Items;
|
||||
|
||||
|
|
@ -13,33 +14,34 @@ public abstract partial class BaseGuard : Mobile
|
|||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (g.Focus == target && !onlyAdditional)
|
||||
{
|
||||
--amount;
|
||||
}
|
||||
--amount;
|
||||
}
|
||||
else if (g.Focus == target && !onlyAdditional)
|
||||
{
|
||||
--amount;
|
||||
}
|
||||
}
|
||||
|
||||
while (amount-- > 0)
|
||||
{
|
||||
caller.Region.MakeGuard(target);
|
||||
region.MakeGuard(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -242,13 +244,6 @@ public class GuardAttackTimer : Timer
|
|||
return;
|
||||
}
|
||||
|
||||
if (_owner.Weapon is Fists)
|
||||
{
|
||||
_owner.Kill();
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (target != null && _owner.Combatant != target)
|
||||
{
|
||||
_owner.Combatant = target;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public partial class WarriorGuard : BaseGuard
|
|||
if (_focus != null)
|
||||
{
|
||||
AttackTimer = new GuardAttackTimer(this);
|
||||
AttackTimer.DoOnTick();
|
||||
AttackTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -152,32 +152,15 @@ public class GuardedRegion : BaseRegion
|
|||
|
||||
public override void MakeGuard(Mobile focus)
|
||||
{
|
||||
BaseGuard useGuard = null;
|
||||
foreach (var m in focus.GetMobilesInRange<BaseGuard>(8))
|
||||
{
|
||||
if (m.Focus == null)
|
||||
{
|
||||
useGuard = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_GuardParams[0] = focus;
|
||||
|
||||
if (useGuard == null)
|
||||
try
|
||||
{
|
||||
m_GuardParams[0] = focus;
|
||||
|
||||
try
|
||||
{
|
||||
GuardType.CreateInstance<object>(m_GuardParams);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
GuardType.CreateInstance<object>(m_GuardParams);
|
||||
}
|
||||
else
|
||||
catch
|
||||
{
|
||||
useGuard.Focus = focus;
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +279,7 @@ public class GuardedRegion : BaseRegion
|
|||
{
|
||||
fakeCall.Say(Utility.Random(1013037, 16));
|
||||
|
||||
MakeGuard(m);
|
||||
BaseGuard.Spawn(fakeCall, m);
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
|
|
@ -332,7 +315,7 @@ public class GuardedRegion : BaseRegion
|
|||
while (queue.Count > 0)
|
||||
{
|
||||
var m = queue.Dequeue();
|
||||
MakeGuard(m);
|
||||
BaseGuard.Spawn(this, m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue