Skip to content

Commit

Permalink
Merge pull request #469 from m-h-c-t/csc-stager
Browse files Browse the repository at this point in the history
Claw Shot City Stager
  • Loading branch information
AardWolf authored Oct 10, 2023
2 parents 83c4343 + d1e1a4c commit 872b508
Show file tree
Hide file tree
Showing 6 changed files with 105 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,5 +1,6 @@
import {type IStager} from './stages.types';
import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk';
import {ClawShotCityStager} from './environments/clawShotCity';
import {FloatingIslandsStager} from './environments/floatingIslands';
import {ForbiddenGroveStager} from './environments/forbiddenGrove';
import {FungalCavernStager} from './environments/fungalCavern';
Expand All @@ -10,6 +11,7 @@ import {SuperBrieFactoryStager} from './environments/superBrieFactory';

const stageModules: IStager[] = [
new BountifulBeanstalkStager(),
new ClawShotCityStager(),
new FloatingIslandsStager(),
new ForbiddenGroveStager(),
new FungalCavernStager(),
Expand Down
26 changes: 0 additions & 26 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {IntakeRejectionEngine} from '@scripts/hunt-filter/engine';
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';
import {LoggerService} from '@scripts/util/logger';
import {getDefaultIntakeMessage, getDefaultUser} from '@tests/scripts/hunt-filter/common';

describe('Claw Shot City exemptions', () => {
let logger: LoggerService;
let stager: (message: IntakeMessage, pre: User, post: User, journal: unknown) => void;
let stager: ClawShotCityStager;
let target: IntakeRejectionEngine;

beforeEach(() => {
logger = {} as LoggerService;
stager = addClawShotCityStage;
stager = new ClawShotCityStager();
target = new IntakeRejectionEngine(logger);

logger.debug = jest.fn();
Expand Down Expand Up @@ -44,8 +44,8 @@ describe('Claw Shot City exemptions', () => {

/** Sets the pre and post message stage based on current pre and post user */
function calculateStage() {
stager(preMessage, preUser, {} as User, {});
stager(postMessage, postUser, {} as User, {});
stager.addStage(preMessage, preUser, {} as User, {});
stager.addStage(postMessage, postUser, {} as User, {});
}
});

Expand Down
64 changes: 64 additions & 0 deletions tests/scripts/modules/stages/environments/clawShotCity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 = {};
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 = {};
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 = {};
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 872b508

Please sign in to comment.