From 5f873e73b8f45b06c5e237be72758f9a30cf610c Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 6 Feb 2024 12:52:56 +0000 Subject: [PATCH] Move handbook override code into `HandbookHelper.hydrate()` - changes now apply to ragfair --- project/assets/configs/ragfair.json | 2 ++ project/src/helpers/HandbookHelper.ts | 32 ++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/project/assets/configs/ragfair.json b/project/assets/configs/ragfair.json index 9b6c80e6..25c3da62 100644 --- a/project/assets/configs/ragfair.json +++ b/project/assets/configs/ragfair.json @@ -206,11 +206,13 @@ }, "unreasonableModPrices": { "5448fe124bdc2da5018b4567": { + "itemType": "Weapon Mod", "enabled": true, "handbookPriceOverMultiplier": 9, "newPriceHandbookMultiplier": 9 }, "57864a66245977548f04a81f": { + "itemType": "Electronics", "enabled": true, "handbookPriceOverMultiplier": 11, "newPriceHandbookMultiplier": 11 diff --git a/project/src/helpers/HandbookHelper.ts b/project/src/helpers/HandbookHelper.ts index 563f0b2f..c91ee3f4 100644 --- a/project/src/helpers/HandbookHelper.ts +++ b/project/src/helpers/HandbookHelper.ts @@ -54,8 +54,29 @@ export class HandbookHelper */ public hydrateLookup(): void { - const handbookDb = this.jsonUtil.clone(this.databaseServer.getTables().templates.handbook); - for (const handbookItem of handbookDb.Items) + // Add handbook overrides found in items.json config into db + for (const itemTpl in this.itemConfig.handbookPriceOverride) + { + let itemToUpdate = this.databaseServer.getTables().templates.handbook.Items.find((item) => + item.Id === itemTpl + ); + if (!itemToUpdate) + { + this.databaseServer.getTables().templates.handbook.Items.push({ + Id: itemTpl, + ParentId: this.databaseServer.getTables().templates.items[itemTpl]._parent, + Price: this.itemConfig.handbookPriceOverride[itemTpl], + }); + itemToUpdate = this.databaseServer.getTables().templates.handbook.Items.find((item) => + item.Id === itemTpl + ); + } + + itemToUpdate.Price = this.itemConfig.handbookPriceOverride[itemTpl]; + } + + const handbookDbClone = this.jsonUtil.clone(this.databaseServer.getTables().templates.handbook); + for (const handbookItem of handbookDbClone.Items) { this.handbookPriceCache.items.byId.set(handbookItem.Id, handbookItem.Price); if (!this.handbookPriceCache.items.byParent.has(handbookItem.ParentId)) @@ -65,7 +86,7 @@ export class HandbookHelper this.handbookPriceCache.items.byParent.get(handbookItem.ParentId).push(handbookItem.Id); } - for (const handbookCategory of handbookDb.Categories) + for (const handbookCategory of handbookDbClone.Categories) { this.handbookPriceCache.categories.byId.set(handbookCategory.Id, handbookCategory.ParentId || null); if (handbookCategory.ParentId) @@ -93,11 +114,6 @@ export class HandbookHelper this.lookupCacheGenerated = true; } - if (this.itemConfig.handbookPriceOverride[tpl]) - { - return this.itemConfig.handbookPriceOverride[tpl]; - } - if (this.handbookPriceCache.items.byId.has(tpl)) { return this.handbookPriceCache.items.byId.get(tpl);