From 4d8e9fc51556adf538e891171330dc88db4480f2 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:22:11 -0700 Subject: [PATCH] fix: Fixes map item iteration when multis are moved (#1562) --- .../{ValueLInkList.cs => ValueLinkList.cs} | 30 +++++++++++++++---- Projects/Server/Maps/Map.cs | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) rename Projects/Server/Collections/{ValueLInkList.cs => ValueLinkList.cs} (94%) diff --git a/Projects/Server/Collections/ValueLInkList.cs b/Projects/Server/Collections/ValueLinkList.cs similarity index 94% rename from Projects/Server/Collections/ValueLInkList.cs rename to Projects/Server/Collections/ValueLinkList.cs index 82ecc3198..00727ab0a 100644 --- a/Projects/Server/Collections/ValueLInkList.cs +++ b/Projects/Server/Collections/ValueLinkList.cs @@ -85,6 +85,11 @@ public struct ValueLinkList where T : class, IValueLinkListNode node.Previous = null; node.OnLinkList = false; Count--; + + if (Count < 0) + { + throw new Exception("Count is negative!"); + } } // Remove all entries before this node, not including this node. @@ -117,6 +122,11 @@ public struct ValueLinkList where T : class, IValueLinkListNode current.Previous = null; Count--; + if (Count < 0) + { + throw new Exception("Count is negative!"); + } + current = previous; } @@ -153,6 +163,11 @@ public struct ValueLinkList where T : class, IValueLinkListNode current.Previous = null; Count--; + if (Count < 0) + { + throw new Exception("Count is negative!"); + } + current = next; } @@ -179,10 +194,9 @@ public struct ValueLinkList where T : class, IValueLinkListNode { First = e; Last = e; - Count++; + Count = 1; + e.OnLinkList = true; } - - e.OnLinkList = true; } public void AddFirst(T e) @@ -205,10 +219,9 @@ public struct ValueLinkList where T : class, IValueLinkListNode { First = e; Last = e; - Count++; + Count = 1; + e.OnLinkList = true; } - - e.OnLinkList = true; } public void AddBefore(T existing, T node) @@ -340,6 +353,11 @@ public struct ValueLinkList where T : class, IValueLinkListNode otherList.Count -= count; + if (otherList.Count < 0) + { + throw new Exception("Count is negative!"); + } + if (Last != null) { Last.Next = start; diff --git a/Projects/Server/Maps/Map.cs b/Projects/Server/Maps/Map.cs index 1c63469fa..99f2b2928 100644 --- a/Projects/Server/Maps/Map.cs +++ b/Projects/Server/Maps/Map.cs @@ -789,7 +789,7 @@ public sealed partial class Map : IComparable, ISpanFormattable, ISpanParsa { if (IsIteratingItems) { - _delayedItemActions.Add((MapAction.Enter, oldLocation, item)); + _delayedItemActions.Add((MapAction.Move, oldLocation, item)); return; }