Module:Damage

From Exiled Kingdoms Wiki
Revision as of 18:03, 7 June 2017 by M3lkor (talk | contribs)

p = {}

resnm = {

   [1] = 'Fire', 
   [2] = 'Cold', 
   [3] = 'Shock', 
   [4] = 'Death', 
   [5] = 'Toxic', 
   [6] = 'Spirit'
   }

rresnm = {

   Fire = 1,
   Cold = 2,
   Shock = 3,
   Death = 4,
   Toxic = 5,
   Spirit = 6
   }

RawDmg = mw.getCurrentFrame().args[1]

function p.Min()

   RawDmgs = mw.text.split(RawDmg,',',true)
   return RawDmgs[1]

end

function p.Max()

   RawDmgs = mw.text.split(RawDmg,',',true)
   return RawDmgs[2]

end

function p.Speed()

   RawDmgs = mw.text.split(RawDmg,',',true)
   return RawDmgs[6]

end

function p.Crit()

   RawDmgs = mw.text.split(RawDmg,',',true)
   return RawDmgs[7]

end

function p.Elen()

   RawDmgs = mw.text.split(RawDmg,',',true)
   return RawDmgs[4]

end

function p.EleDisp()

   RawDmgs = mw.text.split(RawDmg,',',true)
   if (RawDmgs[4] == 0) then
       return 
   end
   txtout = string.format("%s %s", getimg(RawDmgs[5]), RawDmgs[4])
   return txtout

end

function p.EleChk()

   vto = mw.getCurrentFrame().args[2]
   vval = mw.getCurrentFrame().args[3]
   gtles = mw.getCurrentFrame().args[4]
   RawDmgs = mw.text.split(RawDmg,',',true)
   if (vval == nil or vval == ) then
       vval = 0
   end
   isele = 0
   vnum = RawDmgs[rresnm[vto]]
   if (tonumber(vnum) > tonumber(vval)) then
       isele = 1
   end
   return isele

end

function p.FullDisp()

   RawDmgs = mw.text.split(RawDmg,',',true)
   txtout = string.format('%s %s', getimg(RawDmgs[3]), RawDmgs[1])
   if (tonumber(RawDmgs[2]) > 0) then
       txtout = string.format('%s-%s', txtout, RawDmgs[2])
   end
   if (tonumber(RawDmgs[4]) > 0) then
       txtout = string.format('%s +%s%s', txtout, getimg(RawDmgs[5]), RawDmgs[4])
   end
   return txtout

end

function getimg(elemn)

   txtrtn = 
   if (tonumber(elemn) == 0) then
       txtrtn = 'Sword.png'
   else
       txtrtn = string.format('File:%s.png', resnm[tonumber(elemn)], resnm[tonumber(elemn)])
   end
   return txtrtn

end

function p.DPS()

   RawDmgs = mw.text.split(RawDmg,',',true)
   mind = tonumber(RawDmgs[1])
   maxd = tonumber(RawDmgs[2])
   crit = tonumber(RawDmgs[7])
   eled = tonumber(RawDmgs[4])
   speed = tonumber(RawDmgs[6])
   critmult = tonumber(RawDmgs[8])
   if (speed == 0) then
       speed = 10
   end
   if (critmult == 0) then
       critmult = 1.5
   end
   minmax = mind
   speed = speed / 10
   if (maxd > 0) then --minmax
       minmax = (mind + maxd) / 2
   else
       maxd = mind
   end
   basedmg = ((100-crit) / 100) * minmax + eled
   critdmg = (((maxd+1) + (maxd * critmult)) / 2) * (crit / 100)
   rdps = (basedmg + critdmg) * speed
   return string.format('%0.1f',rdps)

end

return p