Replace conditionCounters array with with TaskConditionCounters dictionary

This commit is contained in:
Dev 2023-12-30 21:59:51 +00:00
parent 084cf38582
commit c39e331423
5 changed files with 21 additions and 14 deletions

View File

@ -316,11 +316,12 @@ export class InraidController
*/ */
protected profileHasConditionCounters(profile: IPmcData): boolean protected profileHasConditionCounters(profile: IPmcData): boolean
{ {
if (!profile.ConditionCounters?.Counters) if (!profile.TaskConditionCounters?.Counters)
{ {
return false; return false;
} }
return profile.ConditionCounters.Counters.length > 0;
return Object.keys(profile.TaskConditionCounters).length > 0;
} }
/** /**
@ -364,16 +365,16 @@ export class InraidController
} }
// Loop over all scav counters and add into pmc profile // Loop over all scav counters and add into pmc profile
for (const scavCounter of scavProfile.ConditionCounters.Counters) for (const scavCounter of Object.values(scavProfile.TaskConditionCounters))
{ {
this.logger.debug( this.logger.debug(
`Processing counter: ${scavCounter.id} value:${scavCounter.value} quest:${scavCounter.qid}`, `Processing counter: ${scavCounter.id} value: ${scavCounter.value} quest: ${scavCounter.sourceId}`,
); );
const counterInPmcProfile = pmcProfile.ConditionCounters.Counters.find((x) => x.id === scavCounter.id); const counterInPmcProfile = pmcProfile.TaskConditionCounters.Counters[scavCounter.id];
if (!counterInPmcProfile) if (!counterInPmcProfile)
{ {
// Doesn't exist yet, push it straight in // Doesn't exist yet, push it straight in
pmcProfile.ConditionCounters.Counters.push(scavCounter); pmcProfile.TaskConditionCounters[scavCounter.id] = scavCounter;
continue; continue;
} }
@ -384,7 +385,7 @@ export class InraidController
// Only adjust counter value if its changed // Only adjust counter value if its changed
if (counterInPmcProfile.value !== scavCounter.value) if (counterInPmcProfile.value !== scavCounter.value)
{ {
this.logger.debug(`OVERWRITING with values: ${scavCounter.value} quest: ${scavCounter.qid}`); this.logger.debug(`OVERWRITING with values: ${scavCounter.value} quest: ${scavCounter.sourceId}`);
counterInPmcProfile.value = scavCounter.value; counterInPmcProfile.value = scavCounter.value;
} }
} }

View File

@ -113,7 +113,7 @@ export class PlayerScavGenerator
scavData.Info.Level = this.getScavLevel(existingScavData); scavData.Info.Level = this.getScavLevel(existingScavData);
scavData.Info.Experience = this.getScavExperience(existingScavData); scavData.Info.Experience = this.getScavExperience(existingScavData);
scavData.Quests = existingScavData.Quests ?? []; scavData.Quests = existingScavData.Quests ?? [];
scavData.ConditionCounters = existingScavData.ConditionCounters ?? { Counters: [] }; scavData.TaskConditionCounters = existingScavData.TaskConditionCounters ?? { };
scavData.Notes = existingScavData.Notes ?? { Notes: [] }; scavData.Notes = existingScavData.Notes ?? { Notes: [] };
scavData.WishList = existingScavData.WishList ?? []; scavData.WishList = existingScavData.WishList ?? [];

View File

@ -150,7 +150,7 @@ export class InRaidHelper
profileData.Skills = saveProgressRequest.profile.Skills; profileData.Skills = saveProgressRequest.profile.Skills;
profileData.Stats.Eft = saveProgressRequest.profile.Stats.Eft; profileData.Stats.Eft = saveProgressRequest.profile.Stats.Eft;
profileData.Encyclopedia = saveProgressRequest.profile.Encyclopedia; profileData.Encyclopedia = saveProgressRequest.profile.Encyclopedia;
profileData.ConditionCounters = saveProgressRequest.profile.ConditionCounters; profileData.TaskConditionCounters = saveProgressRequest.profile.TaskConditionCounters;
this.validateTaskConditionCounters(saveProgressRequest, profileData); this.validateTaskConditionCounters(saveProgressRequest, profileData);
@ -196,7 +196,7 @@ export class InRaidHelper
const matchingPreRaidCounter = profileData.TaskConditionCounters[backendCounterKey]; const matchingPreRaidCounter = profileData.TaskConditionCounters[backendCounterKey];
if (!matchingPreRaidCounter) if (!matchingPreRaidCounter)
{ {
this.logger.error(`Backendcounter: ${backendCounterKey} cannot be found in pre-raid data`); this.logger.error(`TaskConditionCounters: ${backendCounterKey} cannot be found in pre-raid data`);
continue; continue;
} }
@ -204,7 +204,7 @@ export class InRaidHelper
if (matchingPreRaidCounter.value !== postRaidValue) if (matchingPreRaidCounter.value !== postRaidValue)
{ {
this.logger.error( this.logger.error(
`Backendcounter: ${backendCounterKey} value is different post raid, old: ${matchingPreRaidCounter.value} new: ${postRaidValue}` `TaskConditionCounters: ${backendCounterKey} value is different post raid, old: ${matchingPreRaidCounter.value} new: ${postRaidValue}`
); );
} }
} }

View File

@ -20,7 +20,6 @@ export interface IBotBase
Stats: Stats; Stats: Stats;
Encyclopedia: Record<string, boolean>; Encyclopedia: Record<string, boolean>;
TaskConditionCounters: Record<string, ITaskConditionCounter>; TaskConditionCounters: Record<string, ITaskConditionCounter>;
ConditionCounters: ConditionCounters;
InsuredItems: InsuredItem[]; InsuredItems: InsuredItem[];
Hideout: Hideout; Hideout: Hideout;
Quests: IQuestStatus[]; Quests: IQuestStatus[];

View File

@ -465,9 +465,16 @@ export class ProfileFixerService
*/ */
public removeDanglingConditionCounters(pmcProfile: IPmcData): void public removeDanglingConditionCounters(pmcProfile: IPmcData): void
{ {
if (pmcProfile.ConditionCounters) if (pmcProfile.TaskConditionCounters)
{ {
pmcProfile.ConditionCounters.Counters = pmcProfile.ConditionCounters.Counters.filter((c) => c.qid !== null); for (const counterId in pmcProfile.TaskConditionCounters)
{
const counter = pmcProfile.TaskConditionCounters[counterId];
if (!counter.sourceId)
{
delete pmcProfile.TaskConditionCounters[counterId];
}
}
} }
} }