Skip to content

Commit

Permalink
fix: Fixes the wrong unit used for BuffIcon Timers (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman authored Jan 27, 2025
1 parent ea36423 commit f241a9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
11 changes: 8 additions & 3 deletions Projects/UOContent/Engines/BuffIcons/BuffIconPackets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions Projects/UOContent/Mobiles/PlayerMobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4478,36 +4478,42 @@ 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,
buffInfo.ID,
buffInfo.TitleCliloc,
buffInfo.SecondaryCliloc,
buffInfo.Args,
ticks
seconds
);
}

Expand Down

0 comments on commit f241a9d

Please sign in to comment.