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:
Kamron Batman 2023-07-03 09:45:22 -07:00 • committed by GitHub
parent d99e72db8f
commit 3b97e8d39c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 391 additions and 280 deletions

View file

@ -867,7 +867,7 @@ public partial class ConditionTeleporter : Teleporter
}
if (GetFlag(ConditionFlag.DenyFollowers) &&
(m.Followers != 0 || m is PlayerMobile mobile && mobile.AutoStabled.Count != 0))
(m.Followers != 0 || m is PlayerMobile mobile && mobile.AutoStabled?.Count != 0))
{
m.SendLocalizedMessage(1077250); // No pets permitted beyond this point.
return false;

View file

@ -166,7 +166,7 @@ public partial class BallOfSummoning : Item, TranslocationItem
{
var pet = Pet;
if (Deleted || pet == null || RootParent != from)
if (Deleted || pet == null || RootParent != from || from is not PlayerMobile pm)
{
return;
}
@ -186,7 +186,7 @@ public partial class BallOfSummoning : Item, TranslocationItem
// The Crystal Ball fills with a blue mist. Your pet is not responding to the summons.
this.SendLocalizedMessageTo(from, 1054125, 0x5);
}
else if ((!pet.Controlled || pet.ControlMaster != from) && !from.Stabled.Contains(pet))
else if ((!pet.Controlled || pet.ControlMaster != from) && pm.Stabled?.Contains(pet) != true)
{
// The Crystal Ball fills with a grey mist. You are not the owner of the pet you are attempting to summon.
this.SendLocalizedMessageTo(from, 1054126, 0x8FD);
@ -221,7 +221,7 @@ public partial class BallOfSummoning : Item, TranslocationItem
{
var pet = Pet;
if (pet == null)
if (pet == null || from is not PlayerMobile pm)
{
return;
}
@ -242,12 +242,8 @@ public partial class BallOfSummoning : Item, TranslocationItem
pet.IsStabled = false;
pet.StabledBy = null;
from.Stabled.Remove(pet);
if (from is PlayerMobile mobile)
{
mobile.AutoStabled.Remove(pet);
}
pm.RemoveStabled(pet);
pm.AutoStabled?.Remove(pet);
}
pet.MoveToWorld(from.Location, from.Map);