From a38a5daeeb49366b572d7cfa8bbff9fdd606e90c Mon Sep 17 00:00:00 2001 From: XerockXMG Date: Sat, 4 Nov 2023 13:31:42 -0400 Subject: [PATCH 1/3] Return previous evolutions from info command --- src/lib/poracleMessage/commands/info.js | 41 +++++-- src/util/getEvoData.js | 135 ++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 src/util/getEvoData.js diff --git a/src/lib/poracleMessage/commands/info.js b/src/lib/poracleMessage/commands/info.js index c36fd3727..4667f3455 100644 --- a/src/lib/poracleMessage/commands/info.js +++ b/src/lib/poracleMessage/commands/info.js @@ -239,6 +239,9 @@ exports.run = async (client, msg, args, options) => { } const mon = monsters[0] + const logReference = mon.id + const monEvos = {} + require('../../../util/getEvoData').setEvolutions(monEvos, client.GameData, client.log, logReference, translator, emojiLookup, platform, mon) const typeData = client.GameData.utilData.types const types = mon.types.map((type) => type.name) const strengths = {} @@ -316,19 +319,35 @@ exports.run = async (client, msg, args, options) => { message = message.concat(`\n**${translator.translate('Third Move Cost')}:**\n${mon.thirdMoveCandy} ${translator.translate('Candies')}\n${new Intl.NumberFormat(language).format(mon.thirdMoveStardust)} ${translator.translate('Stardust')}\n`) } - if (mon.evolutions) { + if (monEvos && monEvos.previousEvolutions.length) { + message = message.concat(`\n**Previous ${translator.translate('Evolutions')}:**`) + for (let i = monEvos.previousEvolutions.length -1; i>= 0; i--) { + const evolution = monEvos.previousEvolutions[i] + message = message.concat(`\n${translator.translate(`${client.GameData.monsters[`${evolution.id}_${evolution.form || 0}`]?.name || 'Unknown'}`)} (${evolution.candyCost} ${translator.translate('Candies')})`) + if (evolution.itemRequirement) message = message.concat(`\n- ${translator.translate('Needed Item')}: ${translator.translate(evolution.itemRequirement)}`) + if (evolution.mustBeBuddy) message = message.concat(`\n\u2705 ${translator.translate('Must Be Buddy')}`) + if (evolution.onlyNighttime) message = message.concat(`\n\u2705 ${translator.translate('Only Nighttime')}`) + if (evolution.onlyDaytime) message = message.concat(`\n\u2705 ${translator.translate('Only Daytime')}`) + if (evolution.tradeBonus) message = message.concat(`\n\u2705 ${translator.translate('Trade Bonus')}`) + message.concat('\n') + if (evolution.questRequirement) message = message.concat(`\n${translator.translate('Special Requirement')}: ${translator.translate(evolution.questRequirement.i18n).replace('{{amount}}', evolution.questRequirement.target)}`) + } + message = message.concat('\n') + } + + if (monEvos && monEvos.evolutions.length) { message = message.concat(`\n**${translator.translate('Evolutions')}:**`) - for (const evolution of mon.evolutions) { - message = message.concat(`\n${translator.translate(`${client.GameData.monsters[`${evolution.evoId}_${evolution.id || 0}`]?.name || 'Unknown'}`)} (${evolution.candyCost} ${translator.translate('Candies')})`) - if (evolution.itemRequirement) message = message.concat(`\n- ${translator.translate('Needed Item')}: ${translator.translate(evolution.itemRequirement)}`) - if (evolution.mustBeBuddy) message = message.concat(`\n\u2705 ${translator.translate('Must Be Buddy')}`) - if (evolution.onlyNighttime) message = message.concat(`\n\u2705 ${translator.translate('Only Nighttime')}`) - if (evolution.onlyDaytime) message = message.concat(`\n\u2705 ${translator.translate('Only Daytime')}`) - if (evolution.tradeBonus) message = message.concat(`\n\u2705 ${translator.translate('Trade Bonus')}`) - message.concat('\n') - if (evolution.questRequirement) message = message.concat(`\n${translator.translate('Special Requirement')}: ${translator.translate(evolution.questRequirement.i18n).replace('{{amount}}', evolution.questRequirement.target)}`) - message = message.concat('\n') + for (const evolution of monEvos.evolutions) { + message = message.concat(`\n${translator.translate(`${client.GameData.monsters[`${evolution.id}_${evolution.form || 0}`]?.name || 'Unknown'}`)} (${evolution.candyCost} ${translator.translate('Candies')})`) + if (evolution.itemRequirement) message = message.concat(`\n- ${translator.translate('Needed Item')}: ${translator.translate(evolution.itemRequirement)}`) + if (evolution.mustBeBuddy) message = message.concat(`\n\u2705 ${translator.translate('Must Be Buddy')}`) + if (evolution.onlyNighttime) message = message.concat(`\n\u2705 ${translator.translate('Only Nighttime')}`) + if (evolution.onlyDaytime) message = message.concat(`\n\u2705 ${translator.translate('Only Daytime')}`) + if (evolution.tradeBonus) message = message.concat(`\n\u2705 ${translator.translate('Trade Bonus')}`) + message.concat('\n') + if (evolution.questRequirement) message = message.concat(`\n${translator.translate('Special Requirement')}: ${translator.translate(evolution.questRequirement.i18n).replace('{{amount}}', evolution.questRequirement.target)}`) } + message = message.concat('\n') } message = message.concat('\n💯:\n') diff --git a/src/util/getEvoData.js b/src/util/getEvoData.js new file mode 100644 index 000000000..f8613baa9 --- /dev/null +++ b/src/util/getEvoData.js @@ -0,0 +1,135 @@ +/* Evolution calculations */ + +function setEvolutions(data, GameData, log, logReference, translator, emojiLookup, platform, monster) { + data.hasEvolutions = monster.evolutions && monster.evolutions.length + + let totalCount = 0 + const evolutions = [] + const previousEvolutions = [] + // Check if mon has a previousEvolution + const previousEvo = Object.values(GameData.monsters).filter((mon) => { + return mon.evolutions && mon.evolutions.some((evo) => evo.evoId === monster.id && mon.form.id === 0) + }) + + // eslint-disable-next-line no-shadow + const calcEvolutions = (monster) => { + if (++totalCount >= 10) { + log.error(`${logReference}: Too many possible evolutions ${monster.id}_${monster.form.id}`) + return + } + + if (monster.evolutions && monster.evolutions.length) { + for (const evo of monster.evolutions) { + const newMonster = GameData.monsters[`${evo.evoId}_${evo.id}`] + + if (newMonster) { + const { types } = newMonster + // eslint-disable-next-line no-shadow + const e = [] + // eslint-disable-next-line no-shadow + const n = [] + + types.forEach((type) => { + e.push(translator.translate(emojiLookup.lookup(GameData.utilData.types[type.name].emoji, platform))) + n.push(type.name) + }) + + const typeName = n.map((type) => translator.translate(type)) + .join(', ') + const emojiString = e.join('') + + const nameEng = newMonster.name + const name = translator.translate(nameEng) + const formNameEng = newMonster.form.name + const formNormalisedEng = formNameEng === 'Normal' ? '' : formNameEng + const formNormalised = translator.translate(formNormalisedEng) + + const fullNameEng = nameEng.concat(formNormalisedEng ? ' ' : '', formNormalisedEng) + const fullName = name.concat(formNormalised ? ' ' : '', formNormalised) + + evolutions.push({ + id: evo.evoId, + form: evo.id, + fullName, + fullNameEng, + formNormalised, + formNormalisedEng, + name, + nameEng, + formNameEng, + typeName, + typeEmoji: emojiString, + baseStats: newMonster.stats, + candyCost: evo.candyCost + }) + + calcEvolutions(newMonster) + } + } + } + } + + const calcDevolutions = (monster) => { + if (++totalCount >= 5) { + log.error(`${logReference}: Too many possible devolutions ${monster.id}_${monster.form.id}`) + return + } + const newMonster = GameData.monsters[`${monster.id}_${monster.form.id || 0}`] + + if (newMonster) { + const { types } = newMonster + // eslint-disable-next-line no-shadow + const e = [] + // eslint-disable-next-line no-shadow + const n = [] + + types.forEach((type) => { + e.push(translator.translate(emojiLookup.lookup(GameData.utilData.types[type.name].emoji, platform))) + n.push(type.name) + }) + + const typeName = n.map((type) => translator.translate(type)) + .join(', ') + const emojiString = e.join('') + + const nameEng = newMonster.name + const name = translator.translate(nameEng) + const formNameEng = newMonster.form.name + const formNormalisedEng = formNameEng === 'Normal' ? '' : formNameEng + const formNormalised = translator.translate(formNormalisedEng) + + const fullNameEng = nameEng.concat(formNormalisedEng ? ' ' : '', formNormalisedEng) + const fullName = name.concat(formNormalised ? ' ' : '', formNormalised) + + previousEvolutions.push({ + id: monster.id, + form: monster.form.id, + fullName, + fullNameEng, + formNormalised, + formNormalisedEng, + name, + nameEng, + formNameEng, + typeName, + typeEmoji: emojiString, + baseStats: newMonster.stats, + candyCost: newMonster.evolutions[0].candyCost // Evolutions is a nested object + }) + // Check if there is another devolution + const nextMonster = Object.values(GameData.monsters).filter((mon) => { + return mon.evolutions && mon.evolutions.some((evo) => evo.evoId === newMonster.id && mon.form.id === 0) + }) + if (nextMonster && nextMonster.length) calcDevolutions(nextMonster[0]) + } + } + + if (data.hasEvolutions) calcEvolutions(monster) + if (previousEvo && previousEvo.length) calcDevolutions(previousEvo[0]) + data.evolutions = evolutions + + data.hasPreviousEvolutions = !!previousEvolutions.length + data.previousEvolutions = previousEvolutions +} + +module.exports = { setEvolutions } \ No newline at end of file From 040f96de9a93da5db44d37a74faf6a5142bbe007 Mon Sep 17 00:00:00 2001 From: XerockXMG Date: Sat, 4 Nov 2023 13:32:58 -0400 Subject: [PATCH 2/3] Replace spaces with tabs --- src/lib/poracleMessage/commands/info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/poracleMessage/commands/info.js b/src/lib/poracleMessage/commands/info.js index 4667f3455..75040436a 100644 --- a/src/lib/poracleMessage/commands/info.js +++ b/src/lib/poracleMessage/commands/info.js @@ -240,8 +240,8 @@ exports.run = async (client, msg, args, options) => { const mon = monsters[0] const logReference = mon.id - const monEvos = {} - require('../../../util/getEvoData').setEvolutions(monEvos, client.GameData, client.log, logReference, translator, emojiLookup, platform, mon) + const monEvos = {} + require('../../../util/getEvoData').setEvolutions(monEvos, client.GameData, client.log, logReference, translator, emojiLookup, platform, mon) const typeData = client.GameData.utilData.types const types = mon.types.map((type) => type.name) const strengths = {} From 1a8bf739d5bbc0b2b636e5a25516d77731ec3c95 Mon Sep 17 00:00:00 2001 From: XerockXMG Date: Sat, 4 Nov 2023 15:46:37 -0400 Subject: [PATCH 3/3] Disable no-shadow --- src/util/getEvoData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/getEvoData.js b/src/util/getEvoData.js index f8613baa9..05affcd8b 100644 --- a/src/util/getEvoData.js +++ b/src/util/getEvoData.js @@ -68,7 +68,7 @@ function setEvolutions(data, GameData, log, logReference, translator, emojiLooku } } } - + // eslint-disable-next-line no-shadow const calcDevolutions = (monster) => { if (++totalCount >= 5) { log.error(`${logReference}: Too many possible devolutions ${monster.id}_${monster.form.id}`)