From 8a118170e7dc22dd3e1f1ff6360a1a2bb63fda49 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:01:27 -0700 Subject: [PATCH] fix: Fixes treasure map chest crash from null guardians (#2236) --- .../UOContent/Items/Containers/TreasureMapChest.cs | 14 ++++++++------ .../Server.Items.TreasureMapChest.v2.json | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Projects/UOContent/Items/Containers/TreasureMapChest.cs b/Projects/UOContent/Items/Containers/TreasureMapChest.cs index 22c5101cf..fffd85db8 100644 --- a/Projects/UOContent/Items/Containers/TreasureMapChest.cs +++ b/Projects/UOContent/Items/Containers/TreasureMapChest.cs @@ -12,6 +12,7 @@ namespace Server.Items; [SerializationGenerator(2, false)] public partial class TreasureMapChest : LockableContainer { + [Tidy] [SerializableField(0, setter: "private")] private List _guardians; @@ -57,7 +58,7 @@ public partial class TreasureMapChest : LockableContainer _level = level; _temporary = temporary; - _guardians = new List(); + _guardians = []; _expireTimer = Timer.DelayCall(TimeSpan.FromHours(3.0), Delete); Fill(this, level); @@ -66,7 +67,7 @@ public partial class TreasureMapChest : LockableContainer public override int LabelNumber => 3000541; public static Type[] Artifacts { get; } = - { + [ typeof(CandelabraOfSouls), typeof(GoldBricks), typeof(PhillipsWoodenSteed), typeof(ArcticDeathDealer), typeof(BlazeOfDeath), typeof(BurglarsBandana), typeof(CavortingClub), typeof(DreadPirateHat), @@ -74,7 +75,7 @@ public partial class TreasureMapChest : LockableContainer typeof(LunaLance), typeof(NightsKiss), typeof(NoxRangersHeavyCrossbow), typeof(PolarBearMask), typeof(VioletCourage), typeof(HeartOfTheLion), typeof(ColdBlood), typeof(AlchemistsBauble) - }; + ]; [CommandProperty(AccessLevel.GameMaster)] public DateTime DeleteTime => _expireTimer.Next; @@ -299,8 +300,9 @@ public partial class TreasureMapChest : LockableContainer if (_level == 0 && from.AccessLevel < AccessLevel.GameMaster) { - foreach (var m in _guardians) + for (var i = 0; i < _guardians.Count; i++) { + var m = _guardians[i]; if (m.Alive) { // You must first kill the guardians before you may open this chest. @@ -366,7 +368,7 @@ public partial class TreasureMapChest : LockableContainer if (notYetLifted) { - _lifted ??= new HashSet(); + _lifted ??= []; _lifted.Add(item); if (Utility.RandomDouble() < 0.1) // 10% chance to spawn a new monster @@ -391,7 +393,7 @@ public partial class TreasureMapChest : LockableContainer private void Deserialize(IGenericReader reader, int version) { - _guardians = new List(); + _guardians = []; _owner = reader.ReadEntity(); _level = reader.ReadInt(); diff --git a/Projects/UOContent/Migrations/Server.Items.TreasureMapChest.v2.json b/Projects/UOContent/Migrations/Server.Items.TreasureMapChest.v2.json index 6510e836b..e44d7e19a 100644 --- a/Projects/UOContent/Migrations/Server.Items.TreasureMapChest.v2.json +++ b/Projects/UOContent/Migrations/Server.Items.TreasureMapChest.v2.json @@ -7,6 +7,7 @@ "type": "System.Collections.Generic.List\u003CServer.Mobile\u003E", "rule": "ListMigrationRule", "ruleArguments": [ + "@Tidy", "Server.Mobile", "SerializableInterfaceMigrationRule" ]