Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds PlayerDeathEvent and CreatureDeathEvent using CodeGeneratedEvents #1927

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crux of the change in this file.

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
6 changes: 5 additions & 1 deletion 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 Expand Up @@ -1843,7 +1847,7 @@ public static void Debuff(Mobile mob)
}

TransformationSpellHelper.RemoveContext(mob, true);
AnimalForm.RemoveContext(mob, true);
AnimalForm.RemoveContext(mob);
DisguisePersistence.StopTimer(mob);

if (!mob.CanBeginAction<PolymorphSpell>())
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
Loading
Loading