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.
This commit is contained in:
parent
d5984ce058
commit
95cd8749a3
26 changed files with 191 additions and 135 deletions
|
|
@ -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<IncognitoSpell>();
|
||||
}
|
||||
|
||||
public static void StopTimer(Mobile m)
|
||||
{
|
||||
if (_table.Remove(m, out var timerToken))
|
||||
|
|
|
|||
|
|
@ -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<Mobile>
|
|||
|
||||
public override SpellCircle Circle => SpellCircle.Seventh;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.PlayerDeath += OnPlayerDeath;
|
||||
}
|
||||
|
||||
public override void OnCast()
|
||||
{
|
||||
Caster.Target = new SpellTarget<Mobile>(this, TargetFlags.Harmful);
|
||||
|
|
@ -75,6 +72,7 @@ public class SpellPlagueSpell : MysticSpell, ITargetingSpell<Mobile>
|
|||
|
||||
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<Mobile>
|
|||
}
|
||||
}
|
||||
|
||||
private static void OnPlayerDeath(Mobile m) => RemoveEffect(m);
|
||||
|
||||
private static void VisualEffect(Mobile to)
|
||||
{
|
||||
to.PlaySound(0x658);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<PolymorphSpell>();
|
||||
}
|
||||
|
||||
public static void StopTimer(Mobile m)
|
||||
{
|
||||
if (_table.Remove(m, out var timer))
|
||||
|
|
|
|||
|
|
@ -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<Mobile>(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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue