Skip to content

Commit

Permalink
Add Claw Shot City stager
Browse files Browse the repository at this point in the history
  • Loading branch information
hymccord committed Oct 5, 2023
1 parent 960b6dd commit 85284aa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions src/scripts/modules/stages/environments/clawShotCity.ts
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';

const stageModules: IStager[] = [
new BountifulBeanstalkStager(),
new ClawShotCityStager(),
new ForbiddenGroveStager(),
new FungalCavernStager(),
new IceFortressStager(),
Expand Down
27 changes: 0 additions & 27 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string, any>} message The message to be sent.
* @param {Object <string, any>} user The user state object, when the hunt was invoked (pre-hunt).
Expand Down
31 changes: 27 additions & 4 deletions tests/scripts/modules/stages/environments/clawShotCity.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 85284aa

Please sign in to comment.