From 3b6760605e239c9661859cca7b1db753abdfe28d Mon Sep 17 00:00:00 2001 From: CactusPie Date: Thu, 23 Nov 2023 11:44:00 +0100 Subject: [PATCH] If a first matching container is full, put loot into the next matching container --- .../QuickTransferPatch.cs | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/CactusPie.ContainerQuickLoot/QuickTransferPatch.cs b/src/CactusPie.ContainerQuickLoot/QuickTransferPatch.cs index 3fc4a46..355d77d 100644 --- a/src/CactusPie.ContainerQuickLoot/QuickTransferPatch.cs +++ b/src/CactusPie.ContainerQuickLoot/QuickTransferPatch.cs @@ -74,14 +74,9 @@ namespace CactusPie.ContainerQuickLoot return true; } - ContainerCollection targetContainerCollection = FindTargetContainerCollection(item, inventory); + IEnumerable targetContainers = FindTargetContainers(item, inventory); - if (targetContainerCollection == null) - { - return true; - } - - foreach (IContainer collectionContainer in targetContainerCollection.Containers) + foreach (IContainer collectionContainer in targetContainers) { if (!(collectionContainer is GClass2318 container)) { @@ -138,10 +133,9 @@ namespace CactusPie.ContainerQuickLoot return true; } - private static ContainerCollection FindTargetContainerCollection(Item item, Inventory inventory) + private static IEnumerable FindTargetContainers(Item item, Inventory inventory) { - ContainerCollection targetContainerCollection = null; - int? lowestFoundPriority = null; + var matchingContainerCollections = new List<(ContainerCollection containerCollection, int priority)>(); foreach (Item inventoryItem in inventory.Equipment.GetAllItems()) { @@ -179,20 +173,15 @@ namespace CactusPie.ContainerQuickLoot string priorityString = regexMatch.Value.Substring(lootTagLength); int priority = priorityString.Length == 0 ? 0 : int.Parse(priorityString); - - if (lowestFoundPriority == null || priority < lowestFoundPriority.Value) - { - lowestFoundPriority = priority; - } - else - { - continue; - } - - targetContainerCollection = containerCollection; + + matchingContainerCollections.Add((containerCollection, priority)); } - return targetContainerCollection; + IEnumerable result = matchingContainerCollections + .OrderBy(x => x.priority) + .SelectMany(x => x.containerCollection.Containers); + + return result; } private static Player GetLocalPlayerFromWorld(GameWorld gameWorld)