Skip to content

Commit

Permalink
Add Queso Geyser stager
Browse files Browse the repository at this point in the history
  • Loading branch information
hymccord committed Jan 19, 2024
1 parent b3ee761 commit defb9f1
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@ import * as detailingFuncs from './modules/details/legacy';
"Furoma Rift": stagingFuncs.addFuromaRiftStage,
"Gnawnian Express Station": stagingFuncs.addTrainStage,
"Iceberg": stagingFuncs.addIcebergStage,
"Queso Geyser": stagingFuncs.addQuesoGeyserStage,
"Seasonal Garden": stagingFuncs.addSeasonalGardenStage,
"Sunken City": stagingFuncs.addSunkenCityStage,
"Table of Contents": stagingFuncs.addTableOfContentsStage,
Expand Down
37 changes: 37 additions & 0 deletions src/scripts/modules/stages/environments/quesoGeyser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {type User} from '@scripts/types/hg';
import {IntakeMessage} from '@scripts/types/mhct';
import {QuesoGeyserState, QuesoGeyserStates} from '@scripts/types/quests/quesoGeyser';
import {type IStager} from '../stages.types';

export class QuesoGeyserStager implements IStager {
readonly environment: string = 'Queso Geyser';

/**
* Report the state of corks and eruptions
*/
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
const quest = userPre.quests.QuestQuesoGeyser;

if (!quest) {
throw new Error('QuestQuesoGeyser is undefined');
}

if (!this.isValidState(quest.state)) {
throw new Error('Skipping hunt due to unknown Queso Geyser state');
}

const state = quest.state;
if (state === "collecting" || state === "claim") {
message.stage = "Cork Collecting";
} else if (state === "corked") {
message.stage = "Pressure Building";
} else if (state === "eruption") {
// Tiny/Small/Medium/Large/Epic Eruption
message.stage = quest.state_name;
}
}

private isValidState(value: unknown): value is QuesoGeyserState {
return typeof value === 'string' && QuesoGeyserStates.includes(value as QuesoGeyserState);
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {LostCityStager} from './environments/lostCity';
import {MoussuPicchuStager} from './environments/moussuPicchu';
import {MousoleumStager} from './environments/mousoleum';
import {MuridaeMarketStager} from './environments/muridaeMarket';
import {QuesoGeyserStager} from './environments/quesoGeyser';
import {SandDunesStager} from './environments/sandDunes';
import {SlushyShorelineStager} from './environments/slushyShoreline';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';
Expand All @@ -40,6 +41,7 @@ const stageModules: IStager[] = [
new MoussuPicchuStager(),
new MousoleumStager(),
new MuridaeMarketStager(),
new QuesoGeyserStager(),
new SandDunesStager(),
new SlushyShorelineStager(),
new SuperBrieFactoryStager(),
Expand Down
18 changes: 0 additions & 18 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,24 +384,6 @@ export function addFortRoxStage(message, user, user_post, hunt) {
}

/**
* Report the state of corks and eruptions
* @param {Object <string, any>} message The message to be sent.
* @param {Object <string, any>} user The user state object, when the hunt was invoked (pre-hunt).
* @param {Object <string, any>} user_post The user state object, after the hunt.
* @param {Object <string, any>} hunt The journal entry corresponding to the active hunt.
*/
export function addQuesoGeyserStage(message, user, user_post, hunt) {
const state = user.quests.QuestQuesoGeyser.state;
if (state === "collecting" || state === "claim") {
message.stage = "Cork Collecting";
} else if (state === "corked") {
message.stage = "Pressure Building";
} else if (state === "eruption") {
// Tiny/Small/Medium/Large/Epic Eruption
message.stage = user.quests.QuestQuesoGeyser.state_name;
}
}

/**
* Report tower stage: Outside, Eclipse, Floors 1-7, 9-15, 17-23, 25-31+, Umbra
* @param {Object <string, any>} message The message to be sent.
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Quests {
QuestMousoleum?: quests.QuestMousoleum
QuestMoussuPicchu?: quests.QuestMoussuPicchu
QuestPollutionOutbreak?: unknown
QuestQuesoGeyser?: unknown
QuestQuesoGeyser?: quests.QuestQuesoGeyser
QuestRelicHunter?: unknown
QuestRiftBristleWoods?: quests.QuestRiftBristleWoods
QuestRiftBurroughs?: unknown
Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from '@scripts/types/quests/livingGarden';
export * from '@scripts/types/quests/lostCity';
export * from '@scripts/types/quests/mousoleum';
export * from '@scripts/types/quests/moussuPicchu';
export * from '@scripts/types/quests/quesoGeyser';
export * from '@scripts/types/quests/sandDunes';
export * from '@scripts/types/quests/superBrieFactory';
export * from '@scripts/types/quests/tableOfContents';
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/types/quests/quesoGeyser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface QuestQuesoGeyser {
state: string // QuesoGeyserState
state_name: string;
}

export const QuesoGeyserStates = [ 'collecting', 'corked', 'eruption', 'claim' ] as const;

export type QuesoGeyserState = typeof QuesoGeyserStates[number];
33 changes: 27 additions & 6 deletions tests/scripts/modules/stages/environments/quesoGeyser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,66 @@
import {addQuesoGeyserStage} from "@scripts/modules/stages/legacy";
import {QuesoGeyserStager} from "@scripts/modules/stages/environments/quesoGeyser";
import {IStager} from "@scripts/modules/stages/stages.types";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Queso Geyser stages', () => {
let stager: IStager;
let message: IntakeMessage;
let preUser: User;
let postUser: User;
const journal = {};

beforeEach(() => {
stager = new QuesoGeyserStager();
message = {} as IntakeMessage;
preUser = {quests: {
QuestQuesoGeyser: getDefaultQuest(),
}} as User;
postUser = {} as User;
});

it('should be for the Queso Geyser environment', () => {
expect(stager.environment).toBe('Queso Geyser');
});

it('should throw when QuestQuesoGeyser is undefined', () => {
preUser.quests.QuestQuesoGeyser = undefined;

expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestQuesoGeyser is undefined');
});

it.each`
state | expected
${'collecting'} | ${'Cork Collecting'}
${'claim'} | ${'Cork Collecting'}
${'corked'} | ${'Pressure Building'}
`('should set stage to $expected when in $state state', ({state, expected}) => {
preUser.quests.QuestQuesoGeyser.state = state;
preUser.quests.QuestQuesoGeyser!.state = state;

addQuesoGeyserStage(message, preUser, postUser, journal);
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe(expected);
});

it.each(
['Tiny', 'Small', 'Medium', 'Large', 'Epic']
)('should set stage to state name %p when in a %p Eruption ', (name) => {
preUser.quests.QuestQuesoGeyser.state = 'eruption';
preUser.quests.QuestQuesoGeyser.state_name = `${name} Eruption`;
preUser.quests.QuestQuesoGeyser!.state = 'eruption';
preUser.quests.QuestQuesoGeyser!.state_name = `${name} Eruption`;

addQuesoGeyserStage(message, preUser, postUser, journal);
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe(`${name} Eruption`);
});

it('should throw when state is unknown', () => {
preUser.quests.QuestQuesoGeyser!.state = 'guaranteed_rib_mode';

expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('Skipping hunt due to unknown Queso Geyser state');
});

function getDefaultQuest() {
return {
state: '',
Expand Down

0 comments on commit defb9f1

Please sign in to comment.