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

SB+ Factory Stager #309

Merged
merged 2 commits into from
Mar 1, 2023
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
24 changes: 0 additions & 24 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,6 @@ import * as stagers from './modules/stages';
"Moussu Picchu": addMoussuPicchuStage,
"Muridae Market": addMuridaeMarketStage,
"Queso Geyser": addQuesoGeyserStage,
"SUPER|brie+ Factory": addSBFactoryStage,
"Sand Dunes": addSandDunesStage,
"Seasonal Garden": addSeasonalGardenStage,
"Slushy Shoreline": addSlushyShorelineStage,
Expand Down Expand Up @@ -1927,29 +1926,6 @@ import * as stagers from './modules/stages';
}
}

/**
* Separate boss-stage hunts from other hunts in rooms.
* @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.
*/
function addSBFactoryStage(message, user, user_post, hunt) {
const factory = user.quests.QuestSuperBrieFactory.factory_atts;
if (message.mouse === "Vincent, The Magnificent" || factory.boss_warning) {
message.stage = "Boss";
} else {
message.stage = (({
"pumping_room": "Pump Room",
"mixing_room": "Mixing Room",
"break_room": "Break Room",
"quality_assurance_room": "QA Room",
})[factory.current_room]);
if (!message.stage || !/Coggy Colby/.test(user.bait_name) ) {
message.stage = "Any Room";
}
}
}

/**
* Report the state of corks and eruptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type IStager } from './stages.types';
import { type IStager } from '../stages.types';
import { type QuestIceFortress } from '@scripts/types/quests/iceFortress';
import { type User } from '@scripts/types/hg';

Expand Down
31 changes: 31 additions & 0 deletions src/scripts/modules/stages/environments/superBrieFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { IStager } from '../stages.types';
import type { User } from '@scripts/types/hg';
import type { RoomType } from '@scripts/types/quests';

export class SuperBrieFactoryStager implements IStager {
readonly environment: string = 'SUPER|brie+ Factory';

readonly roomTypeToStage: Record<RoomType, string> = {
"pumping_room": "Pump Room",
"mixing_room": "Mixing Room",
"break_room": "Break Room",
"quality_assurance_room": "QA Room",
}

addStage(message: any, userPre: User, userPost: User, journal: any): void {
const quest = userPre.quests.QuestSuperBrieFactory;

if (quest == null) {
throw new Error('User is in SB+ factory but quest wasn\'t found.');
}

if (message.mouse === "Vincent, The Magnificent" || quest.factory_atts.boss_warning === true) {
message.stage = "Boss";
} else {
message.stage = this.roomTypeToStage[quest.factory_atts.current_room];
if (!message.stage || !/Coggy Colby/.test(userPre.bait_name) ) {
message.stage = "Any Room";
}
}
}
}
6 changes: 4 additions & 2 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { type IStager } from './stages.types';
import { IceFortressStager } from './iceFortress';
import { IceFortressStager } from './environments/iceFortress';
import { SuperBrieFactoryStager } from './environments/superBrieFactory';

const stageModules: IStager[] = [
new IceFortressStager()
new IceFortressStager(),
new SuperBrieFactoryStager(),
];

export { stageModules }
2 changes: 1 addition & 1 deletion src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface Quests {
QuestRiftWhiskerWoods?: any
QuestSandDunes?: any
QuestSunkenCity?: any
QuestSuperBrieFactory?: any
QuestSuperBrieFactory?: quests.QuestSuperBrieFactory
QuestTableOfContents?: quests.QuestTableOfContents
QuestTrainStation?: any
QuestWinterHunt2021?: any
Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from '@scripts/types/quests/iceFortress';
export * from '@scripts/types/quests/superBrieFactory';
export * from '@scripts/types/quests/tableOfContents';
15 changes: 15 additions & 0 deletions src/scripts/types/quests/superBrieFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export interface QuestSuperBrieFactory {
factory_atts: FactoryAtts;
}

interface FactoryAtts {
current_room: RoomType;
boss_warning: boolean | null;
}

export type RoomType =
| "mixing_room"
| "break_room"
| "pumping_room"
| "quality_assurance_room";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IceFortressStager } from '@scripts/modules/stages/iceFortress'
import { IceFortressStager } from '@scripts/modules/stages/environments/iceFortress'
import { User } from '@scripts/types/hg';

describe('IceFortressStager', () => {
Expand Down
131 changes: 131 additions & 0 deletions tests/scripts/modules/stages/environments/superBrieFactory.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { SuperBrieFactoryStager } from "@scripts/modules/stages/environments/superBrieFactory";
import type { User } from "@scripts/types/hg";
import type { IntakeMessage } from "@scripts/types/mhct";
import type { QuestSuperBrieFactory } from "@scripts/types/quests";

describe("SuperBrieFactoryStager", () => {
const defaultJournal = {};
const defaultQuest: QuestSuperBrieFactory = {
factory_atts: {
current_room: "pumping_room",
boss_warning: null,
}
};
const defaultUser = {
quests: {
QuestSuperBrieFactory: defaultQuest,
},
} as User;

it("is for the SUPER|brie+ Factory environment", () => {
const stager = new SuperBrieFactoryStager();

expect(stager.environment).toBe("SUPER|brie+ Factory");
});

it("throws when the quest is undefined", () => {
const stager = new SuperBrieFactoryStager();
const user = changeFactoryQuest(defaultUser, undefined!);

expect(() => {
stager.addStage({} as any, user, user, defaultJournal);
}).toThrowError("User is in SB+ factory but quest wasn't found.");
});

describe("boss", () => {
it("is Boss stage when pre mouse is Vincent", () => {
const stager = new SuperBrieFactoryStager();
const message = {
mouse: "Vincent, The Magnificent",
} as IntakeMessage;
const preUser = changeFactoryQuest(defaultUser, defaultQuest);

stager.addStage(message, preUser, defaultUser, defaultJournal);

expect(message.stage).toBe("Boss");
});

it("is Boss stage when there is boss_warning", () => {
const stager = new SuperBrieFactoryStager();
const message = {} as IntakeMessage;
const preUser = {
...defaultUser,
quests: {
QuestSuperBrieFactory: {
factory_atts: { boss_warning: true },
},
},
} as User;

stager.addStage(message, preUser, defaultUser, defaultJournal);

expect(message.stage).toBe("Boss");
});
});

describe('rooms', () => {
it.each([
{ room: "pumping_room", expected: "Pump Room" },
{ room: "mixing_room", expected: "Mixing Room" },
{ room: "break_room", expected: "Break Room" },
{ room: "quality_assurance_room", expected: "QA Room" },
])('sets room with Coggy Colby', ({room, expected}) => {

const stager = new SuperBrieFactoryStager();
const message = {} as IntakeMessage;
const preUser = {
...defaultUser,
bait_name: 'Coggy Colby Cheese',
quests: {
QuestSuperBrieFactory: {
factory_atts: { current_room: room },
},
},
} as User;

stager.addStage(message, preUser, defaultUser, defaultJournal);
expect(message.stage).toBe(expected);
});

it('is any room with non-coggy colby', () => {
const stager = new SuperBrieFactoryStager();
const message = {} as IntakeMessage;
const preUser = {
...defaultUser,
bait_name: 'Gouda Cheese',
quests: {
QuestSuperBrieFactory: {
factory_atts: { current_room: 'pumping_room' },
},
},
} as User;

stager.addStage(message, preUser, defaultUser, defaultJournal);
expect(message.stage).toBe('Any Room');
})
});

describe('other rooms', () => {
it('defaults to Any Room for unsupported room type', () => {
const stager = new SuperBrieFactoryStager();
const message = {} as IntakeMessage;
const user = {
...defaultUser,
quests: {
QuestSuperBrieFactory: {
factory_atts: { current_room: 'secret_room' }
}
}
} as unknown as User;

stager.addStage(message, user, defaultUser, defaultJournal)

expect(message.stage).toBe('Any Room');
})
});

function changeFactoryQuest(user: User, quest: QuestSuperBrieFactory): User {
user.quests.QuestSuperBrieFactory = quest;
return user;
}
});