ModernUO/Distribution/Data/Spawns/shared/ilshenar/TwistedWeald.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

241 lines
6.3 KiB
JSON

[
{
"$type": "Spawner",
"guid": "418a0be2-0604-4ff8-b39d-1fb570fa7b7e",
"name": "Spawner (314)",
"location": [2177, 1210, -60],
"map": "Ilshenar",
"count": 2,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 10,
"walkingRange": 10,
"entries": [
{ "name": "LadyLissith", "maxCount": 2, "probability": 100 },
{ "name": "LadySabrix", "maxCount": 2, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "46dc7fc7-d062-4be9-8134-f960352fbca3",
"name": "Spawner (314)",
"location": [2171, 1181, -44],
"map": "Ilshenar",
"count": 10,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 20,
"walkingRange": 20,
"entries": [
{ "name": "CuSidhe", "maxCount": 8, "probability": 100 },
{ "name": "DryadA", "maxCount": 8, "probability": 100 },
{ "name": "Changeling", "maxCount": 8, "probability": 100 },
{ "name": "Satyr", "maxCount": 8, "probability": 100 },
{ "name": "DireWolf", "maxCount": 2, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "5a47595b-b894-4d45-b35d-5714de0c8c51",
"name": "Spawner (314)",
"location": [2206, 1220, -8],
"map": "Ilshenar",
"count": 2,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 20,
"walkingRange": 20,
"entries": [
{ "name": "CuSidhe", "maxCount": 2, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "5cb54b29-10c4-448f-a036-5ba23dcb350a",
"name": "Spawner (314)",
"location": [2224, 1218, 13],
"map": "Ilshenar",
"count": 1,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 8,
"walkingRange": 8,
"entries": [
{ "name": "Swoop", "maxCount": 1, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "68b1853c-f9bd-4bd1-852f-dcc9977a3049",
"name": "Spawner (314)",
"location": [2167, 1266, -60],
"map": "Ilshenar",
"count": 3,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 5,
"walkingRange": 5,
"entries": [
{ "name": "Malefic", "maxCount": 3, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "6eee069d-8662-415f-bdcc-78975f1a54ae",
"name": "Spawner (314)",
"location": [2207, 1180, -36],
"map": "Ilshenar",
"count": 15,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 25,
"walkingRange": 25,
"entries": [
{ "name": "CuSidhe", "maxCount": 12, "probability": 100 },
{ "name": "Dryada", "maxCount": 12, "probability": 100 },
{ "name": "Changeling", "maxCount": 12, "probability": 100 },
{ "name": "Satyr", "maxCount": 12, "probability": 100 },
{ "name": "DireWolf", "maxCount": 3, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "76ef21c0-5e48-410e-84f5-57023fa7efb4",
"name": "Spawner (314)",
"location": [2137, 1216, -60],
"map": "Ilshenar",
"count": 4,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 5,
"walkingRange": 5,
"entries": [
{ "name": "Silk", "maxCount": 4, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "7e991368-4fad-4e2b-af3b-88d360b88627",
"name": "Spawner (314)",
"location": [2157, 1206, -60],
"map": "Ilshenar",
"count": 3,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 5,
"walkingRange": 5,
"entries": [
{ "name": "Virulent", "maxCount": 3, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "852fa8b9-931f-493c-9ee0-200a3f229110",
"name": "Spawner (314)",
"location": [2163, 1189, -48],
"map": "Ilshenar",
"count": 2,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 8,
"walkingRange": 8,
"entries": [
{ "name": "Changeling", "maxCount": 2, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "aa8d4c55-b124-40ae-a0db-31b873c7a549",
"name": "Spawner (314)",
"location": [2134, 1174, -46],
"map": "Ilshenar",
"count": 5,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 5,
"walkingRange": 5,
"entries": [
{ "name": "Gnaw", "maxCount": 5, "probability": 100 },
{ "name": "DireWolf", "maxCount": 5, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "b5b1118b-161e-43fb-80dd-f890dec2be53",
"name": "Spawner (314)",
"location": [2177, 1229, -60],
"map": "Ilshenar",
"count": 4,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 5,
"walkingRange": 5,
"entries": [
{ "name": "GiantBlackWidow", "maxCount": 4, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "cd6dab60-126f-4877-b9dd-f786cbfad49b",
"name": "Spawner (314)",
"location": [2138, 1212, -60],
"map": "Ilshenar",
"count": 8,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 20,
"walkingRange": 20,
"entries": [
{ "name": "Quagmire", "maxCount": 8, "probability": 100 },
{ "name": "WhippingVine", "maxCount": 8, "probability": 100 },
{ "name": "Irk", "maxCount": 8, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "eea8e238-78e9-4d84-a91b-95360f6f2fd6",
"name": "Spawner (314)",
"location": [2170, 1247, -60],
"map": "Ilshenar",
"count": 4,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 10,
"walkingRange": 10,
"entries": [
{ "name": "Malefic", "maxCount": 4, "probability": 100 },
{ "name": "Virulent", "maxCount": 4, "probability": 100 }
]
},
{
"$type": "Spawner",
"guid": "fe2db064-ee88-4f04-8c49-b3d7a56fd9a2",
"name": "Spawner (314)",
"location": [2159, 1223, -60],
"map": "Ilshenar",
"count": 5,
"minDelay": "00:05:00",
"maxDelay": "00:10:00",
"team": 0,
"homeRange": 10,
"walkingRange": 10,
"entries": [
{ "name": "Corpser", "maxCount": 5, "probability": 100 },
{ "name": "Spite", "maxCount": 5, "probability": 100 },
{ "name": "Guile", "maxCount": 5, "probability": 100 }
]
}
]