2016-07-25 11:03:35 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
|
|
|
|
|
|
|
local pgc = {}
|
|
|
|
|
|
|
|
function pgc:init(config)
|
2016-08-14 04:46:18 +02:00
|
|
|
pgc.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('gocalc', true).table
|
|
|
|
pgc.doc = config.cmd_pat .. [[gocalc <required candy> <number of Pokémon> <number of candy>
|
2016-07-25 11:03:35 +02:00
|
|
|
Calculates the number of Pokémon that must be transferred before evolving, how many evolutions the user is able to perform, and how many Pokémon and candy will be left over.
|
|
|
|
All arguments must be positive numbers. Batch jobs may be performed by separating valid sets of arguments by lines.
|
|
|
|
Example (forty pidgeys and three hundred pidgey candies):
|
|
|
|
]] .. config.cmd_pat .. 'gocalc 12 40 300'
|
2016-08-14 04:46:18 +02:00
|
|
|
pgc.command = 'gocalc <required candy> <#pokemon> <#candy>'
|
2016-07-25 11:03:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- This function written by Juan Potato. MIT-licensed.
|
2016-08-15 07:00:24 +02:00
|
|
|
local function pidgey_calc(candies_to_evolve, mons, candies)
|
2016-08-14 04:46:18 +02:00
|
|
|
local transferred = 0;
|
|
|
|
local evolved = 0;
|
2016-07-25 11:03:35 +02:00
|
|
|
|
2016-08-14 04:46:18 +02:00
|
|
|
while true do
|
|
|
|
if math.floor(candies / candies_to_evolve) == 0 or mons == 0 then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
mons = mons - 1
|
|
|
|
candies = candies - candies_to_evolve + 1
|
|
|
|
evolved = evolved + 1
|
|
|
|
if mons == 0 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-25 11:03:35 +02:00
|
|
|
|
2016-08-14 04:46:18 +02:00
|
|
|
while true do
|
|
|
|
if (candies + mons) < (candies_to_evolve + 1) or mons == 0 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
while candies < candies_to_evolve do
|
|
|
|
transferred = transferred + 1
|
|
|
|
mons = mons - 1
|
|
|
|
candies = candies + 1
|
|
|
|
end
|
|
|
|
mons = mons - 1
|
|
|
|
candies = candies - candies_to_evolve + 1
|
|
|
|
evolved = evolved + 1
|
|
|
|
end
|
2016-07-25 11:03:35 +02:00
|
|
|
|
2016-08-14 04:46:18 +02:00
|
|
|
return {
|
|
|
|
transfer = transferred,
|
|
|
|
evolve = evolved,
|
|
|
|
leftover_mons = mons,
|
|
|
|
leftover_candy = candies
|
|
|
|
}
|
2016-07-25 11:03:35 +02:00
|
|
|
end
|
|
|
|
|
2016-08-15 07:00:24 +02:00
|
|
|
local function single_job(input)
|
2016-08-14 04:46:18 +02:00
|
|
|
local req_candy, mons, candies = input:match('^(%d+) (%d+) (%d+)$')
|
|
|
|
req_candy = tonumber(req_candy)
|
|
|
|
mons = tonumber(mons)
|
|
|
|
candies = tonumber(candies)
|
|
|
|
if not (req_candy and mons and candies) then
|
|
|
|
return { err = 'Invalid input: Three numbers expected.' }
|
|
|
|
elseif req_candy > 400 then
|
|
|
|
return { err = 'Invalid required candy: Maximum is 400.' }
|
|
|
|
elseif mons > 1000 then
|
|
|
|
return { err = 'Invalid number of Pokémon: Maximum is 1000.' }
|
|
|
|
elseif candies > 10000 then
|
|
|
|
return { err = 'Invalid number of candies: Maximum is 10000.' }
|
|
|
|
else
|
|
|
|
return pidgey_calc(req_candy, mons, candies)
|
|
|
|
end
|
2016-07-25 11:03:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function pgc:action(msg)
|
2016-08-14 04:46:18 +02:00
|
|
|
local input = utilities.input(msg.text)
|
|
|
|
if not input then
|
2016-10-04 16:07:15 +02:00
|
|
|
utilities.send_reply(msg, pgc.doc, 'html')
|
2016-08-14 04:46:18 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
input = input .. '\n'
|
|
|
|
local output = ''
|
|
|
|
local total_evolutions = 0
|
|
|
|
for line in input:gmatch('(.-)\n') do
|
|
|
|
local info = single_job(line)
|
|
|
|
output = output .. '`' .. line .. '`\n'
|
|
|
|
if info.err then
|
|
|
|
output = output .. info.err .. '\n\n'
|
|
|
|
else
|
|
|
|
total_evolutions = total_evolutions + info.evolve
|
|
|
|
local s = '*Transfer:* %s. \n*Evolve:* %s (%s XP, %s minutes). \n*Leftover:* %s mons, %s candy.\n\n'
|
|
|
|
s = s:format(info.transfer, info.evolve, info.evolve..'k', info.evolve*0.5, info.leftover_mons, info.leftover_candy)
|
|
|
|
output = output .. s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local s = '*Total evolutions:* %s. \n*Recommendation:* %s'
|
|
|
|
local recommendation
|
|
|
|
local egg_count = math.floor(total_evolutions/60)
|
|
|
|
if egg_count < 1 then
|
|
|
|
recommendation = 'Wait until you have atleast sixty Pokémon to evolve before using a lucky egg.'
|
|
|
|
else
|
|
|
|
recommendation = string.format(
|
|
|
|
'Use %s lucky egg%s for %s evolutions.',
|
|
|
|
egg_count,
|
|
|
|
egg_count == 1 and '' or 's',
|
|
|
|
egg_count * 60
|
|
|
|
)
|
|
|
|
end
|
|
|
|
s = s:format(total_evolutions, recommendation)
|
|
|
|
output = output .. s
|
2016-08-23 06:16:32 +02:00
|
|
|
utilities.send_reply(msg, output, true)
|
2016-07-25 11:03:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return pgc
|