Cleanup of comments inside ProfileHelper

merged unnecessary functions
This commit is contained in:
Dev 2024-03-09 16:35:46 +00:00
parent f860642882
commit b11c9579b5

View File

@ -74,6 +74,11 @@ export class ProfileHelper
return this.saveServer.getProfiles(); return this.saveServer.getProfiles();
} }
/**
* Get the pmc and scav profiles as an array by profile id
* @param sessionID
* @returns Array of IPmcData objects
*/
public getCompleteProfile(sessionID: string): IPmcData[] public getCompleteProfile(sessionID: string): IPmcData[]
{ {
const output: IPmcData[] = []; const output: IPmcData[] = [];
@ -107,7 +112,7 @@ export class ProfileHelper
* @param output pmc and scav profiles array * @param output pmc and scav profiles array
* @param pmcProfile post-raid pmc profile * @param pmcProfile post-raid pmc profile
* @param scavProfile post-raid scav profile * @param scavProfile post-raid scav profile
* @returns updated profile array * @returns Updated profile array
*/ */
protected postRaidXpWorkaroundFix( protected postRaidXpWorkaroundFix(
sessionId: string, sessionId: string,
@ -136,7 +141,7 @@ export class ProfileHelper
/** /**
* Check if a nickname is used by another profile loaded by the server * Check if a nickname is used by another profile loaded by the server
* @param nicknameRequest * @param nicknameRequest nickname request object
* @param sessionID Session id * @param sessionID Session id
* @returns True if already used * @returns True if already used
*/ */
@ -150,9 +155,13 @@ export class ProfileHelper
continue; continue;
} }
// SessionIds dont match + nicknames do
if ( if (
!this.sessionIdMatchesProfileId(profile.info.id, sessionID) !this.stringsMatch(profile.info.id, sessionID)
&& this.nicknameMatches(profile.characters.pmc.Info.LowerNickname, nicknameRequest.nickname) && this.stringsMatch(
profile.characters.pmc.Info.LowerNickname.toLowerCase(),
nicknameRequest.nickname.toLowerCase(),
)
) )
{ {
return true; return true;
@ -167,14 +176,9 @@ export class ProfileHelper
return !!(profile?.characters?.pmc?.Info); return !!(profile?.characters?.pmc?.Info);
} }
protected nicknameMatches(profileName: string, nicknameRequest: string): boolean protected stringsMatch(stringA: string, stringB: string): boolean
{ {
return profileName.toLowerCase() === nicknameRequest.toLowerCase(); return stringA === stringB;
}
protected sessionIdMatchesProfileId(profileId: string, sessionId: string): boolean
{
return profileId === sessionId;
} }
/** /**
@ -188,6 +192,11 @@ export class ProfileHelper
pmcData.Info.Experience += experienceToAdd; pmcData.Info.Experience += experienceToAdd;
} }
/**
* Iterate all profiles and find matching pmc profile by provided id
* @param pmcId Profile id to find
* @returns IPmcData
*/
public getProfileByPmcId(pmcId: string): IPmcData public getProfileByPmcId(pmcId: string): IPmcData
{ {
for (const sessionID in this.saveServer.getProfiles()) for (const sessionID in this.saveServer.getProfiles())
@ -202,6 +211,11 @@ export class ProfileHelper
return undefined; return undefined;
} }
/**
* Get the experiecne for the given level
* @param level level to get xp for
* @returns Number of xp points for level
*/
public getExperience(level: number): number public getExperience(level: number): number
{ {
let playerLevel = level; let playerLevel = level;
@ -222,6 +236,10 @@ export class ProfileHelper
return exp; return exp;
} }
/**
* Get the max level a player can be
* @returns Max level
*/
public getMaxLevel(): number public getMaxLevel(): number
{ {
return this.databaseServer.getTables().globals.config.exp.level.exp_table.length - 1; return this.databaseServer.getTables().globals.config.exp.level.exp_table.length - 1;
@ -232,6 +250,11 @@ export class ProfileHelper
return { version: this.getServerVersion() }; return { version: this.getServerVersion() };
} }
/**
* Get full representation of a players profile json
* @param sessionID Profile id to get
* @returns IAkiProfile object
*/
public getFullProfile(sessionID: string): IAkiProfile public getFullProfile(sessionID: string): IAkiProfile
{ {
if (this.saveServer.getProfile(sessionID) === undefined) if (this.saveServer.getProfile(sessionID) === undefined)
@ -242,6 +265,11 @@ export class ProfileHelper
return this.saveServer.getProfile(sessionID); return this.saveServer.getProfile(sessionID);
} }
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return
* @returns IPmcData object
*/
public getPmcProfile(sessionID: string): IPmcData public getPmcProfile(sessionID: string): IPmcData
{ {
const fullProfile = this.getFullProfile(sessionID); const fullProfile = this.getFullProfile(sessionID);
@ -253,6 +281,11 @@ export class ProfileHelper
return this.saveServer.getProfile(sessionID).characters.pmc; return this.saveServer.getProfile(sessionID).characters.pmc;
} }
/**
* Get a full profiles scav-specific sub-profile
* @param sessionID Profiles id
* @returns IPmcData object
*/
public getScavProfile(sessionID: string): IPmcData public getScavProfile(sessionID: string): IPmcData
{ {
return this.saveServer.getProfile(sessionID).characters.scav; return this.saveServer.getProfile(sessionID).characters.scav;
@ -260,7 +293,7 @@ export class ProfileHelper
/** /**
* Get baseline counter values for a fresh profile * Get baseline counter values for a fresh profile
* @returns Stats * @returns Default profile Stats object
*/ */
public getDefaultCounters(): Stats public getDefaultCounters(): Stats
{ {
@ -284,6 +317,11 @@ export class ProfileHelper
}; };
} }
/**
* is this profile flagged for data removal
* @param sessionID Profile id
* @returns True if profile is to be wiped of data/progress
*/
protected isWiped(sessionID: string): boolean protected isWiped(sessionID: string): boolean
{ {
return this.saveServer.getProfile(sessionID).info.wipe; return this.saveServer.getProfile(sessionID).info.wipe;
@ -454,6 +492,12 @@ export class ProfileHelper
profileSkill.LastAccess = this.timeUtil.getTimestamp(); profileSkill.LastAccess = this.timeUtil.getTimestamp();
} }
/**
* Get a speciic common skill from supplied profile
* @param pmcData Player profile
* @param skill Skill get get
* @returns Common skill object from desired profile
*/
public getSkillFromProfile(pmcData: IPmcData, skill: SkillTypes): Common public getSkillFromProfile(pmcData: IPmcData, skill: SkillTypes): Common
{ {
const skillToReturn = pmcData.Skills.Common.find((x) => x.Id === skill); const skillToReturn = pmcData.Skills.Common.find((x) => x.Id === skill);
@ -466,11 +510,21 @@ export class ProfileHelper
return skillToReturn; return skillToReturn;
} }
/**
* Is the provided session id for a developer account
* @param sessionID Profile id ot check
* @returns True if account is developer
*/
public isDeveloperAccount(sessionID: string): boolean public isDeveloperAccount(sessionID: string): boolean
{ {
return this.getFullProfile(sessionID).info.edition.toLowerCase().startsWith(AccountTypes.SPT_DEVELOPER); return this.getFullProfile(sessionID).info.edition.toLowerCase().startsWith(AccountTypes.SPT_DEVELOPER);
} }
/**
* Add stash row bonus to profile or increments rows given count if it already exists
* @param sessionId Profile id to give rows to
* @param rowsToAdd How many rows to give profile
*/
public addStashRowsBonusToProfile(sessionId: string, rowsToAdd: number): void public addStashRowsBonusToProfile(sessionId: string, rowsToAdd: number): void
{ {
const profile = this.getPmcProfile(sessionId); const profile = this.getPmcProfile(sessionId);