fix: Fixes the wrong unit used for BuffIcon Timers (#2093)

This commit is contained in:
Kamron Batman 2025-01-26 22:17:03 -08:00 committed by GitHub
parent ea364237f0
commit f241a9dec0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 11 deletions

View file

@ -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 class BuffIconPackets
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);

View file

@ -4478,28 +4478,34 @@ namespace Server.Mobiles
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 @@ namespace Server.Mobiles
buffInfo.TitleCliloc,
buffInfo.SecondaryCliloc,
buffInfo.Args,
ticks
seconds
);
}