## Summary Phase 3 of the anchored-time work: **every actively-written delta-time value in the engine now stores an anchored timestamp** — absolute on the wire, shifted forward by the downtime at load. Remaining time survives restarts (as delta did), and unlike delta, the bytes do not change on every save, so an idle world serializes identically save after save. The answer to "is it possible everywhere": **yes** — including the one case that looked impossible. ## The GenericPersistence problem, solved `GenericPersistence` bins (`Virtues.bin`, `StealableArtifacts.bin`, …) are raw payloads with no idx header, so they have no anchor of their own — anchored reads there would silently apply zero shift. But the anchor is a property of the **save**, not the file: every file in one save shares one `World.SaveStartTime`, and `Persistence.Load` reads **all** entity indexes (phase 1) before **any** persistence payload (phase 2). So the idx v5 header stamps a save-wide `World.LoadTimeShift`, and generic persistence readers inherit it. No file-format change, no per-bin header, old bins unaffected. ## Converted - **Item v10 → v11**: `LastMoved` — previously whole-minute delta, rewritten every save for every item, the single largest source of idle-save churn — and `DecayResetTime` (retiring the TODO from #2583). **Mobile v37 → v38**: the three stat-gain stamps. **BaseCreature v20 → v21**: `SummonEnd`. - **17 code-generated classes** (`[DeltaDateTime]` → `[AnchoredDateTime]`, version bump + `MigrateFrom` each): the five field spells, TransientItem, VirtueContext (×7 fields), PuzzleChestSolutionAndTime, BaseCamp, BaseBoat, RentedVendor, PlayerVendor, Ethics Player, Sheep, StarRoomGate, ChampionSpawn (×3), Corpse (`TimeOfDeath`, v19). The `MigrateFrom` bodies were generated from each class's current migration schema and are compiler-verified; VirtueContext's save-flagged nullables fall back to the same defaults the old deserialize left in place. Corpse's six migrations moved to a new `Corpse.Migrations.cs`. - **Hand-written sites**: StealableArtifacts (v2), VendorInventory (v1), ML quest objectives (persistence v3) — each gated on its own version. **Not converted, deliberately**: the ~25 read-only `ReadDeltaTime` sites in legacy version fallbacks and migration replays — they decode existing old bytes and must never change. `[DeltaDateTime]`/`WriteDeltaTime` remain available for them. ## Verification - Build 0 errors / 0 warnings; **837 + 708 tests green**. - Schema regeneration produced exactly the 17 expected new `vN.json` files (all `AnchoredTime` rule args), nothing else touched. - **New acceptance tests** pin the point of the whole effort: serializing the same item at two save times **5 hours apart produces byte-identical output**, and `LastMoved`/`DecayResetTime` round-trip **exactly** at sub-minute precision (the old minutes encoding destroyed both properties). ## Notes for review - `LastMoved` grows from a 1–3 byte encoded minutes value to 8-byte ticks per item — the price of byte-stability; it repays itself in incremental-save behavior since unchanged items now produce unchanged bytes. - BaseEscortable-style semantics are unchanged: anchored shift preserves *remaining* time exactly, the same contract delta provided, so no gameplay-visible behavior changes — deadlines simply stop being consumed by downtime that delta already protected against, now with stable bytes. ## Enforcement `WriteDeltaTime` is now `[Obsolete]` (interface + implementation). With the repo's warnings-as-errors, any new delta-time write — hand-written or emitted by a still-unconverted `[DeltaDateTime]` field — fails the build, with the migration instructions in the message. That the full solution still builds with **zero warnings** is itself the proof no active delta writer survived the conversion. `ReadDeltaTime` deliberately stays un-attributed: its remaining callers decode existing old bytes and are correct forever; its XML docs now state the legacy-decode-only contract.
210 lines
4.6 KiB
C#
210 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ModernUO.Serialization;
|
|
using Server.Items;
|
|
using Server.Mobiles;
|
|
|
|
namespace Server.Multis;
|
|
|
|
[SerializationGenerator(2, false)]
|
|
public abstract partial class BaseCamp : BaseMulti
|
|
{
|
|
private void MigrateFrom(V1Content content)
|
|
{
|
|
_items = content.Items;
|
|
_mobiles = content.Mobiles;
|
|
_decayTime = content.DecayTime;
|
|
}
|
|
|
|
[Tidy]
|
|
[SerializableField(0, setter: "private")]
|
|
private List<Item> _items;
|
|
|
|
[Tidy]
|
|
[SerializableField(1, setter: "private")]
|
|
private List<Mobile> _mobiles;
|
|
|
|
[AnchoredDateTime]
|
|
[SerializableField(2, setter: "private")]
|
|
private DateTime _decayTime;
|
|
|
|
private TimeSpan _decayDelay;
|
|
private Timer _decayTimer;
|
|
private Timer _initTimer;
|
|
|
|
public BaseCamp(int multiID) : base(multiID)
|
|
{
|
|
_items = new List<Item>();
|
|
_mobiles = new List<Mobile>();
|
|
_decayDelay = TimeSpan.FromMinutes(30.0);
|
|
RefreshDecay(true);
|
|
|
|
_initTimer = Timer.DelayCall(TimeSpan.Zero, CheckAddComponents);
|
|
}
|
|
|
|
public virtual int EventRange => 10;
|
|
|
|
public TimeSpan DecayDelay
|
|
{
|
|
get => _decayDelay;
|
|
set
|
|
{
|
|
_decayDelay = value;
|
|
RefreshDecay(true);
|
|
}
|
|
}
|
|
|
|
public override bool HandlesOnMovement => true;
|
|
|
|
public void CheckAddComponents()
|
|
{
|
|
_initTimer = null;
|
|
|
|
if (Deleted)
|
|
{
|
|
return;
|
|
}
|
|
|
|
AddComponents();
|
|
}
|
|
|
|
public virtual void AddComponents()
|
|
{
|
|
}
|
|
|
|
public virtual void RefreshDecay(bool setDecayTime)
|
|
{
|
|
if (Deleted)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (setDecayTime)
|
|
{
|
|
_decayTime = Core.Now + _decayDelay;
|
|
}
|
|
|
|
_decayTimer?.Stop();
|
|
_decayTimer = Timer.DelayCall(_decayDelay, Delete);
|
|
}
|
|
|
|
public virtual void AddItem(Item item, int xOffset, int yOffset, int zOffset)
|
|
{
|
|
AddToItems(item);
|
|
|
|
var zavg = Map.GetAverageZ(X + xOffset, Y + yOffset);
|
|
item.MoveToWorld(new Point3D(X + xOffset, Y + yOffset, zavg + zOffset), Map);
|
|
}
|
|
|
|
public virtual void AddMobile(Mobile m, int wanderRange, int xOffset, int yOffset, int zOffset)
|
|
{
|
|
AddToMobiles(m);
|
|
|
|
var zavg = Map.GetAverageZ(X + xOffset, Y + yOffset);
|
|
var loc = new Point3D(X + xOffset, Y + yOffset, zavg + zOffset);
|
|
|
|
if (m is BaseCreature bc)
|
|
{
|
|
bc.RangeHome = wanderRange;
|
|
bc.Home = loc;
|
|
}
|
|
|
|
if (m is BaseVendor)
|
|
{
|
|
m.Direction = Direction.South;
|
|
}
|
|
|
|
m.MoveToWorld(loc, Map);
|
|
}
|
|
|
|
public virtual void OnEnter(Mobile m)
|
|
{
|
|
RefreshDecay(true);
|
|
}
|
|
|
|
public virtual void OnExit(Mobile m)
|
|
{
|
|
RefreshDecay(true);
|
|
}
|
|
|
|
public override void OnMovement(Mobile m, Point3D oldLocation)
|
|
{
|
|
var inOldRange = Utility.InRange(oldLocation, Location, EventRange);
|
|
var inNewRange = Utility.InRange(m.Location, Location, EventRange);
|
|
|
|
if (inNewRange && !inOldRange)
|
|
{
|
|
OnEnter(m);
|
|
}
|
|
else if (inOldRange && !inNewRange)
|
|
{
|
|
OnExit(m);
|
|
}
|
|
}
|
|
|
|
public override void OnAfterDelete()
|
|
{
|
|
base.OnAfterDelete();
|
|
|
|
for (var i = 0; i < _items.Count; ++i)
|
|
{
|
|
_items[i]?.Delete();
|
|
}
|
|
|
|
for (var i = 0; i < _mobiles.Count; ++i)
|
|
{
|
|
var mob = _mobiles[i];
|
|
|
|
if (mob != null && (mob.CantWalk || (mob as BaseCreature)?.IsPrisoner == false))
|
|
{
|
|
mob.Delete();
|
|
}
|
|
}
|
|
|
|
ClearItems();
|
|
ClearMobiles();
|
|
|
|
_decayTimer?.Stop();
|
|
_decayTimer = null;
|
|
|
|
_initTimer?.Stop();
|
|
_initTimer = null;
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
_items = reader.ReadEntityList<Item>();
|
|
_mobiles = reader.ReadEntityList<Mobile>();
|
|
_decayTime = reader.ReadDeltaTime();
|
|
}
|
|
|
|
[AfterDeserialization]
|
|
private void AfterDeserialization()
|
|
{
|
|
var remaining = _decayTime - Core.Now;
|
|
|
|
if (remaining > TimeSpan.Zero)
|
|
{
|
|
_decayDelay = remaining;
|
|
RefreshDecay(false);
|
|
}
|
|
else
|
|
{
|
|
Timer.DelayCall(TimeSpan.Zero, Delete);
|
|
return;
|
|
}
|
|
|
|
_initTimer = Timer.DelayCall(TimeSpan.Zero, CheckAddComponents);
|
|
}
|
|
}
|
|
|
|
[SerializationGenerator(0, false)]
|
|
public partial class LockableBarrel : LockableContainer
|
|
{
|
|
[Constructible]
|
|
public LockableBarrel() : base(0xE77)
|
|
{
|
|
}
|
|
|
|
public override double DefaultWeight => 1.0;
|
|
}
|