From 2bff1d2cbc7913904eccf171ca8ad029a7dd6e92 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:55:10 -0800 Subject: [PATCH] feat: Converts player deletion handling to a generated event (#2029) --- .../Engines/CannedEvil/ChampionTitleSystem.cs | 2 ++ .../Engines/ML Quests/MLQuestSystem.cs | 1 + .../PlayerMurderSystem.cs | 2 ++ Projects/UOContent/Engines/Virtues/Justice.cs | 2 ++ .../Skill Items/Thief/DisguisePersistence.cs | 1 + Projects/UOContent/Misc/StaminaSystem.cs | 2 ++ Projects/UOContent/Mobiles/PlayerMobile.cs | 21 ++++--------------- Projects/UOContent/Multis/Houses/BaseHouse.cs | 2 ++ .../UOContent/Spells/Fifth/MagicReflect.cs | 3 +++ .../UOContent/Spells/First/ReactiveArmor.cs | 3 +++ .../Spells/Mysticism/StoneFormSpell.cs | 1 + .../Spells/Necromancy/AnimateDeadSpell.cs | 2 ++ .../Spells/Necromancy/SummonFamiliar.cs | 2 ++ .../UOContent/Spells/Ninjitsu/AnimalForm.cs | 2 ++ .../UOContent/Spells/Second/Protection.cs | 3 +++ 15 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Projects/UOContent/Engines/CannedEvil/ChampionTitleSystem.cs b/Projects/UOContent/Engines/CannedEvil/ChampionTitleSystem.cs index b19af9298..d82bfaf15 100644 --- a/Projects/UOContent/Engines/CannedEvil/ChampionTitleSystem.cs +++ b/Projects/UOContent/Engines/CannedEvil/ChampionTitleSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using ModernUO.CodeGeneratedEvents; using Server.Collections; using Server.Mobiles; @@ -25,6 +26,7 @@ public class ChampionTitleSystem : GenericPersistence _championTitleTimer.Start(); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void OnPlayerDeleted(Mobile m) { if (m is PlayerMobile pm) diff --git a/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs b/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs index d583c6be7..cfe129675 100644 --- a/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs +++ b/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs @@ -620,6 +620,7 @@ namespace Server.Engines.MLQuests context?.HandleDeath(); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void HandleDeletion(PlayerMobile pm) { var context = GetContext(pm); diff --git a/Projects/UOContent/Engines/Player Murder System/PlayerMurderSystem.cs b/Projects/UOContent/Engines/Player Murder System/PlayerMurderSystem.cs index 7fda051ff..24ecd4543 100644 --- a/Projects/UOContent/Engines/Player Murder System/PlayerMurderSystem.cs +++ b/Projects/UOContent/Engines/Player Murder System/PlayerMurderSystem.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; +using ModernUO.CodeGeneratedEvents; using Server.Collections; using Server.Logging; using Server.Mobiles; @@ -41,6 +42,7 @@ public class PlayerMurderSystem : GenericPersistence EventSink.Disconnected += OnDisconnected; } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void OnPlayerDeleted(Mobile m) { if (m is PlayerMobile pm && _murderContexts.Remove(pm, out var context)) diff --git a/Projects/UOContent/Engines/Virtues/Justice.cs b/Projects/UOContent/Engines/Virtues/Justice.cs index abbb8da1e..25fc6a79d 100644 --- a/Projects/UOContent/Engines/Virtues/Justice.cs +++ b/Projects/UOContent/Engines/Virtues/Justice.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using ModernUO.CodeGeneratedEvents; using Server.Gumps; using Server.Mobiles; using Server.Network; @@ -84,6 +85,7 @@ public class JusticeVirtue VirtueGump.Register(109, OnVirtueUsed); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void OnPlayerDeleted(Mobile m) { if (m is PlayerMobile pm) diff --git a/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs b/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs index 9675ed68b..4309b6a61 100644 --- a/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs +++ b/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs @@ -70,6 +70,7 @@ public class DisguisePersistence : GenericPersistence t.Stop(); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void RemoveTimer(Mobile m) { diff --git a/Projects/UOContent/Misc/StaminaSystem.cs b/Projects/UOContent/Misc/StaminaSystem.cs index 06a9f498a..845496c2e 100644 --- a/Projects/UOContent/Misc/StaminaSystem.cs +++ b/Projects/UOContent/Misc/StaminaSystem.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ModernUO.CodeGeneratedEvents; using Server.Collections; using Server.Logging; using Server.Mobiles; @@ -75,6 +76,7 @@ public static class StaminaSystem } } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void OnPlayerDeleted(Mobile m) { RemoveEntry(m as IHasSteps); diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index f9b607cc9..da7e427cb 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -3357,23 +3357,7 @@ namespace Server.Mobiles var faction = Faction.Find(this); faction?.RemoveMember(this); - MLQuestSystem.HandleDeletion(this); - BaseHouse.HandleDeletion(this); - DisguisePersistence.RemoveTimer(this); - - StaminaSystem.OnPlayerDeleted(this); - JusticeVirtue.OnPlayerDeleted(this); - PlayerMurderSystem.OnPlayerDeleted(this); - ChampionTitleSystem.OnPlayerDeleted(this); - - // Spells - MagicReflectSpell.EndReflect(this); - ReactiveArmorSpell.EndArmor(this); - ProtectionSpell.EndProtection(this); - StoneFormSpell.RemoveEffects(this); - AnimateDeadSpell.RemoveEffects(this); - SummonFamiliarSpell.RemoveEffects(this); - AnimalForm.RemoveLastAnimalForm(this); + PlayerDeletedEvent(this); } public override void GetProperties(IPropertyList list) @@ -4142,6 +4126,9 @@ namespace Server.Mobiles { } + [GeneratedEvent(nameof(PlayerDeletedEvent))] + public static partial void PlayerDeletedEvent(PlayerMobile pm); + public override void OnDelete() { ReceivedHonorContext?.Cancel(); diff --git a/Projects/UOContent/Multis/Houses/BaseHouse.cs b/Projects/UOContent/Multis/Houses/BaseHouse.cs index a50c29b40..095f95569 100644 --- a/Projects/UOContent/Multis/Houses/BaseHouse.cs +++ b/Projects/UOContent/Multis/Houses/BaseHouse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Accounting; using Server.Collections; using Server.ContextMenus; @@ -3260,6 +3261,7 @@ namespace Server.Multis } } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void HandleDeletion(Mobile mob) { var houses = GetHouses(mob); diff --git a/Projects/UOContent/Spells/Fifth/MagicReflect.cs b/Projects/UOContent/Spells/Fifth/MagicReflect.cs index d7f56b3ab..d6a85e91c 100644 --- a/Projects/UOContent/Spells/Fifth/MagicReflect.cs +++ b/Projects/UOContent/Spells/Fifth/MagicReflect.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; +using Server.Mobiles; namespace Server.Spells.Fifth { @@ -132,6 +134,7 @@ namespace Server.Spells.Fifth FinishSequence(); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void EndReflect(Mobile m) { if (!_table.Remove(m, out var mods)) diff --git a/Projects/UOContent/Spells/First/ReactiveArmor.cs b/Projects/UOContent/Spells/First/ReactiveArmor.cs index 6185034a4..887f1228a 100644 --- a/Projects/UOContent/Spells/First/ReactiveArmor.cs +++ b/Projects/UOContent/Spells/First/ReactiveArmor.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; +using Server.Mobiles; namespace Server.Spells.First { @@ -142,6 +144,7 @@ namespace Server.Spells.First } } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void EndArmor(Mobile m) { if (!_table.Remove(m, out var mods)) diff --git a/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs b/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs index 1820fecd0..60ad336c5 100644 --- a/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs +++ b/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs @@ -134,6 +134,7 @@ namespace Server.Spells.Mysticism FinishSequence(); } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void RemoveEffects(Mobile m) { diff --git a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs index d411e7cf4..8ebc42ab8 100644 --- a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Engines.Quests; using Server.Engines.Quests.Necro; using Server.Items; @@ -194,6 +195,7 @@ public class AnimateDeadSpell : NecromancerSpell, ITargetingSpell Caster.SendLocalizedMessage(1061083); // Animate what corpse? } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void RemoveEffects(Mobile caster) { if (_table.Remove(caster, out var list)) diff --git a/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs b/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs index 693f2d2b2..900d7e8cb 100644 --- a/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs +++ b/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Gumps; using Server.Mobiles; using Server.Network; @@ -38,6 +39,7 @@ public class SummonFamiliarSpell : NecromancerSpell new(typeof(VampireBatFamiliar), 1060144, 100.0, 100.0) // Vampire Bat }; + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void RemoveEffects(Mobile m) { if (Table.Remove(m, out var summon)) diff --git a/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs b/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs index 857fea701..24cbeea0a 100644 --- a/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs +++ b/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs @@ -255,6 +255,7 @@ public class AnimalForm : NinjaSpell } } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void RemoveContext(Mobile m) { @@ -303,6 +304,7 @@ public class AnimalForm : NinjaSpell public static bool UnderTransformation(Mobile m, Type type) => GetContext(m)?.Type == type; + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void RemoveLastAnimalForm(Mobile m) => _table.Remove(m); public class AnimalFormEntry diff --git a/Projects/UOContent/Spells/Second/Protection.cs b/Projects/UOContent/Spells/Second/Protection.cs index 55ef9edac..460990bc8 100644 --- a/Projects/UOContent/Spells/Second/Protection.cs +++ b/Projects/UOContent/Spells/Second/Protection.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; +using Server.Mobiles; namespace Server.Spells.Second { @@ -93,6 +95,7 @@ namespace Server.Spells.Second } } + [OnEvent(nameof(PlayerMobile.PlayerDeletedEvent))] public static void EndProtection(Mobile m) { if (!_table.Remove(m, out var mods))