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

Fix Personal Best #281

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
31 changes: 21 additions & 10 deletions src/minecraft/commands/personalBestCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class PersonalBestCommand extends minecraftCommand {
username = this.getArgs(message)[0] || username;
const floor = (this.getArgs(message)[1] ?? "M7").toLowerCase();
const rank = (this.getArgs(message)[2] ?? "S+").toLowerCase();
const floors = ["e", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "m1", "m2", "m3", "m4", "m5", "m6", "m7"];
const ranks = ["", "s", "s+"];
if (floors.includes(floor) === false) {
// eslint-disable-next-line no-throw-literal
throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]";
}
if (ranks.includes(rank) === false) {
// eslint-disable-next-line no-throw-literal
throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]";
}

const data = await getLatestProfile(username);

Expand All @@ -41,41 +51,42 @@ class PersonalBestCommand extends minecraftCommand {
throw `${username} has never played dungeons on ${data.profileData.cute_name}.`;
}

let requested_floor = dungeons.catacombs;
let requested_floor = null;
let time = 0;
const floor_type = floor.charAt(floor.length - 2);
const floor_number = floor.charAt(floor.length - 1);
switch (floor_type) {
case "m":
requested_floor = dungeons.catacombs?.MASTER_MODE_FLOORS?.[`floor_${floor_number}`] ?? null;
requested_floor = dungeons.catacombs?.MASTER_MODE_FLOORS?.[`floor_${floor_number}`] || null;
break;
case "f":
requested_floor = dungeons.catacombs?.floors?.[`floor_${floor_number}`] ?? null;
requested_floor = dungeons.catacombs?.floors?.[`floor_${floor_number}`] || null;
break;
case "e":
requested_floor = dungeons.catacombs?.floors?.entrance ?? null;
requested_floor = dungeons.catacombs?.floors?.entrance || null;
break;
default:
this.send("/gc Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]");
break;
// eslint-disable-next-line no-throw-literal
throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]";
}
// eslint-disable-next-line no-throw-literal
if (requested_floor === null) throw `${username} has never gotten a ${rank} on ${floor} before.`;

switch (rank) {
case "s+":
time = requested_floor.fastest_s_plus;
time = requested_floor?.fastest_s_plus || 0;
break;
case "s":
time = requested_floor.fastest_s;
time = requested_floor?.fastest_s || 0;
break;
default:
this.send("/gc Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]");
time = requested_floor?.fastest || 0;
break;
}

if (time === 0) {
this.send(`/gc ${username} has no PB on ${floor} ${rank}`);
// eslint-disable-next-line no-throw-literal
throw `${username} has no PB on ${floor} ${rank}`;
} else {
this.send(`/gc ${username}'s PB on ${floor} with ${rank} rank is ${millisToMinutesAndSeconds(time)}`);
}
Expand Down
Loading