From 58acfcabad0d32db9c3b856fd6af7a92ee251a59 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 14 Nov 2022 20:56:08 -0800 Subject: [PATCH] fix: Codegens teleporters (#1250) --- Projects/UOContent/Items/Misc/Teleporter.cs | 132 +++++------------- .../Server.Items.ConditionTeleporter.v1.json | 11 ++ .../Server.Items.TimeoutGoal.v0.json | 11 ++ .../Server.Items.TimeoutTeleporter.v1.json | 11 ++ 4 files changed, 67 insertions(+), 98 deletions(-) create mode 100644 Projects/UOContent/Migrations/Server.Items.ConditionTeleporter.v1.json create mode 100644 Projects/UOContent/Migrations/Server.Items.TimeoutGoal.v0.json create mode 100644 Projects/UOContent/Migrations/Server.Items.TimeoutTeleporter.v1.json diff --git a/Projects/UOContent/Items/Misc/Teleporter.cs b/Projects/UOContent/Items/Misc/Teleporter.cs index 67f583709..6ab6f9d91 100644 --- a/Projects/UOContent/Items/Misc/Teleporter.cs +++ b/Projects/UOContent/Items/Misc/Teleporter.cs @@ -638,9 +638,14 @@ public partial class WaitTeleporter : KeywordTeleporter } } -public class TimeoutTeleporter : Teleporter +[SerializationGenerator(1, false)] +public partial class TimeoutTeleporter : Teleporter { - private Dictionary m_Teleporting; + [SerializableField(0)] + [SerializedCommandProperty(AccessLevel.GameMaster)] + private TimeSpan _timeoutDelay; + + private Dictionary _teleporting; [Constructible] public TimeoutTeleporter() : this(new Point3D(0, 0, 0)) @@ -649,31 +654,23 @@ public class TimeoutTeleporter : Teleporter [Constructible] public TimeoutTeleporter(Point3D pointDest, Map mapDest = null, bool creatures = false) - : base(pointDest, mapDest, creatures) => - m_Teleporting = new Dictionary(); - - public TimeoutTeleporter(Serial serial) : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public TimeSpan TimeoutDelay { get; set; } + : base(pointDest, mapDest, creatures) => _teleporting = new Dictionary(); public void StartTimer(Mobile m) { - StartTimer(m, TimeoutDelay); + StartTimer(m, _timeoutDelay); } private void StartTimer(Mobile m, TimeSpan delay) { StopTimer(m); Timer.StartTimer(delay, () => StartTeleport(m), out var timerToken); - m_Teleporting[m] = timerToken; + _teleporting[m] = timerToken; } public void StopTimer(Mobile m) { - if (m_Teleporting.Remove(m, out var t)) + if (_teleporting.Remove(m, out var t)) { t.Cancel(); } @@ -681,7 +678,7 @@ public class TimeoutTeleporter : Teleporter public override void DoTeleport(Mobile m) { - m_Teleporting.Remove(m); + _teleporting.Remove(m); base.DoTeleport(m); } @@ -701,48 +698,30 @@ public class TimeoutTeleporter : Teleporter return true; } - public override void Serialize(IGenericWriter writer) + private void Deserialize(IGenericReader reader, int version) { - base.Serialize(writer); - - writer.Write(0); // version - - writer.Write(TimeoutDelay); - writer.Write(m_Teleporting.Count); - - foreach (var kvp in m_Teleporting) - { - writer.Write(kvp.Key); - writer.Write(kvp.Value.Next); - } - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - - var version = reader.ReadInt(); - - TimeoutDelay = reader.ReadTimeSpan(); - m_Teleporting = new Dictionary(); + _timeoutDelay = reader.ReadTimeSpan(); + _teleporting = new Dictionary(); var count = reader.ReadInt(); for (var i = 0; i < count; ++i) { - var m = reader.ReadEntity(); - var end = reader.ReadDateTime(); - - StartTimer(m, end - Core.Now); + reader.ReadEntity(); + reader.ReadDateTime(); } } } -public class TimeoutGoal : Item +[SerializationGenerator(0, false)] +public partial class TimeoutGoal : Item { + [SerializableField(0)] + [SerializedCommandProperty(AccessLevel.GameMaster)] + private TimeoutTeleporter _teleporter; + [Constructible] - public TimeoutGoal() - : base(0x1822) + public TimeoutGoal() : base(0x1822) { Movable = false; Visible = false; @@ -750,56 +729,26 @@ public class TimeoutGoal : Item Hue = 1154; } - public TimeoutGoal(Serial serial) - : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public TimeoutTeleporter Teleporter { get; set; } - public override string DefaultName => "timeout teleporter goal"; public override bool OnMoveOver(Mobile m) { Teleporter?.StopTimer(m); - return true; } - - public override void Serialize(IGenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - - writer.Write(Teleporter); - } - - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - - var version = reader.ReadInt(); - - Teleporter = reader.ReadEntity(); - } } -public class ConditionTeleporter : Teleporter +[SerializationGenerator(1, false)] +public partial class ConditionTeleporter : Teleporter { - private ConditionFlag m_Flags; + [SerializableField(0, getter: "protected", setter: "protected")] + private ConditionFlag _flags; [Constructible] public ConditionTeleporter() { } - public ConditionTeleporter(Serial serial) - : base(serial) - { - } - [CommandProperty(AccessLevel.GameMaster)] public bool DenyMounted { @@ -964,7 +913,7 @@ public class ConditionTeleporter : Teleporter } default: { - m.SendMessage("You must remove all of your equipment before proceeding."); + m.SendMessage("You must remove all equipment before proceeding."); return false; } } @@ -1044,35 +993,22 @@ public class ConditionTeleporter : Teleporter } } - public override void Serialize(IGenericWriter writer) + private void Deserialize(IGenericReader reader, int version) { - base.Serialize(writer); - - writer.Write(0); // version - - writer.Write((int)m_Flags); + _flags = (ConditionFlag)reader.ReadInt(); } - public override void Deserialize(IGenericReader reader) - { - base.Deserialize(reader); - - var version = reader.ReadInt(); - - m_Flags = (ConditionFlag)reader.ReadInt(); - } - - protected bool GetFlag(ConditionFlag flag) => (m_Flags & flag) != 0; + protected bool GetFlag(ConditionFlag flag) => (_flags & flag) != 0; protected void SetFlag(ConditionFlag flag, bool value) { if (value) { - m_Flags |= flag; + _flags |= flag; } else { - m_Flags &= ~flag; + _flags &= ~flag; } } diff --git a/Projects/UOContent/Migrations/Server.Items.ConditionTeleporter.v1.json b/Projects/UOContent/Migrations/Server.Items.ConditionTeleporter.v1.json new file mode 100644 index 000000000..ee20d0656 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.ConditionTeleporter.v1.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "type": "Server.Items.ConditionTeleporter", + "properties": [ + { + "name": "Flags", + "type": "Server.Items.ConditionTeleporter.ConditionFlag", + "rule": "EnumMigrationRule" + } + ] +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.TimeoutGoal.v0.json b/Projects/UOContent/Migrations/Server.Items.TimeoutGoal.v0.json new file mode 100644 index 000000000..dcb48ebf3 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.TimeoutGoal.v0.json @@ -0,0 +1,11 @@ +{ + "version": 0, + "type": "Server.Items.TimeoutGoal", + "properties": [ + { + "name": "Teleporter", + "type": "Server.Items.TimeoutTeleporter", + "rule": "SerializableInterfaceMigrationRule" + } + ] +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Items.TimeoutTeleporter.v1.json b/Projects/UOContent/Migrations/Server.Items.TimeoutTeleporter.v1.json new file mode 100644 index 000000000..c8d9576e7 --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Items.TimeoutTeleporter.v1.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "type": "Server.Items.TimeoutTeleporter", + "properties": [ + { + "name": "TimeoutDelay", + "type": "System.TimeSpan", + "rule": "PrimitiveTypeMigrationRule" + } + ] +} \ No newline at end of file