feat: Updates to Serialization Generator v2.2 (#1157)

* Adds `SerializationProperty` - This will generate the private variable for serialization. Also provides an option `useField` to specify your own. Example:
  ```cs
  [SerializationProperty(0, useField: nameof(_resource)]
  ```
This commit is contained in:
Kamron Batman 2022-09-04 08:45:27 -07:00 • committed by GitHub
parent d82028a071
commit 89815ad4d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 242 additions and 361 deletions

View file

@ -94,9 +94,6 @@ namespace Server.Items
[SerializableFieldSaveFlag(8)]
private bool ShouldSerializeMaxHitPoints() => _maxHitPoints != 0;
// Field 9
private int _hitPoints;
[InvalidateProperties]
[SerializableField(10)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
@ -105,21 +102,8 @@ namespace Server.Items
[SerializableFieldSaveFlag(10)]
private bool ShouldSerializeCrafter() => _crafter != null;
// Field 11
private ArmorQuality _quality = ArmorQuality.Regular;
// Field 12
private ArmorDurabilityLevel _durability = ArmorDurabilityLevel.Regular;
// Field 13
private ArmorProtectionLevel _protection = ArmorProtectionLevel.Regular;
// Field 14
[SerializableField(14, "private", "private")]
private CraftResource _rawResource;
[SerializableFieldSaveFlag(14)]
private bool ShouldSerializeResource() => _rawResource != DefaultResource;
private bool ShouldSerializeResource() => _resource != DefaultResource;
// Field 15
private int _armorBase = -1;
@ -168,8 +152,8 @@ namespace Server.Items
{
_crafter = null;
_rawResource = DefaultResource;
Hue = CraftResources.GetHue(_rawResource);
_resource = DefaultResource;
Hue = CraftResources.GetHue(_resource);
_hitPoints = _maxHitPoints = Utility.RandomMinMax(InitMinHits, InitMaxHits);
@ -206,7 +190,7 @@ namespace Server.Items
public virtual int OldDexReq => 0;
public virtual int OldIntReq => 0;
[SerializableField(11)]
[SerializableProperty(11)]
[CommandProperty(AccessLevel.GameMaster)]
public ArmorQuality Quality
{
@ -228,7 +212,7 @@ namespace Server.Items
[SerializableFieldSaveFlag(11)]
private bool ShouldSerializeArmorQuality() => _quality != ArmorQuality.Regular;
[SerializableField(12)]
[SerializableProperty(12)]
[CommandProperty(AccessLevel.GameMaster)]
public ArmorDurabilityLevel Durability
{
@ -250,16 +234,16 @@ namespace Server.Items
[SerializableFieldSaveFlag(12)]
private bool ShouldSerializeDurability() => _durability != ArmorDurabilityLevel.Regular;
[SerializableField(13)]
[SerializableProperty(13)]
[CommandProperty(AccessLevel.GameMaster)]
public ArmorProtectionLevel ProtectionLevel
{
get => _protection;
get => _protectionLevel;
set
{
if (_protection != value)
if (_protectionLevel != value)
{
_protection = value;
_protectionLevel = value;
Invalidate();
InvalidateProperties();
@ -271,23 +255,24 @@ namespace Server.Items
}
[SerializableFieldSaveFlag(13)]
private bool ShouldSerializeProtectionLevel() => _protection != ArmorProtectionLevel.Regular;
private bool ShouldSerializeProtectionLevel() => _protectionLevel != ArmorProtectionLevel.Regular;
[SerializableProperty(14)]
[CommandProperty(AccessLevel.GameMaster)]
public CraftResource Resource
{
get => _rawResource;
get => _resource;
set
{
if (_rawResource != value)
if (_resource != value)
{
UnscaleDurability();
RawResource = value;
_resource = value;
if (CraftItem.RetainsColor(GetType()))
{
Hue = CraftResources.GetHue(_rawResource);
Hue = CraftResources.GetHue(_resource);
}
Invalidate();
@ -302,7 +287,7 @@ namespace Server.Items
private CraftResource ResourceDefaultValue() => DefaultResource;
[EncodedInt]
[SerializableField(15)]
[SerializableProperty(15, useField: nameof(_armorBase))]
[CommandProperty(AccessLevel.GameMaster)]
public int BaseArmorRating
{
@ -329,12 +314,12 @@ namespace Server.Items
{
var ar = BaseArmorRating;
if (_protection != ArmorProtectionLevel.Regular)
if (_protectionLevel != ArmorProtectionLevel.Regular)
{
ar += 10 + 5 * (int)_protection;
ar += 10 + 5 * (int)_protectionLevel;
}
ar += _rawResource switch
ar += _resource switch
{
CraftResource.DullCopper => 2,
CraftResource.ShadowIron => 4,
@ -358,7 +343,7 @@ namespace Server.Items
public double ArmorRatingScaled => ArmorRating * ArmorScalar;
[EncodedInt]
[SerializableField(16)]
[SerializableProperty(16, useField: nameof(_strBonus))]
[CommandProperty(AccessLevel.GameMaster)]
public int StrBonus
{
@ -378,7 +363,7 @@ namespace Server.Items
private int StrBonusDefaultValue() => -1;
[EncodedInt]
[SerializableField(17)]
[SerializableProperty(17, useField: nameof(_dexBonus))]
[CommandProperty(AccessLevel.GameMaster)]
public int DexBonus
{
@ -398,7 +383,7 @@ namespace Server.Items
private int DexBonusDefaultValue() => -1;
[EncodedInt]
[SerializableField(18)]
[SerializableProperty(18, useField: nameof(_intBonus))]
[CommandProperty(AccessLevel.GameMaster)]
public int IntBonus
{
@ -418,7 +403,7 @@ namespace Server.Items
private int IntBonusDefaultValue() => -1;
[EncodedInt]
[SerializableField(19)]
[SerializableProperty(19, useField: nameof(_strReq))]
[CommandProperty(AccessLevel.GameMaster)]
public int StrRequirement
{
@ -438,7 +423,7 @@ namespace Server.Items
private int StrReqDefaultValue() => -1;
[EncodedInt]
[SerializableField(20)]
[SerializableProperty(20, useField: nameof(_dexReq))]
[CommandProperty(AccessLevel.GameMaster)]
public int DexRequirement
{
@ -458,7 +443,7 @@ namespace Server.Items
private int DexReqDefaultValue() => -1;
[EncodedInt]
[SerializableField(21)]
[SerializableProperty(21, useField: nameof(_intReq))]
[CommandProperty(AccessLevel.GameMaster)]
public int IntRequirement
{
@ -477,7 +462,7 @@ namespace Server.Items
[SerializableFieldDefault(21)]
private int IntReqDefaultValue() => -1;
[SerializableField(22)]
[SerializableProperty(22, useField: nameof(_meditate))]
[CommandProperty(AccessLevel.GameMaster)]
public AMA MeditationAllowance
{
@ -675,7 +660,7 @@ namespace Server.Items
{
try
{
var res = CraftResources.GetInfo(_rawResource).ResourceTypes[0].CreateInstance<Item>();
var res = CraftResources.GetInfo(_resource).ResourceTypes[0].CreateInstance<Item>();
ScissorHelper(from, res, PlayerConstructed ? item.Resources[0].Amount / 2 : 1);
return true;
@ -693,7 +678,7 @@ namespace Server.Items
public virtual bool CanFortify => true;
[EncodedInt]
[SerializableField(9)]
[SerializableProperty(9)]
[CommandProperty(AccessLevel.GameMaster)]
public int HitPoints
{
@ -864,11 +849,11 @@ namespace Server.Items
}
public CraftAttributeInfo GetResourceAttrs() =>
CraftResources.GetInfo(_rawResource)?.AttributeInfo ?? CraftAttributeInfo.Blank;
CraftResources.GetInfo(_resource)?.AttributeInfo ?? CraftAttributeInfo.Blank;
public int GetProtOffset()
{
return _protection switch
return _protectionLevel switch
{
ArmorProtectionLevel.Guarding => 1,
ArmorProtectionLevel.Hardening => 2,
@ -896,7 +881,7 @@ namespace Server.Items
{
bonus += ArmorAttributes.DurabilityBonus;
var resInfo = CraftResources.GetInfo(_rawResource);
var resInfo = CraftResources.GetInfo(_resource);
CraftAttributeInfo attrInfo = null;
if (resInfo != null)
@ -969,7 +954,7 @@ namespace Server.Items
var v = ArmorAttributes.LowerStatReq;
var info = CraftResources.GetInfo(_rawResource);
var info = CraftResources.GetInfo(_resource);
var attrInfo = info?.AttributeInfo;
@ -1028,9 +1013,9 @@ namespace Server.Items
SkillBonuses.AddTo(m);
}
if (_rawResource == CraftResource.None)
if (_resource == CraftResource.None)
{
_rawResource = DefaultResource;
_resource = DefaultResource;
}
var strBonus = ComputeStatBonus(StatType.Str);
@ -1208,7 +1193,7 @@ namespace Server.Items
public override void AddNameProperty(IPropertyList list)
{
var oreType = _rawResource switch
var oreType = _resource switch
{
CraftResource.DullCopper => 1053108,
CraftResource.ShadowIron => 1053107,
@ -1276,7 +1261,7 @@ namespace Server.Items
return Attributes.SpellChanneling != 0;
}
public virtual int GetLuckBonus() => CraftResources.GetInfo(_rawResource)?.AttributeInfo?.ArmorLuck ?? 0;
public virtual int GetLuckBonus() => CraftResources.GetInfo(_resource)?.AttributeInfo?.ArmorLuck ?? 0;
public override void GetProperties(IPropertyList list)
{
@ -1497,13 +1482,13 @@ namespace Server.Items
attrs.Add(new EquipInfoAttribute(1038000 + (int)_durability));
}
if (_protection > ArmorProtectionLevel.Regular && _protection <= ArmorProtectionLevel.Invulnerability)
if (_protectionLevel > ArmorProtectionLevel.Regular && _protectionLevel <= ArmorProtectionLevel.Invulnerability)
{
attrs.Add(new EquipInfoAttribute(1038005 + (int)_protection));
attrs.Add(new EquipInfoAttribute(1038005 + (int)_protectionLevel));
}
}
else if (_durability != ArmorDurabilityLevel.Regular || _protection > ArmorProtectionLevel.Regular &&
_protection <= ArmorProtectionLevel.Invulnerability)
else if (_durability != ArmorDurabilityLevel.Regular || _protectionLevel > ArmorProtectionLevel.Regular &&
_protectionLevel <= ArmorProtectionLevel.Invulnerability)
{
attrs.Add(new EquipInfoAttribute(1038000)); // Unidentified
}