Automatically merge stacks when moving items

This commit is contained in:
CactusPie 2023-11-20 15:34:24 +01:00
parent b176d90467
commit 208a906f24
2 changed files with 34 additions and 1 deletions

View File

@ -1,6 +1,5 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using JetBrains.Annotations;
namespace CactusPie.ContainerQuickLoot
@ -12,6 +11,8 @@ namespace CactusPie.ContainerQuickLoot
internal static ConfigEntry<bool> EnableForLooseLoot { get; set; }
internal static ConfigEntry<bool> AutoMergeStacks { get; set; }
[UsedImplicitly]
internal void Start()
{
@ -39,6 +40,17 @@ namespace CactusPie.ContainerQuickLoot
)
);
AutoMergeStacks = Config.Bind
(
sectionName,
"Merge stacks",
true,
new ConfigDescription
(
"Automatically merge stacks (money, ammo, etc.) when transferring them into a container"
)
);
new QuickTransferPatch().Enable();
}
}

View File

@ -90,6 +90,27 @@ namespace CactusPie.ContainerQuickLoot
continue;
}
if (ContainerQuickLootPlugin.AutoMergeStacks.Value && item.StackMaxSize > 1 && item.StackObjectsCount != item.StackMaxSize)
{
foreach (KeyValuePair<Item, LocationInGrid> containedItem in container.ContainedItems)
{
if (containedItem.Key.Template._id != item.Template._id)
{
continue;
}
if (containedItem.Key.StackObjectsCount + item.StackObjectsCount > item.StackMaxSize)
{
continue;
}
GStruct375<GClass2599> mergeResult = GClass2585.Merge(item, containedItem.Key, controller, simulate);
__result = new GStruct375<GInterface275>(mergeResult.Value);
return false;
}
}
GClass2580 location = container.FindLocationForItem(item);
if (location == null)
{