From 7d97bc494516f7b01326de2de37b960761a3b489 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 8 Feb 2024 16:01:38 +0000 Subject: [PATCH] Correctly generate ammo boxes for dynamic/static/bot loot with one stack of cartridges. It seems the 0.14 client update now handles ammo boxes having a single stack and properly splits the ammo inside it --- project/src/generators/BotLootGenerator.ts | 2 +- project/src/generators/LocationGenerator.ts | 9 ++------- project/src/helpers/ItemHelper.ts | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/project/src/generators/BotLootGenerator.ts b/project/src/generators/BotLootGenerator.ts index 4f8469d6..7f5620ea 100644 --- a/project/src/generators/BotLootGenerator.ts +++ b/project/src/generators/BotLootGenerator.ts @@ -414,7 +414,7 @@ export class BotLootGenerator // Fill ammo box if (this.itemHelper.isOfBaseclass(itemToAddTemplate._id, BaseClasses.AMMO_BOX)) { - this.itemHelper.addCartridgesToAmmoBox(itemToAddChildrenTo, itemToAddTemplate); + this.itemHelper.addSingleStackCartridgesToAmmoBox(itemToAddChildrenTo, itemToAddTemplate); } // Make money a stack else if (this.itemHelper.isOfBaseclass(itemToAddTemplate._id, BaseClasses.MONEY)) diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index 2cfddc8a..0db2be96 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -3,7 +3,6 @@ import { inject, injectable } from "tsyringe"; import { ContainerHelper } from "@spt-aki/helpers/ContainerHelper"; import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; import { PresetHelper } from "@spt-aki/helpers/PresetHelper"; -import { RagfairServerHelper } from "@spt-aki/helpers/RagfairServerHelper"; import { IContainerMinMax, IStaticContainer } from "@spt-aki/models/eft/common/ILocation"; import { ILocationBase } from "@spt-aki/models/eft/common/ILocationBase"; import { ILooseLoot, Spawnpoint, SpawnpointTemplate, SpawnpointsForced } from "@spt-aki/models/eft/common/ILooseLoot"; @@ -14,7 +13,6 @@ import { IStaticForcedProps, IStaticLootDetails, } from "@spt-aki/models/eft/common/tables/ILootBase"; -import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem"; import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { Money } from "@spt-aki/models/enums/Money"; @@ -24,7 +22,6 @@ import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { SeasonalEventService } from "@spt-aki/services/SeasonalEventService"; -import { HashUtil } from "@spt-aki/utils/HashUtil"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { MathUtil } from "@spt-aki/utils/MathUtil"; import { ObjectId } from "@spt-aki/utils/ObjectId"; @@ -54,10 +51,8 @@ export class LocationGenerator @inject("WinstonLogger") protected logger: ILogger, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @inject("JsonUtil") protected jsonUtil: JsonUtil, - @inject("HashUtil") protected hashUtil: HashUtil, @inject("ObjectId") protected objectId: ObjectId, @inject("RandomUtil") protected randomUtil: RandomUtil, - @inject("RagfairServerHelper") protected ragfairServerHelper: RagfairServerHelper, @inject("ItemHelper") protected itemHelper: ItemHelper, @inject("MathUtil") protected mathUtil: MathUtil, @inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService, @@ -852,7 +847,7 @@ export class LocationGenerator { // Fill with cartridges const ammoBoxItem: Item[] = [{ _id: this.objectId.generate(), _tpl: chosenTpl }]; - this.itemHelper.addCartridgesToAmmoBox(ammoBoxItem, itemTemplate); // ammo box template + this.itemHelper.addSingleStackCartridgesToAmmoBox(ammoBoxItem, itemTemplate); itemWithMods.push(...ammoBoxItem); } else if (this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.MAGAZINE)) @@ -1062,7 +1057,7 @@ export class LocationGenerator // No spawnpoint to fall back on, generate manually else if (this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.AMMO_BOX)) { - this.itemHelper.addCartridgesToAmmoBox(items, itemTemplate); + this.itemHelper.addSingleStackCartridgesToAmmoBox(items, itemTemplate); } else if (this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.MAGAZINE)) { diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 6075c5cf..48c0ee73 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1034,6 +1034,26 @@ export class ItemHelper } } + /** + * Add a single stack of cartridges to the ammo box + * @param ammoBox Box to add cartridges to + * @param ammoBoxDetails Item template from items db + */ + public addSingleStackCartridgesToAmmoBox(ammoBox: Item[], ammoBoxDetails: ITemplateItem): void + { + const ammoBoxMaxCartridgeCount = ammoBoxDetails._props.StackSlots[0]._max_count; + const cartridgeTpl = ammoBoxDetails._props.StackSlots[0]._props.filters[0].Filter[0]; + ammoBox.push( + this.createCartridges( + ammoBox[0]._id, + cartridgeTpl, + ammoBoxMaxCartridgeCount, + 0, + ammoBox[0].upd?.SpawnedInSession, + ), + ); + } + /** * Check if item is stored inside of a container * @param item Item to check is inside of container