## 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.
133 lines
3.8 KiB
C#
133 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ModernUO.Serialization;
|
|
using Server.Mobiles;
|
|
|
|
namespace Server.Engines.PlayerMurderSystem;
|
|
|
|
[SerializationGenerator(2)]
|
|
public partial class MurderContext
|
|
{
|
|
[SerializableField(0)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private TimeSpan _shortTermElapse;
|
|
|
|
[SerializableField(1)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private TimeSpan _longTermElapse;
|
|
|
|
[SerializableField(2, allowFieldChange: nameof(AllowShortTermMurdersChange))]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private int _shortTermMurders;
|
|
|
|
private bool AllowShortTermMurdersChange(ref int value)
|
|
{
|
|
value = Math.Max(value, 0);
|
|
return true;
|
|
}
|
|
|
|
[SerializableField(3)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private int _pingPongs;
|
|
|
|
[SerializableField(4)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private int _bounty;
|
|
|
|
[SerializableField(5)]
|
|
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
|
private DateTime _lastMurderTime;
|
|
|
|
private void MigrateFrom(V0Content content)
|
|
{
|
|
_shortTermElapse = content.ShortTermElapse;
|
|
_longTermElapse = content.LongTermElapse;
|
|
_shortTermMurders = content.ShortTermMurders;
|
|
// Players already at >= 5 kills have crossed the threshold at least once
|
|
_pingPongs = _player.Kills >= 5 ? 1 : 0;
|
|
}
|
|
|
|
private void MigrateFrom(V1Content content)
|
|
{
|
|
_shortTermElapse = content.ShortTermElapse;
|
|
_longTermElapse = content.LongTermElapse;
|
|
_shortTermMurders = content.ShortTermMurders;
|
|
_pingPongs = content.PingPongs;
|
|
// _bounty defaults to 0
|
|
// Default to now so the bounty board date display is sensible for migrated contexts
|
|
_lastMurderTime = Core.Now;
|
|
}
|
|
|
|
[DirtyTrackingEntity]
|
|
public PlayerMobile _player;
|
|
|
|
public PlayerMobile Player => _player;
|
|
|
|
// Wall clock time for next short or long term expiration
|
|
internal DateTime _nextElapse;
|
|
|
|
public MurderContext(PlayerMobile player) => _player = player;
|
|
|
|
public void ResetKillTime()
|
|
{
|
|
var gameTime = _player.GameTime;
|
|
|
|
if (ShortTermMurders > 0)
|
|
{
|
|
ShortTermElapse = gameTime + PlayerMurderSystem.ShortTermMurderDuration;
|
|
}
|
|
|
|
if (_player.Kills > 0)
|
|
{
|
|
LongTermElapse = gameTime + PlayerMurderSystem.LongTermMurderDuration;
|
|
}
|
|
}
|
|
|
|
public void DecayKills()
|
|
{
|
|
var gameTime = _player.GameTime;
|
|
|
|
if (ShortTermMurders > 0 && _shortTermElapse < gameTime)
|
|
{
|
|
ShortTermElapse += PlayerMurderSystem.ShortTermMurderDuration;
|
|
--ShortTermMurders;
|
|
}
|
|
|
|
if (_player.Kills > 0 && _longTermElapse < gameTime)
|
|
{
|
|
LongTermElapse += PlayerMurderSystem.LongTermMurderDuration;
|
|
--_player.Kills;
|
|
}
|
|
}
|
|
|
|
public bool CanRemove() => _pingPongs <= 0 && _shortTermMurders <= 0 && _player.Kills <= 0;
|
|
|
|
public bool CheckStart()
|
|
{
|
|
_nextElapse = DateTime.MaxValue;
|
|
|
|
var now = Core.Now;
|
|
var gameTime = _player.GameTime;
|
|
|
|
if (ShortTermMurders > 0)
|
|
{
|
|
_nextElapse = now + (ShortTermElapse - gameTime);
|
|
}
|
|
|
|
if (_player.Kills > 0)
|
|
{
|
|
_nextElapse = Utility.Min(_nextElapse, now + (LongTermElapse - gameTime));
|
|
}
|
|
|
|
return _nextElapse != DateTime.MaxValue;
|
|
}
|
|
|
|
public class EqualityComparer : IEqualityComparer<MurderContext>
|
|
{
|
|
public static EqualityComparer Default { get; } = new ();
|
|
|
|
public bool Equals(MurderContext x, MurderContext y) => x?._player == y?._player;
|
|
|
|
public int GetHashCode(MurderContext context) => context._player?.GetHashCode() ?? 0;
|
|
}
|
|
}
|