Follow-up to #2574, which added a `.Migrations.cs` partial to `BaseWeapon`. Pure relocation — no behaviour change. ## The inconsistency `BaseArmor` and `BaseClothing` already kept their pre-codegen `Deserialize(reader, version)` in a `.Migrations.cs` partial, but left the `OldSaveFlag` enum and the `GetSaveFlag` helper behind in the main class file — even though every call site is in the partial: | Class | `Deserialize` | `GetSaveFlag` / `OldSaveFlag` | Call sites outside the partial | |---|---|---|---| | `BaseArmor` | already in partial | in main file | 0 of 26 | | `BaseClothing` | already in partial | in main file | 0 of 12 | | `BaseWeapon` | in main file | in main file | — | `BaseWeapon` had all three still inline, with its new `.Migrations.cs` holding only a `MigrateFrom`. ## After All three follow the same layout: `MigrateFrom` newest to oldest, then the pre-codegen `Deserialize`, then `GetSaveFlag`, then `OldSaveFlag`. That moves ~290 lines of legacy read path out of `BaseWeapon.cs` — the file that needed it most at ~3,900 lines — and leaves the main class files describing only how the type behaves today. ## Reviewing this The diff is large and almost entirely noise, so it is probably not worth reading line by line. Two checks are stronger: - **Nothing was lost or altered.** Across each `.cs` / `.Migrations.cs` pair, the multiset of non-blank source lines is identical to `main` except for one added comment (below). The relocation was done mechanically and asserted against that invariant rather than by hand. - **Nothing about serialization moved with the code.** Running `ModernUOSchemaGenerator` after the move emits no new migration files. The complete set of intentional additions: - `using System;` in each of the three partials, for the `[Flags]` attribute (implicit usings are not enabled here). - `// Version 9 (pre-codegen)` above `BaseWeapon`'s moved `Deserialize`, matching the marker `BaseArmor` and `BaseClothing` already carry. Version 9 is correct because `BaseWeapon.v10.json` is its earliest migration schema, so codegen began at 10. Everything else is blank-line placement. ## Verification Full solution builds in Release with 0 errors and 0 warnings; 1516 tests pass (815 `Server.Tests`, 701 `UOContent.Tests`).
125 lines
3.9 KiB
C#
125 lines
3.9 KiB
C#
using System;
|
|
|
|
namespace Server.Items;
|
|
|
|
public partial class BaseClothing
|
|
{
|
|
// PlayerConstructed moved onto Item
|
|
private void MigrateFrom(V7Content content)
|
|
{
|
|
_resource = content.Resource ?? DefaultResource;
|
|
_attributes = content.Attributes ?? AttributesDefaultValue();
|
|
_clothingAttributes = content.ClothingAttributes ?? ClothingAttributesDefaultValue();
|
|
_skillBonuses = content.SkillBonuses ?? SkillBonusesDefaultValue();
|
|
_resistances = content.Resistances ?? ResistancesDefaultValue();
|
|
_maxHitPoints = content.MaxHitPoints ?? 0;
|
|
_hitPoints = content.HitPoints ?? 0;
|
|
PlayerConstructed = content.PlayerConstructed;
|
|
_crafter = content.Crafter;
|
|
_quality = content.Quality ?? ClothingQuality.Regular;
|
|
_strReq = content.StrRequirement ?? -1;
|
|
}
|
|
|
|
private void MigrateFrom(V6Content content)
|
|
{
|
|
_resource = content.RawResource ?? DefaultResource;
|
|
_attributes = content.Attributes ?? AttributesDefaultValue();
|
|
_clothingAttributes = content.ClothingAttributes ?? ClothingAttributesDefaultValue();
|
|
_skillBonuses = content.SkillBonuses ?? SkillBonusesDefaultValue();
|
|
_resistances = content.Resistances ?? ResistancesDefaultValue();
|
|
_maxHitPoints = content.MaxHitPoints ?? 0;
|
|
PlayerConstructed = content.PlayerConstructed;
|
|
Timer.DelayCall((item, crafter) => item._crafter = crafter?.RawName, this, content.Crafter);
|
|
_quality = content.Quality ?? ClothingQuality.Regular;
|
|
_strReq = content.StrRequirement ?? -1;
|
|
}
|
|
|
|
// Version 5 (pre-codegen)
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
var flags = (OldSaveFlag)reader.ReadEncodedInt();
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Resource))
|
|
{
|
|
_resource = (CraftResource)reader.ReadEncodedInt();
|
|
}
|
|
else
|
|
{
|
|
_resource = DefaultResource;
|
|
}
|
|
|
|
Attributes = new AosAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Attributes))
|
|
{
|
|
Attributes.Deserialize(reader);
|
|
}
|
|
|
|
ClothingAttributes = new AosArmorAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.ClothingAttributes))
|
|
{
|
|
ClothingAttributes.Deserialize(reader);
|
|
}
|
|
|
|
SkillBonuses = new AosSkillBonuses(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.SkillBonuses))
|
|
{
|
|
SkillBonuses.Deserialize(reader);
|
|
}
|
|
|
|
Resistances = new AosElementAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Resistances))
|
|
{
|
|
Resistances.Deserialize(reader);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MaxHitPoints))
|
|
{
|
|
_maxHitPoints = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.HitPoints))
|
|
{
|
|
_hitPoints = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Crafter))
|
|
{
|
|
Timer.DelayCall((item, crafter) => item._crafter = crafter?.RawName, this, reader.ReadEntity<Mobile>());
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Quality))
|
|
{
|
|
_quality = (ClothingQuality)reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.StrReq))
|
|
{
|
|
_strReq = reader.ReadEncodedInt();
|
|
}
|
|
|
|
PlayerConstructed = GetSaveFlag(flags, OldSaveFlag.PlayerConstructed);
|
|
}
|
|
|
|
private static bool GetSaveFlag(OldSaveFlag flags, OldSaveFlag toGet) => (flags & toGet) != 0;
|
|
|
|
[Flags]
|
|
private enum OldSaveFlag
|
|
{
|
|
None = 0x00000000,
|
|
Resource = 0x00000001,
|
|
Attributes = 0x00000002,
|
|
ClothingAttributes = 0x00000004,
|
|
SkillBonuses = 0x00000008,
|
|
Resistances = 0x00000010,
|
|
MaxHitPoints = 0x00000020,
|
|
HitPoints = 0x00000040,
|
|
PlayerConstructed = 0x00000080,
|
|
Crafter = 0x00000100,
|
|
Quality = 0x00000200,
|
|
StrReq = 0x00000400
|
|
}
|
|
}
|