From 85284aa352a96dbcb10f2d17cd6e846e07e88ecb Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Mon, 3 Apr 2023 10:44:23 -0400 Subject: [PATCH] Add Claw Shot City stager --- src/scripts/main.js | 1 - .../stages/environments/clawShotCity.ts | 34 +++++++++++++++++++ src/scripts/modules/stages/index.ts | 2 ++ src/scripts/modules/stages/legacy.js | 27 --------------- .../stages/environments/clawShotCity.spec.ts | 31 ++++++++++++++--- 5 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 src/scripts/modules/stages/environments/clawShotCity.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index ca1be9d4..f25287cf 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1195,7 +1195,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Balack's Cove": stagingFuncs.addBalacksCoveStage, "Bristle Woods Rift": stagingFuncs.addBristleWoodsRiftStage, "Burroughs Rift": stagingFuncs.addBurroughsRiftStage, - "Claw Shot City": stagingFuncs.addClawShotCityStage, "Cursed City": stagingFuncs.addLostCityStage, "Festive Comet": stagingFuncs.addFestiveCometStage, "Frozen Vacant Lot": stagingFuncs.addFestiveCometStage, diff --git a/src/scripts/modules/stages/environments/clawShotCity.ts b/src/scripts/modules/stages/environments/clawShotCity.ts new file mode 100644 index 00000000..e3a4d3be --- /dev/null +++ b/src/scripts/modules/stages/environments/clawShotCity.ts @@ -0,0 +1,34 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class ClawShotCityStager implements IStager { + readonly environment: string = 'Claw Shot City'; + + /** + * Separate hunts with certain mice available from those without. + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + const quest = userPre.quests.QuestClawShotCity; + + if (!quest) { + throw new Error('QuestClawShotCity is undefined'); + } + + /** + * !map_active && !has_wanted_poster => Bounty Hunter can be attracted + * !map_active && has_wanted_poster => Bounty Hunter is not attracted + * map_active && !has_wanted_poster => On a Wanted Poster + */ + + if (!quest.map_active && !quest.has_wanted_poster) { + message.stage = "No poster"; + } else if (!quest.map_active && quest.has_wanted_poster) { + message.stage = "Has poster"; + } else if (quest.map_active) { + message.stage = "Using poster"; + } else { + throw new Error("Unexpected Claw Shot City quest state"); + } + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 30bfb6b9..6d6ee56d 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -1,5 +1,6 @@ import {type IStager} from './stages.types'; import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk'; +import {ClawShotCityStager} from './environments/clawShotCity'; import {ForbiddenGroveStager} from './environments/forbiddenGrove'; import {FungalCavernStager} from './environments/fungalCavern'; import {IceFortressStager} from './environments/iceFortress'; @@ -7,6 +8,7 @@ import {SuperBrieFactoryStager} from './environments/superBrieFactory'; const stageModules: IStager[] = [ new BountifulBeanstalkStager(), + new ClawShotCityStager(), new ForbiddenGroveStager(), new FungalCavernStager(), new IceFortressStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index ed5433fa..1ea545f4 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -26,33 +26,6 @@ export function addHarbourStage(message, user, user_post, hunt) { } } -/** - * Separate hunts with certain mice available from those without. - * @param {import("@scripts/types/mhct").IntakeMessage} message The message to be sent. - * @param {import("@scripts/types/hg").User} user The user state object, when the hunt was invoked (pre-hunt). - * @param {import("@scripts/types/hg").User} user_post The user state object, after the hunt. - * @param {unknown} hunt The journal entry corresponding to the active hunt. - */ -export function addClawShotCityStage(message, user, user_post, hunt) { - const quest = user.quests.QuestClawShotCity; - /** - * !map_active && !has_wanted_poster => Bounty Hunter can be attracted - * !map_active && has_wanted_poster => Bounty Hunter is not attracted - * map_active && !has_wanted_poster => On a Wanted Poster - */ - - if (!quest.map_active && !quest.has_wanted_poster) { - message.stage = "No poster"; - } else if (!quest.map_active && quest.has_wanted_poster) { - message.stage = "Has poster"; - } else if (quest.map_active) { - message.stage = "Using poster"; - } else { - throw new Error("Unexpected Claw Shot City quest state"); - } -} - -/** * Set the stage based on decoration and boss status. * @param {Object } message The message to be sent. * @param {Object } user The user state object, when the hunt was invoked (pre-hunt). diff --git a/tests/scripts/modules/stages/environments/clawShotCity.spec.ts b/tests/scripts/modules/stages/environments/clawShotCity.spec.ts index e4f38b56..4871d90b 100644 --- a/tests/scripts/modules/stages/environments/clawShotCity.spec.ts +++ b/tests/scripts/modules/stages/environments/clawShotCity.spec.ts @@ -1,41 +1,64 @@ -import {addClawShotCityStage} from '@scripts/modules/stages/legacy'; +import {ClawShotCityStager} from '@scripts/modules/stages/environments/clawShotCity'; import {User} from '@scripts/types/hg'; import {IntakeMessage} from '@scripts/types/mhct'; describe('ClawShotCityStager', () => { + it('Should be for the "Claw Shot City" environment', () => { + const stager = new ClawShotCityStager(); + expect(stager.environment).toBe('Claw Shot City'); + }); + it('Sets stage to "No poster" if user has no map or poster', () => { + const stager = new ClawShotCityStager(); + const message = {} as IntakeMessage; const preUser = {quests: {QuestClawShotCity: { map_active: false, has_wanted_poster: false, }}} as User; const postUser = {} as User; const journal = {}; - addClawShotCityStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe('No poster'); }); it('Sets stage to "Has poster" if user has no map but has poster', () => { + const stager = new ClawShotCityStager(); + const message = {} as IntakeMessage; const preUser = {quests: {QuestClawShotCity: { map_active: false, has_wanted_poster: true, }}} as User; const postUser = {} as User; const journal = {}; - addClawShotCityStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe('Has poster'); }); it('Sets stage to "Using poster" if user has an active map', () => { + const stager = new ClawShotCityStager(); + const message = {} as IntakeMessage; const preUser = {quests: {QuestClawShotCity: { map_active: true, has_wanted_poster: false, }}} as User; const postUser = {} as User; const journal = {}; - addClawShotCityStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe('Using poster'); }); + + it.each([undefined, null])('throws when quest is %p', (quest) => { + const stager = new ClawShotCityStager(); + + const message = {} as IntakeMessage; + const preUser = {quests: {QuestClawShotCity: quest}} as User; + const postUser = {} as User; + const journal = {}; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestClawShotCity'); + }); });