Skip to content

Commit

Permalink
Add Burroughs Rift stager
Browse files Browse the repository at this point in the history
  • Loading branch information
hymccord committed Jan 31, 2024
1 parent fdc6b8e commit 0220d55
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 30 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 = {
"Burroughs Rift": stagingFuncs.addBurroughsRiftStage,
"Festive Comet": stagingFuncs.addFestiveCometStage,
"Frozen Vacant Lot": stagingFuncs.addFestiveCometStage,
"Foreword Farm": stagingFuncs.addForewordFarmStage,
Expand Down
36 changes: 36 additions & 0 deletions src/scripts/modules/stages/environments/burroughsRift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {type User} from '@scripts/types/hg';
import {IntakeMessage} from '@scripts/types/mhct';
import {MistTier, MistTiers} from '@scripts/types/quests';
import {type IStager} from '../stages.types';

export class BurroughsRiftStager implements IStager {
readonly environment: string = 'Burroughs Rift';

readonly tierToStage: Record<MistTier, string> = {
'tier_0': 'Mist 0',
'tier_1': 'Mist 1-5',
'tier_2': 'Mist 6-18',
'tier_3': 'Mist 19-20',
};

/**
* Report the misting state
*/
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
const quest = userPre.quests.QuestRiftBurroughs;

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

if (!this.isValidMistTier(quest.mist_tier)) {
throw new Error('Skipping unknown Burroughs Rift mist state');
}

message.stage = this.tierToStage[quest.mist_tier];
}

private isValidMistTier(value: unknown): value is MistTier {
return typeof value === 'string' && MistTiers.includes(value as MistTier);
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {type IStager} from './stages.types';
import {BalacksCoveStager} from './environments/balacksCove';
import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk';
import {BristleWoodsRiftStager} from './environments/bristleWoodsRift';
import {BurroughsRiftStager} from './environments/burroughsRift';
import {ClawShotCityStager} from './environments/clawShotCity';
import {CursedCityStager} from './environments/cursedCity';
import {FieryWarpathStager} from './environments/fieryWarpath';
Expand All @@ -28,6 +29,7 @@ const stageModules: IStager[] = [
new BalacksCoveStager(),
new BountifulBeanstalkStager(),
new BristleWoodsRiftStager(),
new BurroughsRiftStager(),
new ClawShotCityStager(),
new CursedCityStager(),
new FieryWarpathStager(),
Expand Down
20 changes: 0 additions & 20 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,6 @@ export function addToxicSpillStage(message, user, user_post, hunt) {
}
}

/**
* Report the misting state
* @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 addBurroughsRiftStage(message, user, user_post, hunt) {
const quest = user.quests.QuestRiftBurroughs;
message.stage = (({
"tier_0": "Mist 0",
"tier_1": "Mist 1-5",
"tier_2": "Mist 6-18",
"tier_3": "Mist 19-20",
})[quest.mist_tier]);
if (!message.stage) {
message.location = null;
}
}

/**
* Report on the unique minigames in each sub-location. Reject hunts for which the train
* moved / updated / departed, as the hunt stage is ambiguous.
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 @@ -59,7 +59,7 @@ export interface Quests {
QuestQuesoGeyser?: quests.QuestQuesoGeyser
QuestRelicHunter?: unknown
QuestRiftBristleWoods?: quests.QuestRiftBristleWoods
QuestRiftBurroughs?: unknown
QuestRiftBurroughs?: quests.QuestRiftBurroughs
QuestRiftFuroma?: unknown
QuestRiftWhiskerWoods?: unknown
QuestSandDunes?: quests.QuestSandDunes
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/types/quests/burroughsRift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface QuestRiftBurroughs {
mist_tier: string // MistTier
}

export const MistTiers = ['tier_0', 'tier_1', 'tier_2', 'tier_3'] as const;

export type MistTier = typeof MistTiers[number];
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from '@scripts/types/quests/balacksCove';
export * from '@scripts/types/quests/bountifulBeanstalk';
export * from '@scripts/types/quests/bristleWoodsRift';
export * from '@scripts/types/quests/burroughsRift';
export * from '@scripts/types/quests/clawShotCity';
export * from '@scripts/types/quests/floatingIslands';
export * from '@scripts/types/quests/forbiddenGrove';
Expand Down
27 changes: 19 additions & 8 deletions tests/scripts/modules/stages/environments/burroughsRift.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import {addBurroughsRiftStage} from "@scripts/modules/stages/legacy";
import {BurroughsRiftStager} from "@scripts/modules/stages/environments/burroughsRift";
import {IStager} from "@scripts/modules/stages/stages.types";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Burroughs Rift stages', () => {
let stager: IStager;
let message: IntakeMessage;
let preUser: User;
let postUser: User;
const journal = {};

beforeEach(() => {
stager = new BurroughsRiftStager();
message = {} as IntakeMessage;
preUser = {} as User;
postUser = {} as User;
});

it('should be for the Burroughs Rift environment', () => {
expect(stager.environment).toBe('Burroughs Rift');
});

it('should throw when QuestRiftBurroughs is undefined', () => {
preUser.quests = {};

expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestRiftBurroughs is undefined');
});

it.each`
level | expected
${'tier_0'} | ${'Mist 0'}
Expand All @@ -26,21 +40,18 @@ describe('Burroughs Rift stages', () => {
mist_tier: level,
}};

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

expect(message.stage).toBe(expected);
});

it('should set location to null when mist level is unknown', () => {
it('should throw when mist level is unknown', () => {
message.location = {id: 0, name: ''};
preUser.quests = {QuestRiftBurroughs: {
mist_tier: 'tier_42',
}};

expect(message.location).not.toBeNull();

addBurroughsRiftStage(message, preUser, postUser, journal);

expect(message.location).toBeNull();
expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('Skipping unknown Burroughs Rift mist state');
});
});

0 comments on commit 0220d55

Please sign in to comment.