From f241a9dec0fd4b93b26c33994810572fba0b696d Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 26 Jan 2025 22:17:03 -0800 Subject: [PATCH] fix: Fixes the wrong unit used for BuffIcon Timers (#2093) --- .../Engines/BuffIcons/BuffIconPackets.cs | 11 +++++++--- Projects/UOContent/Mobiles/PlayerMobile.cs | 22 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Projects/UOContent/Engines/BuffIcons/BuffIconPackets.cs b/Projects/UOContent/Engines/BuffIcons/BuffIconPackets.cs index 61db36a5c..42a8bd080 100644 --- a/Projects/UOContent/Engines/BuffIcons/BuffIconPackets.cs +++ b/Projects/UOContent/Engines/BuffIcons/BuffIconPackets.cs @@ -6,7 +6,13 @@ namespace Server.Engines.BuffIcons; public static class BuffIconPackets { public static void SendAddBuffPacket( - this NetState ns, Serial mob, BuffIcon iconID, int titleCliloc, int secondaryCliloc, TextDefinition args, long ticks + this NetState ns, + Serial mob, + BuffIcon iconID, + int titleCliloc, + int secondaryCliloc, + TextDefinition args, + long seconds ) { if (ns.CannotSendPackets()) @@ -28,8 +34,7 @@ public static void SendAddBuffPacket( writer.Write((short)0x1); // command (0 = remove, 1 = add, 2 = data) writer.Write(0); - // Truncate to whole seconds - The packet should be delayed by the partial seconds and then sent "on the second" - writer.Write((short)(ticks / 1000)); + writer.Write((short)seconds); writer.Clear(3); writer.Write(titleCliloc); writer.Write(secondaryCliloc); diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 8b4e82603..d4861299e 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -4478,28 +4478,34 @@ public void SendAddBuffPacket(BuffInfo buffInfo) return; } - var duration = Utility.Max(buffInfo.Duration - (Core.Now - buffInfo.StartTime), TimeSpan.Zero).TotalSeconds; - var rounded = Math.Round(duration); - var offset = duration - rounded; + var duration = Utility.Max(buffInfo.Duration - (Core.Now - buffInfo.StartTime), TimeSpan.Zero); + if (duration == TimeSpan.Zero) + { + SendAddBuffPacket(buffInfo, 0); + return; + } + + var roundedSeconds = Math.Round(duration.TotalSeconds); + var offset = duration.TotalMilliseconds - roundedSeconds * TimeSpan.MillisecondsPerSecond; if (offset > 0) { - Timer.DelayCall(TimeSpan.FromSeconds(offset), () => + Timer.DelayCall(TimeSpan.FromMilliseconds(offset), () => { // They are still online, we still have the buff icon in the table, and it is the same buff icon if (NetState != null && m_BuffTable?.GetValueOrDefault(buffInfo.ID) == buffInfo) { - SendAddBuffPacket(buffInfo, (long)rounded); + SendAddBuffPacket(buffInfo, (long)roundedSeconds); } } ); } else // Round up, will be removed a little bit early by the server { - SendAddBuffPacket(buffInfo, (long)rounded); + SendAddBuffPacket(buffInfo, (long)roundedSeconds); } } - private void SendAddBuffPacket(BuffInfo buffInfo, long ticks) + private void SendAddBuffPacket(BuffInfo buffInfo, long seconds) { NetState.SendAddBuffPacket( Serial, @@ -4507,7 +4513,7 @@ private void SendAddBuffPacket(BuffInfo buffInfo, long ticks) buffInfo.TitleCliloc, buffInfo.SecondaryCliloc, buffInfo.Args, - ticks + seconds ); }