changed implementation, added skill progress

This commit is contained in:
CamBurr 2023-08-17 21:37:12 -06:00
parent 97862b155a
commit b39a5d967c
2 changed files with 27 additions and 120 deletions

View File

@ -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;
}
}

View File

@ -1,14 +1,38 @@
import { DependencyContainer } from "tsyringe"; import { DependencyContainer } from "tsyringe";
import { IPreAkiLoadMod } from "@spt-aki/models/external/IPreAkiLoadMod" 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 class Mod implements IPreAkiLoadMod
{ {
private static container: DependencyContainer;
// Perform these actions before server fully loads // Perform these actions before server fully loads
public preAkiLoad(container: DependencyContainer): void public preAkiLoad(container: DependencyContainer): void
{ {
container.register<ScavXpCountsInRaidHelper>("ScavXpCountsInRaidHelper", ScavXpCountsInRaidHelper); Mod.container = container;
container.register("InRaidHelper", {useToken: "ScavXpCountsInRaidHelper"}); const oldClass = Mod.container.resolve<InRaidHelper>("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>("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"});
} }
} }