Skip to content

Commit

Permalink
get level function + finished team member info
Browse files Browse the repository at this point in the history
  • Loading branch information
Killermaschine88 committed Jun 25, 2022
1 parent 2bc326c commit 577f92d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ npm-debug.log*
node_modules/
.npm
.env
constants/JSON
constants/JSON/emojiList.json
constants/JSON/INFO.js
constants/JSON/pokemonList.json
31 changes: 22 additions & 9 deletions commands/interaction/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,49 @@ module.exports = {
await reply.edit({ content: "Loading Game <a:wait:989262887317028924>", embeds: [], components: [] });
Game = new GameMap(profiles[id]);
Game.setStarted().setProfileIndex(id).setVariables(interaction, collector).setMessage(reply).updateMessage();
} else if (id === "newProfile") {
//Profile Generation Modal
}

//Profile Generation Modal
if (id === "newProfile") {
i.showModal(newProfileModal);
} else if (id === "newProfileModal") {
//Handles name input
}

//Handles name input
if (id === "newProfileModal") {
await i.deferUpdate().catch((err) => err);
name = i.fields.getTextInputValue("name").trim();
if (badName(name)) return i.deferUpdate().catch((err) => err), collector.stop("Name input was invalid");
if (await hasProfileWithName(interaction, name)) return i.deferUpdate().catch((err) => err), interaction.followUp({ content: `Can't create another profile with the name \`${name}\` as a profile with that name already exists.`, ephemeral: true });

//Show new embed with starter pokemons (function like save selection generation)
await reply.edit(generateStarterSelection());
} else if (["starter0", "starter1", "starter2"].includes(id)) {
}

//Generate profile and update message
if (["starter0", "starter1", "starter2"].includes(id)) {
const starterPokemon = getStarterPokemon(id.replace("starter", ""));

//Generate profile and update message
Game = new GameMap();
await createProfile(interaction, name, Game, starterPokemon);
profiles = (await interaction.client.mongo.findOne({ _id: interaction.user.id })).profiles;
await interaction.editReply(generateProfileSelection(profiles));
} else if (id === "movement") {
// Returning components back to walking row
Game.updateMessage();
}

//Defering
await i.deferUpdate().catch((err) => err);

collector.resetTimer(); //Reset timer on input

// Returning components back to walking row
if (id === "movement") {
Game.updateMessage();
}

//Pokemon Menu handler
if (id.startsWith("pokemonTeam_")) {
Game.getPokemonTeamInfo(i, id.replace("pokemonTeam_", "")); // Display info for selected pokemon in team
}

//Menu Handler
if (["menu", "pokedex", "pokemonTeam", "bag", "save", "exitAndSave", "backToMenu"].includes(id)) {
await menuHandler(i, Game);
Expand Down
2 changes: 2 additions & 0 deletions constants/JSON/xpList.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ const xpList = {
99: 590000,
100: 600000,
};

module.exports = { xpList }
45 changes: 40 additions & 5 deletions constants/pokemon/functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let emojis = require("../JSON/emojiList");
const pokemonList = require("../JSON/pokemonList");
const { getRandomNumber, emojiStringToId } = require("../util/functions");
const { xpList } = require("../JSON/xpList")
const { getRandomNumber, emojiStringToId, titleCase } = require("../util/functions");
const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");
const { uploadEmoji } = require("../../constants/util/emoji");
const { client } = require("../../index");
Expand Down Expand Up @@ -190,13 +191,47 @@ function generateMenu() {
function getPokemonTeamRow(team) {
const rows = [new MessageActionRow().addComponents(new MessageSelectMenu().setPlaceholder("Select a Pokemon to View").setMinValues(1).setMaxValues(1).setCustomId("pokemonTeamSelect"))];

rows[0].components[0].options.push({ label: "Back to Menu", value: "backToMenu", emoji: { id: "977989090714714183" }})
rows[0].components[0].options.push({ label: "Back to Menu", value: "backToMenu", emoji: { id: "977989090714714183" } });

for(let i = 0; i < team.length; i++) {
rows[0].components[0].options.push({ label: team[i].name, value: `pokemon_${i}`, emoji: { id: emojiStringToId(getEmoji(team[i].id )) }})
for (let i = 0; i < team.length; i++) {
rows[0].components[0].options.push({ label: team[i].name, value: `pokemonTeam_${i}`, emoji: { id: emojiStringToId(getEmoji(team[i].id)) } });
}

return { components: rows };
}

module.exports = { getPokemonTeamRow, generateMenu, getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon, generateProfileSelection, getStarterPokemon, generateStarterSelection };
function returnPokemonStats(stats) {
let str = "";
for (const [key, value] of Object.entries(stats)) {
str += `${titleCase(key.split("-").join(" "))}: **${value}**\n`;
}
return str;
}

function returnPokemonMoves(moves) {
let str = "";
const filtered = moves.filter((move) => move?.selected);
for (const move of filtered) {
if(move.type === "status") {
//str += `${move.name}: Healing: ${move.data.healing}\n`
} else {
str += `**${move.name}:** Type: ${titleCase(move.data.type)}, Accuracy: ${move.data.accuracy}, Power: ${move.data.power}\n`
}
}
return str;
}

function getPokemonLevel(xp) {
xp = 175
let i = 1;
let level = 0;
let xpLeft = xp
while(xpLeft >= 0 && xpLeft - xpList[i] >= 0) {
xpLeft = xpLeft - xpList[i]
level++
i++
}
return `${level}`;
}

module.exports = { returnPokemonMoves, getPokemonLevel, returnPokemonStats, getPokemonTeamRow, generateMenu, getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon, generateProfileSelection, getStarterPokemon, generateStarterSelection };
11 changes: 10 additions & 1 deletion constants/pokemon/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon } = require("./functions");
const { getEmoji, getOffset, handleMovement, generateMap, pokemonFound, generateRandomPokemon, returnPokemonStats, getPokemonLevel, returnPokemonMoves } = require("./functions");
const { MessageEmbed } = require("discord.js");
const { rows } = require("./constants");
const { getCurrentProfile } = require("./mongoFunctions");
Expand Down Expand Up @@ -160,6 +160,15 @@ class GameMap {
return obj;
}

getPokemonTeamInfo(int, id) {
const pokemon = this.profile.team[id];
const pokemonEmbed = new MessageEmbed().setTitle(`Team Member info for ${pokemon.name} ${getEmoji(pokemon.name)}`).setDescription(`Level: **${getPokemonLevel(pokemon.xp)}**\nTypes: **${pokemon.types.join(", ")}**`);
pokemonEmbed.addField("Stats", `${returnPokemonStats(pokemon.stats)}`, true);
pokemonEmbed.addField("Moves", `${returnPokemonMoves(pokemon.moves)}`, true);

int.followUp({ embeds: [pokemonEmbed], ephemeral: true });
}

// Unused atm
}

Expand Down
2 changes: 2 additions & 0 deletions constants/util/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function generatePokemonEntry(name) {
obj["id"] = name.toUpperCase();
obj["pokemonId"] = pokemon.id;
obj["xp"] = 0;
obj["heldItem"] = null;
obj["isShiny"] = false;
obj["types"] = returnTypes(pokemon.types);
obj["stats"] = returnStats(pokemon.stats);
obj["moves"] = await returnMoves(pokemon.moves);
Expand Down
4 changes: 2 additions & 2 deletions constants/util/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function titleCase(str) {
}

function emojiStringToId(emoji) {
return emoji.split(":")[2].replace(">", "")
return emoji.split(":")[2].replace(">", "");
}

module.exports = { getRandomNumber, sleep, badName, titleCase, emojiStringToId };;
module.exports = { getRandomNumber, sleep, badName, titleCase, emojiStringToId };

0 comments on commit 577f92d

Please sign in to comment.