Fix hasBuyRestrictions erroring on bad input data

Fix isItemTplStackable erroring on bad input data
This commit is contained in:
Dev 2023-11-05 12:37:17 +00:00
parent 84f3f0e3d5
commit 8f70b03284

View File

@ -465,7 +465,8 @@ class ItemHelper
*/
public hasBuyRestrictions(itemToCheck: Item): boolean
{
if (itemToCheck.upd.BuyRestrictionCurrent !== undefined && itemToCheck.upd.BuyRestrictionMax !== undefined)
if (itemToCheck.upd?.BuyRestrictionCurrent !== undefined
&& itemToCheck.upd?.BuyRestrictionMax !== undefined)
{
return true;
}
@ -505,7 +506,13 @@ class ItemHelper
*/
public isItemTplStackable(tpl: string): boolean
{
return this.databaseServer.getTables().templates.items[tpl]._props.StackMaxSize > 1;
const item = this.databaseServer.getTables().templates.items[tpl];
if (!item)
{
return undefined;
}
return item._props.StackMaxSize > 1;
}
/**