updated setFindInRaidStatusForItem()
to be protected + added return type
Improve comments inside `InventoryHelper`
This commit is contained in:
parent
3bc9833e57
commit
bf317b6c2f
@ -21,6 +21,7 @@ import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInven
|
||||
import { IInventoryTransferRequestData } from "@spt-aki/models/eft/inventory/IInventoryTransferRequestData";
|
||||
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
|
||||
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
|
||||
import { BonusType } from "@spt-aki/models/enums/BonusType";
|
||||
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
||||
import { Traders } from "@spt-aki/models/enums/Traders";
|
||||
import { IInventoryConfig, RewardDetails } from "@spt-aki/models/spt/config/IInventoryConfig";
|
||||
@ -187,7 +188,7 @@ export class InventoryHelper
|
||||
* @param itemWithChildren An item
|
||||
* @param foundInRaid Item was found in raid
|
||||
*/
|
||||
private setFindInRaidStatusForItem(itemWithChildren: Item[], foundInRaid: boolean)
|
||||
protected setFindInRaidStatusForItem(itemWithChildren: Item[], foundInRaid: boolean): void
|
||||
{
|
||||
for (const item of itemWithChildren)
|
||||
{
|
||||
@ -212,7 +213,7 @@ export class InventoryHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove properties from a Upd object used by a trader/ragfair
|
||||
* Remove properties from a Upd object used by a trader/ragfair that are unnecessary to a player
|
||||
* @param upd Object to update
|
||||
*/
|
||||
protected removeTraderRagfairRelatedUpdProperties(upd: Upd): void
|
||||
@ -479,9 +480,10 @@ export class InventoryHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an items stack size based on its StackMaxSize value
|
||||
* @param assortItems Items to add to inventory
|
||||
* @param requestItem Details of purchased item to add to inventory
|
||||
* @param result Array split stacks are added to
|
||||
* @param result Array split stacks are appended to
|
||||
*/
|
||||
protected splitStackIntoSmallerChildStacks(
|
||||
assortItems: Item[],
|
||||
@ -605,10 +607,16 @@ export class InventoryHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete desired item from a player profiles mail
|
||||
* @param sessionId Session id
|
||||
* @param removeRequest Remove request
|
||||
* @param output OPTIONAL - IItemEventRouterResponse
|
||||
*/
|
||||
public removeItemAndChildrenFromMailRewards(
|
||||
sessionId: string,
|
||||
removeRequest: IInventoryRemoveRequestData,
|
||||
output: IItemEventRouterResponse,
|
||||
output: IItemEventRouterResponse = undefined,
|
||||
): void
|
||||
{
|
||||
const fullProfile = this.profileHelper.getFullProfile(sessionId);
|
||||
@ -647,10 +655,19 @@ export class InventoryHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find item by id in player inventory and remove x of its count
|
||||
* @param pmcData player profile
|
||||
* @param itemId Item id to decrement StackObjectsCount of
|
||||
* @param countToRemove Number of item to remove
|
||||
* @param sessionID Session id
|
||||
* @param output IItemEventRouterResponse
|
||||
* @returns IItemEventRouterResponse
|
||||
*/
|
||||
public removeItemByCount(
|
||||
pmcData: IPmcData,
|
||||
itemId: string,
|
||||
count: number,
|
||||
countToRemove: number,
|
||||
sessionID: string,
|
||||
output: IItemEventRouterResponse = undefined,
|
||||
): IItemEventRouterResponse
|
||||
@ -660,16 +677,17 @@ export class InventoryHelper
|
||||
return output;
|
||||
}
|
||||
|
||||
// Goal is to keep removing items until we can remove part of an items stack
|
||||
const itemsToReduce = this.itemHelper.findAndReturnChildrenAsItems(pmcData.Inventory.items, itemId);
|
||||
let remainingCount = count;
|
||||
let remainingCount = countToRemove;
|
||||
for (const itemToReduce of itemsToReduce)
|
||||
{
|
||||
const itemCount = this.itemHelper.getItemStackSize(itemToReduce);
|
||||
const itemStackSize = this.itemHelper.getItemStackSize(itemToReduce);
|
||||
|
||||
// remove whole stack
|
||||
if (remainingCount >= itemCount)
|
||||
// Remove whole stack
|
||||
if (remainingCount >= itemStackSize)
|
||||
{
|
||||
remainingCount -= itemCount;
|
||||
remainingCount -= itemStackSize;
|
||||
this.removeItem(pmcData, itemToReduce._id, sessionID, output);
|
||||
}
|
||||
else
|
||||
@ -684,6 +702,7 @@ export class InventoryHelper
|
||||
|
||||
if (remainingCount === 0)
|
||||
{
|
||||
// Desired count of item has been removed / we ran out of items to remove
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -691,9 +710,12 @@ export class InventoryHelper
|
||||
return output;
|
||||
}
|
||||
|
||||
/* Calculate Size of item input
|
||||
* inputs Item template ID, Item Id, InventoryItem (item from inventory having _id and _tpl)
|
||||
* outputs [width, height]
|
||||
/**
|
||||
* Get the height and width of an item - can have children that alter size
|
||||
* @param itemTpl Item to get size of
|
||||
* @param itemID Items id to get size of
|
||||
* @param inventoryItems
|
||||
* @returns [width, height]
|
||||
*/
|
||||
public getItemSize(itemTpl: string, itemID: string, inventoryItems: Item[]): number[]
|
||||
{
|
||||
@ -835,33 +857,24 @@ export class InventoryHelper
|
||||
];
|
||||
}
|
||||
|
||||
protected getInventoryItemHash(inventoryItem: Item[]): InventoryHelper.InventoryItemHash
|
||||
{
|
||||
const inventoryItemHash: InventoryHelper.InventoryItemHash = { byItemId: {}, byParentId: {} };
|
||||
|
||||
for (const item of inventoryItem)
|
||||
{
|
||||
inventoryItemHash.byItemId[item._id] = item;
|
||||
|
||||
if (!("parentId" in item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(item.parentId in inventoryItemHash.byParentId))
|
||||
{
|
||||
inventoryItemHash.byParentId[item.parentId] = [];
|
||||
}
|
||||
inventoryItemHash.byParentId[item.parentId].push(item);
|
||||
}
|
||||
return inventoryItemHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a blank two-dimentional representation of a container
|
||||
* @param containerH Horizontal size of container
|
||||
* @param containerY Vertical size of container
|
||||
* @returns Two-dimensional representation of container
|
||||
*/
|
||||
protected getBlankContainerMap(containerH: number, containerY: number): number[][]
|
||||
{
|
||||
return Array(containerY).fill(0).map(() => Array(containerH).fill(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param containerH Horizontal size of container
|
||||
* @param containerV Vertical size of container
|
||||
* @param itemList
|
||||
* @param containerId Id of the container
|
||||
* @returns Two-dimensional representation of container
|
||||
*/
|
||||
public getContainerMap(containerH: number, containerV: number, itemList: Item[], containerId: string): number[][]
|
||||
{
|
||||
const container2D: number[][] = this.getBlankContainerMap(containerH, containerV);
|
||||
@ -917,6 +930,27 @@ export class InventoryHelper
|
||||
return container2D;
|
||||
}
|
||||
|
||||
protected getInventoryItemHash(inventoryItem: Item[]): InventoryHelper.InventoryItemHash
|
||||
{
|
||||
const inventoryItemHash: InventoryHelper.InventoryItemHash = { byItemId: {}, byParentId: {} };
|
||||
for (const item of inventoryItem)
|
||||
{
|
||||
inventoryItemHash.byItemId[item._id] = item;
|
||||
|
||||
if (!("parentId" in item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(item.parentId in inventoryItemHash.byParentId))
|
||||
{
|
||||
inventoryItemHash.byParentId[item.parentId] = [];
|
||||
}
|
||||
inventoryItemHash.byParentId[item.parentId].push(item);
|
||||
}
|
||||
return inventoryItemHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the inventory that needs to be modified (scav/pmc etc)
|
||||
* Changes made to result apply to character inventory
|
||||
@ -983,10 +1017,11 @@ export class InventoryHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Made a 2d array table with 0 - free slot and 1 - used slot
|
||||
* @param {Object} pmcData
|
||||
* @param {string} sessionID
|
||||
* @returns Array
|
||||
* Get a two dimensional array to represent stash slots
|
||||
* 0 value = free, 1 = taken
|
||||
* @param pmcData Player profile
|
||||
* @param sessionID session id
|
||||
* @returns 2-dimensional array
|
||||
*/
|
||||
protected getStashSlotMap(pmcData: IPmcData, sessionID: string): number[][]
|
||||
{
|
||||
@ -999,6 +1034,11 @@ export class InventoryHelper
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a blank two-dimensional array representation of a container
|
||||
* @param containerTpl Container to get data for
|
||||
* @returns blank two-dimensional array
|
||||
*/
|
||||
public getContainerSlotMap(containerTpl: string): number[][]
|
||||
{
|
||||
const containerTemplate = this.itemHelper.getItem(containerTpl)[1];
|
||||
@ -1009,6 +1049,11 @@ export class InventoryHelper
|
||||
return this.getBlankContainerMap(containerH, containerV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a two-dimensional array representation of the players sorting table
|
||||
* @param pmcData Player profile
|
||||
* @returns two-dimensional array
|
||||
*/
|
||||
protected getSortingTableSlotMap(pmcData: IPmcData): number[][]
|
||||
{
|
||||
return this.getContainerMap(10, 45, pmcData.Inventory.items, pmcData.Inventory.sortingTable);
|
||||
|
Loading…
x
Reference in New Issue
Block a user