From fe94aa050ab26bf5089f7e2a796323ffb702d106 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:20:10 -0700 Subject: [PATCH] fix: Fixes gauntlet spawner and map item deserialization (#1170) --- .../UOContent/Engines/Doom/GauntletSpawner.cs | 125 +++++++++--------- Projects/UOContent/Items/Maps/MapItem.cs | 11 +- 2 files changed, 71 insertions(+), 65 deletions(-) diff --git a/Projects/UOContent/Engines/Doom/GauntletSpawner.cs b/Projects/UOContent/Engines/Doom/GauntletSpawner.cs index 76d27f205..2d99f424d 100644 --- a/Projects/UOContent/Engines/Doom/GauntletSpawner.cs +++ b/Projects/UOContent/Engines/Doom/GauntletSpawner.cs @@ -84,63 +84,10 @@ namespace Server.Engines.Doom get => m_State; set { - if (m_State == value) + if (m_State != value) { - return; - } - - m_State = value; - - var hue = 0; - var lockDoors = m_State == GauntletSpawnerState.InProgress; - - hue = m_State switch - { - GauntletSpawnerState.InSequence => InSequenceItemHue, - GauntletSpawnerState.InProgress => InProgressItemHue, - GauntletSpawnerState.Completed => CompletedItemHue, - _ => hue - }; - - if (Door != null) - { - Door.Hue = hue; - Door.Locked = lockDoors; - - if (lockDoors) - { - Door.KeyValue = Key.RandomValue(); - Door.Open = false; - } - - if (Door.Link != null) - { - Door.Link.Hue = hue; - Door.Link.Locked = lockDoors; - - if (lockDoors) - { - Door.Link.KeyValue = Key.RandomValue(); - Door.Open = false; - } - } - } - - if (Addon != null) - { - Addon.Hue = hue; - } - - if (m_State == GauntletSpawnerState.InProgress) - { - CreateRegion(); - FullSpawn(); - - Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice, out _timerToken); - } - else - { - Stop(); + m_State = value; + Update(); } } } @@ -151,6 +98,64 @@ namespace Server.Engines.Doom public Region Region { get; set; } + private void Update(bool shouldSpawn = true) + { + var lockDoors = m_State == GauntletSpawnerState.InProgress; + + var hue = m_State switch + { + GauntletSpawnerState.InSequence => InSequenceItemHue, + GauntletSpawnerState.InProgress => InProgressItemHue, + GauntletSpawnerState.Completed => CompletedItemHue, + _ => 0 + }; + + if (Door != null) + { + Door.Hue = hue; + Door.Locked = lockDoors; + + if (lockDoors) + { + Door.KeyValue = Key.RandomValue(); + Door.Open = false; + } + + if (Door.Link != null) + { + Door.Link.Hue = hue; + Door.Link.Locked = lockDoors; + + if (lockDoors) + { + Door.Link.KeyValue = Key.RandomValue(); + Door.Open = false; + } + } + } + + if (Addon != null) + { + Addon.Hue = hue; + } + + if (m_State == GauntletSpawnerState.InProgress) + { + CreateRegion(); + + if (shouldSpawn) + { + FullSpawn(); + } + + Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice, out _timerToken); + } + else + { + Stop(); + } + } + public override string DefaultName => "doom spawner"; public virtual void CreateRegion() @@ -222,11 +227,9 @@ namespace Server.Engines.Doom return; } - BaseTrap trap; - var random = Utility.Random(100); - trap = random switch + BaseTrap trap = random switch { < 22 => new SawTrap(Utility.RandomBool() ? SawTrapType.WestFloor : SawTrapType.NorthFloor), < 44 => new SpikeTrap(Utility.RandomBool() ? SpikeTrapType.WestFloor : SpikeTrapType.NorthFloor), @@ -446,11 +449,13 @@ namespace Server.Engines.Doom Addon = reader.ReadEntity(); Sequence = reader.ReadEntity(); - State = (GauntletSpawnerState)reader.ReadInt(); + m_State = (GauntletSpawnerState)reader.ReadInt(); break; } } + + Timer.DelayCall(() => Update(false)); } } } diff --git a/Projects/UOContent/Items/Maps/MapItem.cs b/Projects/UOContent/Items/Maps/MapItem.cs index 6fe549253..ddabca698 100644 --- a/Projects/UOContent/Items/Maps/MapItem.cs +++ b/Projects/UOContent/Items/Maps/MapItem.cs @@ -284,17 +284,18 @@ public partial class MapItem : Item, ICraftable { // Version 0 doesn't serialize Facet/Editable, and count is not encoded - Bounds = reader.ReadRect2D(); + _bounds = reader.ReadRect2D(); - Width = reader.ReadInt(); - Height = reader.ReadInt(); + _width = reader.ReadInt(); + _height = reader.ReadInt(); - Protected = reader.ReadBool(); + _protected = reader.ReadBool(); var count = reader.ReadInt(); + _pins = new List(count); for (var i = 0; i < count; i++) { - Pins.Add(reader.ReadPoint2D()); + _pins.Add(reader.ReadPoint2D()); } } }