Skip to content

Commit

Permalink
Add Balack's Cove stager
Browse files Browse the repository at this point in the history
  • Loading branch information
hymccord committed Oct 26, 2023
1 parent f8f65a7 commit fd3d312
Show file tree
Hide file tree
Showing 8 changed files with 70 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 @@ -1174,7 +1174,6 @@ import * as detailingFuncs from './modules/details/legacy';

/** @type {Object <string, Function>} */
const location_stage_lookup = {
"Balack's Cove": stagingFuncs.addBalacksCoveStage,
"Bristle Woods Rift": stagingFuncs.addBristleWoodsRiftStage,
"Burroughs Rift": stagingFuncs.addBurroughsRiftStage,
"Cursed City": stagingFuncs.addLostCityStage,
Expand Down
35 changes: 35 additions & 0 deletions src/scripts/modules/stages/environments/balacksCove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {type User} from '@scripts/types/hg';
import {type IntakeMessage} from '@scripts/types/mhct';
import {type IStager} from '../stages.types';

export class BalacksCoveStager implements IStager {
readonly environment: string = 'Balack\'s Cove';

/**
* Set the stage based on the tide. Reject hunts near tide intensity changes.
*/
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
const quest = userPre.quests.QuestBalacksCove;

if (!quest) {
throw new Error('QuestBalacksCove is undefined');
}

const tide = quest.tide.level;
const direction = quest.tide.direction;
const progress = quest.tide.percent;
const imminent_state_change = (progress >= 99
// Certain transitions do not change the tide intensity, and are OK to track.
&& !(tide === "low" && direction === "in")
&& !(tide === "high" && direction === "out"));
if (!imminent_state_change && tide) {
message.stage = tide.charAt(0).toUpperCase() + tide.substr(1);
if (message.stage === "Med") {
message.stage = "Medium";
}
message.stage += " Tide";
} else {
throw new Error('Skipping hunt due to imminent tide change');
}
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {type IStager} from './stages.types';
import {BalacksCoveStager} from './environments/balacksCove';
import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk';
import {ClawShotCityStager} from './environments/clawShotCity';
import {FloatingIslandsStager} from './environments/floatingIslands';
Expand All @@ -11,6 +12,7 @@ import {MousoleumStager} from './environments/mousoleum';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';

const stageModules: IStager[] = [
new BalacksCoveStager(),
new BountifulBeanstalkStager(),
new ClawShotCityStager(),
new FloatingIslandsStager(),
Expand Down
26 changes: 0 additions & 26 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,6 @@ export function addFieryWarpathStage(message, user, user_post, hunt) {
message.stage = (wave === "portal") ? "Portal" : `Wave ${wave}`;
}

/**
* Set the stage based on the tide. Reject hunts near tide intensity changes.
* @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).
* @param {Object <string, any>} user_post The user state object, after the hunt.
* @param {Object <string, any>} hunt The journal entry corresponding to the active hunt.
*/
export function addBalacksCoveStage(message, user, user_post, hunt) {
const tide = user.quests.QuestBalacksCove.tide.level;
const direction = user.quests.QuestBalacksCove.tide.direction;
const progress = user.quests.QuestBalacksCove.tide.percent;
const imminent_state_change = (progress >= 99
// Certain transitions do not change the tide intensity, and are OK to track.
&& !(tide === "low" && direction === "in")
&& !(tide === "high" && direction === "out"));
if (!imminent_state_change && tide) {
message.stage = tide.charAt(0).toUpperCase() + tide.substr(1);
if (message.stage === "Med") {
message.stage = "Medium";
}
message.stage += " Tide";
} else {
message.location = null;
}
}

/**
* Read the viewing attributes to determine the season. Reject hunts where the season changed.
* @param {Object <string, any>} message The message to be sent.
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface User {
// TODO: Define needed interfaces for quests in /types/quests/<QuestName>.ts
export interface Quests {
QuestAncientCity?: unknown
QuestBalacksCove?: unknown
QuestBalacksCove?: quests.QuestBalacksCove
QuestBountifulBeanstalk?: quests.QuestBountifulBeanstalk
QuestClawShotCity?: quests.QuestClawShotCity
QuestFloatingIslands?: quests.QuestFloatingIslands
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/types/quests/balacksCove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface QuestBalacksCove {
tide: {
level: 'low' | 'med' | 'high'
direction: 'in' | 'out'
percent: number
}
}
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@scripts/types/quests/balacksCove';
export * from '@scripts/types/quests/bountifulBeanstalk';
export * from '@scripts/types/quests/clawShotCity';
export * from '@scripts/types/quests/floatingIslands';
Expand Down
28 changes: 24 additions & 4 deletions tests/scripts/modules/stages/environments/balacksCove.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import {addBalacksCoveStage} from "@scripts/modules/stages/legacy";
import {BalacksCoveStager} from "@scripts/modules/stages/environments/balacksCove";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Balack\'s Cove stages', () => {

it('should be for the "Balack\'s Cove" environment', () => {
const stager = new BalacksCoveStager();
expect(stager.environment).toBe('Balack\'s Cove');
});

it.each`
tide | expected
${'low'} | ${'Low'}
${'med'} | ${'Medium'}
${'high'} | ${'High'}
`('should set stage to High, Medium, or Low', ({tide, expected}) => {
const stager = new BalacksCoveStager();

const message = {} as IntakeMessage;
const preUser = {quests: {QuestBalacksCove: {tide: {
level: tide,
Expand All @@ -19,12 +26,14 @@ describe('Balack\'s Cove stages', () => {
const postUser = {} as User;
const journal = {};

addBalacksCoveStage(message, preUser, postUser, journal);
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe(`${expected} Tide`);
});

it('should reject imminent tide changes', () => {
const stager = new BalacksCoveStager();

const message = {} as IntakeMessage;
const preUser = {quests: {QuestBalacksCove: {tide: {
level: 'high',
Expand All @@ -34,8 +43,19 @@ describe('Balack\'s Cove stages', () => {
const postUser = {} as User;
const journal = {};

addBalacksCoveStage(message, preUser, postUser, journal);
expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('Skipping hunt due to imminent tide change');
});

it.each([undefined, null])('should throw when quest is %p', (quest) => {
const stager = new BalacksCoveStager();

const message = {} as IntakeMessage;
const preUser = {quests: {QuestBalacksCove: quest}} as User;
const postUser = {} as User;
const journal = {};

expect(message.location).toBe(null);
expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestBalacksCove is undefined');
});
});

0 comments on commit fd3d312

Please sign in to comment.