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

Allows info command to return Previous Evolutions #881

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
41 changes: 30 additions & 11 deletions src/lib/poracleMessage/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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')
Expand Down
135 changes: 135 additions & 0 deletions src/util/getEvoData.js
Original file line number Diff line number Diff line change
@@ -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 }