mirror of
https://github.com/modernuo/ModernUO
synced 2026-08-11 22:23:06 -04:00
### Summary - Fixes various memory leaks related to spells - Fixes Spell Plague - Added ability to determine if `sdi` should take effect for Spell Damage. - Fixes animal form timer ticking non-stop while logged out.
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Server.Mobiles;
|
|
|
|
namespace Server.Spells;
|
|
|
|
public class UnsummonTimer : Timer
|
|
{
|
|
// Track timers since some of them are really long and might hold references to long dead/deleted mobs
|
|
private static readonly Dictionary<BaseCreature, UnsummonTimer> _timers = new();
|
|
private readonly BaseCreature _creature;
|
|
private readonly Action _onUnsummon;
|
|
|
|
public static void StopTimer(BaseCreature creature)
|
|
{
|
|
if (_timers.Remove(creature, out var timer))
|
|
{
|
|
timer.Stop();
|
|
}
|
|
}
|
|
|
|
public UnsummonTimer(BaseCreature creature, TimeSpan delay, Action onUnsummon = null) : base(delay)
|
|
{
|
|
_onUnsummon = onUnsummon;
|
|
_creature = creature;
|
|
|
|
ref var timer = ref CollectionsMarshal.GetValueRefOrAddDefault(_timers, creature, out bool exists);
|
|
if (exists)
|
|
{
|
|
timer.Stop();
|
|
}
|
|
|
|
timer = this;
|
|
}
|
|
|
|
protected override void OnTick()
|
|
{
|
|
// BaseCreature.OnAfterDelete will remove the creature from the timers table
|
|
_creature?.Delete();
|
|
_onUnsummon?.Invoke();
|
|
}
|
|
}
|