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

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

Merged
merged 1 commit into from
Jan 27, 2025
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
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
Loading