From 95cd8749a3c762094c50b3a5e113c412fe057d61 Mon Sep 17 00:00:00 2001 From: Guyute Date: Fri, 6 Sep 2024 00:23:03 -0400 Subject: [PATCH] feat: Adds PlayerDeathEvent and CreatureDeathEvent using code generated events (#1927) ### Summary - Adds [Code Generated Events](https://github.com/modernuo/CodeGeneratedEvents) - Removes EventSink.PlayerDeath - Adds `PlayerDeathEvent` and `CreatureDeathEvent` using code generated events > [!Important] > **Developer Note** > Use `[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]` instead of `EventSink.PlayerDeath` delegate > Check this commit for examples of how to use this. --- Projects/Server/Events/EventSink.cs | 8 -- Projects/Server/Items/VirtualHair.cs | 1 - Projects/Server/Mobiles/Mobile.cs | 131 +++++++++++++----- .../UOContent/Engines/ConPVP/DuelContext.cs | 6 +- .../Engines/ML Quests/MLQuestSystem.cs | 2 + Projects/UOContent/Engines/Party/Party.cs | 6 +- .../ReportMurdererGump.cs | 7 +- .../Halloween/2012/Engines/PlayerZombies.cs | 9 +- .../Skill Items/Thief/DisguisePersistence.cs | 2 + .../8th Anniversary Items/Talismans.cs | 2 +- Projects/UOContent/Misc/AOS.cs | 2 +- Projects/UOContent/Misc/Guild.cs | 2 +- Projects/UOContent/Mobiles/BaseCreature.cs | 12 +- .../UOContent/Mobiles/Healers/PricedHealer.cs | 1 - .../Humanoid/Melee/KhaldunRevenant.cs | 9 +- .../Mobiles/Monsters/LBR/Meers/MeerMage.cs | 9 +- Projects/UOContent/Mobiles/PlayerMobile.cs | 28 ++-- Projects/UOContent/Skills/Stealing.cs | 6 +- Projects/UOContent/Spells/Fifth/Incognito.cs | 8 ++ .../Spells/Mysticism/SpellPlagueSpell.cs | 10 +- .../Spells/Mysticism/StoneFormSpell.cs | 13 +- .../UOContent/Spells/Ninjitsu/AnimalForm.cs | 19 ++- .../UOContent/Spells/Seventh/Polymorph.cs | 9 ++ .../Spells/Spellweaving/GiftOfLife.cs | 20 +-- Projects/UOContent/UOContent.csproj | 2 + version.json | 2 +- 26 files changed, 191 insertions(+), 135 deletions(-) diff --git a/Projects/Server/Events/EventSink.cs b/Projects/Server/Events/EventSink.cs index 129e256e7..b112cb72d 100644 --- a/Projects/Server/Events/EventSink.cs +++ b/Projects/Server/Events/EventSink.cs @@ -34,14 +34,6 @@ public static partial class EventSink public static event Action Disconnected; public static void InvokeDisconnected(Mobile m) => Disconnected?.Invoke(m); - public static event Action PlayerDeath; - public static void InvokePlayerDeath(Mobile m) => PlayerDeath?.Invoke(m); - - public static event Action VirtueMacroRequest; - - public static void InvokeVirtueMacroRequest(Mobile mobile, int virtueID) => - VirtueMacroRequest?.Invoke(mobile, virtueID); - public static event Action PaperdollRequest; public static void InvokePaperdollRequest(Mobile beholder, Mobile beheld) => diff --git a/Projects/Server/Items/VirtualHair.cs b/Projects/Server/Items/VirtualHair.cs index 89310e21a..ce6735073 100644 --- a/Projects/Server/Items/VirtualHair.cs +++ b/Projects/Server/Items/VirtualHair.cs @@ -1,6 +1,5 @@ using System; using System.Buffers; -using System.Runtime.CompilerServices; using ModernUO.Serialization; using Server.Network; diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index adcdfbc60..122c44b10 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -2847,6 +2847,7 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro Layer.FacialHair ); } + ourState.Send(facialHairPacket); } @@ -2984,6 +2985,7 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro Layer.FacialHair ); } + state.Send(facialHairPacket); } @@ -3429,7 +3431,6 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro Skills[mod.Skill]?.Update(); } } - } public virtual void AddSkillMod(SkillMod mod) @@ -4826,37 +4827,34 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro if (!m_Player) { Delete(); + return; } - else - { - m_NetState.SendDeathStatus(); - Warmode = false; + m_NetState.SendDeathStatus(); - BodyMod = 0; - // Body = this.Female ? 0x193 : 0x192; - Body = Race.GhostBody(this); + Warmode = false; - var deathShroud = new Item(0x204E) { Movable = false, Layer = Layer.OuterTorso }; + BodyMod = 0; + // Body = this.Female ? 0x193 : 0x192; + Body = Race.GhostBody(this); - AddItem(deathShroud); + var deathShroud = new Item(0x204E) { Movable = false, Layer = Layer.OuterTorso }; - Items.Remove(deathShroud); - Items.Insert(0, deathShroud); + AddItem(deathShroud); - Poison = null; - Combatant = null; + Items.Remove(deathShroud); + Items.Insert(0, deathShroud); - Hits = 0; - Stam = 0; - Mana = 0; + Poison = null; + Combatant = null; - EventSink.InvokePlayerDeath(this); + Hits = 0; + Stam = 0; + Mana = 0; - ProcessDelta(); + ProcessDelta(); - CheckStatTimers(); - } + CheckStatTimers(); } public virtual bool CheckTarget(Mobile from, Target targ, object targeted) => true; @@ -5070,7 +5068,8 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro { var rootItem = root as Item; - Span buffer = stackalloc byte[OutgoingPlayerPackets.DragEffectPacketLength].InitializePacket(); + Span buffer = stackalloc byte[OutgoingPlayerPackets.DragEffectPacketLength] + .InitializePacket(); foreach (var ns in map.GetClientsInRange(from.Location)) { @@ -5588,7 +5587,8 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro ProcessDelta(); Span regBuffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)].InitializePacket(); - Span mutBuffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(mutatedText)].InitializePacket(); + Span mutBuffer = + stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(mutatedText)].InitializePacket(); // TODO: Should this be sorted like onSpeech is below? for (var i = 0; i < hears.Count; ++i) @@ -5598,7 +5598,16 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro if (mutatedArgs == null || !CheckHearsMutatedSpeech(heard, mutateContext)) { var length = OutgoingMessagePackets.CreateMessage( - regBuffer, Serial, Body, type, hue, 3, false, m_Language, Name, text + regBuffer, + Serial, + Body, + type, + hue, + 3, + false, + m_Language, + Name, + text ); if (length != regBuffer.Length) @@ -5612,7 +5621,16 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro else { var length = OutgoingMessagePackets.CreateMessage( - mutBuffer, Serial, Body, type, hue, 3, false, m_Language, Name, mutatedText + mutBuffer, + Serial, + Body, + type, + hue, + 3, + false, + m_Language, + Name, + mutatedText ); if (length != mutBuffer.Length) @@ -6899,10 +6917,12 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro } } - var range = new Rectangle2D(m_Location.X - Core.GlobalMaxUpdateRange, + var range = new Rectangle2D( + m_Location.X - Core.GlobalMaxUpdateRange, m_Location.Y - Core.GlobalMaxUpdateRange, Core.GlobalMaxUpdateRange * 2 + 1, - Core.GlobalMaxUpdateRange * 2 + 1); + Core.GlobalMaxUpdateRange * 2 + 1 + ); foreach (var multi in m_Map.GetMultisInBounds(range)) { @@ -8072,7 +8092,8 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro m_Map == null ? Map.MobileBoundsEnumerable.Empty : m_Map.GetMobilesInRange(m_Location, range); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Map.ClientAtEnumerable GetClientsAt() => m_Map == null ? Map.ClientAtEnumerable.Empty : Map.GetClientsAt(m_Location); + public Map.ClientAtEnumerable GetClientsAt() => + m_Map == null ? Map.ClientAtEnumerable.Empty : Map.GetClientsAt(m_Location); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Map.ClientBoundsEnumerable GetClientsInRange(int range) => @@ -8852,7 +8873,16 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro ) { var length = OutgoingMessagePackets.CreateMessage( - buffer, Serial, Body, type, hue, 3, ascii, Language, Name, text + buffer, + Serial, + Body, + type, + hue, + 3, + ascii, + Language, + Name, + text ); if (length != buffer.Length) @@ -8879,7 +8909,15 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro if (state.Mobile.CanSee(this) && (noLineOfSight || state.Mobile.InLOS(this))) { var length = OutgoingMessagePackets.CreateMessageLocalized( - buffer, Serial, Body, type, hue, 3, number, Name, args + buffer, + Serial, + Body, + type, + hue, + 3, + number, + Name, + args ); if (length != buffer.Length) @@ -8915,7 +8953,17 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro ) { var length = OutgoingMessagePackets.CreateMessageLocalizedAffix( - buffer, Serial, Body, type, hue, 3, number, Name, affixType, affix, args + buffer, + Serial, + Body, + type, + hue, + 3, + number, + Name, + affixType, + affix, + args ); if (length != buffer.Length) @@ -8959,7 +9007,15 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro if (state != m_NetState && state.Mobile.CanSee(this)) { var length = OutgoingMessagePackets.CreateMessageLocalized( - buffer, Serial, Body, type, hue, 3, number, Name, args + buffer, + Serial, + Body, + type, + hue, + 3, + number, + Name, + args ); if (length != buffer.Length) @@ -8986,7 +9042,16 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro if (state != m_NetState && state.Mobile.CanSee(this)) { var length = OutgoingMessagePackets.CreateMessage( - buffer, Serial, Body, type, hue, 3, ascii, Language, Name, text + buffer, + Serial, + Body, + type, + hue, + 3, + ascii, + Language, + Name, + text ); if (length != buffer.Length) diff --git a/Projects/UOContent/Engines/ConPVP/DuelContext.cs b/Projects/UOContent/Engines/ConPVP/DuelContext.cs index c44bb85c2..6004b6ba3 100644 --- a/Projects/UOContent/Engines/ConPVP/DuelContext.cs +++ b/Projects/UOContent/Engines/ConPVP/DuelContext.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Engines.PartySystem; using Server.Factions; using Server.Gumps; @@ -596,6 +597,9 @@ namespace Server.Engines.ConPVP } } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeath(PlayerMobile m) => m.DuelContext?.OnDeath(m, m.Corpse); + public void OnDeath(Mobile mob, Container corpse) { if (!Registered || !Started) @@ -1843,7 +1847,7 @@ namespace Server.Engines.ConPVP } TransformationSpellHelper.RemoveContext(mob, true); - AnimalForm.RemoveContext(mob, true); + AnimalForm.RemoveContext(mob); DisguisePersistence.StopTimer(mob); if (!mob.CanBeginAction()) diff --git a/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs b/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs index b028ddc85..d583c6be7 100644 --- a/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs +++ b/Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using ModernUO.CodeGeneratedEvents; using Server.Commands; using Server.Commands.Generic; using Server.Engines.MLQuests.Gumps; @@ -611,6 +612,7 @@ namespace Server.Engines.MLQuests return context; } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void HandleDeath(PlayerMobile pm) { var context = GetContext(pm); diff --git a/Projects/UOContent/Engines/Party/Party.cs b/Projects/UOContent/Engines/Party/Party.cs index 23988158a..e474885c8 100644 --- a/Projects/UOContent/Engines/Party/Party.cs +++ b/Projects/UOContent/Engines/Party/Party.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Factions; +using Server.Mobiles; using Server.Network; using Server.Targeting; @@ -99,7 +101,6 @@ namespace Server.Engines.PartySystem public static void Configure() { EventSink.Logout += EventSink_Logout; - EventSink.PlayerDeath += EventSink_PlayerDeath; CommandSystem.Register("ListenToParty", AccessLevel.GameMaster, ListenToParty_OnCommand); } @@ -135,7 +136,8 @@ namespace Server.Engines.PartySystem } } - public static void EventSink_PlayerDeath(Mobile from) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(Mobile from) { var p = Get(from); diff --git a/Projects/UOContent/Engines/Player Murder System/ReportMurdererGump.cs b/Projects/UOContent/Engines/Player Murder System/ReportMurdererGump.cs index 770444439..31b4a6bc3 100644 --- a/Projects/UOContent/Engines/Player Murder System/ReportMurdererGump.cs +++ b/Projects/UOContent/Engines/Player Murder System/ReportMurdererGump.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Gumps; using Server.Misc; using Server.Mobiles; @@ -26,16 +27,16 @@ public class ReportMurdererGump : StaticGump public static void Initialize() { _recentlyReportedDelay = ServerConfiguration.GetOrUpdateSetting("murderSystem.recentlyReportedDelay", TimeSpan.FromMinutes(10)); - EventSink.PlayerDeath += OnPlayerDeath; } - public static void OnPlayerDeath(Mobile m) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(PlayerMobile m) { List killers = null; HashSet toGive = null; // Guards won't take reports of the death of a thief! - bool notInThievesGuild = m is not PlayerMobile { NpcGuild: NpcGuild.ThievesGuild }; + bool notInThievesGuild = m.NpcGuild != NpcGuild.ThievesGuild; foreach (var ai in m.Aggressors) { diff --git a/Projects/UOContent/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs b/Projects/UOContent/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs index 30e41249e..9f27c75ae 100644 --- a/Projects/UOContent/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs +++ b/Projects/UOContent/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using ModernUO.Serialization; using Server.Events.Halloween; using Server.Items; @@ -60,15 +61,13 @@ namespace Server.Engines.Events { _timer = Timer.DelayCall(tick, 0, Timer_Callback); _clearTimer = Timer.DelayCall(clear, 0, Clear_Callback); - - EventSink.PlayerDeath += EventSink_PlayerDeath; } } - public static void EventSink_PlayerDeath(Mobile m) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(PlayerMobile pm) { - if (m is PlayerMobile { Deleted: false } pm && - _timer.Running && !_deathQueue.Contains(pm) && _deathQueue.Count < m_DeathQueueLimit) + if (_timer.Running && !_deathQueue.Contains(pm) && _deathQueue.Count < m_DeathQueueLimit) { _deathQueue.Add(pm); } diff --git a/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs b/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs index a6cd023a1..9675ed68b 100644 --- a/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs +++ b/Projects/UOContent/Items/Skill Items/Thief/DisguisePersistence.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Mobiles; namespace Server.Items; @@ -69,6 +70,7 @@ public class DisguisePersistence : GenericPersistence t.Stop(); } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void RemoveTimer(Mobile m) { if (Timers.Remove(m, out var t)) diff --git a/Projects/UOContent/Items/Special/8th Anniversary Items/Talismans.cs b/Projects/UOContent/Items/Special/8th Anniversary Items/Talismans.cs index 83cf1ff95..091cc242b 100644 --- a/Projects/UOContent/Items/Special/8th Anniversary Items/Talismans.cs +++ b/Projects/UOContent/Items/Special/8th Anniversary Items/Talismans.cs @@ -36,7 +36,7 @@ public partial class BaseFormTalisman : Item if (parent is Mobile m) { - AnimalForm.RemoveContext(m, true); + AnimalForm.RemoveContext(m); } } diff --git a/Projects/UOContent/Misc/AOS.cs b/Projects/UOContent/Misc/AOS.cs index dbead8fdf..ec8c09b84 100644 --- a/Projects/UOContent/Misc/AOS.cs +++ b/Projects/UOContent/Misc/AOS.cs @@ -1248,7 +1248,7 @@ namespace Server if (m.Skills.Ninjitsu.Value < AnimalForm.Entries[i].ReqSkill) { - AnimalForm.RemoveContext(m, true); + AnimalForm.RemoveContext(m); } } diff --git a/Projects/UOContent/Misc/Guild.cs b/Projects/UOContent/Misc/Guild.cs index ee6eaf04b..3c9707160 100644 --- a/Projects/UOContent/Misc/Guild.cs +++ b/Projects/UOContent/Misc/Guild.cs @@ -1050,7 +1050,7 @@ namespace Server.Guilds } } - public static void HandleDeath(Mobile victim, Mobile killer = null) + public static void HandleDeath(Mobile victim, Mobile killer) { if (!NewGuildSystem) { diff --git a/Projects/UOContent/Mobiles/BaseCreature.cs b/Projects/UOContent/Mobiles/BaseCreature.cs index 2cc3adea1..b6558209a 100644 --- a/Projects/UOContent/Mobiles/BaseCreature.cs +++ b/Projects/UOContent/Mobiles/BaseCreature.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using ModernUO.CodeGeneratedEvents; using Server.Collections; using Server.ContextMenus; using Server.Engines.ConPVP; @@ -155,7 +156,7 @@ namespace Server.Mobiles } } - public abstract class BaseCreature : Mobile, IHonorTarget, IQuestGiver + public abstract partial class BaseCreature : Mobile, IHonorTarget, IQuestGiver { public enum Allegiance { @@ -3248,10 +3249,11 @@ namespace Server.Mobiles } } + [GeneratedEvent(nameof(CreatureDeathEvent))] + public static partial void CreatureDeathEvent(Mobile m); + public override void OnDeath(Container c) { - MeerMage.StopEffect(this, false); - if (IsBonded) { Effects.PlaySound(this, GetDeathSound()); @@ -3312,7 +3314,7 @@ namespace Server.Mobiles OwnerAbandonTime = DateTime.MinValue; } - GiftOfLifeSpell.HandleDeath(this); + CreatureDeathEvent(this); CheckStatTimers(); return; @@ -3435,6 +3437,8 @@ namespace Server.Mobiles { c.Delete(); } + + CreatureDeathEvent(this); } public override void OnDelete() diff --git a/Projects/UOContent/Mobiles/Healers/PricedHealer.cs b/Projects/UOContent/Mobiles/Healers/PricedHealer.cs index fdf127374..c214a8cab 100644 --- a/Projects/UOContent/Mobiles/Healers/PricedHealer.cs +++ b/Projects/UOContent/Mobiles/Healers/PricedHealer.cs @@ -1,5 +1,4 @@ using ModernUO.Serialization; -using Server.Gumps; namespace Server.Mobiles; diff --git a/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs b/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs index 4de259a0a..f8e3ea8a7 100644 --- a/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs +++ b/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using ModernUO.Serialization; using Server.Items; @@ -65,12 +66,8 @@ namespace Server.Mobiles public override bool BardImmune => true; public override Poison PoisonImmune => Poison.Lethal; - public new static void Initialize() - { - EventSink.PlayerDeath += EventSink_PlayerDeath; - } - - public static void EventSink_PlayerDeath(Mobile m) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(Mobile m) { var lastKiller = m.LastKiller; diff --git a/Projects/UOContent/Mobiles/Monsters/LBR/Meers/MeerMage.cs b/Projects/UOContent/Mobiles/Monsters/LBR/Meers/MeerMage.cs index c34c9b9ab..178436fb9 100644 --- a/Projects/UOContent/Mobiles/Monsters/LBR/Meers/MeerMage.cs +++ b/Projects/UOContent/Mobiles/Monsters/LBR/Meers/MeerMage.cs @@ -1,6 +1,7 @@ using ModernUO.Serialization; using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Items; namespace Server.Mobiles @@ -152,7 +153,9 @@ namespace Server.Mobiles public static bool UnderEffect(Mobile m) => m_Table.ContainsKey(m); - public static void StopEffect(Mobile m, bool message) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + [OnEvent(nameof(CreatureDeathEvent))] + public static void StopEffect(Mobile m, bool message = false) { if (m_Table.Remove(m, out var timer)) { @@ -170,7 +173,7 @@ namespace Server.Mobiles { if (!m.Alive) { - StopEffect(m, false); + StopEffect(m); return; } @@ -197,7 +200,7 @@ namespace Server.Mobiles if (!m.Alive) { - StopEffect(m, false); + StopEffect(m); } } } diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index b88f3a9fb..61b1a01ad 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Accounting; using Server.Collections; using Server.ContextMenus; @@ -34,7 +35,6 @@ using Server.Spells.Mysticism; using Server.Spells.Necromancy; using Server.Spells.Ninjitsu; using Server.Spells.Second; -using Server.Spells.Seventh; using Server.Spells.Sixth; using Server.Spells.Spellweaving; using Server.Targeting; @@ -97,7 +97,7 @@ namespace Server.Mobiles DismountRecovery = 1070859 // You cannot mount while recovering from a dismount special maneuver. } - public class PlayerMobile : Mobile, IHonorTarget, IHasSteps + public partial class PlayerMobile : Mobile, IHonorTarget, IHasSteps { private static bool m_NoRecursion; @@ -1089,7 +1089,7 @@ namespace Server.Mobiles } else if (AnimalForm.UnderTransformation(this)) { - AnimalForm.RemoveContext(this, true); + AnimalForm.RemoveContext(this); } } @@ -2549,6 +2549,9 @@ namespace Server.Mobiles return res; } + [GeneratedEvent(nameof(PlayerDeathEvent))] + public static partial void PlayerDeathEvent(PlayerMobile m); + public override void OnDeath(Container c) { if (m_NonAutoreinsuredItems > 0) @@ -2563,27 +2566,14 @@ namespace Server.Mobiles HueMod = -1; NameMod = null; SavagePaintExpiration = TimeSpan.Zero; - SetHairMods(-1, -1); - PolymorphSpell.StopTimer(this); - IncognitoSpell.StopTimer(this); - DisguisePersistence.RemoveTimer(this); - AnimalForm.RemoveContext(this, true); - - EndAction(); - EndAction(); - - MeerMage.StopEffect(this, false); - if (Flying) { Flying = false; BuffInfo.RemoveBuff(this, BuffIcon.Fly); } - StolenItem.ReturnOnDeath(this, c); - if (PermaFlags.Count > 0) { PermaFlags.Clear(); @@ -2669,10 +2659,6 @@ namespace Server.Mobiles Guilds.Guild.HandleDeath(this, killer); - MLQuestSystem.HandleDeath(this); - - DuelContext?.OnDeath(this, c); - if (m_BuffTable != null) { using var queue = PooledRefQueue.Create(); @@ -2690,6 +2676,8 @@ namespace Server.Mobiles RemoveBuff(queue.Dequeue()); } } + + PlayerDeathEvent(this); } public override bool MutateSpeech(List hears, ref string text, ref object context) diff --git a/Projects/UOContent/Skills/Stealing.cs b/Projects/UOContent/Skills/Stealing.cs index 760dfed43..c0459a621 100644 --- a/Projects/UOContent/Skills/Stealing.cs +++ b/Projects/UOContent/Skills/Stealing.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Engines.ConPVP; using Server.Engines.Stealables; using Server.Factions; @@ -465,10 +466,13 @@ namespace Server.SkillHandlers return false; } - public static void ReturnOnDeath(Mobile killed, Container corpse) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void ReturnOnDeath(Mobile killed) { Clean(); + var corpse = killed.Corpse; + foreach (var si in m_Queue) { if (si.Stolen.RootParent == corpse && si.Victim != null && !si.IsExpired) diff --git a/Projects/UOContent/Spells/Fifth/Incognito.cs b/Projects/UOContent/Spells/Fifth/Incognito.cs index 68797a656..a1092a307 100644 --- a/Projects/UOContent/Spells/Fifth/Incognito.cs +++ b/Projects/UOContent/Spells/Fifth/Incognito.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Factions; using Server.Items; using Server.Mobiles; @@ -124,6 +125,13 @@ namespace Server.Spells.Fifth FinishSequence(); } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(Mobile m) + { + StopTimer(m); + m.EndAction(); + } + public static void StopTimer(Mobile m) { if (_table.Remove(m, out var timerToken)) diff --git a/Projects/UOContent/Spells/Mysticism/SpellPlagueSpell.cs b/Projects/UOContent/Spells/Mysticism/SpellPlagueSpell.cs index 360dad773..f1ed5d675 100644 --- a/Projects/UOContent/Spells/Mysticism/SpellPlagueSpell.cs +++ b/Projects/UOContent/Spells/Mysticism/SpellPlagueSpell.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; +using Server.Mobiles; using Server.Targeting; namespace Server.Spells.Mysticism; @@ -25,11 +27,6 @@ public class SpellPlagueSpell : MysticSpell, ITargetingSpell public override SpellCircle Circle => SpellCircle.Seventh; - public static void Initialize() - { - EventSink.PlayerDeath += OnPlayerDeath; - } - public override void OnCast() { Caster.Target = new SpellTarget(this, TargetFlags.Harmful); @@ -75,6 +72,7 @@ public class SpellPlagueSpell : MysticSpell, ITargetingSpell public static bool UnderEffect(Mobile m) => _table.ContainsKey(m); + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static bool RemoveEffect(Mobile m) { if (_table.Remove(m, out var timer)) @@ -95,8 +93,6 @@ public class SpellPlagueSpell : MysticSpell, ITargetingSpell } } - private static void OnPlayerDeath(Mobile m) => RemoveEffect(m); - private static void VisualEffect(Mobile to) { to.PlaySound(0x658); diff --git a/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs b/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs index 3648abb85..1820fecd0 100644 --- a/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs +++ b/Projects/UOContent/Spells/Mysticism/StoneFormSpell.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Factions; +using Server.Mobiles; using Server.Spells.Fifth; using Server.Spells.Ninjitsu; using Server.Spells.Seventh; @@ -26,11 +28,6 @@ namespace Server.Spells.Mysticism public override SpellCircle Circle => SpellCircle.Fourth; - public static void Initialize() - { - EventSink.PlayerDeath += OnPlayerDeath; - } - public static bool UnderEffect(Mobile m) => _table.ContainsKey(m); public override bool CheckCast() @@ -137,6 +134,7 @@ namespace Server.Spells.Mysticism FinishSequence(); } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] public static void RemoveEffects(Mobile m) { if (!_table.Remove(m, out var mods)) @@ -154,10 +152,5 @@ namespace Server.Spells.Mysticism BuffInfo.RemoveBuff(m, BuffIcon.StoneForm); } - - private static void OnPlayerDeath(Mobile m) - { - RemoveEffects(m); - } } } diff --git a/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs b/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs index c4588e4d8..857fea701 100644 --- a/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs +++ b/Projects/UOContent/Spells/Ninjitsu/AnimalForm.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Gumps; using Server.Items; using Server.Mobiles; @@ -135,7 +136,7 @@ public class AnimalForm : NinjaSpell } else if (context != null) { - RemoveContext(Caster, context, true); + RemoveContext(Caster, context); Caster.Mana -= mana; } else @@ -254,17 +255,18 @@ public class AnimalForm : NinjaSpell } } - public static void RemoveContext(Mobile m, bool resetGraphics) + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void RemoveContext(Mobile m) { var context = GetContext(m); if (context != null) { - RemoveContext(m, context, resetGraphics); + RemoveContext(m, context); } } - public static void RemoveContext(Mobile m, AnimalFormContext context, bool resetGraphics) + public static void RemoveContext(Mobile m, AnimalFormContext context) { _table.Remove(m); @@ -287,11 +289,8 @@ public class AnimalForm : NinjaSpell m.RemoveSkillMod(mod); } - if (resetGraphics) - { - m.HueMod = -1; - m.BodyMod = 0; - } + m.HueMod = -1; + m.BodyMod = 0; m.FixedParticles(0x3728, 10, 13, 2023, EffectLayer.Waist); @@ -517,7 +516,7 @@ public class AnimalFormTimer : Timer { if (_mobile.Deleted || !_mobile.Alive || _mobile.Body != _body || _mobile.Hue != _hue) { - AnimalForm.RemoveContext(_mobile, true); + AnimalForm.RemoveContext(_mobile); Stop(); return; } diff --git a/Projects/UOContent/Spells/Seventh/Polymorph.cs b/Projects/UOContent/Spells/Seventh/Polymorph.cs index 4505de7cc..448b3f95c 100644 --- a/Projects/UOContent/Spells/Seventh/Polymorph.cs +++ b/Projects/UOContent/Spells/Seventh/Polymorph.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Factions; using Server.Gumps; using Server.Items; +using Server.Mobiles; using Server.Spells.Fifth; namespace Server.Spells.Seventh @@ -184,6 +186,13 @@ namespace Server.Spells.Seventh FinishSequence(); } + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnPlayerDeathEvent(Mobile m) + { + StopTimer(m); + m.EndAction(); + } + public static void StopTimer(Mobile m) { if (_table.Remove(m, out var timer)) diff --git a/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs b/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs index 320fcc3fe..7118854b7 100644 --- a/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs +++ b/Projects/UOContent/Spells/Spellweaving/GiftOfLife.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ModernUO.CodeGeneratedEvents; using Server.Gumps; using Server.Mobiles; using Server.Targeting; @@ -70,17 +71,14 @@ namespace Server.Spells.Spellweaving } } - public static void Initialize() - { - EventSink.PlayerDeath += HandleDeath; - } - public override void OnCast() { Caster.Target = new SpellTarget(this, TargetFlags.Beneficial); } - public static void HandleDeath(Mobile m) + [OnEvent(nameof(BaseCreature.CreatureDeathEvent))] + [OnEvent(nameof(PlayerMobile.PlayerDeathEvent))] + public static void OnDeathEvent(Mobile m) { if (_table.ContainsKey(m)) { @@ -130,16 +128,6 @@ namespace Server.Spells.Spellweaving timer.DoExpire(); } - public static void OnLogin(Mobile m) - { - if (m?.Alive != false || _table[m] == null) - { - return; - } - - HandleDeath_OnCallback(m); - } - private class ExpireTimer : Timer { private Mobile _mobile; diff --git a/Projects/UOContent/UOContent.csproj b/Projects/UOContent/UOContent.csproj index 02d8700a0..9d1b616a0 100644 --- a/Projects/UOContent/UOContent.csproj +++ b/Projects/UOContent/UOContent.csproj @@ -42,6 +42,8 @@ + + diff --git a/version.json b/version.json index 43964a515..8c814674f 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.13.4" + "version": "0.13.5" }