From af29fa0243b0949311310bd8a6ad5e77f43c005f Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:42:32 -0800 Subject: [PATCH] fix: Codegens fishing pole (#1288) --- .../Items/Skill Items/Fishing/FishingPole.cs | 106 +++++++----------- .../Fishing/Misc/SpecialFishingNet.cs | 72 +++--------- .../Server.Items.FabledFishingNet.v0.json | 4 + .../Server.Items.FishingPole.v0.json | 4 + .../Server.Items.SpecialFishingNet.v0.json | 14 +++ 5 files changed, 79 insertions(+), 121 deletions(-) create mode 100644 Projects/UOContent/Migrations/Server.Items.FabledFishingNet.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.FishingPole.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.SpecialFishingNet.v0.json diff --git a/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs b/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs index 2c16aab5f..8523d1135 100644 --- a/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs +++ b/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs @@ -1,77 +1,55 @@ using System.Collections.Generic; +using ModernUO.Serialization; using Server.ContextMenus; using Server.Engines.Harvest; using Server.Network; -namespace Server.Items +namespace Server.Items; + +[SerializationGenerator(0, false)] +public partial class FishingPole : Item { - public class FishingPole : Item + [Constructible] + public FishingPole() : base(0x0DC0) { - [Constructible] - public FishingPole() : base(0x0DC0) + Layer = Layer.TwoHanded; + Weight = 8.0; + } + + public override void OnDoubleClick(Mobile from) + { + var loc = GetWorldLocation(); + + if (!from.InLOS(loc) || !from.InRange(loc, 2)) { - Layer = Layer.TwoHanded; - Weight = 8.0; + from.LocalOverheadMessage(MessageType.Regular, 0x3E9, 1019045); // I can't reach that } - - public FishingPole(Serial serial) : base(serial) + else { - } - - public override void OnDoubleClick(Mobile from) - { - var loc = GetWorldLocation(); - - if (!from.InLOS(loc) || !from.InRange(loc, 2)) - { - from.LocalOverheadMessage(MessageType.Regular, 0x3E9, 1019045); // I can't reach that - } - else - { - Fishing.System.BeginHarvesting(from, this); - } - } - - public override void GetContextMenuEntries(Mobile from, List list) - { - base.GetContextMenuEntries(from, list); - - BaseHarvestTool.AddContextMenuEntries(from, this, list, Fishing.System); - } - - public override bool CheckConflictingLayer(Mobile m, Item item, Layer layer) - { - if (base.CheckConflictingLayer(m, item, layer)) - { - return true; - } - - if (layer == Layer.OneHanded) - { - m.SendLocalizedMessage(500214); // You already have something in both hands. - return true; - } - - return false; - } - - 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 < 1 && Layer == Layer.OneHanded) - { - Layer = Layer.TwoHanded; - } + Fishing.System.BeginHarvesting(from, this); } } + + public override void GetContextMenuEntries(Mobile from, List list) + { + base.GetContextMenuEntries(from, list); + + BaseHarvestTool.AddContextMenuEntries(from, this, list, Fishing.System); + } + + public override bool CheckConflictingLayer(Mobile m, Item item, Layer layer) + { + if (base.CheckConflictingLayer(m, item, layer)) + { + return true; + } + + if (layer == Layer.OneHanded) + { + m.SendLocalizedMessage(500214); // You already have something in both hands. + return true; + } + + return false; + } } diff --git a/Projects/UOContent/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs b/Projects/UOContent/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs index a52b38a20..98530468e 100644 --- a/Projects/UOContent/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs +++ b/Projects/UOContent/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs @@ -1,4 +1,5 @@ using System; +using ModernUO.Serialization; using Server.Mobiles; using Server.Multis; using Server.Spells; @@ -6,7 +7,8 @@ using Server.Targeting; namespace Server.Items; -public class SpecialFishingNet : Item +[SerializationGenerator(0, false)] +public partial class SpecialFishingNet : Item { private static int[] _hues = { @@ -37,6 +39,10 @@ public class SpecialFishingNet : Item 0x1797, 0x179C }; + [SerializableField(0)] + [SerializedCommandProperty(AccessLevel.GameMaster)] + private bool _inUse; + [Constructible] public SpecialFishingNet() : base(0x0DCA) { @@ -44,15 +50,8 @@ public class SpecialFishingNet : Item Hue = Utility.RandomDouble() < 0.01 ? _hues.RandomElement() : 0x8A0; } - public SpecialFishingNet(Serial serial) : base(serial) - { - } - public override int LabelNumber => 1041079; // a special fishing net - [CommandProperty(AccessLevel.GameMaster)] - public bool InUse { get; set; } - public virtual bool RequireDeepWater => true; public override void GetProperties(IPropertyList list) @@ -68,42 +67,18 @@ public class SpecialFishingNet : Item list.Add(1017410); // Special Fishing Net } - public override void Serialize(IGenericWriter writer) + [AfterDeserialization] + private void AfterDeserialization() { - base.Serialize(writer); - - writer.Write(1); // version - - writer.Write(InUse); - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - - var version = reader.ReadInt(); - - switch (version) + if (_inUse) { - case 1: - { - InUse = reader.ReadBool(); - - if (InUse) - { - Delete(); - } - - break; - } + Delete(); } - - Stackable = false; } public override void OnDoubleClick(Mobile from) { - if (InUse) + if (_inUse) { from.SendLocalizedMessage(1010483); // Someone is already using that net! } @@ -120,7 +95,7 @@ public class SpecialFishingNet : Item public void OnTarget(Mobile from, object obj) { - if (Deleted || InUse) + if (Deleted || _inUse) { return; } @@ -422,15 +397,12 @@ public class SpecialFishingNet : Item } } -public class FabledFishingNet : SpecialFishingNet +[SerializationGenerator(0, false)] +public partial class FabledFishingNet : SpecialFishingNet { [Constructible] public FabledFishingNet() => Hue = 0x481; - public FabledFishingNet(Serial serial) : base(serial) - { - } - public override int LabelNumber => 1063451; // a fabled fishing net protected override void AddNetProperties(IPropertyList list) @@ -445,18 +417,4 @@ public class FabledFishingNet : SpecialFishingNet base.FinishEffect(p, map, from); } - - 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(); - } } diff --git a/Projects/UOContent/Migrations/Server.Items.FabledFishingNet.v0.json b/Projects/UOContent/Migrations/Server.Items.FabledFishingNet.v0.json new file mode 100644 index 000000000..ff8fd56c4 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.FabledFishingNet.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.FabledFishingNet" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.FishingPole.v0.json b/Projects/UOContent/Migrations/Server.Items.FishingPole.v0.json new file mode 100644 index 000000000..113c83690 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.FishingPole.v0.json @@ -0,0 +1,4 @@ +{ + "version": 0, + "type": "Server.Items.FishingPole" +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.SpecialFishingNet.v0.json b/Projects/UOContent/Migrations/Server.Items.SpecialFishingNet.v0.json new file mode 100644 index 000000000..84353aa1d --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.SpecialFishingNet.v0.json @@ -0,0 +1,14 @@ +{ + "version": 0, + "type": "Server.Items.SpecialFishingNet", + "properties": [ + { + "name": "InUse", + "type": "bool", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file