Module:Heroes

-- /skill -- /data

local heroes = mw.loadData('Module:Heroes/data') local skills = mw.loadData('Module:Heroes/skill') local f = require("Module:Functions")

local p = {}

local maxSkillLvl = 10 local maxLvl = 30 local maxPromotion = 5 local promotionHealt = {1,1.1,1.1,1.3,1.3} local promotionDamage = {1,1,1.1,1.1,1.3} local rarityMultiplier = {1,1.25,1.5} local rarity = {"R","SR","SSR"}

function p.infobox(frame) local heroName = mw.title.getCurrentTitle.text local hero = heroes[heroName] if hero == nil then return "Please insert data to Module:Heroes/data" end local args = { image = heroName.." full.png", rarity = hero.rarity, defence = hero.defense.."%", atkrate = hero.attackrate }	return frame:expandTemplate { title = 'Infobox hero', args = args } end

function p.skill(frame) local heroName = mw.title.getCurrentTitle.text local hero = heroes[heroName] if hero == nil then return end local dname = hero.defskill local pname = hero.passkill local def = skills[dname] local pas = skills[pname] local data = {'==Skills=='} local d = 0 local p = 0 if def == nil then d = 1 table.insert(data,'Defense skill "'..dname..'" is missing. You can add it here')  end if pas == nil then p = 1 table.insert(data,'Passive skill "'..pname..'" is missing. You can add it here')  end if (d ~= 1 or p ~= 1)==true then table.insert(data,'{| style="text-align:center"') if d~= 1 then table.insert(data, '! Active') end if s~= 1 then table.insert(data, '! Passive') end table.insert(data,'|-') if d~= 1 then table.insert(data,'| "..dname.."") end        if s~= 1 then table.insert(data,'|  "..pname.."") end table.insert(data,'|-') if d~= 1 then table.insert(data,'|'..def.description) end if s~= 1 then table.insert(data,'|'..pas.description) end table.insert(data,'|}') end for i, j in pairs(data) do mw.log(j) end return table.concat(data,"\n") end

function p.stats(frame) local heroName = mw.title.getCurrentTitle.text local hero = heroes[heroName] if hero == nil then return end local data = { '==Stats==' }   local tab = 0 for i in f.range(maxPromotion) do       if tab == 0 then table.insert(data, ' '..i..'=') tab=1 else table.insert(data, '|-|'..i..'=') end table.insert(data,'{| class="wikitable" style="text-align: center; width: 100%"') table.insert(data,'|+ Average is shown in green ') table.insert(data,'|-') table.insert(data,'! LvL') table.insert(data,'! HP') table.insert(data,'! DPH') table.insert(data,'! DPS') table.insert(data,'|-') for x in f.range(maxLvl) do            damage=f.split(hero.damage,"-") damageI=f.split(hero.damageI,"-") ar=hero.attackrate hp=check(hero.hp,f.round(((hero.hp+hero.hpI*(x-1))*promotionHealt[i]),1)) damageMax = check(tonumber(damage[1]),f.round(((tonumber(damage[2])+tonumber(damageI[2])*(x-1))*promotionDamage[i]),1)) damageMin = check(tonumber(damage[1]),f.round(((tonumber(damage[1])+tonumber(damageI[1])*(x-1))*promotionDamage[i]),1)) dps=(f.round(damageMin/ar,1)+f.round(damageMax/ar,1))/2 average=(damageMax+damageMin)/2 table.insert(data,'|'..x)           table.insert(data,'|'..f.numbers(hp)) table.insert(data,'|'..f.numbers(damageMin).." ~ "..f.numbers(damageMax)..' ≈ '..f.numbers(average).." ") table.insert(data,'|'..f.numbers(f.round(damageMin/ar,1)).." ~ "..f.numbers(f.round(damageMax/ar,1))..' ≈ '..f.numbers(dps).." ") table.insert(data,'|-') end table.insert(data,'|}') end table.insert(data, ' ') for i, j in pairs(data) do mw.log(j) end return frame:preprocess(table.concat(data,"\n")) end

function check(stat,full) if stat ~= 0 then return full end return 0 end

function p.table local data = { '==List==', '{| class="wikitable mw-datatable sortable" style="text-align: center;"', '|+ LvL '..maxLvl..' stats + max promotion', '|+ Average is shown in green ', '|-',       '! Hero', '! class="unsortable" |Image', '! Rarity', '! HP', '! DPH', '! DPS', '! Defence', '! Attack Rate (sec)', '|-'   }    for name, hero in pairs(heroes) do         ar=hero.attackrate damage=f.split(hero.damage,"-") damageI=f.split(hero.damageI,"-") ph=promotionHealt[#promotionHealt] pd=promotionDamage[#promotionDamage] hp=check(hero.hp,f.round(((hero.hp+hero.hpI*(maxLvl-1))*ph),1)) damageMax = check(tonumber(damage[1]),f.round(((tonumber(damage[2])+tonumber(damageI[2])*(maxLvl-1))*pd),1)) damageMin = check(tonumber(damage[1]),f.round(((tonumber(damage[1])+tonumber(damageI[1])*(maxLvl-1))*pd),1)) dps=(f.round(damageMin/ar,1)+f.round(damageMax/ar,1))/2 average=(damageMax+damageMin)/2 table.insert(data, '| '..name..'') table.insert(data, '|') table.insert(data, '| ")       table.insert(data, '|'..f.numbers(hp))        table.insert(data, '| data-sort-value='..average..'|'..f.numbers(damageMin).." ~ "..f.numbers(damageMax)..' '..f.numbers(average).." ") table.insert(data,'| data-sort-value='..dps..'|'..f.numbers(f.round(damageMin/ar,1)).." ~ "..f.numbers(f.round(damageMax/ar,1))..' '..f.numbers(dps).." ")           table.insert(data, '|'..hero.defense.."%")        table.insert(data, '|'..ar)        table.insert(data, '|-')    end    table.insert(data, '|}')    for i, j in pairs(data) do mw.log(j) end    return table.concat(data,"\n") end

function p.xp(frame) local skillCost={2,4,8,14,22,30,40,50,60} local promotion = {2,4,8,16} local data = {'==XP table=='} local tab = 0 for i, j in pairs(rarity) do       if tab == 0 then table.insert(data, ' '..j..'=') tab=1 else table.insert(data, '|-|'..j..'=') end table.insert(data,'{| class="wikitable" style="text-align: center; width: 100%"') table.insert(data,'|+ XP required for next LvL ') table.insert(data,'|-') table.insert(data,'! LvL') table.insert(data,'! XP') table.insert(data,'|-') for x in f.range(maxLvl) do            table.insert(data,'|'..x)            if x==maxLvl then table.insert(data,'| /') else table.insert(data,'|'..f.numbers((3*(x+1)^2-3*(x+1)+1)*80*rarityMultiplier[i])) end table.insert(data,'|-') end table.insert(data,'|}') end if tab == 0 then table.insert(data, ' Skills =') tab=1 else table.insert(data, '|-| Skills =') end table.insert(data,'{| class="wikitable" style="text-align: center; width: 100%"') table.insert(data,'|+ Shards required for next LvL ') table.insert(data,'|-') table.insert(data,'! LvL') table.insert(data,'! Shards') table.insert(data,'|-') for i, j in pairs(skillCost) do        table.insert(data,'|'..i)        table.insert(data,'|'..f.numbers(j)) table.insert(data,'|-') end table.insert(data,'|'..#skillCost+1) table.insert(data,'| /') table.insert(data,'|-') table.insert(data,'|}') if tab == 0 then table.insert(data, ' Promotion =') tab=1 else table.insert(data, '|-| Promotion =') end table.insert(data,'{| class="wikitable" style="text-align: center; width: 100%"') table.insert(data,'|+ Coins required for next Promotion ') table.insert(data,'|-') table.insert(data,'! Promotion') table.insert(data,'! Coins') table.insert(data,'|-') for i, j in pairs(promotion) do        table.insert(data,'|'..i)        table.insert(data,'|'..f.numbers(j*10000)) table.insert(data,'|-') end table.insert(data,'|'..#promotion+1) table.insert(data,'| /') table.insert(data,'|-') table.insert(data,'|}') table.insert(data, ' ') for i, j in pairs(data) do mw.log(j) end return frame:preprocess(table.concat(data,"\n")) end

return p