## Why Delta world saves (only changed entities re-serialized during the freeze) need two things from content: `Serialize` must be pure, and an unchanged entity must produce identical bytes on every save. An audit of the tree found the places that break this today. This PR fixes them and adds a diagnostic that measures byte stability in a running world over real time. No wire format changes, no version bumps. ## What - **Guild**: `Serialize` ran the daily guildmaster recalculation (dictionary-order tie breaks, random picks, mutates another entity), war expiry, and the alliance leadership check on every save. That work now runs from `GuildMaintenanceTimer` (the former `WarTimer`, now started for both guild systems; the war and alliance checks are no-ops without the new guild system). - **BaseHouse**: the `DecayLevel` getter wrote `LastRefreshed` and advanced the dynamic decay stage on every read, so any undecayable house changed its persisted bytes whenever a sign, gump, or `[Props` looked at it. It is now a pure read; `UpdateDecay()` on the decay tick advances the stage and refreshes a house that leaves the undecayable state. - **Locked-down container contents decay through `DecayScheduler`** instead of a sweep inside `BaseHouse.Serialize`. `Item.CanDecay` now accepts a parent container whose new `Container.ContentsDecay` is true (locked down and not secure) when the content item is not itself locked down or secured; the `IsLockedDown`/`IsSecure` setters re-evaluate a container and its direct contents; `OnDecay` resolves the region from the world location. `BaseBoard`, `Aquarium` and `FishBowl` override `ContentsDecay` to false, matching the exclusions of the old sweep. Items already inside such containers are picked up at load, where every item re-evaluates its registration. The per-save O(all locked-down items) walk is gone; the work is now event driven. - **BraceletOfBinding**: the `Bound` getter nulled its backing field for a deleted target; it now returns null for a missing or deleted target without writing. - **`[SaveStability [delaySeconds=60] [sampleStride=1]`** (Administrator): hashes the serialized bytes of every entity in every registered entity persistence (`Persistence.EntityPersistences`, new), waits the delay in real time, hashes again, and reports per type how many records changed. Both passes are chunked under a 20 ms per-tick budget. Serializing twice inside one tick cannot see drift derived from `Core.Now`, which is frozen within a tick; the real-time wait is the point. On an idle shard the only legitimate churn is NPC movement and regeneration, so a static type with a high changed fraction is a serialization bug. `[SaveStability cancel` stops a run. Engine additions: `Container.ContentsDecay` / `UpdateContentsDecayRegistration()`, the `CanDecay`/`OnDecay` change above, and diagnostic-facing `IGenericEntityPersistence.Name`, `EntityCount`, `EnumerateEntities()`, and `Persistence.EntityPersistences`. ## Behaviour notes - Fealty recalculation now happens on the minute timer for both guild systems instead of at save time. - A house that becomes decayable is refreshed on its next decay tick rather than at the exact moment of transition (at most one minute later). - Contents of locked-down containers now decay on their own schedule (same `LastMoved + DecayTime` rule) instead of at the next world save after becoming due. ## Testing - New tests: `GuildSerializePurityTests`, `HouseDecayPurityTests`, `SaveStabilityTests` (stable entities hash identically after the clock advances; a clock-stamped record is reported by type only after the clock advances; the snapshot covers Items, Mobiles and Guilds). - `LockedDownContainerDecayTests` (Server.Tests): registration on drop, lock/secure/release transitions, excluded containers, nested containers, and decay on schedule through the scheduler. - Full suites: Server.Tests 855 passed, UOContent.Tests 765 passed.
173 lines
4.4 KiB
C#
173 lines
4.4 KiB
C#
using System;
|
|
using Server.Items;
|
|
using Xunit;
|
|
|
|
namespace Server.Tests;
|
|
|
|
[Collection("Sequential Server Tests")]
|
|
public class LockedDownContainerDecayTests
|
|
{
|
|
public LockedDownContainerDecayTests()
|
|
{
|
|
DecayScheduler.ResetForTests();
|
|
|
|
// Content assigns these at startup (BaseHouse); the engine tests have no content.
|
|
if (Item.LockedDownFlag == 0)
|
|
{
|
|
Item.LockedDownFlag = 1;
|
|
Item.SecureFlag = 2;
|
|
}
|
|
}
|
|
|
|
private class TestChest : Container
|
|
{
|
|
public TestChest() : base(0xE43)
|
|
{
|
|
}
|
|
}
|
|
|
|
private class KeepsContentsChest : Container
|
|
{
|
|
public KeepsContentsChest() : base(0xE43)
|
|
{
|
|
}
|
|
|
|
public override bool ContentsDecay => false;
|
|
}
|
|
|
|
private static Item NewLoot() => new Item(0x1F03) { Movable = true, Visible = true };
|
|
|
|
private static TestChest PlaceLockedDownChest(int x)
|
|
{
|
|
var chest = new TestChest { Movable = false };
|
|
chest.MoveToWorld(new Point3D(x, 100, 0), Map.Felucca);
|
|
chest.IsLockedDown = true;
|
|
return chest;
|
|
}
|
|
|
|
[Fact]
|
|
public void ItemDroppedIntoLockedDownContainer_IsTracked()
|
|
{
|
|
var chest = PlaceLockedDownChest(120);
|
|
var loot = NewLoot();
|
|
|
|
chest.AddItem(loot);
|
|
|
|
Assert.True(loot.CanDecay());
|
|
Assert.True(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void ItemInOrdinaryContainer_IsNotTracked()
|
|
{
|
|
var chest = new TestChest();
|
|
chest.MoveToWorld(new Point3D(121, 100, 0), Map.Felucca);
|
|
var loot = NewLoot();
|
|
|
|
chest.AddItem(loot);
|
|
|
|
Assert.False(loot.CanDecay());
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void LockingAndReleasingContainer_RegistersAndUnregistersContents()
|
|
{
|
|
var chest = new TestChest { Movable = false };
|
|
chest.MoveToWorld(new Point3D(122, 100, 0), Map.Felucca);
|
|
var loot = NewLoot();
|
|
chest.AddItem(loot);
|
|
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.IsLockedDown = true;
|
|
Assert.True(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.IsSecure = true; // secure containers keep their contents
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.IsSecure = false;
|
|
Assert.True(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.IsLockedDown = false;
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void ContainerThatKeepsContents_DoesNotTrackThem()
|
|
{
|
|
var board = new KeepsContentsChest { Movable = false };
|
|
board.MoveToWorld(new Point3D(123, 100, 0), Map.Felucca);
|
|
board.IsLockedDown = true;
|
|
var piece = NewLoot();
|
|
|
|
board.AddItem(piece);
|
|
|
|
Assert.False(DecayScheduler.IsRegistered(piece));
|
|
|
|
board.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void NestedContainerContents_AreNotTracked()
|
|
{
|
|
var chest = PlaceLockedDownChest(124);
|
|
var bag = new TestChest();
|
|
chest.AddItem(bag);
|
|
var loot = NewLoot();
|
|
bag.AddItem(loot);
|
|
|
|
Assert.True(DecayScheduler.IsRegistered(bag));
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void LockedDownItemInsideLockedDownContainer_IsNotTracked()
|
|
{
|
|
var chest = PlaceLockedDownChest(125);
|
|
var loot = NewLoot();
|
|
chest.AddItem(loot);
|
|
loot.IsLockedDown = true;
|
|
|
|
Assert.False(DecayScheduler.IsRegistered(loot));
|
|
|
|
chest.Delete();
|
|
}
|
|
|
|
[Fact]
|
|
public void TrackedContents_DecayOnSchedule()
|
|
{
|
|
var start = Core._now;
|
|
|
|
try
|
|
{
|
|
var chest = PlaceLockedDownChest(126);
|
|
var loot = NewLoot();
|
|
chest.AddItem(loot);
|
|
|
|
var deadline = start + loot.DecayTime + TimeSpan.FromMinutes(2);
|
|
for (var now = start; now <= deadline && !loot.Deleted; now += TimeSpan.FromMilliseconds(256))
|
|
{
|
|
Core._now = now;
|
|
DecayScheduler.ProcessTick(now);
|
|
}
|
|
|
|
Assert.True(loot.Deleted, "Contents of a locked-down container must decay.");
|
|
Assert.False(chest.Deleted, "The locked-down container itself must not decay.");
|
|
|
|
chest.Delete();
|
|
}
|
|
finally
|
|
{
|
|
Core._now = start;
|
|
}
|
|
}
|
|
}
|