don't require Stackable base type for stacking logic

This commit is contained in:
Tyfon
2024-07-19 12:54:51 -07:00
parent fea43bcada
commit e19cf80c35
5 changed files with 32 additions and 41 deletions

View File

@@ -119,7 +119,6 @@ public static class SortPatches
{
Error error = null;
var mergeableItems = lootItem.Grids.SelectMany(g => g.Items)
.OfType<Stackable>()
.Where(i => i.StackObjectsCount < i.StackMaxSize)
.ToArray();
@@ -131,7 +130,7 @@ public static class SortPatches
continue;
}
if (InteractionsHandlerClass.smethod_0(lootItem.Grids, item, out Stackable targetItem, 1))
if (Sorter.FindStackForMerge(lootItem.Grids, item, out Item targetItem, 1))
{
var operation = InteractionsHandlerClass.TransferOrMerge(item, targetItem, inventoryController, true);
if (operation.Succeeded)

View File

@@ -27,44 +27,10 @@ public static class StackFirItemsPatches
return method;
}
// Reimplementing this entire method to ignore SpawnedInSession for certain types
[PatchPrefix]
public static bool Prefix(IEnumerable<EFT.InventoryLogic.IContainer> containersToPut, Item itemToMerge, ref object mergeableItem, int overrideCount, ref bool __result)
public static bool Prefix(IEnumerable<EFT.InventoryLogic.IContainer> containersToPut, Item itemToMerge, ref Item mergeableItem, int overrideCount, ref bool __result)
{
if (!MergeableItemType.IsInstanceOfType(itemToMerge))
{
mergeableItem = null;
__result = false;
}
if (overrideCount <= 0)
{
overrideCount = itemToMerge.StackObjectsCount;
}
bool ignoreSpawnedInSession;
if (itemToMerge.Template is MoneyClass)
{
ignoreSpawnedInSession = Settings.MergeFIRMoney.Value;
}
else if (itemToMerge.Template is AmmoTemplate)
{
ignoreSpawnedInSession = Settings.MergeFIRAmmo.Value;
}
else
{
ignoreSpawnedInSession = Settings.MergeFIROther.Value;
}
mergeableItem = containersToPut.SelectMany(x => x.Items)
.Where(MergeableItemType.IsInstanceOfType)
.Where(x => x != itemToMerge)
.Where(x => x.TemplateId == itemToMerge.TemplateId)
.Where(x => ignoreSpawnedInSession || x.SpawnedInSession == itemToMerge.SpawnedInSession)
.Where(x => x.StackObjectsCount < x.StackMaxSize)
.FirstOrDefault(x => overrideCount <= x.StackMaxSize - x.StackObjectsCount);
__result = mergeableItem != null;
__result = Sorter.FindStackForMerge(containersToPut, itemToMerge, out mergeableItem, overrideCount);
return false;
}
}

View File

@@ -106,4 +106,30 @@ public static class Sorter
return operation;
}
// Recreation of InteractionsHandlerClass.smethod_0, but without the out type being Stackable.
// minimumStackSpace of 0 means complete merge only, i.e. mininumStackSpace = itemToMerge.StackObjectCount
public static bool FindStackForMerge(IEnumerable<EFT.InventoryLogic.IContainer> containers, Item itemToMerge, out Item mergeableItem, int minimumStackSpace = 0)
{
if (minimumStackSpace <= 0)
{
minimumStackSpace = itemToMerge.StackObjectsCount;
}
bool ignoreSpawnedInSession = itemToMerge.Template switch
{
MoneyClass _ => Settings.MergeFIRMoney.Value,
AmmoTemplate _ => Settings.MergeFIRMoney.Value,
_ => Settings.MergeFIROther.Value,
};
mergeableItem = containers.SelectMany(x => x.Items)
.Where(x => x != itemToMerge)
.Where(x => x.TemplateId == itemToMerge.TemplateId)
.Where(x => ignoreSpawnedInSession || x.SpawnedInSession == itemToMerge.SpawnedInSession)
.Where(x => x.StackObjectsCount < x.StackMaxSize)
.FirstOrDefault(x => minimumStackSpace <= x.StackMaxSize - x.StackObjectsCount);
return mergeableItem != null;
}
}

View File

@@ -15,8 +15,8 @@
</PropertyGroup>
<PropertyGroup>
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.2-debug</PathToSPT>
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.2</PathToSPT>
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.3-debug</PathToSPT>
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.3</PathToSPT>
</PropertyGroup>
<ItemGroup>

View File

@@ -38,7 +38,7 @@ import ignore from "ignore";
import archiver from "archiver";
import winston from "winston";
const sptPath = "/SPT/3.9.2-debug";
const sptPath = "/SPT/3.9.3-debug";
// Get the command line arguments to determine whether to use verbose logging.
const args = process.argv.slice(2);