Skip to content

Commit

Permalink
feat: Adds PlayerDeathEvent and CreatureDeathEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
IcculusC authored and kamronbatman committed Sep 6, 2024
1 parent d5984ce commit 9125e76
Show file tree
Hide file tree
Showing 25 changed files with 197 additions and 123 deletions.
8 changes: 0 additions & 8 deletions Projects/Server/Events/EventSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ public static partial class EventSink
public static event Action<Mobile> Disconnected;
public static void InvokeDisconnected(Mobile m) => Disconnected?.Invoke(m);

public static event Action<Mobile> PlayerDeath;
public static void InvokePlayerDeath(Mobile m) => PlayerDeath?.Invoke(m);

public static event Action<Mobile, int> VirtueMacroRequest;

public static void InvokeVirtueMacroRequest(Mobile mobile, int virtueID) =>
VirtueMacroRequest?.Invoke(mobile, virtueID);

public static event Action<Mobile, Mobile> PaperdollRequest;

public static void InvokePaperdollRequest(Mobile beholder, Mobile beheld) =>
Expand Down
1 change: 0 additions & 1 deletion Projects/Server/Items/VirtualHair.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using ModernUO.Serialization;
using Server.Network;

Expand Down
131 changes: 98 additions & 33 deletions Projects/Server/Mobiles/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@ public virtual void ProcessDelta()
Layer.FacialHair
);
}

ourState.Send(facialHairPacket);
}

Expand Down Expand Up @@ -2984,6 +2985,7 @@ public virtual void ProcessDelta()
Layer.FacialHair
);
}

state.Send(facialHairPacket);
}

Expand Down Expand Up @@ -3429,7 +3431,6 @@ public virtual void ValidateSkillMods()
Skills[mod.Skill]?.Update();
}
}

}

public virtual void AddSkillMod(SkillMod mod)
Expand Down Expand Up @@ -4826,37 +4827,34 @@ public virtual void OnDeath(Container c)
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;
Expand Down Expand Up @@ -5070,7 +5068,8 @@ public virtual void Lift(Item item, int amount, out bool rejected, out LRReason
{
var rootItem = root as Item;

Span<byte> buffer = stackalloc byte[OutgoingPlayerPackets.DragEffectPacketLength].InitializePacket();
Span<byte> buffer = stackalloc byte[OutgoingPlayerPackets.DragEffectPacketLength]
.InitializePacket();

foreach (var ns in map.GetClientsInRange(from.Location))
{
Expand Down Expand Up @@ -5588,7 +5587,8 @@ public virtual void DoSpeech(string text, int[] keywords, MessageType type, int
ProcessDelta();

Span<byte> regBuffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)].InitializePacket();
Span<byte> mutBuffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(mutatedText)].InitializePacket();
Span<byte> mutBuffer =
stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(mutatedText)].InitializePacket();

// TODO: Should this be sorted like onSpeech is below?
for (var i = 0; i < hears.Count; ++i)
Expand All @@ -5598,7 +5598,16 @@ public virtual void DoSpeech(string text, int[] keywords, MessageType type, int
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)
Expand All @@ -5612,7 +5621,16 @@ public virtual void DoSpeech(string text, int[] keywords, MessageType type, int
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)
Expand Down Expand Up @@ -6899,10 +6917,12 @@ public void SendEverything()
}
}

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))
{
Expand Down Expand Up @@ -8072,7 +8092,8 @@ public Map.MobileBoundsEnumerable<T> GetMobilesInRange<T>(int range) where T : M
m_Map == null ? Map.MobileBoundsEnumerable<T>.Empty : m_Map.GetMobilesInRange<T>(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) =>
Expand Down Expand Up @@ -8852,7 +8873,16 @@ public void PublicOverheadMessage(
)
{
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)
Expand All @@ -8879,7 +8909,15 @@ public void PublicOverheadMessage(MessageType type, int hue, int number, string
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)
Expand Down Expand Up @@ -8915,7 +8953,17 @@ public void PublicOverheadMessage(
)
{
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)
Expand Down Expand Up @@ -8959,7 +9007,15 @@ public void NonlocalOverheadMessage(MessageType type, int hue, int number, strin
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)
Expand All @@ -8986,7 +9042,16 @@ public void NonlocalOverheadMessage(MessageType type, int hue, bool ascii, strin
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)
Expand Down
4 changes: 4 additions & 0 deletions Projects/UOContent/Engines/ConPVP/DuelContext.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -596,6 +597,9 @@ public void OnLocationChanged(Mobile mob)
}
}

[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)
Expand Down
2 changes: 2 additions & 0 deletions Projects/UOContent/Engines/ML Quests/MLQuestSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -611,6 +612,7 @@ public static MLQuestContext GetOrCreateContext(PlayerMobile pm)
return context;
}

[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
public static void HandleDeath(PlayerMobile pm)
{
var context = GetContext(pm);
Expand Down
6 changes: 4 additions & 2 deletions Projects/UOContent/Engines/Party/Party.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -99,7 +101,6 @@ public void OnStatsQuery(Mobile beholder, Mobile beheld)
public static void Configure()
{
EventSink.Logout += EventSink_Logout;
EventSink.PlayerDeath += EventSink_PlayerDeath;

CommandSystem.Register("ListenToParty", AccessLevel.GameMaster, ListenToParty_OnCommand);
}
Expand Down Expand Up @@ -135,7 +136,8 @@ public static void ListenToParty_OnTarget(Mobile from, object obj)
}
}

public static void EventSink_PlayerDeath(Mobile from)
[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
public static void OnPlayerDeathEvent(Mobile from)
{
var p = Get(from);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Gumps;
using Server.Misc;
using Server.Mobiles;
Expand All @@ -26,16 +27,16 @@ private ReportMurdererGump(List<Mobile> killers, int idx = 0) : base(0, 0)
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<Mobile> killers = null;
HashSet<Mobile> 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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Events.Halloween;
using Server.Items;
Expand Down Expand Up @@ -60,15 +61,13 @@ public static void Initialize()
{
_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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;

namespace Server.Items;
Expand Down Expand Up @@ -69,6 +70,7 @@ public static void StopTimer(Mobile m)
t.Stop();
}

[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
public static void RemoveTimer(Mobile m)
{
if (Timers.Remove(m, out var t))
Expand Down
Loading

0 comments on commit 9125e76

Please sign in to comment.