Handle moving items into sorting table when stash has no space
This commit is contained in:
parent
ab359a703e
commit
e84781be5f
@ -101,7 +101,7 @@ export class InventoryHelper
|
|||||||
return this.httpResponse.appendErrorToOutput(output, message);
|
return this.httpResponse.appendErrorToOutput(output, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle when item being bought is a preset
|
// Handle when item being bought is a preset
|
||||||
const item = fenceItems[itemIndex];
|
const item = fenceItems[itemIndex];
|
||||||
if (item.upd?.sptPresetId)
|
if (item.upd?.sptPresetId)
|
||||||
{
|
{
|
||||||
@ -137,6 +137,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);
|
||||||
|
|
||||||
for (const itemToAdd of itemsToAdd)
|
for (const itemToAdd of itemsToAdd)
|
||||||
{
|
{
|
||||||
@ -161,7 +162,8 @@ export class InventoryHelper
|
|||||||
|
|
||||||
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.stash;
|
||||||
itemToAdd.location = {
|
itemToAdd.location = {
|
||||||
x: findSlotResult.x,
|
x: findSlotResult.x,
|
||||||
y: findSlotResult.y,
|
y: findSlotResult.y,
|
||||||
@ -170,8 +172,29 @@ export class InventoryHelper
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const findStashSlotResult = this.containerHelper.findSlotForItem(stashFS2D, itemSize[0], itemSize[1]);
|
||||||
|
const itemSizeX = findStashSlotResult.rotation ? itemSize[1] : itemSize[0];
|
||||||
|
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?
|
||||||
|
}
|
||||||
|
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"));
|
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};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successfully found slot for every item, run callback, catch if it fails (e.g. payMoney() might fail)
|
// Successfully found slot for every item, run callback, catch if it fails (e.g. payMoney() might fail)
|
||||||
@ -235,7 +258,7 @@ export class InventoryHelper
|
|||||||
output.profileChanges[sessionID].items.new.push({
|
output.profileChanges[sessionID].items.new.push({
|
||||||
_id: idForItemToAdd,
|
_id: idForItemToAdd,
|
||||||
_tpl: itemToAdd.itemRef._tpl,
|
_tpl: itemToAdd.itemRef._tpl,
|
||||||
parentId: pmcData.Inventory.stash,
|
parentId: itemToAdd.containerId,
|
||||||
slotId: "hideout",
|
slotId: "hideout",
|
||||||
location: { x: itemToAdd.location.x, y: itemToAdd.location.y, r: itemToAdd.location.rotation ? 1 : 0 },
|
location: { x: itemToAdd.location.x, y: itemToAdd.location.y, r: itemToAdd.location.rotation ? 1 : 0 },
|
||||||
upd: upd
|
upd: upd
|
||||||
@ -244,7 +267,7 @@ export class InventoryHelper
|
|||||||
pmcData.Inventory.items.push({
|
pmcData.Inventory.items.push({
|
||||||
_id: idForItemToAdd,
|
_id: idForItemToAdd,
|
||||||
_tpl: itemToAdd.itemRef._tpl,
|
_tpl: itemToAdd.itemRef._tpl,
|
||||||
parentId: pmcData.Inventory.stash,
|
parentId: itemToAdd.containerId,
|
||||||
slotId: "hideout",
|
slotId: "hideout",
|
||||||
location: { x: itemToAdd.location.x, y: itemToAdd.location.y, r: itemToAdd.location.rotation ? 1 : 0 },
|
location: { x: itemToAdd.location.x, y: itemToAdd.location.y, r: itemToAdd.location.rotation ? 1 : 0 },
|
||||||
upd: this.jsonUtil.clone(upd) // Clone upd to prevent multi-purchases of same item referencing same upd object in memory
|
upd: this.jsonUtil.clone(upd) // Clone upd to prevent multi-purchases of same item referencing same upd object in memory
|
||||||
@ -785,19 +808,10 @@ export class InventoryHelper
|
|||||||
return this.getContainerMap(playerStashSize[0], playerStashSize[1], pmcData.Inventory.items, pmcData.Inventory.stash);
|
return this.getContainerMap(playerStashSize[0], playerStashSize[1], pmcData.Inventory.items, pmcData.Inventory.stash);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStashType(sessionID: string): string
|
protected getSortingTableSlotMap(pmcData: IPmcData): number[][]
|
||||||
{
|
{
|
||||||
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
return this.getContainerMap(10, 45, pmcData.Inventory.items, pmcData.Inventory.stash);
|
||||||
const stashObj = pmcData.Inventory.items.find(item => item._id === pmcData.Inventory.stash);
|
|
||||||
if (!stashObj)
|
|
||||||
{
|
|
||||||
this.logger.error(this.localisationService.getText("inventory-unable_to_find_stash"));
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
return stashObj._tpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Get Player Stash Proper Size
|
/* Get Player Stash Proper Size
|
||||||
* input: null
|
* input: null
|
||||||
@ -816,6 +830,19 @@ export class InventoryHelper
|
|||||||
return [stashX, stashY];
|
return [stashX, stashY];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getStashType(sessionID: string): string
|
||||||
|
{
|
||||||
|
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
||||||
|
const stashObj = pmcData.Inventory.items.find(item => item._id === pmcData.Inventory.stash);
|
||||||
|
if (!stashObj)
|
||||||
|
{
|
||||||
|
this.logger.error(this.localisationService.getText("inventory-unable_to_find_stash"));
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return stashObj._tpl;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper function to transfer an item from one profile to another.
|
* Internal helper function to transfer an item from one profile to another.
|
||||||
* fromProfileData: Profile of the source.
|
* fromProfileData: Profile of the source.
|
||||||
|
@ -6,4 +6,6 @@ export interface IAddItemTempObject
|
|||||||
count: number
|
count: number
|
||||||
isPreset: boolean
|
isPreset: boolean
|
||||||
location?: Location
|
location?: Location
|
||||||
|
// Container item will be placed in - stash or sorting table
|
||||||
|
containerId?: string
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user