Cleanup of getExaminedItemTpl()
This commit is contained in:
parent
6032573815
commit
5e94e3fef0
@ -701,52 +701,56 @@ export class InventoryController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the tplid of an item from the examine request object
|
* Get the tplid of an item from the examine request object
|
||||||
* @param body response request
|
* @param request Response request
|
||||||
* @returns tplid
|
* @returns tplId
|
||||||
*/
|
*/
|
||||||
protected getExaminedItemTpl(body: IInventoryExamineRequestData): string
|
protected getExaminedItemTpl(request: IInventoryExamineRequestData): string
|
||||||
{
|
{
|
||||||
if (this.presetHelper.isPreset(body.item))
|
if (this.presetHelper.isPreset(request.item))
|
||||||
{
|
{
|
||||||
return this.presetHelper.getBaseItemTpl(body.item);
|
return this.presetHelper.getBaseItemTpl(request.item);
|
||||||
}
|
}
|
||||||
else if (body.fromOwner.id === Traders.FENCE)
|
|
||||||
|
if (request.fromOwner.id === Traders.FENCE)
|
||||||
{
|
{
|
||||||
// get tpl from fence assorts
|
// Get tpl from fence assorts
|
||||||
return this.fenceService.getRawFenceAssorts().items.find((x) => x._id === body.item)._tpl;
|
return this.fenceService.getRawFenceAssorts().items.find((x) => x._id === request.item)._tpl;
|
||||||
}
|
}
|
||||||
else if (body.fromOwner.type === "Trader")
|
|
||||||
{ // not fence
|
if (request.fromOwner.type === "Trader")
|
||||||
|
{
|
||||||
|
// Not fence
|
||||||
// get tpl from trader assort
|
// get tpl from trader assort
|
||||||
return this.databaseServer.getTables().traders[body.fromOwner.id].assort.items.find((item) =>
|
return this.databaseServer.getTables().traders[request.fromOwner.id].assort.items.find((item) =>
|
||||||
item._id === body.item
|
item._id === request.item
|
||||||
)._tpl;
|
)._tpl;
|
||||||
}
|
}
|
||||||
else if (body.fromOwner.type === "RagFair")
|
|
||||||
|
if (request.fromOwner.type === "RagFair")
|
||||||
{
|
{
|
||||||
// try to get tplid from items.json first
|
// Try to get tplid from items.json first
|
||||||
const item = this.databaseServer.getTables().templates.items[body.item];
|
const item = this.itemHelper.getItem(request.item);
|
||||||
if (item)
|
if (item[0])
|
||||||
{
|
{
|
||||||
return item._id;
|
return item[1]._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try alternate way of getting offer if first approach fails
|
// Try alternate way of getting offer if first approach fails
|
||||||
let offer = this.ragfairOfferService.getOfferByOfferId(body.item);
|
let offer = this.ragfairOfferService.getOfferByOfferId(request.item);
|
||||||
if (!offer)
|
if (!offer)
|
||||||
{
|
{
|
||||||
offer = this.ragfairOfferService.getOfferByOfferId(body.fromOwner.id);
|
offer = this.ragfairOfferService.getOfferByOfferId(request.fromOwner.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try find examine item inside offer items array
|
// Try find examine item inside offer items array
|
||||||
const matchingItem = offer.items.find((x) => x._id === body.item);
|
const matchingItem = offer.items.find((offerItem) => offerItem._id === request.item);
|
||||||
if (matchingItem)
|
if (matchingItem)
|
||||||
{
|
{
|
||||||
return matchingItem._tpl;
|
return matchingItem._tpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unable to find item in database or ragfair
|
// Unable to find item in database or ragfair
|
||||||
throw new Error(this.localisationService.getText("inventory-unable_to_find_item", body.item));
|
throw new Error(this.localisationService.getText("inventory-unable_to_find_item", request.item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user