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`).
311 lines
8.3 KiB
C#
311 lines
8.3 KiB
C#
using System;
|
|
using Server.Engines.Craft;
|
|
|
|
namespace Server.Items;
|
|
|
|
public partial class BaseWeapon
|
|
{
|
|
// PlayerConstructed moved onto Item
|
|
private void MigrateFrom(V10Content content)
|
|
{
|
|
_damageLevel = content.DamageLevel ?? WeaponDamageLevel.Regular;
|
|
_accuracyLevel = content.AccuracyLevel ?? WeaponAccuracyLevel.Regular;
|
|
_durabilityLevel = content.DurabilityLevel ?? WeaponDurabilityLevel.Regular;
|
|
_quality = content.Quality ?? WeaponQuality.Regular;
|
|
_hitPoints = content.HitPoints ?? 0;
|
|
_maxHitPoints = content.MaxHitPoints ?? 0;
|
|
_slayer = content.Slayer ?? SlayerName.None;
|
|
_poison = content.Poison;
|
|
_poisonCharges = content.PoisonCharges ?? 0;
|
|
_crafter = content.Crafter;
|
|
_identified = content.Identified;
|
|
_strRequirement = content.StrRequirement ?? -1;
|
|
_dexRequirement = content.DexRequirement ?? -1;
|
|
_intRequirement = content.IntRequirement ?? -1;
|
|
_minDamage = content.MinDamage ?? -1;
|
|
_maxDamage = content.MaxDamage ?? -1;
|
|
_hitSound = content.HitSound ?? -1;
|
|
_missSound = content.MissSound ?? -1;
|
|
_speed = content.Speed ?? -1;
|
|
_maxRange = content.MaxRange ?? -1;
|
|
_skill = content.Skill ?? (SkillName)(-1);
|
|
_type = content.Type ?? (WeaponType)(-1);
|
|
_animation = content.Animation ?? (WeaponAnimation)(-1);
|
|
_resource = content.Resource ?? CraftResource.Iron;
|
|
_attributes = content.Attributes ?? AttributesDefaultValue();
|
|
_weaponAttributes = content.WeaponAttributes ?? WeaponAttributesDefaultValue();
|
|
PlayerConstructed = content.PlayerConstructed;
|
|
_skillBonuses = content.SkillBonuses ?? SkillBonusesDefaultValue();
|
|
_slayer2 = content.Slayer2 ?? SlayerName.None;
|
|
_aosElementDamages = content.AosElementDamages ?? AosElementAttributesDefaultValue();
|
|
_engravedText = content.EngravedText;
|
|
}
|
|
|
|
// Version 9 (pre-codegen)
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
var flags = (OldSaveFlag)reader.ReadInt();
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.DamageLevel))
|
|
{
|
|
_damageLevel = (WeaponDamageLevel)reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.AccuracyLevel))
|
|
{
|
|
_accuracyLevel = (WeaponAccuracyLevel)reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.DurabilityLevel))
|
|
{
|
|
_durabilityLevel = (WeaponDurabilityLevel)reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Quality))
|
|
{
|
|
_quality = (WeaponQuality)reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_quality = WeaponQuality.Regular;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Hits))
|
|
{
|
|
_hitPoints = reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MaxHits))
|
|
{
|
|
_maxHitPoints = reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Slayer))
|
|
{
|
|
_slayer = (SlayerName)reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Poison))
|
|
{
|
|
_poison = reader.ReadPoison();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.PoisonCharges))
|
|
{
|
|
_poisonCharges = reader.ReadInt();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Crafter))
|
|
{
|
|
Timer.DelayCall(crafter => _crafter = crafter?.RawName, reader.ReadEntity<Mobile>());
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Identified))
|
|
{
|
|
_identified = version >= 6 || reader.ReadBool();
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.StrReq))
|
|
{
|
|
_strRequirement = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_strRequirement = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.DexReq))
|
|
{
|
|
_dexRequirement = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_dexRequirement = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.IntReq))
|
|
{
|
|
_intRequirement = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_intRequirement = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MinDamage))
|
|
{
|
|
_minDamage = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_minDamage = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MaxDamage))
|
|
{
|
|
_maxDamage = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_maxDamage = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.HitSound))
|
|
{
|
|
_hitSound = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_hitSound = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MissSound))
|
|
{
|
|
_missSound = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_missSound = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Speed))
|
|
{
|
|
if (version < 9)
|
|
{
|
|
_speed = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_speed = reader.ReadFloat();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_speed = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.MaxRange))
|
|
{
|
|
_maxRange = reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_maxRange = -1;
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Skill))
|
|
{
|
|
_skill = (SkillName)reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_skill = (SkillName)(-1);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Type))
|
|
{
|
|
_type = (WeaponType)reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_type = (WeaponType)(-1);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Animation))
|
|
{
|
|
_animation = (WeaponAnimation)reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_animation = (WeaponAnimation)(-1);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Resource))
|
|
{
|
|
_resource = (CraftResource)reader.ReadInt();
|
|
}
|
|
else
|
|
{
|
|
_resource = CraftResource.Iron;
|
|
}
|
|
|
|
Attributes = new AosAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Attributes))
|
|
{
|
|
Attributes.Deserialize(reader);
|
|
}
|
|
|
|
WeaponAttributes = new AosWeaponAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.WeaponAttributes))
|
|
{
|
|
WeaponAttributes.Deserialize(reader);
|
|
}
|
|
|
|
PlayerConstructed = GetSaveFlag(flags, OldSaveFlag.PlayerConstructed);
|
|
|
|
SkillBonuses = new AosSkillBonuses(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.SkillBonuses))
|
|
{
|
|
SkillBonuses.Deserialize(reader);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.Slayer2))
|
|
{
|
|
_slayer2 = (SlayerName)reader.ReadInt();
|
|
}
|
|
|
|
AosElementDamages = new AosElementAttributes(this);
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.ElementalDamages))
|
|
{
|
|
AosElementDamages.Deserialize(reader);
|
|
}
|
|
|
|
if (GetSaveFlag(flags, OldSaveFlag.EngravedText))
|
|
{
|
|
_engravedText = reader.ReadString();
|
|
}
|
|
}
|
|
|
|
private static bool GetSaveFlag(OldSaveFlag flags, OldSaveFlag toGet) => (flags & toGet) != 0;
|
|
|
|
[Flags]
|
|
private enum OldSaveFlag
|
|
{
|
|
None = 0x00000000,
|
|
DamageLevel = 0x00000001,
|
|
AccuracyLevel = 0x00000002,
|
|
DurabilityLevel = 0x00000004,
|
|
Quality = 0x00000008,
|
|
Hits = 0x00000010,
|
|
MaxHits = 0x00000020,
|
|
Slayer = 0x00000040,
|
|
Poison = 0x00000080,
|
|
PoisonCharges = 0x00000100,
|
|
Crafter = 0x00000200,
|
|
Identified = 0x00000400,
|
|
StrReq = 0x00000800,
|
|
DexReq = 0x00001000,
|
|
IntReq = 0x00002000,
|
|
MinDamage = 0x00004000,
|
|
MaxDamage = 0x00008000,
|
|
HitSound = 0x00010000,
|
|
MissSound = 0x00020000,
|
|
Speed = 0x00040000,
|
|
MaxRange = 0x00080000,
|
|
Skill = 0x00100000,
|
|
Type = 0x00200000,
|
|
Animation = 0x00400000,
|
|
Resource = 0x00800000,
|
|
Attributes = 0x01000000,
|
|
WeaponAttributes = 0x02000000,
|
|
PlayerConstructed = 0x04000000,
|
|
SkillBonuses = 0x08000000,
|
|
Slayer2 = 0x10000000,
|
|
ElementalDamages = 0x20000000,
|
|
EngravedText = 0x40000000
|
|
}
|
|
}
|