diff --git a/src/lib/generators/rtdx/data.ts b/src/lib/generators/rtdx/data.ts index daf0ba2..aa05739 100755 --- a/src/lib/generators/rtdx/data.ts +++ b/src/lib/generators/rtdx/data.ts @@ -85,15 +85,16 @@ const Data = { dungeons: { all(validOnly = false) { const dungeons: DungeonData[] = []; - for (const [i, dungeon] of RomData.dungeons.entries()) { - if (validOnly && !dungeon.valid) continue; + for (const dungeon of RomData.dungeons) { const index = parseInt(dungeon.const.slice(1)); + const valid = dungeon.valid && index <= 45; + if (validOnly && !valid) continue; dungeons.push({ name: dungeon.name, index, floors: dungeon.floors, ascending: dungeon.ascending, - valid: dungeon.valid && index <= 45, + valid, }); } return dungeons; diff --git a/src/lib/generators/rtdx/generate.ts b/src/lib/generators/rtdx/generate.ts index 8f92045..c4304bc 100755 --- a/src/lib/generators/rtdx/generate.ts +++ b/src/lib/generators/rtdx/generate.ts @@ -37,12 +37,7 @@ interface PasswordData { dungeon: number; floor: number; pokemon: number; - /** - * 1 = Regular, - * 2 = Special, - * 3 = Deluxe - */ - reward: 1 | 2 | 3; + reward: number; revive: number; } @@ -81,7 +76,13 @@ function serialize(data: RescueData | RevivalData): string { return shuffled.join(''); } -export function generateRescue(data: { team: string; dungeon: number; floor: number; pokemon: number }): string { +export function generateRescue(data: { + team: string; + dungeon: number; + floor: number; + pokemon: number; + reward: number; +}): string { if (data.team.length < 1 || data.team.length > 12) throw new Error('Team name must be between 1 and 12 characters'); const team: number[] = []; for (const char of data.team) { @@ -91,17 +92,14 @@ export function generateRescue(data: { team: string; dungeon: number; floor: num } team.push(index); } + const dungeonData = Data.dungeons.get(data.dungeon); - if (!dungeonData.valid) { - throw new Error('Invalid dungeon'); - } - if (data.floor < 1 || data.floor > dungeonData.floors) { - throw new Error('Invalid floor'); - } + if (!dungeonData.valid) throw new Error('Invalid dungeon'); + if (data.floor < 1 || data.floor > dungeonData.floors) throw new Error('Invalid floor'); - if (!Data.pokemon.get(data.pokemon).valid) { - throw new Error('Invalid Pokemon'); - } + if (!Data.pokemon.get(data.pokemon).valid) throw new Error('Invalid Pokemon'); + + if (data.reward < 0 || data.reward > 3) throw new Error('Invalid reward type'); const rescueData: RescueData = { timestamp: Math.round(Date.now() / 1000), @@ -110,7 +108,7 @@ export function generateRescue(data: { team: string; dungeon: number; floor: num dungeon: data.dungeon, floor: data.floor, pokemon: data.pokemon, - reward: 3, + reward: data.reward, }; return serialize(rescueData); } @@ -123,9 +121,7 @@ export function generateRevival(password: string, teamName: string): string { const team: number[] = []; for (const char of teamName) { const index = Data.charmap_text.indexOf(char); - if (index < 0) { - throw new Error(`Invalid character in team name: ${char}`); - } + if (index < 0) throw new Error(`Invalid character in team name: ${char}`); team.push(index); } diff --git a/src/routes/(rtdx)/rtdx-rescue/+page.svelte b/src/routes/(rtdx)/rtdx-rescue/+page.svelte index d2df5aa..6647ad9 100644 --- a/src/routes/(rtdx)/rtdx-rescue/+page.svelte +++ b/src/routes/(rtdx)/rtdx-rescue/+page.svelte @@ -13,6 +13,7 @@ ...values, dungeon: parseInt(values.dungeon), pokemon: parseInt(values.pokemon), + reward: parseInt(values.reward), }), onSubmit(values) { try { @@ -59,6 +60,14 @@ {/each} +
+ + +