diff --git a/project/assets/database/locales/server/en.json b/project/assets/database/locales/server/en.json index 24280595..b3c9910e 100644 --- a/project/assets/database/locales/server/en.json +++ b/project/assets/database/locales/server/en.json @@ -83,6 +83,7 @@ "inventory-unable_to_fill_container": "[OOB] for item: {{id}}; Error message: {{error}}", "inventory-unable_to_find_item": "getExaminedItemTpl() Unable to find item with tpl: %s in database or flea", "inventory-unable_to_find_stash": "No stash found", + "inventory-return_default_size": "Defaulting item %s to size 1x1", "item-durability_value_invalid_use_default": "getRepairableItemQualityValue() weapon tpl: %s durability value is invalid, defaulting to 1", "linux_use_priviledged_port_non_root": "Non-root processes cannot bind to ports below 1024", "location-containers_generated_success": "A total of %s static containers generated", diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index d6c66c3d..ce3f5658 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -528,7 +528,7 @@ export class InventoryHelper * inputs Item template ID, Item Id, InventoryItem (item from inventory having _id and _tpl) * outputs [width, height] */ - public getItemSize(itemTpl: string, itemID: string, inventoryItem: Item[]): Record + public getItemSize(itemTpl: string, itemID: string, inventoryItem: Item[]): number[] { // -> Prepares item Width and height returns [sizeX, sizeY] return this.getSizeByInventoryItemHash(itemTpl, itemID, this.getInventoryItemHash(inventoryItem)); @@ -536,20 +536,31 @@ export class InventoryHelper // note from 2027: there IS a thing i didn't explore and that is Merges With Children // -> Prepares item Width and height returns [sizeX, sizeY] - protected getSizeByInventoryItemHash(itemTpl: string, itemID: string, inventoryItemHash: InventoryHelper.InventoryItemHash): Record + protected getSizeByInventoryItemHash(itemTpl: string, itemID: string, inventoryItemHash: InventoryHelper.InventoryItemHash): number[] { const toDo = [itemID]; const result = this.itemHelper.getItem(itemTpl); const tmpItem = result[1]; + // Invalid item or no object if (!(result[0] && result[1])) { this.logger.error(this.localisationService.getText("inventory-invalid_item_missing_from_db", itemTpl)); } - if (!tmpItem._props) + // item found but no _props property + if (tmpItem && !tmpItem._props) { - this.logger.error(`Item ${tmpItem._id} ${tmpItem._name} is missing a props field, a size for it cannot be acquired`); + this.logger.error(`Item ${itemTpl} ${tmpItem?._name} is missing a props field, a size for it cannot be acquired`); + } + + // No item object or getItem() returned false + if (!(tmpItem && result[0])) + { + // return default size of 1x1 + this.logger.error(this.localisationService.getText("inventory-return_default_size", itemTpl)); + + return [1, 1]; } const rootItem = inventoryItemHash.byItemId[itemID];