Skip to content

Commit

Permalink
RTDX Rescue: Fix dungeons list and add back option to pick reward
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik99999 committed Feb 25, 2024
1 parent 614dd4c commit f00e507
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/lib/generators/rtdx/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 16 additions & 20 deletions src/lib/generators/rtdx/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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),
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions src/routes/(rtdx)/rtdx-rescue/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
...values,
dungeon: parseInt(values.dungeon),
pokemon: parseInt(values.pokemon),
reward: parseInt(values.reward),
}),
onSubmit(values) {
try {
Expand Down Expand Up @@ -59,6 +60,14 @@
{/each}
</select>
</div>
<div class="form-group">
<label for="reward">Reward:</label>
<select class="form-control" id="reward" name="reward" required>
<option value="3">Deluxe</option>
<option value="2">Special</option>
<option value="1">Regular</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Generate</button>
</form>
<PasswordImage {password} type="rescue" />

0 comments on commit f00e507

Please sign in to comment.