Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Burroughs Rift stager #525

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions tests/scripts/modules/stages/environments/burroughsRift.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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'}
${'tier_1'} | ${'Mist 1-5'}
${'tier_2'} | ${'Mist 6-18'}
${'tier_3'} | ${'Mist 19-20'}
`('should set stage to $expected when mist is at $level', ({level, expected}) => {

preUser.quests = {QuestRiftBurroughs: {
mist_tier: level,
}};

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

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

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

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