ModernUO/Distribution/Data/Spawns/shared/trammel/TramCropsLS.json
Kamron Batman d8a64f3316
refactor(spawners): replace DynamicJson with typed SpawnerDto records (#2505)
## Summary

Removes the dated `DynamicJson` JSON helper and migrates spawner JSON (de)serialization to a polymorphic `record SpawnerDto` hierarchy. `DynamicJson` was the last remaining consumer (regions moved off it in #1400).

The key correctness improvement: **System.Text.Json deserializes plain DTO records, never a live `Item`.** Previously, deserializing directly into an `Item` meant STJ constructed world-registered objects *before* the data was validated — a malformed/hand-edited spawn file could leave orphaned spawner Items in the world save. Now a parse failure is GC-only; `dto.ToSpawner()` constructs the spawner only from a fully-validated DTO and self-cleans on failure.

## What changed

- **New:** `SpawnerDto` (abstract) + `SpawnerDataDto` / `RegionSpawnerDto` / `ProximitySpawnerDto`, each marked with a reusable `[JsonDiscoverableType]` opt-in attribute. Auto-discovered at the `Configure` phase — no manual registration list (avoids the regions `Register<T>()` footgun), open to custom spawner subtypes.
- **Symmetric mapping:** `BaseSpawner.ToDto()` (export) ⇄ `SpawnerDto.ToSpawner()` (import). `ToSpawner()` deletes-and-rethrows on any failure, so the importer can never orphan an Item.
- **`SpawnerJsonSerializer`** wires `$type` polymorphism on the `SpawnerDto` root with loud collision/constructibility validation.
- **Import/export commands** rewired to the typed DTO path (reflection `FindTypeByName`/`CreateInstance` removed).
- **Data migration:** the 109 `Distribution/Data/Spawns/**` files moved from `"type"`→`"$type"` and legacy `homeRange`→`spawnBounds`. The runtime still *reads* legacy `homeRange` for external files. The `homeRange→spawnBounds` formula is proven equivalent to the runtime conversion (`BoundsEquivalenceTests`, hr=0/1/3/7).
- **Deleted:** `Projects/Server/Json/DynamicJson.cs`.

Sparse export output matches the legacy `ToJson` (nullable DTO properties + `WhenWritingNull`). Binary world-save serialization is untouched.

## Tests

- DTO round-trip per spawner type; sparse-default omission; legacy `homeRange` read; export/import file round-trip.
- `Import_MalformedFile_LeaksNoWorldItems` — proves a mid-array parse failure constructs zero world Items.
- `AllSpawnFilesLoadTests` — every migrated spawn file deserializes and builds.
- Duplicate-discriminator validation.
- UOContent.Tests 485/485, Server.Tests 710/710, build clean.

## Follow-up (not in this PR)

`Rectangle3DConverter.Write` (in `Projects/Server/`) omits `z1/z2` when `Start.Z == -128`, so a future server-side export of a `homeRange`-style spawner round-trips depth 256→255. Pre-existing and out of scope here (Server change); the migrated data reads correctly. Worth a separate small converter PR.
2026-06-25 23:24:45 -07:00

338 lines
8.8 KiB
JSON

[
{
"$type": "RegionSpawner",
"guid": "0da29e36-7bff-4fcf-803d-79dd16212653",
"name": "Spawner",
"location": [1216, 1604, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableTurnip", "maxCount": 6, "probability": 100 }
],
"region": "A Turnip Field in Britain 2"
},
{
"$type": "RegionSpawner",
"guid": "1025906e-047c-460b-9bb8-581f57ff1357",
"name": "Spawner",
"location": [823, 2274, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCabbage", "maxCount": 6, "probability": 100 }
],
"region": "A Cabbage Field in Skara Brae 2"
},
{
"$type": "RegionSpawner",
"guid": "185e475b-36cf-4dad-8776-537e84b15e42",
"name": "Spawner",
"location": [823, 2355, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCotton", "maxCount": 6, "probability": 100 }
],
"region": "A Cotton Field in Skara Brae"
},
{
"$type": "RegionSpawner",
"guid": "34b0579c-1fc6-4868-82c5-09138c5e5878",
"name": "Spawner",
"location": [1152, 1576, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 8, "probability": 100 }
],
"region": "A Wheatfield in Britain 5"
},
{
"$type": "RegionSpawner",
"guid": "41a583ac-749c-40a7-8658-fb3deb1b222a",
"name": "Spawner",
"location": [823, 2264, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableOnion", "maxCount": 6, "probability": 100 }
],
"region": "An Onion Field in Skara Brae"
},
{
"$type": "RegionSpawner",
"guid": "4656ad9d-a455-4217-9316-ec10d10cf68c",
"name": "Spawner",
"location": [1231, 1723, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableOnion", "maxCount": 8, "probability": 100 }
],
"region": "An Onion Field in Britain 1"
},
{
"$type": "RegionSpawner",
"guid": "57551e80-0018-4fcf-8b83-9d39ef19b0a6",
"name": "Spawner",
"location": [1215, 1723, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCarrot", "maxCount": 8, "probability": 100 }
],
"region": "A Carrot Field in Britain 1"
},
{
"$type": "RegionSpawner",
"guid": "59e99d3b-b727-491b-b0f3-03a441b10c04",
"name": "Spawner",
"location": [843, 2352, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 6, "probability": 100 }
],
"region": "A Wheatfield in Skara Brae 2"
},
{
"$type": "RegionSpawner",
"guid": "690ccc1c-2ac8-4f05-8066-695aa53c98aa",
"name": "Spawner",
"location": [675, 1179, 0],
"map": "Trammel",
"count": 10,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "Sheep", "maxCount": 10, "probability": 100 }
],
"region": "A Field of Sheep in Yew 2"
},
{
"$type": "RegionSpawner",
"guid": "69dfbe70-b46c-42b0-9ff1-351fd9651884",
"name": "Spawner",
"location": [4567, 1475, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCotton", "maxCount": 8, "probability": 100 }
],
"region": "A Cotton Field in Moonglow"
},
{
"$type": "RegionSpawner",
"guid": "79af53a5-33e2-4fdb-95dd-278a050e54fc",
"name": "Spawner",
"location": [567, 1239, 0],
"map": "Trammel",
"count": 5,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 5, "probability": 100 }
],
"region": "A Wheatfield in Yew 1"
},
{
"$type": "RegionSpawner",
"guid": "8408baaa-0de1-4cb0-ad89-973782e3a565",
"name": "Spawner",
"location": [571, 1099, 0],
"map": "Trammel",
"count": 10,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "Sheep", "maxCount": 10, "probability": 100 }
],
"region": "A Farm in Yew"
},
{
"$type": "RegionSpawner",
"guid": "85cc6fca-4f66-4428-aa3a-347a88523a4b",
"name": "Spawner",
"location": [1120, 1624, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 8, "probability": 100 }
],
"region": "A Wheatfield in Britain 4"
},
{
"$type": "RegionSpawner",
"guid": "997d9ff5-ad2b-421b-ae76-6794e7e88150",
"name": "Spawner",
"location": [1183, 1683, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCabbage", "maxCount": 8, "probability": 100 }
],
"region": "A Cabbage Field in Britain 1"
},
{
"$type": "RegionSpawner",
"guid": "ab0cb920-b25f-4811-8ef6-938549dbfa27",
"name": "Spawner",
"location": [1232, 1604, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCarrot", "maxCount": 6, "probability": 100 }
],
"region": "A Carrot Field in Britain 2"
},
{
"$type": "RegionSpawner",
"guid": "afdfec82-dac3-43df-bd7b-cd2cfad5f265",
"name": "Spawner",
"location": [1135, 1791, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 8, "probability": 100 }
],
"region": "A Wheatfield in Britain 1"
},
{
"$type": "RegionSpawner",
"guid": "b17f2f9c-9d36-4bea-87db-69f8effc4926",
"name": "Spawner",
"location": [675, 939, 0],
"map": "Trammel",
"count": 10,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "Sheep", "maxCount": 10, "probability": 100 }
],
"region": "A Field of Sheep in Yew 1"
},
{
"$type": "RegionSpawner",
"guid": "bfb677f7-e824-46f6-95ef-ee5602f4f9c3",
"name": "Spawner",
"location": [1199, 1683, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableTurnip", "maxCount": 8, "probability": 100 }
],
"region": "A Turnip Field in Britain 1"
},
{
"$type": "RegionSpawner",
"guid": "c052a5e0-493d-483e-a98a-665cf05c5c14",
"name": "Spawner",
"location": [823, 2254, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCarrot", "maxCount": 6, "probability": 100 }
],
"region": "A Carrot Field in Skara Brae"
},
{
"$type": "RegionSpawner",
"guid": "c42ef172-78c8-4c5e-b26c-fcc3fc3da1cc",
"name": "Spawner",
"location": [1199, 1823, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 8, "probability": 100 }
],
"region": "A Wheatfield in Britain 2"
},
{
"$type": "RegionSpawner",
"guid": "d5b08634-5c5d-4bc2-b6cd-74cb06132423",
"name": "Spawner",
"location": [1231, 1887, 0],
"map": "Trammel",
"count": 8,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 8, "probability": 100 }
],
"region": "A Wheatfield in Britain 3"
},
{
"$type": "RegionSpawner",
"guid": "df4c5918-b490-4257-9aeb-541b44980b27",
"name": "Spawner",
"location": [823, 2264, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableCabbage", "maxCount": 6, "probability": 100 }
],
"region": "A Cabbage Field in Skara Brae 1"
},
{
"$type": "RegionSpawner",
"guid": "ee6692af-82cf-477e-96ec-375be7a23db9",
"name": "Spawner",
"location": [813, 2163, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 6, "probability": 100 }
],
"region": "A Wheatfield in Skara Brae 1"
},
{
"$type": "RegionSpawner",
"guid": "fb826650-9fad-43ff-8ba1-9d848f1f26c5",
"name": "Spawner",
"location": [375, 1191, 0],
"map": "Trammel",
"count": 6,
"minDelay": "00:00:10",
"maxDelay": "00:00:30",
"entries": [
{ "name": "FarmableWheat", "maxCount": 6, "probability": 100 }
],
"region": "A Wheatfield in Yew 2"
}
]