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`).
229 lines
7.3 KiB
C#
229 lines
7.3 KiB
C#
using System;
|
|
using AMA = Server.Items.ArmorMeditationAllowance;
|
|
|
|
namespace Server.Items;
|
|
|
|
public partial class BaseArmor
|
|
{
|
|
// PlayerConstructed moved onto Item
|
|
private void MigrateFrom(V9Content content)
|
|
{
|
|
_attributes = content.Attributes ?? AttributesDefaultValue();
|
|
_armorAttributes = content.ArmorAttributes ?? ArmorAttributesDefaultValue();
|
|
_physicalBonus = content.PhysicalBonus ?? 0;
|
|
_fireBonus = content.FireBonus ?? 0;
|
|
_coldBonus = content.ColdBonus ?? 0;
|
|
_poisonBonus = content.PoisonBonus ?? 0;
|
|
_energyBonus = content.EnergyBonus ?? 0;
|
|
_identified = content.Identified;
|
|
_maxHitPoints = content.MaxHitPoints ?? 0;
|
|
_hitPoints = content.HitPoints ?? 0;
|
|
_crafter = content.Crafter;
|
|
_quality = content.Quality ?? ArmorQuality.Regular;
|
|
_durability = content.Durability ?? ArmorDurabilityLevel.Regular;
|
|
_protectionLevel = content.ProtectionLevel ?? ArmorProtectionLevel.Regular;
|
|
_resource = content.Resource ?? DefaultResource;
|
|
_armorBase = content.BaseArmorRating ?? -1;
|
|
_strBonus = content.StrBonus ?? -1;
|
|
_dexBonus = content.DexBonus ?? -1;
|
|
_intBonus = content.IntBonus ?? -1;
|
|
_strReq = content.StrRequirement ?? -1;
|
|
_dexReq = content.DexRequirement ?? -1;
|
|
_intReq = content.IntRequirement ?? -1;
|
|
_meditate = content.MeditationAllowance ?? (AMA)(-1);
|
|
_skillBonuses = content.SkillBonuses ?? SkillBonusesDefaultValue();
|
|
PlayerConstructed = content.PlayerConstructed;
|
|
}
|
|
|
|
private void MigrateFrom(V8Content content)
|
|
{
|
|
_attributes = content.Attributes ?? AttributesDefaultValue();
|
|
_armorAttributes = content.ArmorAttributes ?? ArmorAttributesDefaultValue();
|
|
_physicalBonus = content.PhysicalBonus ?? 0;
|
|
_fireBonus = content.FireBonus ?? 0;
|
|
_coldBonus = content.ColdBonus ?? 0;
|
|
_poisonBonus = content.PoisonBonus ?? 0;
|
|
_energyBonus = content.EnergyBonus ?? 0;
|
|
_identified = content.Identified;
|
|
_maxHitPoints = content.MaxHitPoints ?? 0;
|
|
_hitPoints = content.HitPoints ?? 0;
|
|
Timer.DelayCall((item, crafter) => item._crafter = crafter?.RawName, this, content.Crafter);
|
|
_quality = content.Quality ?? ArmorQuality.Regular;
|
|
_durability = content.Durability ?? ArmorDurabilityLevel.Regular;
|
|
_resource = content.RawResource ?? DefaultResource;
|
|
_armorBase = content.BaseArmorRating ?? -1;
|
|
_strBonus = content.StrBonus ?? -1;
|
|
_dexBonus = content.DexBonus ?? -1;
|
|
_intBonus = content.IntBonus ?? -1;
|
|
_strReq = content.StrRequirement ?? -1;
|
|
_dexReq = content.DexRequirement ?? -1;
|
|
_intReq = content.IntRequirement ?? -1;
|
|
_meditate = content.MeditationAllowance ?? (AMA)(-1);
|
|
_skillBonuses = content.SkillBonuses ?? SkillBonusesDefaultValue();
|
|
PlayerConstructed = content.PlayerConstructed;
|
|
}
|
|
|
|
// Version 7 (pre-codegen)
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
var flags = (OldSaveFlag)reader.ReadEncodedInt();
|
|
|
|
Attributes = new AosAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Attributes))
|
|
{
|
|
Attributes.Deserialize(reader);
|
|
}
|
|
|
|
ArmorAttributes = new AosArmorAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.ArmorAttributes))
|
|
{
|
|
ArmorAttributes.Deserialize(reader);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.PhysicalBonus))
|
|
{
|
|
_physicalBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.FireBonus))
|
|
{
|
|
_fireBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.ColdBonus))
|
|
{
|
|
_coldBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.PoisonBonus))
|
|
{
|
|
_poisonBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.EnergyBonus))
|
|
{
|
|
_energyBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
_identified = GetSaveFlag(flags, OldSaveFlag.Identified);
|
|
|
|
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 = (ArmorQuality)reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Durability))
|
|
{
|
|
_durability = (ArmorDurabilityLevel)reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Protection))
|
|
{
|
|
_protectionLevel = (ArmorProtectionLevel)reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Resource))
|
|
{
|
|
_resource = (CraftResource)reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.BaseArmor))
|
|
{
|
|
_armorBase = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.StrBonus))
|
|
{
|
|
_strBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.DexBonus))
|
|
{
|
|
_dexBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.IntBonus))
|
|
{
|
|
_intBonus = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.StrReq))
|
|
{
|
|
_strReq = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.DexReq))
|
|
{
|
|
_dexReq = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.IntReq))
|
|
{
|
|
_intReq = reader.ReadEncodedInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MedAllowance))
|
|
{
|
|
_meditate = (AMA)reader.ReadEncodedInt();
|
|
}
|
|
|
|
SkillBonuses = new AosSkillBonuses(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.SkillBonuses))
|
|
{
|
|
SkillBonuses.Deserialize(reader);
|
|
}
|
|
|
|
PlayerConstructed = GetSaveFlag(flags, OldSaveFlag.PlayerConstructed);
|
|
}
|
|
|
|
private static bool GetSaveFlag(OldSaveFlag flags, OldSaveFlag toGet) => (flags & toGet) != 0;
|
|
|
|
[Flags]
|
|
private enum OldSaveFlag
|
|
{
|
|
None = 0x00000000,
|
|
Attributes = 0x00000001,
|
|
ArmorAttributes = 0x00000002,
|
|
PhysicalBonus = 0x00000004,
|
|
FireBonus = 0x00000008,
|
|
ColdBonus = 0x00000010,
|
|
PoisonBonus = 0x00000020,
|
|
EnergyBonus = 0x00000040,
|
|
Identified = 0x00000080,
|
|
MaxHitPoints = 0x00000100,
|
|
HitPoints = 0x00000200,
|
|
Crafter = 0x00000400,
|
|
Quality = 0x00000800,
|
|
Durability = 0x00001000,
|
|
Protection = 0x00002000,
|
|
Resource = 0x00004000,
|
|
BaseArmor = 0x00008000,
|
|
StrBonus = 0x00010000,
|
|
DexBonus = 0x00020000,
|
|
IntBonus = 0x00040000,
|
|
StrReq = 0x00080000,
|
|
DexReq = 0x00100000,
|
|
IntReq = 0x00200000,
|
|
MedAllowance = 0x00400000,
|
|
SkillBonuses = 0x00800000,
|
|
PlayerConstructed = 0x01000000
|
|
}
|
|
}
|