Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost City stager #501

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,15 +1176,13 @@ import * as detailingFuncs from './modules/details/legacy';
const location_stage_lookup = {
"Bristle Woods Rift": stagingFuncs.addBristleWoodsRiftStage,
"Burroughs Rift": stagingFuncs.addBurroughsRiftStage,
"Cursed City": stagingFuncs.addLostCityStage,
"Festive Comet": stagingFuncs.addFestiveCometStage,
"Frozen Vacant Lot": stagingFuncs.addFestiveCometStage,
"Foreword Farm": stagingFuncs.addForewordFarmStage,
"Fort Rox": stagingFuncs.addFortRoxStage,
"Furoma Rift": stagingFuncs.addFuromaRiftStage,
"Gnawnian Express Station": stagingFuncs.addTrainStage,
"Iceberg": stagingFuncs.addIcebergStage,
"Lost City": stagingFuncs.addLostCityStage,
"Queso Geyser": stagingFuncs.addQuesoGeyserStage,
"Seasonal Garden": stagingFuncs.addSeasonalGardenStage,
"Sunken City": stagingFuncs.addSunkenCityStage,
Expand Down
20 changes: 20 additions & 0 deletions src/scripts/modules/stages/environments/cursedCity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {type User} from '@scripts/types/hg';
import {type IntakeMessage} from '@scripts/types/mhct';
import {type IStager} from '../stages.types';

export class CursedCityStager implements IStager {
readonly environment: string = 'Cursed City';

/**
* Indicate whether or not the Cursed / Corrupt mouse is present
*/
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
// TODO: Partially cursed, for Cursed City?
const quest = userPre.quests.QuestLostCity;
if (!quest) {
throw new Error('QuestLostCity is undefined');
}

message.stage = (quest.minigame.is_cursed) ? "Cursed" : "Not Cursed";
}
}
20 changes: 20 additions & 0 deletions src/scripts/modules/stages/environments/lostCity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {type User} from '@scripts/types/hg';
import {type IntakeMessage} from '@scripts/types/mhct';
import {type IStager} from '../stages.types';

export class LostCityStager implements IStager {
readonly environment: string = 'Lost City';

/**
* Indicate whether or not the Cursed / Corrupt mouse is present
*/
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
// TODO: Partially cursed, for Cursed City?
const quest = userPre.quests.QuestLostCity;
if (!quest) {
throw new Error('QuestLostCity is undefined');
}

message.stage = (quest.minigame.is_cursed) ? "Cursed" : "Not Cursed";
}
}
4 changes: 4 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {type IStager} from './stages.types';
import {BalacksCoveStager} from './environments/balacksCove';
import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk';
import {ClawShotCityStager} from './environments/clawShotCity';
import {CursedCityStager} from './environments/cursedCity';
import {FieryWarpathStager} from './environments/fieryWarpath';
import {FloatingIslandsStager} from './environments/floatingIslands';
import {ForbiddenGroveStager} from './environments/forbiddenGrove';
Expand All @@ -10,6 +11,7 @@ import {HarbourStager} from './environments/harbour';
import {IceFortressStager} from './environments/iceFortress';
import {LabyrinthStager} from './environments/labyrinth';
import {LivingGardenStager} from './environments/livingGarden';
import {LostCityStager} from './environments/lostCity';
import {MoussuPicchuStager} from './environments/moussuPicchu';
import {MousoleumStager} from './environments/mousoleum';
import {MuridaeMarketStager} from './environments/muridaeMarket';
Expand All @@ -22,6 +24,7 @@ const stageModules: IStager[] = [
new BalacksCoveStager(),
new BountifulBeanstalkStager(),
new ClawShotCityStager(),
new CursedCityStager(),
new FieryWarpathStager(),
new FloatingIslandsStager(),
new ForbiddenGroveStager(),
Expand All @@ -30,6 +33,7 @@ const stageModules: IStager[] = [
new IceFortressStager(),
new LabyrinthStager(),
new LivingGardenStager(),
new LostCityStager(),
new MoussuPicchuStager(),
new MousoleumStager(),
new MuridaeMarketStager(),
Expand Down
12 changes: 0 additions & 12 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ export function addSeasonalGardenStage(message, user, user_post, hunt) {
}
}

/**
* Indicate whether or not the Cursed / Corrupt mouse is present
* @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 addLostCityStage(message, user, user_post, hunt) {
// TODO: Partially cursed, for Cursed City?
message.stage = (user.quests.QuestLostCity.minigame.is_cursed) ? "Cursed" : "Not Cursed";
}

/**
* Report the current distance / obstacle.
* TODO: Stage / hunt details for first & second icewing hunting?
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 @@ -52,7 +52,7 @@ export interface Quests {
QuestIceFortress?: quests.QuestIceFortress;
QuestLabyrinth?: quests.QuestLabyrinth
QuestLivingGarden?: quests.QuestLivingGarden
QuestLostCity?: unknown
QuestLostCity?: quests.QuestLostCity
QuestMousoleum?: quests.QuestMousoleum
QuestMoussuPicchu?: quests.QuestMoussuPicchu
QuestPollutionOutbreak?: 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 @@ -9,6 +9,7 @@ export * from '@scripts/types/quests/iceberg';
export * from '@scripts/types/quests/iceFortress';
export * from '@scripts/types/quests/labyrinth';
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/sandDunes';
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/types/quests/lostCity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface QuestLostCity {
minigame: {
is_cursed: boolean
}
}
96 changes: 96 additions & 0 deletions tests/scripts/modules/stages/environments/lostCity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {CursedCityStager} from "@scripts/modules/stages/environments/cursedCity";
import {LostCityStager} from "@scripts/modules/stages/environments/lostCity";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Lost City stages', () => {
it('should be for the "Lost City" environment', () => {
const stager = new LostCityStager();
expect(stager.environment).toBe('Lost City');
});

it('should set stage to "Cursed" when user is cursed', () => {
const stager = new LostCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: {minigame: {
is_cursed: true,
}}}} as User;
const postUser = {} as User;
const journal = {};

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

expect(message.stage).toBe('Cursed');
});

it('should set stage to "Cursed" when user is not cursed', () => {
const stager = new LostCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: {minigame: {
is_cursed: false,
}}}} as User;
const postUser = {} as User;
const journal = {};

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

expect(message.stage).toBe('Not Cursed');
});

it.each([undefined, null])('should throw when QuestLostCity is %p', (state) => {
const stager = new LostCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: state}} as User;
const postUser = {} as User;
const journal = {};

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

describe('Cursed City stages', () => {
it('should be for the "Cursed City" environment', () => {
const stager = new CursedCityStager();
expect(stager.environment).toBe('Cursed City');
});

it('should set stage to "Cursed" when user is cursed', () => {
const stager = new CursedCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: {minigame: {
is_cursed: true,
}}}} as User;
const postUser = {} as User;
const journal = {};

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

expect(message.stage).toBe('Cursed');
});

it('should set stage to "Cursed" when user is not cursed', () => {
const stager = new CursedCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: {minigame: {
is_cursed: false,
}}}} as User;
const postUser = {} as User;
const journal = {};

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

expect(message.stage).toBe('Not Cursed');
});

it.each([undefined, null])('should throw when QuestLostCity is %p', (state) => {
const stager = new CursedCityStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLostCity: state}} as User;
const postUser = {} as User;
const journal = {};

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