private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf)
{
if (setIf)
flags |= toSet;
}
private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet)
{
return ((flags & toGet) != 0);
}
[Flags]
private enum SaveFlag
{
None = 0x00000000,
Resource = 0x00000001,
Attributes = 0x00000002,
ClothingAttributes = 0x00000004,
SkillBonuses = 0x00000008,
Resistances = 0x00000010,
MaxHitPoints = 0x00000020,
HitPoints = 0x00000040,
PlayerConstructed = 0x00000080,
Crafter = 0x00000100,
Quality = 0x00000200,
StrReq = 0x00000400,
#region Imbuing
// TimesImbued = 0x12000000,
#endregion
}
#region Mondain's Legacy Sets
private static void SetSaveFlag(ref SetFlag flags, SetFlag toSet, bool setIf)
{
if (setIf)
flags |= toSet;
}
private static bool GetSaveFlag(SetFlag flags, SetFlag toGet)
{
return ((flags & toGet) != 0);
}
[Flags]
private enum SetFlag
{
None = 0x00000000,
Attributes = 0x00000001,
ArmorAttributes = 0x00000002,
SkillBonuses = 0x00000004,
PhysicalBonus = 0x00000008,
FireBonus = 0x00000010,
ColdBonus = 0x00000020,
PoisonBonus = 0x00000040,
EnergyBonus = 0x00000080,
SetHue = 0x00000100,
LastEquipped = 0x00000200,
SetEquipped = 0x00000400,
SetSelfRepair = 0x00000800,
}
#endregion
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)6); // version
#region SF Imbuing
writer.Write((int)m_TimesImbued); // Imbuing
writer.Write((bool)Physical_Modded);
writer.Write((bool)Fire_Modded);
writer.Write((bool)Cold_Modded);
writer.Write((bool)Poison_Modded);
writer.Write((bool)Energy_Modded);
#endregion
#region Mondain's Legacy Sets
SetFlag sflags = SetFlag.None;
SetSaveFlag(ref sflags, SetFlag.Attributes, !m_SetAttributes.IsEmpty);
SetSaveFlag(ref sflags, SetFlag.SkillBonuses, !m_SetSkillBonuses.IsEmpty);
SetSaveFlag(ref sflags, SetFlag.PhysicalBonus, m_SetPhysicalBonus != 0);
SetSaveFlag(ref sflags, SetFlag.FireBonus, m_SetFireBonus != 0);
SetSaveFlag(ref sflags, SetFlag.ColdBonus, m_SetColdBonus != 0);
SetSaveFlag(ref sflags, SetFlag.PoisonBonus, m_SetPoisonBonus != 0);
SetSaveFlag(ref sflags, SetFlag.EnergyBonus, m_SetEnergyBonus != 0);
SetSaveFlag(ref sflags, SetFlag.SetHue, m_SetHue != 0);
SetSaveFlag(ref sflags, SetFlag.LastEquipped, m_LastEquipped);
SetSaveFlag(ref sflags, SetFlag.SetEquipped, m_SetEquipped);
SetSaveFlag(ref sflags, SetFlag.SetSelfRepair, m_SetSelfRepair != 0);
writer.WriteEncodedInt((int)sflags);
if (GetSaveFlag(sflags, SetFlag.Attributes))
m_SetAttributes.Serialize(writer);
if (GetSaveFlag(sflags, SetFlag.SkillBonuses))
m_SetSkillBonuses.Serialize(writer);
if (GetSaveFlag(sflags, SetFlag.PhysicalBonus))
writer.WriteEncodedInt((int)m_SetPhysicalBonus);
if (GetSaveFlag(sflags, SetFlag.FireBonus))
writer.WriteEncodedInt((int)m_SetFireBonus);
if (GetSaveFlag(sflags, SetFlag.ColdBonus))
writer.WriteEncodedInt((int)m_SetColdBonus);
if (GetSaveFlag(sflags, SetFlag.PoisonBonus))
writer.WriteEncodedInt((int)m_SetPoisonBonus);
if (GetSaveFlag(sflags, SetFlag.EnergyBonus))
writer.WriteEncodedInt((int)m_SetEnergyBonus);
if (GetSaveFlag(sflags, SetFlag.SetHue))
writer.WriteEncodedInt((int)m_SetHue);
if (GetSaveFlag(sflags, SetFlag.LastEquipped))
writer.Write((bool)m_LastEquipped);
if (GetSaveFlag(sflags, SetFlag.SetEquipped))
writer.Write((bool)m_SetEquipped);
if (GetSaveFlag(sflags, SetFlag.SetSelfRepair))
writer.WriteEncodedInt((int)m_SetSelfRepair);
#endregion
// Version 5
SaveFlag flags = SaveFlag.None;
SetSaveFlag(ref flags, SaveFlag.Resource, m_Resource != DefaultResource);
SetSaveFlag(ref flags, SaveFlag.Attributes, !m_AosAttributes.IsEmpty);
SetSaveFlag(ref flags, SaveFlag.ClothingAttributes, !m_AosClothingAttributes.IsEmpty);
SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !m_AosSkillBonuses.IsEmpty);
SetSaveFlag(ref flags, SaveFlag.Resistances, !m_AosResistances.IsEmpty);
SetSaveFlag(ref flags, SaveFlag.MaxHitPoints, m_MaxHitPoints != 0);
SetSaveFlag(ref flags, SaveFlag.HitPoints, m_HitPoints != 0);
SetSaveFlag(ref flags, SaveFlag.PlayerConstructed, m_PlayerConstructed != false);
SetSaveFlag(ref flags, SaveFlag.Crafter, m_Crafter != null);
SetSaveFlag(ref flags, SaveFlag.Quality, m_Quality != ClothingQuality.Regular);
SetSaveFlag(ref flags, SaveFlag.StrReq, m_StrReq != -1);
#region Imbuing
// SetSaveFlag(ref flags, SaveFlag.TimesImbued, m_TimesImbued != 0);
#endregion
writer.WriteEncodedInt((int)flags);
if (GetSaveFlag(flags, SaveFlag.Resource))
writer.WriteEncodedInt((int)m_Resource);
if (GetSaveFlag(flags, SaveFlag.Attributes))
m_AosAttributes.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.ClothingAttributes))
m_AosClothingAttributes.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.SkillBonuses))
m_AosSkillBonuses.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.Resistances))
m_AosResistances.Serialize(writer);
if (GetSaveFlag(flags, SaveFlag.MaxHitPoints))
writer.WriteEncodedInt((int)m_MaxHitPoints);
if (GetSaveFlag(flags, SaveFlag.HitPoints))
writer.WriteEncodedInt((int)m_HitPoints);
if (GetSaveFlag(flags, SaveFlag.Crafter))
writer.Write((Mobile)m_Crafter);
if (GetSaveFlag(flags, SaveFlag.Quality))
writer.WriteEncodedInt((int)m_Quality);
if (GetSaveFlag(flags, SaveFlag.StrReq))
writer.WriteEncodedInt((int)m_StrReq);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 6:
{
#region SF Imbuing
//SF Imbuing
{
m_TimesImbued = reader.ReadInt();
Physical_Modded = reader.ReadBool();
Fire_Modded = reader.ReadBool();
Cold_Modded = reader.ReadBool();
Poison_Modded = reader.ReadBool();
Energy_Modded = reader.ReadBool();
}
#endregion
#region Mondain's Legacy Sets
SetFlag sflags = (SetFlag)reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.Attributes))
m_SetAttributes = new AosAttributes(this, reader);
else
m_SetAttributes = new AosAttributes(this);
if (GetSaveFlag(sflags, SetFlag.ArmorAttributes))
m_SetSelfRepair = (new AosArmorAttributes(this, reader)).SelfRepair;
if (GetSaveFlag(sflags, SetFlag.SkillBonuses))
m_SetSkillBonuses = new AosSkillBonuses(this, reader);
else
m_SetSkillBonuses = new AosSkillBonuses(this);
if (GetSaveFlag(sflags, SetFlag.PhysicalBonus))
m_SetPhysicalBonus = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.FireBonus))
m_SetFireBonus = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.ColdBonus))
m_SetColdBonus = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.PoisonBonus))
m_SetPoisonBonus = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.EnergyBonus))
m_SetEnergyBonus = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.SetHue))
m_SetHue = reader.ReadEncodedInt();
if (GetSaveFlag(sflags, SetFlag.LastEquipped))
m_LastEquipped = reader.ReadBool();
if (GetSaveFlag(sflags, SetFlag.SetEquipped))
m_SetEquipped = reader.ReadBool();
if (GetSaveFlag(sflags, SetFlag.SetSelfRepair))
m_SetSelfRepair = reader.ReadEncodedInt();
#endregion
goto case 5;
}
case 5:
{
SaveFlag flags = (SaveFlag)reader.ReadEncodedInt();
if (GetSaveFlag(flags, SaveFlag.Resource))
m_Resource = (CraftResource)reader.ReadEncodedInt();
else
m_Resource = DefaultResource;
if (GetSaveFlag(flags, SaveFlag.Attributes))
m_AosAttributes = new AosAttributes(this, reader);
else
m_AosAttributes = new AosAttributes(this);
if (GetSaveFlag(flags, SaveFlag.ClothingAttributes))
m_AosClothingAttributes = new AosArmorAttributes(this, reader);
else
m_AosClothingAttributes = new AosArmorAttributes(this);
if (GetSaveFlag(flags, SaveFlag.SkillBonuses))
m_AosSkillBonuses = new AosSkillBonuses(this, reader);
else
m_AosSkillBonuses = new AosSkillBonuses(this);
if (GetSaveFlag(flags, SaveFlag.Resistances))
m_AosResistances = new AosElementAttributes(this, reader);
else
m_AosResistances = new AosElementAttributes(this);
if (GetSaveFlag(flags, SaveFlag.MaxHitPoints))
m_MaxHitPoints = reader.ReadEncodedInt();
if (GetSaveFlag(flags, SaveFlag.HitPoints))
m_HitPoints = reader.ReadEncodedInt();
if (GetSaveFlag(flags, SaveFlag.Crafter))
m_Crafter = reader.ReadMobile();
if (GetSaveFlag(flags, SaveFlag.Quality))
m_Quality = (ClothingQuality)reader.ReadEncodedInt();
else
m_Quality = ClothingQuality.Regular;
if (GetSaveFlag(flags, SaveFlag.StrReq))
m_StrReq = reader.ReadEncodedInt();
else
m_StrReq = -1;
if (GetSaveFlag(flags, SaveFlag.PlayerConstructed))
m_PlayerConstructed = true;
break;
}
case 4:
{
m_Resource = (CraftResource)reader.ReadInt();
goto case 3;
}
case 3:
{
m_AosAttributes = new AosAttributes(this, reader);
m_AosClothingAttributes = new AosArmorAttributes(this, reader);
m_AosSkillBonuses = new AosSkillBonuses(this, reader);
m_AosResistances = new AosElementAttributes(this, reader);
goto case 2;
}
case 2:
{
m_PlayerConstructed = reader.ReadBool();
goto case 1;
}
case 1:
{
m_Crafter = reader.ReadMobile();
m_Quality = (ClothingQuality)reader.ReadInt();
break;
}
case 0:
{
m_Crafter = null;
m_Quality = ClothingQuality.Regular;
break;
}
}
#region Mondain's Legacy Sets
if (m_SetAttributes == null)
m_SetAttributes = new AosAttributes(this);
if (m_SetSkillBonuses == null)
m_SetSkillBonuses = new AosSkillBonuses(this);
#endregion
if (version < 2)
m_PlayerConstructed = true; // we don't know, so, assume it's crafted
if (version < 3)
{
m_AosAttributes = new AosAttributes(this);
m_AosClothingAttributes = new AosArmorAttributes(this);
m_AosSkillBonuses = new AosSkillBonuses(this);
m_AosResistances = new AosElementAttributes(this);
}
if (version < 4)
m_Resource = DefaultResource;
if (m_MaxHitPoints == 0 && m_HitPoints == 0)
m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax(InitMinHits, InitMaxHits);
Mobile parent = Parent as Mobile;
if (parent != null)
{
if (Core.AOS)
m_AosSkillBonuses.AddTo(parent);
AddStatBonuses(parent);
parent.CheckStatTimers();
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.