diff --git a/src/lib/poracleMessage/commands/info.js b/src/lib/poracleMessage/commands/info.js index c36fd3727..75040436a 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..05affcd8b --- /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) + } + } + } + } + // eslint-disable-next-line no-shadow + 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