diff --git a/src/scripts/main.js b/src/scripts/main.js index 38ace48d..b75959bf 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1176,7 +1176,6 @@ 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, @@ -1184,7 +1183,6 @@ import * as detailingFuncs from './modules/details/legacy'; "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, diff --git a/src/scripts/modules/stages/environments/cursedCity.ts b/src/scripts/modules/stages/environments/cursedCity.ts new file mode 100644 index 00000000..88e82fa2 --- /dev/null +++ b/src/scripts/modules/stages/environments/cursedCity.ts @@ -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"; + } +} diff --git a/src/scripts/modules/stages/environments/lostCity.ts b/src/scripts/modules/stages/environments/lostCity.ts new file mode 100644 index 00000000..e2a1e2cf --- /dev/null +++ b/src/scripts/modules/stages/environments/lostCity.ts @@ -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"; + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index c3a80263..47bfda01 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -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'; @@ -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'; @@ -22,6 +24,7 @@ const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), new ClawShotCityStager(), + new CursedCityStager(), new FieryWarpathStager(), new FloatingIslandsStager(), new ForbiddenGroveStager(), @@ -30,6 +33,7 @@ const stageModules: IStager[] = [ new IceFortressStager(), new LabyrinthStager(), new LivingGardenStager(), + new LostCityStager(), new MoussuPicchuStager(), new MousoleumStager(), new MuridaeMarketStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index c7954167..0bc64145 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -105,18 +105,6 @@ export function addSeasonalGardenStage(message, user, user_post, hunt) { } } -/** - * Indicate whether or not the Cursed / Corrupt mouse is present - * @param {Object } message The message to be sent. - * @param {Object } user The user state object, when the hunt was invoked (pre-hunt). - * @param {Object } user_post The user state object, after the hunt. - * @param {Object } 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? diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 0b50d029..ef483bc8 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -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 diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 14cd0e4e..3206b947 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -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'; diff --git a/src/scripts/types/quests/lostCity.ts b/src/scripts/types/quests/lostCity.ts new file mode 100644 index 00000000..2aefc548 --- /dev/null +++ b/src/scripts/types/quests/lostCity.ts @@ -0,0 +1,5 @@ +export interface QuestLostCity { + minigame: { + is_cursed: boolean + } +} diff --git a/tests/scripts/modules/stages/environments/lostCity.spec.ts b/tests/scripts/modules/stages/environments/lostCity.spec.ts new file mode 100644 index 00000000..e4258785 --- /dev/null +++ b/tests/scripts/modules/stages/environments/lostCity.spec.ts @@ -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'); + }); +});