Skip to content

Commit

Permalink
feat: add hideout_main_stash_access_via profile override
Browse files Browse the repository at this point in the history
  • Loading branch information
Trap committed Aug 7, 2024
1 parent e95a8cc commit 790bd91
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"debug": true,
"override_by_profiles": {
"Stalker On Tarkov": {
"initial_offraid_position": "TherapistStash"
"initial_offraid_position": "TherapistStash",
"hideout_main_stash_access_via": ["TherapistStash"]
}
},
"initial_offraid_position": "MechanicStash",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type OffraidRegenConfig = {

export type OverrideByProfiles = ByProfileId<{
initial_offraid_position?: string;
hideout_main_stash_access_via: AccessVia;
}>;

export type Config = {
Expand Down
8 changes: 4 additions & 4 deletions src/path-to-tarkov-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class PathToTarkovController {
const parsed = JSON.parse(rawResult);
const items: Record<string, ITemplateItem> = parsed.data;

const size = this.stashController.getStashSize(offraidPosition);
const size = this.stashController.getStashSize(offraidPosition, sessionId);

if (size === null) {
this.debug(`[${sessionId}] main stash selected`);
Expand Down Expand Up @@ -235,7 +235,7 @@ export class PathToTarkovController {
const parsed = JSON.parse(rawResult);
const areas: IHideoutArea[] = parsed.data;

const hideoutEnabled = this.stashController.getHideoutEnabled(offraidPosition);
const hideoutEnabled = this.stashController.getHideoutEnabled(offraidPosition, sessionId);

areas.forEach(area => {
if (!isIgnoredArea(area, this.config)) {
Expand Down Expand Up @@ -512,9 +512,9 @@ export class PathToTarkovController {
const profile: Profile = this.saveServer.getProfile(sessionId);
const profileTemplateId = profile.info.edition;

const overrideByProfiles = this.config.override_by_profiles?.[profileTemplateId] ?? {};
const overrideByProfiles = this.config.override_by_profiles?.[profileTemplateId];

return overrideByProfiles.initial_offraid_position ?? this.config.initial_offraid_position;
return overrideByProfiles?.initial_offraid_position ?? this.config.initial_offraid_position;
};

getOffraidPosition = (sessionId: string): string => {
Expand Down
31 changes: 19 additions & 12 deletions src/stash-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DatabaseServer } from '@spt/servers/DatabaseServer';
import type { SaveServer } from '@spt/servers/SaveServer';
import type { ConfigGetter, Profile, StashConfig } from './config';
import type { AccessVia, ConfigGetter, Profile, StashConfig } from './config';
import { EMPTY_STASH, SLOT_ID_HIDEOUT, SLOT_ID_LOCKED_STASH, STANDARD_STASH_ID } from './config';
import {
checkAccessVia,
Expand Down Expand Up @@ -97,13 +97,20 @@ export class StashController {
}
}

private getMainStashAvailable(offraidPosition: string): boolean {
const multiStashEnabled = this.getConfig().hideout_multistash_enabled;
private getMainStashAccessVia(sessionId: string): AccessVia {
const defaultMainStashAccessVia = this.getConfig().hideout_main_stash_access_via;
const profile: Profile = this.saveServer.getProfile(sessionId);
const profileTemplateId = profile.info.edition;

const mainStashAvailable = checkAccessVia(
this.getConfig().hideout_main_stash_access_via,
offraidPosition,
);
const overrideByProfiles = this.getConfig().override_by_profiles?.[profileTemplateId];

return overrideByProfiles?.hideout_main_stash_access_via ?? defaultMainStashAccessVia;
}

private getMainStashAvailable(offraidPosition: string, sessionId: string): boolean {
const multiStashEnabled = this.getConfig().hideout_multistash_enabled;
const mainStashAccessVia = this.getMainStashAccessVia(sessionId);
const mainStashAvailable = checkAccessVia(mainStashAccessVia, offraidPosition);

return mainStashAvailable || multiStashEnabled === false;
}
Expand All @@ -128,7 +135,7 @@ export class StashController {
}

updateStash(offraidPosition: string, sessionId: string): void {
const mainStashAvailable = this.getMainStashAvailable(offraidPosition);
const mainStashAvailable = this.getMainStashAvailable(offraidPosition, sessionId);
const secondaryStash = this.getSecondaryStash(offraidPosition);
const profile: Profile = this.saveServer.getProfile(sessionId);

Expand All @@ -154,8 +161,8 @@ export class StashController {
});
}

getStashSize(offraidPosition: string): number | null {
const mainStashAvailable = this.getMainStashAvailable(offraidPosition);
getStashSize(offraidPosition: string, sessionId: string): number | null {
const mainStashAvailable = this.getMainStashAvailable(offraidPosition, sessionId);
const secondaryStash = this.getSecondaryStash(offraidPosition);

if (mainStashAvailable) {
Expand All @@ -165,7 +172,7 @@ export class StashController {
return secondaryStash.size;
}

getHideoutEnabled(offraidPosition: string): boolean {
return this.getMainStashAvailable(offraidPosition);
getHideoutEnabled(offraidPosition: string, sessionId: string): boolean {
return this.getMainStashAvailable(offraidPosition, sessionId);
}
}

0 comments on commit 790bd91

Please sign in to comment.