From 0fa22f034938a0382e8c949a3d3016a24719f05f Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 21 Sep 2024 10:34:45 +0100 Subject: [PATCH] Reworked hideout code to remove all buffs/debuffs from profile after completing hideout wall Added code to be run when 39x profiles are migrated Renamed `checkAndUpgradeWall` to `SetWallVisibleIfPrereqsMet` --- project/src/controllers/GameController.ts | 6 +++++ project/src/controllers/HideoutController.ts | 11 ++++----- project/src/helpers/HideoutHelper.ts | 24 +++++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index ce73134b..742aa2a3 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -255,6 +255,12 @@ export class GameController { fullProfile.characters.pmc.Inventory.favoriteItems = []; } + // Remove wall debuffs + const wallAreaDb = this.databaseService + .getHideout() + .areas.find((area) => area.type === HideoutAreas.EMERGENCY_WALL); + this.hideoutHelper.removeHideoutWallBuffsAndDebuffs(wallAreaDb, fullProfile.characters.pmc); + // Equipment area const equipmentArea = fullProfile.characters.pmc.Hideout.Areas.find( (area) => area.type === HideoutAreas.EQUIPMENT_PRESETS_STAND, diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 4056b76a..a7b3f19d 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -227,15 +227,12 @@ export class HideoutController { profileHideoutArea.type === HideoutAreas.WATER_COLLECTOR || profileHideoutArea.type === HideoutAreas.MEDSTATION ) { - this.checkAndUpgradeWall(pmcData); + this.SetWallVisibleIfPrereqsMet(pmcData); } - // Cleanup temporary fuel usage buffs from mopping floor if wall is complete as it would result in too many bonuses + // Cleanup temporary buffs/debuffs from wall if complete if (profileHideoutArea.type === HideoutAreas.EMERGENCY_WALL && profileHideoutArea.level === 6) { - // Get everything except specific fuel consumption buffs - pmcData.Bonuses = pmcData.Bonuses.filter( - (bonus) => bonus.type !== BonusType.FUEL_CONSUMPTION || (bonus.value >= -10 && bonus.value <= 0), - ); + this.hideoutHelper.removeHideoutWallBuffsAndDebuffs(hideoutData, pmcData); } // Add Skill Points Per Area Upgrade @@ -250,7 +247,7 @@ export class HideoutController { * Upgrade wall status to visible in profile if medstation/water collector are both level 1 * @param pmcData Player profile */ - protected checkAndUpgradeWall(pmcData: IPmcData): void { + protected SetWallVisibleIfPrereqsMet(pmcData: IPmcData): void { const medStation = pmcData.Hideout.Areas.find((area) => area.type === HideoutAreas.MEDSTATION); const waterCollector = pmcData.Hideout.Areas.find((area) => area.type === HideoutAreas.WATER_COLLECTOR); if (medStation?.level >= 1 && waterCollector?.level >= 1) { diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index ac9a6272..99e70f34 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -4,7 +4,7 @@ import { ProfileHelper } from "@spt/helpers/ProfileHelper"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { HideoutArea, IHideoutImprovement, Production, Productive } from "@spt/models/eft/common/tables/IBotBase"; import { Item, Upd } from "@spt/models/eft/common/tables/IItem"; -import { StageBonus } from "@spt/models/eft/hideout/IHideoutArea"; +import { IHideoutArea, StageBonus } from "@spt/models/eft/hideout/IHideoutArea"; import { IHideoutContinuousProductionStartRequestData } from "@spt/models/eft/hideout/IHideoutContinuousProductionStartRequestData"; import { IHideoutProduction } from "@spt/models/eft/hideout/IHideoutProduction"; import { IHideoutSingleProductionStartRequestData } from "@spt/models/eft/hideout/IHideoutSingleProductionStartRequestData"; @@ -1284,4 +1284,26 @@ export class HideoutHelper { return result; } + + /** + * The wall pollutes a profile with various temp buffs/debuffs, + * Remove them all + * @param wallAreaDb Hideout area data + * @param pmcData Player profile + */ + public removeHideoutWallBuffsAndDebuffs(wallAreaDb: IHideoutArea, pmcData: IPmcData) { + // Smush all stage bonuses into one array for easy iteration + const wallBonuses = Object.values(wallAreaDb.stages).flatMap((stage) => stage.bonuses); + + // Get all bonus Ids that the wall adds + const bonusIdsToRemove: string[] = []; + for (const bonus of wallBonuses) { + bonusIdsToRemove.push(bonus.id); + } + + this.logger.debug(`Removing: ${bonusIdsToRemove.length} bonuses from profile`); + + // Remove the wall bonuses from profile by id + pmcData.Bonuses = pmcData.Bonuses.filter((bonus) => !bonusIdsToRemove.includes(bonus.id)); + } }