## Why Delta world saves re-serialize an entity only when it has been marked dirty. An audit of the generated classes found three ways serialized state changes without a mark; this PR closes the ones that do not need a new generator package. ## What - **Custom `[SerializableProperty]` setters mark dirty.** Twelve hand-written setters assigned their backing field without `this.MarkDirty()`. `PlagueBeastLord.OpenedBy` was an auto-property carrying the attribute with no backing field at all; it is now a generated field with the same name, order and command-property exposure. - **Generated sub-objects are linked to their owner.** Without a `[DirtyTrackingEntity]` member the generator emits setters that mark nothing. Eight entity-owned sub-objects now carry the link and receive the owner through the constructor the generator calls: `BOBFilter` (owner is `IEntity`: a `PlayerMobile` or a `BulkOrderBook`), `BOBLargeSubEntry`, `PuzzleChestSolution` and `PuzzleChestSolutionAndTime`, `TalismanAttribute` (the random factories now take the talisman), `VendorItem`, `PlayerBBMessage`, `RaffleEntry`, `ShardPollOption`. Migration schemas were regenerated with the pinned tool; the only change is the value rule argument becoming `DeserializationRequiresParent`. - **BaseVendor uses the generator; restock amounts are no longer persisted.** The only state it wrote was which buy entries had grown restock amounts, packed by index into the live `SBInfos` tables. Restock is transient now and rebuilds on load; version 1 records are read and discarded through the legacy path. Every vendor subclass now serializes through a generated chain. ## Generator 4.1.0 This PR adopts SerializationGenerator 4.1.0 (modernuo/SerializationGenerator#55): SG3019/SG3020 diagnostics, `[VolatileSerializedState]`, `StopXxx()` timer helpers, and owner-constructor preference for sub-objects (so dictionary values are constructed with their owner; the 4.0.0 relink fallback is gone). `PlayerVendor.v3.json` gains `DeserializationRequiresParent` for its `VendorItem` values so the migration content struct constructs them with their vendor. SG3019 is an error under `TreatWarningsAsErrors` and generator diagnostics ignore pragmas, so the five contexts that live in whole-file player-keyed persistences (`ChampionTitle`, `ChampionTitleContext`, `MurderContext`, `VirtueContext`, `JailRecord`) now carry a `[DirtyTrackingEntity]` link to their `PlayerMobile`, which is where they will live once those blobs move onto the player record. `JailSystem.EmptyRecord` keeps a null player (`[CanBeNull]`). `ChampionTitle` needs both a context and a player constructor because the generator resolves the rule against the containing type but emits the call with the parent field; a comment in the file records this. ## Wire format Unchanged. No version bumps except `BaseVendor` 1 to 2 (which now writes nothing of its own). Schema diffs are rule-argument only (`DeserializationRequiresParent`). ## Testing Server.Tests 848 passed, UOContent.Tests 759 passed.
246 lines
5.6 KiB
C#
246 lines
5.6 KiB
C#
using System;
|
|
using ModernUO.Serialization;
|
|
|
|
namespace Server.Items;
|
|
|
|
[SerializationGenerator(3, false)]
|
|
public abstract partial class FillableContainer : LockableContainer
|
|
{
|
|
[SerializableField(1)]
|
|
[DeserializeTimer(nameof(DeserializeRespawnTimer))]
|
|
private Timer _respawnTimer;
|
|
|
|
private void DeserializeRespawnTimer(TimeSpan delay) => _respawnTimer = Timer.DelayCall(delay, Respawn);
|
|
|
|
private void MigrateFrom(V2Content content)
|
|
{
|
|
_contentType = content.ContentType;
|
|
|
|
if (content.RespawnTimerDelay != TimeSpan.MinValue)
|
|
{
|
|
DeserializeRespawnTimer(content.RespawnTimerDelay);
|
|
}
|
|
}
|
|
|
|
public FillableContainer(int itemID) : base(itemID)
|
|
{
|
|
Movable = false;
|
|
_contentType = FillableContentType.None;
|
|
}
|
|
|
|
public virtual int MinRespawnMinutes => 60;
|
|
public virtual int MaxRespawnMinutes => 90;
|
|
|
|
public virtual bool IsLockable => true;
|
|
public virtual bool IsTrappable => IsLockable;
|
|
|
|
public virtual int SpawnThreshold => 2;
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public DateTime NextRespawnTime => _respawnTimer?.Next ?? DateTime.MinValue;
|
|
|
|
[SerializableProperty(0)]
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public FillableContentType ContentType
|
|
{
|
|
get => _contentType;
|
|
set
|
|
{
|
|
if (_contentType == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ClearContents();
|
|
_contentType = value;
|
|
this.MarkDirty();
|
|
Respawn();
|
|
}
|
|
}
|
|
|
|
protected void ClearContents()
|
|
{
|
|
for (var i = Items.Count - 1; i >= 0; --i)
|
|
{
|
|
if (i < Items.Count)
|
|
{
|
|
Items[i].Delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnMapChange()
|
|
{
|
|
base.OnMapChange();
|
|
AcquireContent();
|
|
}
|
|
|
|
public override void OnLocationChange(Point3D oldLocation)
|
|
{
|
|
base.OnLocationChange(oldLocation);
|
|
AcquireContent();
|
|
}
|
|
|
|
public virtual void AcquireContent()
|
|
{
|
|
if (_contentType == FillableContentType.None)
|
|
{
|
|
_contentType = FillableContent.Acquire(GetWorldLocation(), Map);
|
|
}
|
|
|
|
if (_contentType != FillableContentType.None)
|
|
{
|
|
Respawn();
|
|
}
|
|
}
|
|
|
|
public override void LockPick(Mobile from)
|
|
{
|
|
base.LockPick(from);
|
|
CheckRespawn();
|
|
}
|
|
|
|
public override void OnItemRemoved(Item item)
|
|
{
|
|
CheckRespawn();
|
|
}
|
|
|
|
public override void OnAfterDelete()
|
|
{
|
|
base.OnAfterDelete();
|
|
|
|
_respawnTimer?.Stop();
|
|
_respawnTimer = null;
|
|
}
|
|
|
|
public int GetItemsCount()
|
|
{
|
|
var count = 0;
|
|
|
|
foreach (var item in Items)
|
|
{
|
|
count += item.Amount;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
public void CheckRespawn()
|
|
{
|
|
if (_respawnTimer?.Running == true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var delay = TimeSpan.FromMinutes(Utility.RandomMinMax(MinRespawnMinutes, MaxRespawnMinutes));
|
|
_respawnTimer = Timer.DelayCall(delay, Respawn);
|
|
}
|
|
|
|
public void Respawn()
|
|
{
|
|
_respawnTimer?.Stop();
|
|
_respawnTimer = null;
|
|
|
|
if (_contentType == FillableContentType.None || Deleted)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GenerateContent();
|
|
|
|
var level = FillableContent.Lookup(_contentType).Level;
|
|
|
|
if (IsLockable)
|
|
{
|
|
Locked = true;
|
|
|
|
var difficulty = (level - 1) * 30;
|
|
|
|
LockLevel = difficulty - 10;
|
|
MaxLockLevel = difficulty + 30;
|
|
RequiredSkill = difficulty;
|
|
}
|
|
|
|
if (IsTrappable && (level > 1 || Utility.Random(5) < 4))
|
|
{
|
|
TrapType = level > Utility.Random(5) ? TrapType.PoisonTrap : TrapType.ExplosionTrap;
|
|
TrapPower = level * Utility.RandomMinMax(10, 30);
|
|
TrapLevel = level;
|
|
}
|
|
else
|
|
{
|
|
TrapType = TrapType.None;
|
|
TrapPower = 0;
|
|
TrapLevel = 0;
|
|
}
|
|
}
|
|
|
|
protected virtual int GetSpawnCount()
|
|
{
|
|
var itemsCount = GetItemsCount();
|
|
|
|
if (itemsCount > SpawnThreshold)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var maxSpawnCount = (1 + SpawnThreshold - itemsCount) * 2;
|
|
|
|
return Utility.RandomMinMax(0, maxSpawnCount);
|
|
}
|
|
|
|
public virtual void GenerateContent()
|
|
{
|
|
if (_contentType == FillableContentType.None || Deleted)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var content = FillableContent.Lookup(_contentType);
|
|
|
|
var toSpawn = GetSpawnCount();
|
|
|
|
for (var i = 0; i < toSpawn; ++i)
|
|
{
|
|
var item = content.Construct();
|
|
|
|
if (item == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var list = Items;
|
|
|
|
for (var j = 0; j < list.Count; ++j)
|
|
{
|
|
var subItem = list[j];
|
|
|
|
if (subItem is not Container && subItem.StackWith(null, item, false))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!item.Deleted)
|
|
{
|
|
DropItem(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
_contentType = (FillableContentType)reader.ReadInt();
|
|
var respawnTimerNext = reader.ReadDeltaTime();
|
|
DeserializeRespawnTimer(respawnTimerNext == DateTime.MinValue ? TimeSpan.MinValue : respawnTimerNext - Core.Now);
|
|
}
|
|
|
|
[AfterDeserialization]
|
|
private void AfterDeserialization()
|
|
{
|
|
if (_respawnTimer?.Running != true)
|
|
{
|
|
CheckRespawn();
|
|
}
|
|
}
|
|
}
|