From fa0bf86a088d2003dfeb05c3bfd7b07f55111ac8 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 27 Mar 2022 15:02:29 -0700 Subject: [PATCH] fix: Codegens furniture containers (#977) --- .../Items/Containers/FurnitureContainer.cs | 577 ++++++------------ .../Migrations/Server.Items.Armoire.v0.json | 4 + .../Server.Items.CherryArmoire.v0.json | 4 + .../Migrations/Server.Items.Drawer.v0.json | 4 + .../Server.Items.ElegantArmoire.v0.json | 4 + .../Server.Items.EmptyBookcase.v0.json | 4 + .../Server.Items.FancyArmoire.v0.json | 4 + .../Server.Items.FancyDrawer.v0.json | 4 + .../Server.Items.FullBookcase.v0.json | 4 + .../Server.Items.MapleArmoire.v0.json | 4 + .../Server.Items.RedArmoire.v0.json | 4 + .../Server.Items.ShortCabinet.v0.json | 4 + .../Server.Items.TallCabinet.v0.json | 4 + 13 files changed, 247 insertions(+), 378 deletions(-) create mode 100644 Projects/UOContent/Migrations/Server.Items.Armoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.CherryArmoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.Drawer.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.ElegantArmoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.EmptyBookcase.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.FancyArmoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.FancyDrawer.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.FullBookcase.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.MapleArmoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.RedArmoire.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.ShortCabinet.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.TallCabinet.v0.json diff --git a/Projects/UOContent/Items/Containers/FurnitureContainer.cs b/Projects/UOContent/Items/Containers/FurnitureContainer.cs index 07dbe1597..e718faa1e 100644 --- a/Projects/UOContent/Items/Containers/FurnitureContainer.cs +++ b/Projects/UOContent/Items/Containers/FurnitureContainer.cs @@ -1,419 +1,240 @@ using System; using System.Collections.Generic; -namespace Server.Items +namespace Server.Items; + +[Furniture] +[Flippable(0x2815, 0x2816)] +[Serializable(0, false)] +public partial class TallCabinet : BaseContainer { - [Furniture] - [Flippable(0x2815, 0x2816)] - public class TallCabinet : BaseContainer + [Constructible] + public TallCabinet() : base(0x2815) => Weight = 1.0; +} + +[Furniture] +[Flippable(0x2817, 0x2818)] +[Serializable(0, false)] +public partial class ShortCabinet : BaseContainer +{ + [Constructible] + public ShortCabinet() : base(0x2817) => Weight = 1.0; +} + +[Furniture] +[Flippable(0x2857, 0x2858)] +[Serializable(0, false)] +public partial class RedArmoire : BaseContainer +{ + [Constructible] + public RedArmoire() : base(0x2857) => Weight = 1.0; +} + +[Furniture] +[Flippable(0x285D, 0x285E)] +[Serializable(0, false)] +public partial class CherryArmoire : BaseContainer +{ + [Constructible] + public CherryArmoire() : base(0x285D) => Weight = 1.0; +} + +[Furniture] +[Flippable(0x285B, 0x285C)] +[Serializable(0, false)] +public partial class MapleArmoire : BaseContainer +{ + [Constructible] + public MapleArmoire() : base(0x285B) => Weight = 1.0; +} + +[Furniture] +[Flippable(0x2859, 0x285A)] +[Serializable(0, false)] +public partial class ElegantArmoire : BaseContainer +{ + [Constructible] + public ElegantArmoire() : base(0x2859) => Weight = 1.0; +} + +[Furniture] +[Serializable(0)] +[Flippable(0x2D07, 0x2D08)] +public partial class FancyElvenArmoire : BaseContainer +{ + [Constructible] + public FancyElvenArmoire() : base(0x2D07) => Weight = 1.0; + public override int DefaultGumpID => 0x4E; + public override int DefaultDropSound => 0x42; +} + +[Furniture] +[Serializable(0)] +[Flippable(0x2D05, 0x2D06)] +public partial class SimpleElvenArmoire : BaseContainer +{ + [Constructible] + public SimpleElvenArmoire() : base(0x2D05) => Weight = 1.0; + public override int DefaultGumpID => 0x4F; + public override int DefaultDropSound => 0x42; +} + +[Furniture] +[Flippable(0xa97, 0xa99, 0xa98, 0xa9a, 0xa9b, 0xa9c)] +[Serializable(0, false)] +public partial class FullBookcase : BaseContainer +{ + [Constructible] + public FullBookcase() : base(0xA97) => Weight = 1.0; +} + +[Furniture] +[Flippable(0xa9d, 0xa9e)] +[Serializable(0, false)] +public partial class EmptyBookcase : BaseContainer +{ + [Constructible] + public EmptyBookcase() : base(0xA9D) { - [Constructible] - public TallCabinet() : base(0x2815) => Weight = 1.0; + } +} - public TallCabinet(Serial serial) : base(serial) - { - } +[Furniture] +[Flippable(0xa2c, 0xa34)] +[Serializable(0, false)] +public partial class Drawer : BaseContainer +{ + [Constructible] + public Drawer() : base(0xA2C) => Weight = 1.0; +} - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } +[Furniture] +[Flippable(0xa30, 0xa38)] +[Serializable(0, false)] +public partial class FancyDrawer : BaseContainer +{ + [Constructible] + public FancyDrawer() : base(0xA30) => Weight = 1.0; +} - public override void Deserialize(IGenericReader reader) +[Furniture] +[Flippable(0xa4f, 0xa53)] +[Serializable(0, false)] +public partial class Armoire : BaseContainer +{ + [Constructible] + public Armoire() : base(0xA4F) => Weight = 1.0; + + public override void DisplayTo(Mobile m) + { + if (DynamicFurniture.Open(this, m)) { - base.Deserialize(reader); - var version = reader.ReadInt(); + base.DisplayTo(m); } } - [Furniture] - [Flippable(0x2817, 0x2818)] - public class ShortCabinet : BaseContainer + [AfterDeserialization] + private void AfterDeserialization() { - [Constructible] - public ShortCabinet() : base(0x2817) => Weight = 1.0; + DynamicFurniture.Close(this); + } +} - public ShortCabinet(Serial serial) : base(serial) - { - } +[Furniture] +[Flippable(0xa4d, 0xa51)] +[Serializable(0, false)] +public partial class FancyArmoire : BaseContainer +{ + [Constructible] + public FancyArmoire() : base(0xA4D) => Weight = 1.0; - public override void Serialize(IGenericWriter writer) + public override void DisplayTo(Mobile m) + { + if (DynamicFurniture.Open(this, m)) { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); + base.DisplayTo(m); } } - [Furniture] - [Flippable(0x2857, 0x2858)] - public class RedArmoire : BaseContainer + [AfterDeserialization] + private void AfterDeserialization() { - [Constructible] - public RedArmoire() : base(0x2857) => Weight = 1.0; - - public RedArmoire(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } + DynamicFurniture.Close(this); } +} - [Furniture] - [Flippable(0x285D, 0x285E)] - public class CherryArmoire : BaseContainer +public static class DynamicFurniture +{ + private static readonly Dictionary _table = new(); + + public static bool Open(Container c, Mobile m) { - [Constructible] - public CherryArmoire() : base(0x285D) => Weight = 1.0; - - public CherryArmoire(Serial serial) : base(serial) + if (_table.ContainsKey(c)) { + c.SendRemovePacket(); + Close(c); + c.Delta(ItemDelta.Update); + c.ProcessDelta(); + return false; } - public override void Serialize(IGenericWriter writer) + if (c is Armoire or FancyArmoire) { - base.Serialize(writer); - writer.Write(0); // version - } + Timer t = new FurnitureTimer(c, m); + t.Start(); + _table[c] = t; - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Flippable(0x285B, 0x285C)] - public class MapleArmoire : BaseContainer - { - [Constructible] - public MapleArmoire() : base(0x285B) => Weight = 1.0; - - public MapleArmoire(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Flippable(0x2859, 0x285A)] - public class ElegantArmoire : BaseContainer - { - [Constructible] - public ElegantArmoire() : base(0x2859) => Weight = 1.0; - - public ElegantArmoire(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Serializable(0)] - [Flippable(0x2D07, 0x2D08)] - public partial class FancyElvenArmoire : BaseContainer - { - [Constructible] - public FancyElvenArmoire() : base(0x2D07) => Weight = 1.0; - public override int DefaultGumpID => 0x4E; - public override int DefaultDropSound => 0x42; - } - - [Furniture] - [Serializable(0)] - [Flippable(0x2D05, 0x2D06)] - public partial class SimpleElvenArmoire : BaseContainer - { - [Constructible] - public SimpleElvenArmoire() : base(0x2D05) => Weight = 1.0; - public override int DefaultGumpID => 0x4F; - public override int DefaultDropSound => 0x42; - } - - [Furniture] - [Flippable(0xa97, 0xa99, 0xa98, 0xa9a, 0xa9b, 0xa9c)] - public class FullBookcase : BaseContainer - { - [Constructible] - public FullBookcase() : base(0xA97) => Weight = 1.0; - - public FullBookcase(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Flippable(0xa9d, 0xa9e)] - public class EmptyBookcase : BaseContainer - { - [Constructible] - public EmptyBookcase() : base(0xA9D) - { - } - - public EmptyBookcase(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - - writer.Write(1); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - - if (version == 0 && Weight == 1.0) + c.ItemID = c.ItemID switch { - Weight = -1; - } + 0xA4D => 0xA4C, + 0xA4F => 0xA4E, + 0xA51 => 0xA50, + 0xA53 => 0xA52, + _ => c.ItemID + }; } + + return true; } - [Furniture] - [Flippable(0xa2c, 0xa34)] - public class Drawer : BaseContainer + public static void Close(Container c) { - [Constructible] - public Drawer() : base(0xA2C) => Weight = 1.0; - - public Drawer(Serial serial) : base(serial) + if (_table.Remove(c, out var t)) { + t.Stop(); } - public override void Serialize(IGenericWriter writer) + if (c is Armoire or FancyArmoire) { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Flippable(0xa30, 0xa38)] - public class FancyDrawer : BaseContainer - { - [Constructible] - public FancyDrawer() : base(0xA30) => Weight = 1.0; - - public FancyDrawer(Serial serial) : base(serial) - { - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - } - } - - [Furniture] - [Flippable(0xa4f, 0xa53)] - public class Armoire : BaseContainer - { - [Constructible] - public Armoire() : base(0xA4F) => Weight = 1.0; - - public Armoire(Serial serial) : base(serial) - { - } - - public override void DisplayTo(Mobile m) - { - if (DynamicFurniture.Open(this, m)) + c.ItemID = c.ItemID switch { - base.DisplayTo(m); - } - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - - DynamicFurniture.Close(this); - } - } - - [Furniture] - [Flippable(0xa4d, 0xa51)] - public class FancyArmoire : BaseContainer - { - [Constructible] - public FancyArmoire() : base(0xA4D) => Weight = 1.0; - - public FancyArmoire(Serial serial) : base(serial) - { - } - - public override void DisplayTo(Mobile m) - { - if (DynamicFurniture.Open(this, m)) - { - base.DisplayTo(m); - } - } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - writer.Write(0); // version - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - var version = reader.ReadInt(); - - DynamicFurniture.Close(this); - } - } - - public static class DynamicFurniture - { - private static readonly Dictionary m_Table = new(); - - public static bool Open(Container c, Mobile m) - { - if (m_Table.ContainsKey(c)) - { - c.SendRemovePacket(); - Close(c); - c.Delta(ItemDelta.Update); - c.ProcessDelta(); - return false; - } - - if (c is Armoire or FancyArmoire) - { - Timer t = new FurnitureTimer(c, m); - t.Start(); - m_Table[c] = t; - - c.ItemID = c.ItemID switch - { - 0xA4D => 0xA4C, - 0xA4F => 0xA4E, - 0xA51 => 0xA50, - 0xA53 => 0xA52, - _ => c.ItemID - }; - } - - return true; - } - - public static void Close(Container c) - { - if (m_Table.Remove(c, out var t)) - { - t.Stop(); - } - - if (c is Armoire or FancyArmoire) - { - c.ItemID = c.ItemID switch - { - 0xA4C => 0xA4D, - 0xA4E => 0xA4F, - 0xA50 => 0xA51, - 0xA52 => 0xA53, - _ => c.ItemID - }; - } - } - } - - public class FurnitureTimer : Timer - { - private readonly Container m_Container; - private readonly Mobile m_Mobile; - - public FurnitureTimer(Container c, Mobile m) : base(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5)) - { - - m_Container = c; - m_Mobile = m; - } - - protected override void OnTick() - { - if (m_Mobile.Map != m_Container.Map || !m_Mobile.InRange(m_Container.GetWorldLocation(), 3)) - { - DynamicFurniture.Close(m_Container); - } + 0xA4C => 0xA4D, + 0xA4E => 0xA4F, + 0xA50 => 0xA51, + 0xA52 => 0xA53, + _ => c.ItemID + }; + } + } +} + +public class FurnitureTimer : Timer +{ + private readonly Container _container; + private readonly Mobile _mobile; + + public FurnitureTimer(Container c, Mobile m) : base(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5)) + { + + _container = c; + _mobile = m; + } + + protected override void OnTick() + { + if (_mobile.Map != _container.Map || !_mobile.InRange(_container.GetWorldLocation(), 3)) + { + DynamicFurniture.Close(_container); } } } diff --git a/Projects/UOContent/Migrations/Server.Items.Armoire.v0.json b/Projects/UOContent/Migrations/Server.Items.Armoire.v0.json new file mode 100644 index 000000000..e410f3ea9 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.Armoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.Armoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.CherryArmoire.v0.json b/Projects/UOContent/Migrations/Server.Items.CherryArmoire.v0.json new file mode 100644 index 000000000..b554f6ad5 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.CherryArmoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.CherryArmoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.Drawer.v0.json b/Projects/UOContent/Migrations/Server.Items.Drawer.v0.json new file mode 100644 index 000000000..1fcf3a71f --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.Drawer.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.Drawer" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.ElegantArmoire.v0.json b/Projects/UOContent/Migrations/Server.Items.ElegantArmoire.v0.json new file mode 100644 index 000000000..4f2625986 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.ElegantArmoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.ElegantArmoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.EmptyBookcase.v0.json b/Projects/UOContent/Migrations/Server.Items.EmptyBookcase.v0.json new file mode 100644 index 000000000..f5e4c51b8 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.EmptyBookcase.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.EmptyBookcase" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.FancyArmoire.v0.json b/Projects/UOContent/Migrations/Server.Items.FancyArmoire.v0.json new file mode 100644 index 000000000..b69db6c19 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.FancyArmoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.FancyArmoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.FancyDrawer.v0.json b/Projects/UOContent/Migrations/Server.Items.FancyDrawer.v0.json new file mode 100644 index 000000000..40cde68fe --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.FancyDrawer.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.FancyDrawer" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.FullBookcase.v0.json b/Projects/UOContent/Migrations/Server.Items.FullBookcase.v0.json new file mode 100644 index 000000000..c3d2eb68d --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.FullBookcase.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.FullBookcase" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.MapleArmoire.v0.json b/Projects/UOContent/Migrations/Server.Items.MapleArmoire.v0.json new file mode 100644 index 000000000..2f0d3f4fa --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.MapleArmoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.MapleArmoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.RedArmoire.v0.json b/Projects/UOContent/Migrations/Server.Items.RedArmoire.v0.json new file mode 100644 index 000000000..92d088926 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.RedArmoire.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.RedArmoire" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.ShortCabinet.v0.json b/Projects/UOContent/Migrations/Server.Items.ShortCabinet.v0.json new file mode 100644 index 000000000..04937d754 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.ShortCabinet.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.ShortCabinet" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.TallCabinet.v0.json b/Projects/UOContent/Migrations/Server.Items.TallCabinet.v0.json new file mode 100644 index 000000000..3503ffa6d --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.TallCabinet.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.TallCabinet" +} \ No newline at end of file