fix: Fixes stabled, abilities targeting self, and unsummon memory leak (#1418)
## **MAJOR CHANGE** * `Stabled` has been moved to `PlayerMobile`. * New methods added, `PlayerMobile.AddStabled` and `PlayerMobile.RemoveStabled`. * Added `PlayerMobile.AddFollower` and `PlayerMobile.RemoveFollower`. * `Stabled`, `AutoStabled`, and `AllFollowers` are now `HashSet` and **_CAN BE NULL_**. ### Summary * Fixes monster abilities causing harm to the monster through reflect * Adds `CanTriggerAgainstSelf` to override this for healing or some other self-affecting ability * Fixes a major memory leak where `UnsummonTimer` from animated dead spell lasts up-to 24hrs and therefore holds onto references of dead/deleted mobs. * Fixes another minor leak where a mob is not unregistered from the animated dead spell list until the next spell cast.
This commit is contained in:
parent
d99e72db8f
commit
3b97e8d39c
13 changed files with 391 additions and 280 deletions
|
|
@ -1,23 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Spells
|
||||
namespace Server.Spells;
|
||||
|
||||
public class UnsummonTimer : Timer
|
||||
{
|
||||
internal 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 BaseCreature _creature;
|
||||
|
||||
public static void StopTimer(BaseCreature creature)
|
||||
{
|
||||
private readonly BaseCreature m_Creature;
|
||||
|
||||
public UnsummonTimer(BaseCreature creature, TimeSpan delay) : base(delay)
|
||||
if (_timers.Remove(creature, out var timer))
|
||||
{
|
||||
m_Creature = creature;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (!m_Creature.Deleted)
|
||||
{
|
||||
m_Creature.Delete();
|
||||
}
|
||||
timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public UnsummonTimer(BaseCreature creature, TimeSpan delay) : base(delay)
|
||||
{
|
||||
_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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue