don't require Stackable base type for stacking logic
This commit is contained in:
@@ -119,7 +119,6 @@ public static class SortPatches
|
|||||||
{
|
{
|
||||||
Error error = null;
|
Error error = null;
|
||||||
var mergeableItems = lootItem.Grids.SelectMany(g => g.Items)
|
var mergeableItems = lootItem.Grids.SelectMany(g => g.Items)
|
||||||
.OfType<Stackable>()
|
|
||||||
.Where(i => i.StackObjectsCount < i.StackMaxSize)
|
.Where(i => i.StackObjectsCount < i.StackMaxSize)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ public static class SortPatches
|
|||||||
continue;
|
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);
|
var operation = InteractionsHandlerClass.TransferOrMerge(item, targetItem, inventoryController, true);
|
||||||
if (operation.Succeeded)
|
if (operation.Succeeded)
|
||||||
|
@@ -27,44 +27,10 @@ public static class StackFirItemsPatches
|
|||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reimplementing this entire method to ignore SpawnedInSession for certain types
|
|
||||||
[PatchPrefix]
|
[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))
|
__result = Sorter.FindStackForMerge(containersToPut, itemToMerge, out mergeableItem, overrideCount);
|
||||||
{
|
|
||||||
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;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
Sorter.cs
26
Sorter.cs
@@ -106,4 +106,30 @@ public static class Sorter
|
|||||||
|
|
||||||
return operation;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -15,8 +15,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.2-debug</PathToSPT>
|
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.3-debug</PathToSPT>
|
||||||
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.2</PathToSPT>
|
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.3</PathToSPT>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -38,7 +38,7 @@ import ignore from "ignore";
|
|||||||
import archiver from "archiver";
|
import archiver from "archiver";
|
||||||
import winston from "winston";
|
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.
|
// Get the command line arguments to determine whether to use verbose logging.
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
|
Reference in New Issue
Block a user