Fixed issues with moving items to sorting table after opening sealed container

Also allow money from sold flea offers to enter sorting table

Remove unused addItem() from InventoryController

Add optional param to inventoryHelper.addItem() to allow use of sorting table, default = off
This commit is contained in:
Dev 2023-07-23 12:29:00 +01:00
parent e84781be5f
commit c5332986eb
4 changed files with 42 additions and 31 deletions

View File

@ -364,15 +364,6 @@ export class InventoryController
return output; return output;
} }
/**
* Give Item
* its used for "add" item like gifts etc.
*/
public addItem(pmcData: IPmcData, body: IAddItemRequestData, output: IItemEventRouterResponse, sessionID: string, callback: any, foundInRaid = false, addUpd = null): IItemEventRouterResponse
{
return this.inventoryHelper.addItem(pmcData, body, output, sessionID, callback, foundInRaid, addUpd);
}
/** /**
* Handles folding of Weapons * Handles folding of Weapons
*/ */
@ -819,7 +810,7 @@ export class InventoryController
this.inventoryHelper.removeItem(pmcData, body.item, sessionID, output); this.inventoryHelper.removeItem(pmcData, body.item, sessionID, output);
// Add reward items to player inventory // Add reward items to player inventory
this.inventoryHelper.addItem(pmcData, newItemRequest, output, sessionID, null, foundInRaid); this.inventoryHelper.addItem(pmcData, newItemRequest, output, sessionID, null, foundInRaid, null, true);
return output; return output;
} }

View File

@ -98,6 +98,16 @@ export class ContainerHelper
return new FindSlotResult(); return new FindSlotResult();
} }
/**
* Find a free slot for an item to be placed at
* @param container2D Container to palce item in
* @param x Container x size
* @param y Container y size
* @param itemW Items width
* @param itemH Items height
* @param rotate is item rotated
* @returns Location to place item
*/
public fillContainerMapWithItem(container2D: number[][], x: number, y: number, itemW: number, itemH: number, rotate: boolean): number[][] public fillContainerMapWithItem(container2D: number[][], x: number, y: number, itemW: number, itemH: number, rotate: boolean): number[][]
{ {
const itemWidth = rotate ? itemH : itemW; const itemWidth = rotate ? itemH : itemW;

View File

@ -69,9 +69,10 @@ export class InventoryHelper
* @param callback Code to execute later (function) * @param callback Code to execute later (function)
* @param foundInRaid Will results added to inventory be set as found in raid * @param foundInRaid Will results added to inventory be set as found in raid
* @param addUpd Additional upd properties for items being added to inventory * @param addUpd Additional upd properties for items being added to inventory
* @param useSortingTable Allow items to go into sorting table when stash has no space
* @returns IItemEventRouterResponse * @returns IItemEventRouterResponse
*/ */
public addItem(pmcData: IPmcData, request: IAddItemRequestData, output: IItemEventRouterResponse, sessionID: string, callback: { (): void }, foundInRaid = false, addUpd = null): IItemEventRouterResponse public addItem(pmcData: IPmcData, request: IAddItemRequestData, output: IItemEventRouterResponse, sessionID: string, callback: { (): void }, foundInRaid = false, addUpd = null, useSortingTable = false): IItemEventRouterResponse
{ {
const itemLib: Item[] = []; // TODO: what is the purpose of this property const itemLib: Item[] = []; // TODO: what is the purpose of this property
const itemsToAdd: IAddItemTempObject[] = []; const itemsToAdd: IAddItemTempObject[] = [];
@ -137,7 +138,7 @@ export class InventoryHelper
// Find an empty slot in stash for each of the items being added // Find an empty slot in stash for each of the items being added
let stashFS2D = this.getStashSlotMap(pmcData, sessionID); let stashFS2D = this.getStashSlotMap(pmcData, sessionID);
let sortingTableFS2D = this.getStashSlotMap(pmcData, sessionID); let sortingTableFS2D = this.getSortingTableSlotMap(pmcData);
for (const itemToAdd of itemsToAdd) for (const itemToAdd of itemsToAdd)
{ {
@ -172,28 +173,37 @@ export class InventoryHelper
} }
else else
{ {
const findStashSlotResult = this.containerHelper.findSlotForItem(stashFS2D, itemSize[0], itemSize[1]); // Space not foundin main stash, use sorting table or just error out
const itemSizeX = findStashSlotResult.rotation ? itemSize[1] : itemSize[0]; if (useSortingTable)
const itemSizeY = findStashSlotResult.rotation ? itemSize[0] : itemSize[1];
try
{ {
sortingTableFS2D = this.containerHelper.fillContainerMapWithItem(sortingTableFS2D, findStashSlotResult.x, findStashSlotResult.y, itemSizeX, itemSizeY, false); // TODO: rotation not passed in, bad? const findSortingSlotResult = this.containerHelper.findSlotForItem(sortingTableFS2D, itemSize[0], itemSize[1]);
} const itemSizeX = findSortingSlotResult.rotation ? itemSize[1] : itemSize[0];
catch (err) const itemSizeY = findSortingSlotResult.rotation ? itemSize[0] : itemSize[1];
{ try
const errorText = typeof err === "string" ? ` -> ${err}` : ""; {
this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText)); sortingTableFS2D = this.containerHelper.fillContainerMapWithItem(sortingTableFS2D, findSortingSlotResult.x, findSortingSlotResult.y, itemSizeX, itemSizeY, false); // TODO: rotation not passed in, bad?
}
catch (err)
{
const errorText = typeof err === "string" ? ` -> ${err}` : "";
this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText));
return this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space"));
}
// Store details for object, incuding container item will be placed in
itemToAdd.containerId = pmcData.Inventory.sortingTable;
itemToAdd.location = {
x: findSortingSlotResult.x,
y: findSortingSlotResult.y,
r: findSortingSlotResult.rotation ? 1 : 0,
rotation: findSortingSlotResult.rotation};
}
else
{
return this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); return this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space"));
} }
// Store details for object, incuding container item will be placed in
itemToAdd.containerId = pmcData.Inventory.sortingTable;
itemToAdd.location = {
x: findStashSlotResult.x,
y: findStashSlotResult.y,
r: findStashSlotResult.rotation ? 1 : 0,
rotation: findStashSlotResult.rotation};
} }
} }
@ -810,7 +820,7 @@ export class InventoryHelper
protected getSortingTableSlotMap(pmcData: IPmcData): number[][] protected getSortingTableSlotMap(pmcData: IPmcData): number[][]
{ {
return this.getContainerMap(10, 45, pmcData.Inventory.items, pmcData.Inventory.stash); return this.getContainerMap(10, 45, pmcData.Inventory.items, pmcData.Inventory.sortingTable);
} }
/* Get Player Stash Proper Size /* Get Player Stash Proper Size

View File

@ -161,7 +161,7 @@ export class PaymentService
tid: body.tid tid: body.tid
}; };
output = this.inventoryHelper.addItem(pmcData, request, output, sessionID, null, false); output = this.inventoryHelper.addItem(pmcData, request, output, sessionID, null, false, null, true);
} }
// set current sale sum // set current sale sum