From 7bc867a8f74f96c6da7889a3f274bd55347ee386 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 16 Feb 2024 09:59:43 +0000 Subject: [PATCH] Replace `labsAccessCardChancePercent` with `lootItemsToAddChancePercent` inside `playerscav.json` Fixed scav generation on profile generation always using fence rep 0 Added small % chance to add red flare to pscav --- project/assets/configs/playerscav.json | 55 ++++++++---- project/src/controllers/ProfileController.ts | 4 +- project/src/generators/PlayerScavGenerator.ts | 84 +++++++++++++------ .../models/spt/config/IPlayerScavConfig.ts | 2 +- 4 files changed, 101 insertions(+), 44 deletions(-) diff --git a/project/assets/configs/playerscav.json b/project/assets/configs/playerscav.json index 42fcba44..4c6ff1fc 100644 --- a/project/assets/configs/playerscav.json +++ b/project/assets/configs/playerscav.json @@ -77,7 +77,9 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "labsAccessCardChancePercent": 0, + "lootItemsToAddChancePercent": { + } }, "-6": { "botTypeForLoot": "assault", @@ -162,7 +164,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "-5": { "botTypeForLoot": "assault", @@ -247,7 +250,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "-4": { "botTypeForLoot": "assault", @@ -332,7 +336,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "-3": { "botTypeForLoot": "assault", @@ -417,7 +422,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "-2": { "botTypeForLoot": "assault", @@ -502,7 +508,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "-1": { "botTypeForLoot": "assault", @@ -587,7 +594,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "0": { "botTypeForLoot": "assault", @@ -672,7 +680,8 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 0 + "lootItemsToAddChancePercent": { + } }, "1": { "botTypeForLoot": "assault", @@ -759,7 +768,9 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 3 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 3 + } }, "2": { "botTypeForLoot": "assault", @@ -842,7 +853,10 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 6 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 6, + "62178c4d4ecf221597654e3d": 3 + } }, "3": { "botTypeForLoot": "assault", @@ -928,7 +942,10 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 11 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 11, + "62178c4d4ecf221597654e3d": 8 + } }, "4": { "botTypeForLoot": "assault", @@ -1013,7 +1030,11 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 17 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 17, + "62178c4d4ecf221597654e3d": 13 + + } }, "5": { "botTypeForLoot": "assault", @@ -1098,7 +1119,10 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 22 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 22, + "62178c4d4ecf221597654e3d": 18 + } }, "6": { "botTypeForLoot": "assault", @@ -1182,7 +1206,10 @@ "whitelist": [] } }, - "labsAccessCardChancePercent": 27 + "lootItemsToAddChancePercent": { + "5c94bbff86f7747ee735c08f": 27, + "62178c4d4ecf221597654e3d": 23 + } } } } diff --git a/project/src/controllers/ProfileController.ts b/project/src/controllers/ProfileController.ts index fcdbb806..bed75009 100644 --- a/project/src/controllers/ProfileController.ts +++ b/project/src/controllers/ProfileController.ts @@ -214,10 +214,10 @@ export class ProfileController this.givePlayerStartingQuestRewards(profileDetails, sessionID, response); } - this.saveServer.getProfile(sessionID).characters.scav = this.generatePlayerScav(sessionID); - this.resetAllTradersInProfile(sessionID); + this.saveServer.getProfile(sessionID).characters.scav = this.generatePlayerScav(sessionID); + // Store minimal profile and reload it this.saveServer.saveProfile(sessionID); this.saveServer.loadProfile(sessionID); diff --git a/project/src/generators/PlayerScavGenerator.ts b/project/src/generators/PlayerScavGenerator.ts index 3757e815..4ccd3c35 100644 --- a/project/src/generators/PlayerScavGenerator.ts +++ b/project/src/generators/PlayerScavGenerator.ts @@ -7,7 +7,7 @@ import { BotWeaponGeneratorHelper } from "@spt-aki/helpers/BotWeaponGeneratorHel import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; -import { Settings, Skills, Stats } from "@spt-aki/models/eft/common/tables/IBotBase"; +import { IBotBase, Settings, Skills, Stats } from "@spt-aki/models/eft/common/tables/IBotBase"; import { IBotType } from "@spt-aki/models/eft/common/tables/IBotType"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; import { AccountTypes } from "@spt-aki/models/enums/AccountTypes"; @@ -67,10 +67,7 @@ export class PlayerScavGenerator const pmcDataClone = this.jsonUtil.clone(profile.characters.pmc); const existingScavDataClone = this.jsonUtil.clone(profile.characters.scav); - // scav profile can be empty on first profile creation - const scavKarmaLevel = (Object.keys(existingScavDataClone).length === 0) - ? 0 - : this.getScavKarmaLevel(pmcDataClone); + const scavKarmaLevel = this.getScavKarmaLevel(pmcDataClone); // use karma level to get correct karmaSettings const playerScavKarmaSettings = this.playerScavConfig.karmaLevel[scavKarmaLevel]; @@ -121,28 +118,12 @@ export class PlayerScavGenerator scavData.WishList = existingScavDataClone.WishList ?? []; scavData.Encyclopedia = pmcDataClone.Encyclopedia; - // Add an extra labs card to pscav backpack based on config chance - if (this.randomUtil.getChance100(playerScavKarmaSettings.labsAccessCardChancePercent)) - { - const labsCard = this.itemHelper.getItem("5c94bbff86f7747ee735c08f")[1]; - const itemsToAdd: Item[] = [{ - _id: this.hashUtil.generate(), - _tpl: labsCard._id, - ...this.botGeneratorHelper.generateExtraPropertiesForItem(labsCard), - }]; - const result = this.botWeaponGeneratorHelper.addItemWithChildrenToEquipmentSlot( - ["TacticalVest", "Pockets", "Backpack"], - itemsToAdd[0]._id, - labsCard._id, - itemsToAdd, - scavData.Inventory, - ); - - if (result !== ItemAddedResult.SUCCESS) - { - this.logger.debug(`Unable to add keycard to bot. Reason: ${ItemAddedResult[result]}`); - } - } + // Add additional items to player scav as loot + this.addAdditionalLootToPlayerScavContainers(playerScavKarmaSettings.lootItemsToAddChancePercent, scavData, [ + "TacticalVest", + "Pockets", + "Backpack", + ]); // Remove secure container scavData = this.profileHelper.removeSecureContainer(scavData); @@ -156,6 +137,55 @@ export class PlayerScavGenerator return scavData; } + /** + * Add items picked from `playerscav.lootItemsToAddChancePercent` + * @param possibleItemsToAdd dict of tpl + % chance to be added + * @param scavData + * @param containersToAddTo Possible slotIds to add loot to + */ + protected addAdditionalLootToPlayerScavContainers( + possibleItemsToAdd: Record, + scavData: IBotBase, + containersToAddTo: string[], + ): void + { + for (const tpl in possibleItemsToAdd) + { + const shouldAdd = this.randomUtil.getChance100(possibleItemsToAdd[tpl]); + if (!shouldAdd) + { + continue; + } + + const itemResult = this.itemHelper.getItem(tpl); + if (!itemResult[0]) + { + this.logger.warning(`Unable to add ${tpl} to player scav, not an item`); + continue; + } + + const itemTemplate = itemResult[1]; + const itemsToAdd: Item[] = [{ + _id: this.hashUtil.generate(), + _tpl: itemTemplate._id, + ...this.botGeneratorHelper.generateExtraPropertiesForItem(itemTemplate), + }]; + + const result = this.botWeaponGeneratorHelper.addItemWithChildrenToEquipmentSlot( + containersToAddTo, + itemsToAdd[0]._id, + itemTemplate._id, + itemsToAdd, + scavData.Inventory, + ); + + if (result !== ItemAddedResult.SUCCESS) + { + this.logger.debug(`Unable to add keycard to bot. Reason: ${ItemAddedResult[result]}`); + } + } + } + /** * Get the scav karama level for a profile * Is also the fence trader rep level diff --git a/project/src/models/spt/config/IPlayerScavConfig.ts b/project/src/models/spt/config/IPlayerScavConfig.ts index f21a436a..65fdde08 100644 --- a/project/src/models/spt/config/IPlayerScavConfig.ts +++ b/project/src/models/spt/config/IPlayerScavConfig.ts @@ -13,7 +13,7 @@ export interface KarmaLevel modifiers: Modifiers; itemLimits: ItemLimits; equipmentBlacklist: Record; - labsAccessCardChancePercent: number; + lootItemsToAddChancePercent: Record; } export interface Modifiers