diff --git a/src/ScavXpCountsInRaidHelper.ts b/src/ScavXpCountsInRaidHelper.ts deleted file mode 100644 index 595b8bb..0000000 --- a/src/ScavXpCountsInRaidHelper.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { inject, injectable } from "tsyringe"; - -import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; -import { ISaveProgressRequestData } from "@spt-aki/models/eft/inRaid/ISaveProgressRequestData"; -import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; -import { ConfigServer } from "@spt-aki/servers/ConfigServer"; -import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; -import { SaveServer } from "@spt-aki/servers/SaveServer"; -import { LocalisationService } from "@spt-aki/services/LocalisationService"; -import { ProfileFixerService } from "@spt-aki/services/ProfileFixerService"; -import { JsonUtil } from "@spt-aki/utils/JsonUtil"; -import { InventoryHelper } from "@spt-aki/helpers/InventoryHelper"; -import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; -import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper"; -import { QuestHelper } from "@spt-aki/helpers/QuestHelper"; -import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper"; -import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; - -// We need to declare this class as injectable, this will add the container -// metadata -// You dont need to worry too much about that, just remember to add this -@injectable() -export class ScavXpCountsInRaidHelper extends InRaidHelper // <<<<=== This class extends the callback class -{ - // We need to make sure we use the constructor and pass the dependencies to the parent class! - constructor( - @inject("WinstonLogger") protected logger: ILogger, - @inject("SaveServer") protected saveServer: SaveServer, - @inject("JsonUtil") protected jsonUtil: JsonUtil, - @inject("ItemHelper") protected itemHelper: ItemHelper, - @inject("DatabaseServer") protected databaseServer: DatabaseServer, - @inject("InventoryHelper") protected inventoryHelper: InventoryHelper, - @inject("QuestHelper") protected questHelper: QuestHelper, - @inject("PaymentHelper") protected paymentHelper: PaymentHelper, - @inject("LocalisationService") protected localisationService: LocalisationService, - @inject("ProfileFixerService") protected profileFixerService: ProfileFixerService, - @inject("ConfigServer") protected configServer: ConfigServer, - @inject("ProfileHelper") protected profileHelper: ProfileHelper - ) - { - // Pass the parent class the dependencies it needs to work - super(logger, saveServer, jsonUtil, itemHelper, databaseServer, inventoryHelper, questHelper, paymentHelper, localisationService, profileFixerService, configServer); - } - - // We override the parent method with the EXACT same signature - public override updateProfileBaseStats(profileData: IPmcData, saveProgressRequest: ISaveProgressRequestData, sessionID: string): IPmcData - { - if (saveProgressRequest.isPlayerScav) - { - const pmcData = this.profileHelper.getPmcProfile(sessionID); - pmcData.Info.Experience += profileData.Stats.TotalSessionExperience; - saveProgressRequest.profile.Skills.Common.forEach((skill) => - { - pmcData.Skills.Common.find(p => p.Id === skill.Id).Progress += skill.PointsEarnedDuringSession; - }) - } - - // remove old skill fatigue - this.resetSkillPointsEarnedDuringRaid(saveProgressRequest.profile); - - // set profile data - profileData.Info.Level = saveProgressRequest.profile.Info.Level; - profileData.Skills = saveProgressRequest.profile.Skills; - profileData.Stats = saveProgressRequest.profile.Stats; - profileData.Encyclopedia = saveProgressRequest.profile.Encyclopedia; - profileData.ConditionCounters = saveProgressRequest.profile.ConditionCounters; - - for (const backendCounterKey in saveProgressRequest.profile.BackendCounters) - { - if (!saveProgressRequest.profile.BackendCounters[backendCounterKey].id) - { - continue; - } - - const matchingPreRaidCounter = profileData.BackendCounters[backendCounterKey]; - if (!matchingPreRaidCounter) - { - this.logger.error(`Backendcounter: ${backendCounterKey} cannot be found in pre-raid data`); - - continue; - } - - if (matchingPreRaidCounter.value !== saveProgressRequest.profile.BackendCounters[backendCounterKey].value) - { - this.logger.error(`Backendcounter: ${backendCounterKey} value is different post raid, old: ${matchingPreRaidCounter.value} new: saveProgressRequest.profile.BackendCounters[backendCounterKey].value`); - } - } - - this.processFailedQuests(sessionID, profileData, profileData.Quests, saveProgressRequest.profile.Quests); - profileData.Quests = saveProgressRequest.profile.Quests; - - // Transfer effects from request to profile - this.transferPostRaidLimbEffectsToProfile(saveProgressRequest, profileData); - - this.applyTraderStandingAdjustments(profileData.TradersInfo, saveProgressRequest.profile.TradersInfo); - - profileData.SurvivorClass = saveProgressRequest.profile.SurvivorClass; - - // add experience points - profileData.Info.Experience += profileData.Stats.TotalSessionExperience; - - profileData.Stats.TotalSessionExperience = 0; - - // Remove the Lab card - this.removeMapAccessKey(saveProgressRequest, sessionID); - - this.setPlayerInRaidLocationStatusToNone(sessionID); - - if (!saveProgressRequest.isPlayerScav) - { - this.profileFixerService.checkForAndFixPmcProfileIssues(profileData); - } - - return profileData; - } - -} \ No newline at end of file diff --git a/src/mod.ts b/src/mod.ts index 3179066..f92e263 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,14 +1,38 @@ import { DependencyContainer } from "tsyringe"; import { IPreAkiLoadMod } from "@spt-aki/models/external/IPreAkiLoadMod" -import { ScavXpCountsInRaidHelper } from "./ScavXpCountsInRaidHelper"; +import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper"; +import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; +import { ISaveProgressRequestData } from "@spt-aki/models/eft/inRaid/ISaveProgressRequestData"; +import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; class Mod implements IPreAkiLoadMod { + private static container: DependencyContainer; + // Perform these actions before server fully loads public preAkiLoad(container: DependencyContainer): void { - container.register("ScavXpCountsInRaidHelper", ScavXpCountsInRaidHelper); - container.register("InRaidHelper", {useToken: "ScavXpCountsInRaidHelper"}); + Mod.container = container; + const oldClass = Mod.container.resolve("InRaidHelper"); + + container.afterResolution("InRaidHelper", (_t, result: InRaidHelper) => + { + result.updateProfileBaseStats = (profileData: IPmcData, saveProgressRequest: ISaveProgressRequestData, sessionID: string): IPmcData => + { + if (saveProgressRequest.isPlayerScav) + { + const profileHelper = Mod.container.resolve("ProfileHelper"); + const pmcData = profileHelper.getPmcProfile(sessionID); + pmcData.Info.Experience += saveProgressRequest.profile.Stats.TotalSessionExperience; + saveProgressRequest.profile.Skills.Common.forEach((skill) => + { + pmcData.Skills.Common.find(p => p.Id === skill.Id).Progress += skill.PointsEarnedDuringSession; + }) + + return oldClass.updateProfileBaseStats(profileData, saveProgressRequest, sessionID); + } + } + }, {frequency: "Always"}); } }