diff --git a/src/helpers.ts b/src/helpers.ts new file mode 100644 index 0000000..b8ea7f4 --- /dev/null +++ b/src/helpers.ts @@ -0,0 +1,38 @@ +// Copyright (C) 2024 Platinum +// +// This file is part of spt-the-blacklist. +// +// spt-the-blacklist is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// spt-the-blacklist is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with spt-the-blacklist. If not, see . + +import { Category } from "@spt-aki/models/eft/common/tables/IHandbookBase"; + +// There are so many child categories of attachments, this will return all categories using recursion so I don't have to type each ID. +export function getAttachmentCategoryIds(handbookCategories: Category[]): string[] { + const weaponPartsAndModsId = "5b5f71a686f77447ed5636ab"; + const weaponPartsChildrenCategories = getChildCategoriesRecursively(handbookCategories, weaponPartsAndModsId); + const childrenIds = weaponPartsChildrenCategories.map(category => category.Id); + const attachmentCategoryIds = [weaponPartsAndModsId]; + + return attachmentCategoryIds.concat(childrenIds); +} + +function getChildCategoriesRecursively(handbookCategories: Category[], parentId: string): Category[] { + const childCategories = handbookCategories.filter(category => category.ParentId === parentId); + const grandChildrenCategories = childCategories.reduce( + (memo, category) => memo.concat(this.getChildCategoriesRecursively(handbookCategories, category.Id)), + [] + ); + + return childCategories.concat(grandChildrenCategories); +} \ No newline at end of file diff --git a/src/mod.ts b/src/mod.ts index ae76f90..80c8063 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -28,6 +28,7 @@ import { Category } from "@spt-aki/models/eft/common/tables/IHandbookBase"; import config from "../config.json"; import advancedConfig from "../advancedConfig.json"; +import { getAttachmentCategoryIds } from "./helpers"; class TheBlacklistMod implements IPostDBLoadModAsync { private logger: ILogger; @@ -63,7 +64,7 @@ class TheBlacklistMod implements IPostDBLoadModAsync { let attachmentPriceLimitedCount = 0; if (config.limitMaxPriceOfAttachments) { - this.initialiseAttachmentCategoryIds(tables.templates.handbook.Categories); + this.attachmentCategoryIds = getAttachmentCategoryIds(tables.templates.handbook.Categories); } // Find all items to update by looping through handbook which is a better indicator of useable items. @@ -149,24 +150,7 @@ class TheBlacklistMod implements IPostDBLoadModAsync { } } - private initialiseAttachmentCategoryIds(handbookCategories: Category[]) { - const weaponPartsAndModsId = "5b5f71a686f77447ed5636ab"; - const weaponPartsChildrenCategories = this.getChildCategoriesRecursively(handbookCategories, weaponPartsAndModsId); - const childrenIds = weaponPartsChildrenCategories.map(category => category.Id); - - this.attachmentCategoryIds.push(weaponPartsAndModsId); - this.attachmentCategoryIds = this.attachmentCategoryIds.concat(childrenIds); - } - - private getChildCategoriesRecursively(handbookCategories: Category[], parentId: string): Category[] { - const childCategories = handbookCategories.filter(category => category.ParentId === parentId); - const grandChildrenCategories = childCategories.reduce( - (memo, category) => memo.concat(this.getChildCategoriesRecursively(handbookCategories, category.Id)), - [] - ); - - return childCategories.concat(grandChildrenCategories); - } + private getUpdatedPrice(item: ITemplateItem, prices: Record): number | undefined { const currentFleaPrice = prices[item._id]; diff --git a/src/priceService.ts b/src/priceService.ts new file mode 100644 index 0000000..723ab4b --- /dev/null +++ b/src/priceService.ts @@ -0,0 +1,17 @@ +// Copyright (C) 2024 Platinum +// +// This file is part of spt-the-blacklist. +// +// spt-the-blacklist is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// spt-the-blacklist is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with spt-the-blacklist. If not, see . +