refactor: store DecayResetTime via WriteDeltaTime pending the anchored-time port

Delta ticks at full precision instead of clamped whole minutes; the read
guard against LastMoved stays since LastMoved is still minute-rounded.
Swaps to Write/ReadAnchoredTime mechanically once the save-time anchor is
ported. Safe to reshape the v10 payload: no v10 saves exist yet.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kamron Batman 2026-08-22 11:52:03 -07:00
parent 867d440b5d
commit 251c1efce7
2 changed files with 8 additions and 7 deletions

View file

@ -325,9 +325,10 @@ public class DecayRegistrationTests
var copy = new Item(item.Serial); var copy = new Item(item.Serial);
copy.Deserialize(new BufferReader(writer.Buffer)); copy.Deserialize(new BufferReader(writer.Buffer));
// LastMoved persists as whole minutes; allow that much slack. // The stamp is stored as a delta, so it ages only by the real time between
// write and read - milliseconds here, the downtime in production.
Assert.True( Assert.True(
(copy.ScheduledDecayTime - expected).Duration() <= TimeSpan.FromMinutes(1), (copy.ScheduledDecayTime - expected).Duration() <= TimeSpan.FromSeconds(5),
"The restarted decay window must survive a save/load cycle." "The restarted decay window must survive a save/load cycle."
); );

View file

@ -1026,8 +1026,8 @@ public partial class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropert
if (GetSaveFlag(flags, SaveFlag.DecayReset)) if (GetSaveFlag(flags, SaveFlag.DecayReset))
{ {
var resetMinutes = new TimeSpan(now - info.m_DecayReset.Ticks).TotalMinutes; // Replace with WriteAnchoredTime once the save-time anchor is ported.
writer.WriteEncodedInt((int)Math.Clamp(resetMinutes, 0, int.MaxValue)); writer.WriteDeltaTime(info.m_DecayReset);
} }
if (GetSaveFlag(flags, SaveFlag.Direction)) if (GetSaveFlag(flags, SaveFlag.Direction))
@ -2778,10 +2778,10 @@ public partial class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropert
if (version >= 10 && GetSaveFlag(flags, SaveFlag.DecayReset)) if (version >= 10 && GetSaveFlag(flags, SaveFlag.DecayReset))
{ {
var reset = Core.Now - TimeSpan.FromMinutes(reader.ReadEncodedInt()); var reset = reader.ReadDeltaTime();
// Minute rounding can land the stamp on LastMoved; keep it only while it // LastMoved is stored at whole-minute precision; keep the stamp only
// extends the deadline. // while it still extends the deadline.
if (reset > LastMoved) if (reset > LastMoved)
{ {
DecayResetTime = reset; DecayResetTime = reset;