Module:Sandbox/User:Sfoxrs/3
Documentation for this module may be created at Module:Sandbox/User:Sfoxrs/3/doc
-- <pre>
local p = {}
local yesno = require ("Module:Yesno")
function p.main(frame)
math.randomseed(os.time())
local args = frame:getParent().args
local min_hit = tonumber(args.minHit) or 0
local max_hit = tonumber(args.maxHit) or 0
local gearLevel20 = yesno(args.level20) or false
local proc = {.005,.010,.015,.020,.025}
if gearLevel20 then
for perkRank =1,5 do
proc[perkRank] = proc[perkRank]*1.1
end
end
local luckyDamage = 0
local totalDamage = 0
local averageDamageBetweenProcs = {0,0,0,0,0}
local averageDamageRatioOverTime = {0,0,0,0,0}
local pastHits = 0 --hits that failed to proc.
local luckyHit = 0
local res = ""
if min_hit > max_hit then
return "The minimum hit must not be higher than the maximum hit."
end
for perkRank = 1,5 do
luckyDamage=0
totalDamage=0
for n = 0,1499 do
pastHits=0
for iHitsNoProc = 1,n do
local randomHit = math.floor(math.random(min_hit,max_hit))
pastHits = pastHits + randomHit
end
luckyHit = math.floor(math.random(min_hit,max_hit))
luckyDamage = luckyDamage + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits + 1))
totalDamage = totalDamage + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits + luckyHit))
averageDamageBetweenProcs[perkRank] = averageDamageBetweenProcs[perkRank] + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits + 1) / (pastHits + luckyHit) )
end
averageDamageRatioOverTime[perkRank] = averageDamageRatioOverTime[perkRank] + luckyDamage/totalDamage
end
for perkRank = 1,5 do
res = res .. "Average damage reduction from Lucky " .. perkRank .. " : " .. string.format("%2.2f",(1-averageDamageRatioOverTime[perkRank])*100) .. "%<br/>"
end
res = res .. "<br/>"
for perkRank = 1,5 do
res = res .. "Average damage reduction between procs from Lucky " .. perkRank .. " : " .. string.format("%2.2f",(1-averageDamageBetweenProcs[perkRank])*100) .. "%<br/>"
end
return res
end
return p