fix: Fixes TimeSpan rounding issues (#1610)

### Summary

TLDR - .NET Framework rounded TimeSpan (and some DateTime) methods to the nearest millisecond. This was actually _expected_ accidentally for parts of RunUO.

We are aiming to fix this and clean up some other bad assumptions.

Closes #1604
This commit is contained in:
Kamron Batman 2023-11-22 18:03:56 -08:00 • committed by GitHub
parent 98727d13b3
commit 331f24cb71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 91 additions and 87 deletions

View file

@ -4506,7 +4506,23 @@ namespace Server.Mobiles
if (NetState?.BuffIcon == true)
{
b.SendAddBuffPacket(NetState, Serial);
// Synchronize the buff icon as close to _on the second_ as we can.
var msecs = b.TimeLength.Milliseconds;
if (msecs >= 8)
{
Timer.DelayCall(TimeSpan.FromMilliseconds(msecs), (buffInfo, pm) =>
{
// They are still online, we still have the buff icon in the table, and it is the same buff icon
if (pm.NetState != null && pm.m_BuffTable.TryGetValue(buffInfo.ID, out var checkBuff) && checkBuff == buffInfo)
{
buffInfo.SendAddBuffPacket(pm.NetState, pm.Serial);
}
}, b, this);
}
else
{
b.SendAddBuffPacket(NetState, Serial);
}
}
}

View file

@ -1451,56 +1451,51 @@ namespace Server.Mobiles
public override void OnClick()
{
if (m_Vendor.SupportsBulkOrders(m_From))
if (!m_Vendor.SupportsBulkOrders(m_From))
{
var ts = m_Vendor.GetNextBulkOrder(m_From);
return;
}
var totalSeconds = (int)ts.TotalSeconds;
var totalHours = (totalSeconds + 3599) / 3600;
var totalMinutes = (totalSeconds + 59) / 60;
var ts = m_Vendor.GetNextBulkOrder(m_From);
if (Core.SE ? totalMinutes == 0 : totalHours == 0)
var totalSeconds = ts.TotalSeconds;
// Let them get a bulk order if they are within 1 second.
if (totalSeconds < 1)
{
m_From.SendLocalizedMessage(1049038); // You can get an order now.
if (Core.AOS)
{
m_From.SendLocalizedMessage(1049038); // You can get an order now.
var bulkOrder = m_Vendor.CreateBulkOrder(m_From, true);
if (Core.AOS)
if (bulkOrder is LargeBOD bod)
{
var bulkOrder = m_Vendor.CreateBulkOrder(m_From, true);
if (bulkOrder is LargeBOD bod)
{
m_From.SendGump(new LargeBODAcceptGump(m_From, bod));
}
else if (bulkOrder is SmallBOD smallBod)
{
m_From.SendGump(new SmallBODAcceptGump(m_From, smallBod));
}
m_From.SendGump(new LargeBODAcceptGump(m_From, bod));
}
else if (bulkOrder is SmallBOD smallBod)
{
m_From.SendGump(new SmallBODAcceptGump(m_From, smallBod));
}
}
}
else
{
var oldSpeechHue = m_Vendor.SpeechHue;
m_Vendor.SpeechHue = 0x3B2;
if (Core.SE)
{
// An offer may be available in about ~1_minutes~ minutes.
m_Vendor.SayTo(m_From, 1072058, $"{Math.Ceiling(totalSeconds / 60):F0}");
}
else
{
var oldSpeechHue = m_Vendor.SpeechHue;
m_Vendor.SpeechHue = 0x3B2;
if (Core.SE)
{
m_Vendor.SayTo(
m_From,
1072058,
totalMinutes.ToString()
); // An offer may be available in about ~1_minutes~ minutes.
}
else
{
m_Vendor.SayTo(
m_From,
1049039,
totalHours.ToString()
); // An offer may be available in about ~1_hours~ hours.
}
m_Vendor.SpeechHue = oldSpeechHue;
// An offer may be available in about ~1_hours~ hours.
m_Vendor.SayTo(m_From, 1049039, $"{Math.Ceiling(totalSeconds / 3600):F0}");
}
m_Vendor.SpeechHue = oldSpeechHue;
}
}
}