fix(codegen): Fixes various code gen issues. Adds better embedded serialization support (#688)

* Adds save flag support (see `ElvenGlasses` for an example)
* Updates AOSAttributes so they are code genned
* Fixes embedded object support by adding an `IRawSerializable`
* Fixes various inconsistencies in serializing with codegen
This commit is contained in:
Kamron Batman 2021-08-17 02:43:52 -07:00 committed by GitHub
parent 69af652a18
commit 2c8097f707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 787 additions and 507 deletions

View file

@ -1173,22 +1173,18 @@ namespace Server.Items
{
var flags = (SaveFlag)reader.ReadEncodedInt();
Attributes = new AosAttributes(this);
if (GetSaveFlag(flags, SaveFlag.Attributes))
{
Attributes = new AosAttributes(this, reader);
}
else
{
Attributes = new AosAttributes(this);
Attributes.Deserialize(reader);
}
ArmorAttributes = new AosArmorAttributes(this);
if (GetSaveFlag(flags, SaveFlag.ArmorAttributes))
{
ArmorAttributes = new AosArmorAttributes(this, reader);
}
else
{
ArmorAttributes = new AosArmorAttributes(this);
ArmorAttributes.Deserialize(reader);
}
if (GetSaveFlag(flags, SaveFlag.PhysicalBonus))
@ -1356,9 +1352,11 @@ namespace Server.Items
m_Meditate = (AMA)(-1);
}
SkillBonuses = new AosSkillBonuses(this);
if (GetSaveFlag(flags, SaveFlag.SkillBonuses))
{
SkillBonuses = new AosSkillBonuses(this, reader);
SkillBonuses.Deserialize(reader);
}
if (GetSaveFlag(flags, SaveFlag.PlayerConstructed))
@ -1370,8 +1368,11 @@ namespace Server.Items
}
case 4:
{
Attributes = new AosAttributes(this, reader);
ArmorAttributes = new AosArmorAttributes(this, reader);
Attributes = new AosAttributes(this);
Attributes.Deserialize(reader);
ArmorAttributes = new AosArmorAttributes(this);
ArmorAttributes.Deserialize(reader);
goto case 3;
}
case 3:

View file

@ -1,6 +1,7 @@
namespace Server.Items
{
public class ArtsGlasses : ElvenGlasses
[Serializable(0, false)]
public partial class ArtsGlasses : ElvenGlasses
{
[Constructible]
public ArtsGlasses()
@ -12,10 +13,6 @@ namespace Server.Items
Hue = 0x73;
}
public ArtsGlasses(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1073363; // Reading Glasses of the Arts
public override int BasePhysicalResistance => 10;
@ -26,22 +23,5 @@ namespace Server.Items
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(1);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
if (version == 0 && Hue == 0)
{
Hue = 0x73;
}
}
}
}

View file

@ -1,18 +1,13 @@
using System;
namespace Server.Items
{
public class ElvenGlasses : BaseArmor
[Serializable(0, false)]
public partial class ElvenGlasses : BaseArmor
{
[Constructible]
public ElvenGlasses() : base(0x2FB8)
{
Weight = 2;
WeaponAttributes = new AosWeaponAttributes(this);
}
public ElvenGlasses(Serial serial) : base(serial)
{
_weaponAttributes = new AosWeaponAttributes(this);
}
public override int LabelNumber => 1032216; // elven glasses
@ -35,8 +30,18 @@ namespace Server.Items
public override CraftResource DefaultResource => CraftResource.RegularLeather;
public override ArmorMeditationAllowance DefMedAllowance => ArmorMeditationAllowance.All;
[CommandProperty(AccessLevel.GameMaster, canModify: true)]
public AosWeaponAttributes WeaponAttributes { get; private set; }
[SerializableField(0, setter: "private")]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster, canModify: true)]")]
public AosWeaponAttributes _weaponAttributes;
[SerializableFieldSaveFlag(0)]
private bool ShouldSerializeWeaponAttributes() => !_weaponAttributes.IsEmpty;
[AfterDeserialization]
private void AfterDeserialization()
{
_weaponAttributes ??= new AosWeaponAttributes(this);
}
public override void AppendChildNameProperties(ObjectPropertyList list)
{
@ -44,133 +49,80 @@ namespace Server.Items
int prop;
if ((prop = WeaponAttributes.HitColdArea) != 0)
if ((prop = _weaponAttributes.HitColdArea) != 0)
{
list.Add(1060416, prop.ToString()); // hit cold area ~1_val~%
}
if ((prop = WeaponAttributes.HitDispel) != 0)
if ((prop = _weaponAttributes.HitDispel) != 0)
{
list.Add(1060417, prop.ToString()); // hit dispel ~1_val~%
}
if ((prop = WeaponAttributes.HitEnergyArea) != 0)
if ((prop = _weaponAttributes.HitEnergyArea) != 0)
{
list.Add(1060418, prop.ToString()); // hit energy area ~1_val~%
}
if ((prop = WeaponAttributes.HitFireArea) != 0)
if ((prop = _weaponAttributes.HitFireArea) != 0)
{
list.Add(1060419, prop.ToString()); // hit fire area ~1_val~%
}
if ((prop = WeaponAttributes.HitFireball) != 0)
if ((prop = _weaponAttributes.HitFireball) != 0)
{
list.Add(1060420, prop.ToString()); // hit fireball ~1_val~%
}
if ((prop = WeaponAttributes.HitHarm) != 0)
if ((prop = _weaponAttributes.HitHarm) != 0)
{
list.Add(1060421, prop.ToString()); // hit harm ~1_val~%
}
if ((prop = WeaponAttributes.HitLeechHits) != 0)
if ((prop = _weaponAttributes.HitLeechHits) != 0)
{
list.Add(1060422, prop.ToString()); // hit life leech ~1_val~%
}
if ((prop = WeaponAttributes.HitLightning) != 0)
if ((prop = _weaponAttributes.HitLightning) != 0)
{
list.Add(1060423, prop.ToString()); // hit lightning ~1_val~%
}
if ((prop = WeaponAttributes.HitLowerAttack) != 0)
if ((prop = _weaponAttributes.HitLowerAttack) != 0)
{
list.Add(1060424, prop.ToString()); // hit lower attack ~1_val~%
}
if ((prop = WeaponAttributes.HitLowerDefend) != 0)
if ((prop = _weaponAttributes.HitLowerDefend) != 0)
{
list.Add(1060425, prop.ToString()); // hit lower defense ~1_val~%
}
if ((prop = WeaponAttributes.HitMagicArrow) != 0)
if ((prop = _weaponAttributes.HitMagicArrow) != 0)
{
list.Add(1060426, prop.ToString()); // hit magic arrow ~1_val~%
}
if ((prop = WeaponAttributes.HitLeechMana) != 0)
if ((prop = _weaponAttributes.HitLeechMana) != 0)
{
list.Add(1060427, prop.ToString()); // hit mana leech ~1_val~%
}
if ((prop = WeaponAttributes.HitPhysicalArea) != 0)
if ((prop = _weaponAttributes.HitPhysicalArea) != 0)
{
list.Add(1060428, prop.ToString()); // hit physical area ~1_val~%
}
if ((prop = WeaponAttributes.HitPoisonArea) != 0)
if ((prop = _weaponAttributes.HitPoisonArea) != 0)
{
list.Add(1060429, prop.ToString()); // hit poison area ~1_val~%
}
if ((prop = WeaponAttributes.HitLeechStam) != 0)
if ((prop = _weaponAttributes.HitLeechStam) != 0)
{
list.Add(1060430, prop.ToString()); // hit stamina leech ~1_val~%
}
}
private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf)
{
if (setIf)
{
flags |= toSet;
}
}
private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet) => (flags & toGet) != 0;
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
var flags = SaveFlag.None;
SetSaveFlag(ref flags, SaveFlag.WeaponAttributes, !WeaponAttributes.IsEmpty);
writer.Write((int)flags);
if (GetSaveFlag(flags, SaveFlag.WeaponAttributes))
{
WeaponAttributes.Serialize(writer);
}
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
var flags = (SaveFlag)reader.ReadInt();
if (GetSaveFlag(flags, SaveFlag.WeaponAttributes))
{
WeaponAttributes = new AosWeaponAttributes(this, reader);
}
else
{
WeaponAttributes = new AosWeaponAttributes(this);
}
}
[Flags]
private enum SaveFlag
{
None = 0x00000000,
WeaponAttributes = 0x00000001
}
}
}

View file

@ -5,7 +5,7 @@ namespace Server.Items
[Constructible]
public LyricalGlasses()
{
WeaponAttributes.HitLowerDefend = 20;
_weaponAttributes.HitLowerDefend = 20;
Attributes.NightSight = 1;
Attributes.ReflectPhysical = 15;

View file

@ -5,7 +5,7 @@ namespace Server.Items
[Constructible]
public MaceShieldGlasses()
{
WeaponAttributes.HitLowerDefend = 30;
_weaponAttributes.HitLowerDefend = 30;
Attributes.BonusStr = 10;
Attributes.BonusDex = 5;