-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #551 from hymccord/sunken-city-stager
Convert Sunken City stager
- Loading branch information
Showing
8 changed files
with
108 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SunkenCityStager implements IStager { | ||
readonly environment: string = 'Sunken City'; | ||
|
||
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { | ||
const quest = userPre.quests.QuestSunkenCity; | ||
|
||
if (!quest) { | ||
throw new Error('QuestSunkenCity is undefined'); | ||
} | ||
|
||
if (!quest.is_diving) { | ||
message.stage = "Docked"; | ||
return; | ||
} | ||
|
||
const depth = quest.distance; | ||
message.stage = quest.zone_name; | ||
if (depth < 2000) { | ||
message.stage += " 0-2km"; | ||
} else if (depth < 10000) { | ||
message.stage += " 2-10km"; | ||
} else if (depth < 15000) { | ||
message.stage += " 10-15km"; | ||
} else if (depth < 25000) { | ||
message.stage += " 15-25km"; | ||
} else if (depth >= 25000) { | ||
message.stage += " 25km+"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface QuestSunkenCity { | ||
is_diving: boolean; | ||
distance: number; | ||
zone_name: string; | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/scripts/modules/stages/environments/sunkenCity.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {SunkenCityStager} from "@scripts/modules/stages/environments/sunkenCity"; | ||
import {User} from "@scripts/types/hg"; | ||
import {IntakeMessage} from "@scripts/types/mhct"; | ||
|
||
describe('Sunken City stages', () => { | ||
it('should be for the "Sunken City" environment', () => { | ||
const stager = new SunkenCityStager(); | ||
expect(stager.environment).toBe('Sunken City'); | ||
}); | ||
|
||
it('should set stage to "Docked" if user is not diving', () => { | ||
const stager = new SunkenCityStager(); | ||
const message = {} as IntakeMessage; | ||
const preUser = {quests: {QuestSunkenCity: { | ||
is_diving: false, | ||
}}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe('Docked'); | ||
}); | ||
|
||
it.each` | ||
distance | expected | ||
${0} | ${'0-2km'} | ||
${1990} | ${'0-2km'} | ||
${2000} | ${'2-10km'} | ||
${9990} | ${'2-10km'} | ||
${10000} | ${'10-15km'} | ||
${14990} | ${'10-15km'} | ||
${15000} | ${'15-25km'} | ||
${24990} | ${'15-25km'} | ||
${25000} | ${'25km+'} | ||
${100000} | ${'25km+'} | ||
`('should append "$expected" to zone name when depth is $distance', ({distance, expected}) => { | ||
const stager = new SunkenCityStager(); | ||
const message = {} as IntakeMessage; | ||
const preUser = {quests: {QuestSunkenCity: { | ||
is_diving: true, | ||
distance: distance, | ||
zone_name: 'Test Zone', | ||
}}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe(`Test Zone ${expected}`); | ||
}); | ||
|
||
it.each([undefined, null])('should throw when QuestSunken city is %p', (state) => { | ||
const stager = new SunkenCityStager(); | ||
const message = {} as IntakeMessage; | ||
const preUser = {quests: {QuestSunkenCity: state}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('QuestSunkenCity is undefined'); | ||
}); | ||
}); |