Difference between revisions of "Module:AttackSpell"
CommanderC (talk | contribs) |
CommanderC (talk | contribs) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
+ | |||
+ | function p.to_number(x) | ||
+ | local n = string.gsub(x, ",", "") | ||
+ | return tonumber(n) | ||
+ | end | ||
function p.calc_hit(frame) | function p.calc_hit(frame) | ||
− | local hit_adder = | + | local hit_adder = p.to_number(frame.args[1]) |
− | local hit_num = | + | local hit_num = p.to_number(frame.args[2]) |
− | local hit_denom = | + | local hit_denom = p.to_number(frame.args[3]) |
− | local power = | + | local power = p.to_number(frame.args[4]) |
− | local powercap = | + | local powercap = p.to_number(frame.args[5]) |
if not hit_adder or not hit_num or not hit_denom or not power or not powercap then | if not hit_adder or not hit_num or not hit_denom or not power or not powercap then | ||
− | return | + | return "" |
end | end | ||
if power > powercap then | if power > powercap then | ||
power = powercap | power = powercap | ||
end | end | ||
− | return tostring(hit_adder + power * hit_num / hit_denom) | + | return tostring(math.ceil(hit_adder + power * hit_num / hit_denom)) |
+ | end | ||
+ | |||
+ | function p.calc_damage(frame) | ||
+ | local hit_adder = p.to_number(frame.args[1]) | ||
+ | local hit_num = p.to_number(frame.args[2]) | ||
+ | local hit_denom = p.to_number(frame.args[3]) | ||
+ | local power = p.to_number(frame.args[4]) | ||
+ | local powercap = p.to_number(frame.args[5]) | ||
+ | local resistance = p.to_number(frame.args[6]) | ||
+ | |||
+ | if not hit_adder or not hit_num or not hit_denom or not power or not powercap or not resistance then | ||
+ | return "" | ||
+ | end | ||
+ | if power > powercap then | ||
+ | power = powercap | ||
+ | end | ||
+ | return tostring(math.ceil((hit_adder + power * hit_num / hit_denom) / resistance)) | ||
end | end | ||
return p | return p |
Latest revision as of 19:55, 23 May 2014
Documentation for this module may be created at Module:AttackSpell/doc
local p = {} function p.to_number(x) local n = string.gsub(x, ",", "") return tonumber(n) end function p.calc_hit(frame) local hit_adder = p.to_number(frame.args[1]) local hit_num = p.to_number(frame.args[2]) local hit_denom = p.to_number(frame.args[3]) local power = p.to_number(frame.args[4]) local powercap = p.to_number(frame.args[5]) if not hit_adder or not hit_num or not hit_denom or not power or not powercap then return "" end if power > powercap then power = powercap end return tostring(math.ceil(hit_adder + power * hit_num / hit_denom)) end function p.calc_damage(frame) local hit_adder = p.to_number(frame.args[1]) local hit_num = p.to_number(frame.args[2]) local hit_denom = p.to_number(frame.args[3]) local power = p.to_number(frame.args[4]) local powercap = p.to_number(frame.args[5]) local resistance = p.to_number(frame.args[6]) if not hit_adder or not hit_num or not hit_denom or not power or not powercap or not resistance then return "" end if power > powercap then power = powercap end return tostring(math.ceil((hit_adder + power * hit_num / hit_denom) / resistance)) end return p