fix: Fixes double calls with Target cancel and spell sequences (#1840)

### Summary
- Cleans up target cancellation being called incorrectly.
- An invalid target type (which should never happen), now calls `OnTargetUntargetable` instead of `OnTargetCanceled`
- Removes double calls to `FinishSequence` in Spells.
This commit is contained in:
Kamron Batman 2024-06-17 15:19:06 -07:00 committed by GitHub
parent 9c0b57213a
commit b8ad5c671d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 201 additions and 406 deletions

View file

@ -38,7 +38,7 @@ public abstract class Target
public static void Cancel(Mobile m)
{
m.NetState.SendCancelTarget();
m.Target?.OnTargetCancel(m, TargetCancelType.Canceled);
m.Target?.Cancel(m, TargetCancelType.Canceled);
}
public void BeginTimeout(Mobile from, long delay)
@ -57,15 +57,14 @@ public abstract class Target
m_TimeoutTimer = null;
}
public void Timeout(Mobile from)
public void Timeout(Mobile m)
{
m.NetState.SendCancelTarget();
CancelTimeout();
from.ClearTarget();
m.ClearTarget();
Cancel(from);
OnTargetCancel(from, TargetCancelType.Timeout);
OnTargetFinish(from);
OnTargetCancel(m, TargetCancelType.Timeout);
OnTargetFinish(m);
}
public virtual void SendTargetTo(NetState ns) => ns.SendTargetReq(this);
@ -84,7 +83,6 @@ public abstract class Target
if (!AllowGround)
{
// We should actually never get here. If we do, it's probably a misbehaving client/macro.
OnTargetCancel(from, TargetCancelType.Canceled);
return false;
}
@ -161,7 +159,7 @@ public abstract class Target
Map map = null;
Item item = null;
Mobile mobile = null;
bool isValidTargetType = true;
var isValidTargetType = true;
bool valid = targeted switch
{
@ -176,13 +174,10 @@ public abstract class Target
{
if (!isValidTargetType)
{
OnTargetCancel(from, TargetCancelType.Canceled);
OnTargetUntargetable(from, targeted);
}
OnTargetFinish(from);
}
if (map == null || map != from.Map || Range >= 0 && !from.InRange(loc, Range))
else if (map == null || map != from.Map || Range >= 0 && !from.InRange(loc, Range))
{
OnTargetOutOfRange(from, targeted);
}
@ -206,7 +201,7 @@ public abstract class Target
{
OnTargetUntargetable(from, targeted);
}
else if (mobile?.CheckTarget(from, this, mobile) == false)
else if (mobile?.CheckTarget(from, this, targeted) == false)
{
OnTargetUntargetable(from, mobile);
}
@ -271,20 +266,20 @@ public abstract class Target
private class TimeoutTimer : Timer
{
private readonly Mobile m_Mobile;
private readonly Target m_Target;
private readonly Mobile _mobile;
private readonly Target _target;
public TimeoutTimer(Target target, Mobile m, TimeSpan delay) : base(delay)
{
m_Target = target;
m_Mobile = m;
_target = target;
_mobile = m;
}
protected override void OnTick()
{
if (m_Mobile.Target == m_Target)
if (_mobile.Target == _target)
{
m_Target.Timeout(m_Mobile);
_target.Timeout(_mobile);
}
}
}