From 8871f586d22252e9b93787d88d03460ab5cdddf2 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 4 Apr 2023 10:15:29 -0400 Subject: [PATCH] Add Lost/Cursed City stager --- src/scripts/main.js | 2 - .../modules/stages/environments/cursedCity.ts | 20 +++++ .../modules/stages/environments/lostCity.ts | 20 +++++ src/scripts/modules/stages/index.ts | 4 + src/scripts/modules/stages/legacy.js | 12 --- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/lostCity.ts | 5 ++ .../stages/environments/lostCity.spec.ts | 73 ++++++++++++++++++- 9 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 src/scripts/modules/stages/environments/cursedCity.ts create mode 100644 src/scripts/modules/stages/environments/lostCity.ts create mode 100644 src/scripts/types/quests/lostCity.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index 4518b143..d49a4106 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, "Fiery Warpath": stagingFuncs.addFieryWarpathStage, @@ -1186,7 +1185,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Gnawnian Express Station": stagingFuncs.addTrainStage, "Iceberg": stagingFuncs.addIcebergStage, "Living Garden": stagingFuncs.addGardenStage, - "Lost City": stagingFuncs.addLostCityStage, "Muridae Market": stagingFuncs.addMuridaeMarketStage, "Queso Geyser": stagingFuncs.addQuesoGeyserStage, "Sand Dunes": stagingFuncs.addSandDunesStage, 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 3ca898bf..eee2f4d4 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -2,12 +2,14 @@ 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 {FloatingIslandsStager} from './environments/floatingIslands'; import {ForbiddenGroveStager} from './environments/forbiddenGrove'; import {FungalCavernStager} from './environments/fungalCavern'; import {HarbourStager} from './environments/harbour'; import {IceFortressStager} from './environments/iceFortress'; import {LabyrinthStager} from './environments/labyrinth'; +import {LostCityStager} from './environments/lostCity'; import {MoussuPicchuStager} from './environments/moussuPicchu'; import {MousoleumStager} from './environments/mousoleum'; import {SlushyShorelineStager} from './environments/slushyShoreline'; @@ -17,12 +19,14 @@ const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), new ClawShotCityStager(), + new CursedCityStager(), new FloatingIslandsStager(), new ForbiddenGroveStager(), new FungalCavernStager(), new HarbourStager(), new IceFortressStager(), new LabyrinthStager(), + new LostCityStager(), new MoussuPicchuStager(), new MousoleumStager(), new SlushyShorelineStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index bd418d0d..2a138d37 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -138,18 +138,6 @@ export function addSandDunesStage(message, user, user_post, hunt) { message.stage = (user.quests.QuestSandDunes.minigame.has_stampede) ? "Stampede" : "No Stampede"; } -/** - * 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 55b684eb..01a03193 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?: unknown - 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 912018ee..ea7dac4f 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -8,6 +8,7 @@ export * from '@scripts/types/quests/harbour'; export * from '@scripts/types/quests/iceberg'; export * from '@scripts/types/quests/iceFortress'; export * from '@scripts/types/quests/labyrinth'; +export * from '@scripts/types/quests/lostCity'; export * from '@scripts/types/quests/mousoleum'; export * from '@scripts/types/quests/moussuPicchu'; export * from '@scripts/types/quests/superBrieFactory'; 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 index cd27f0a3..107d4b1e 100644 --- a/tests/scripts/modules/stages/environments/lostCity.spec.ts +++ b/tests/scripts/modules/stages/environments/lostCity.spec.ts @@ -1,9 +1,16 @@ -import {addLostCityStage} from "@scripts/modules/stages/legacy"; +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/Cursed City stages', () => { +describe('Lost City stages', () => { + it('should be for the "" 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, @@ -11,12 +18,13 @@ describe('Lost/Cursed City stages', () => { const postUser = {} as User; const journal = {}; - addLostCityStage(message, preUser, postUser, 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, @@ -24,8 +32,65 @@ describe('Lost/Cursed City stages', () => { const postUser = {} as User; const journal = {}; - addLostCityStage(message, preUser, postUser, 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 "" 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'); + }); });