Module:Sandbox/User:Sfoxrs

From WIDEVERSE Wiki
Revision as of 21:23, 4 November 2021 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sandbox/User:Sfoxrs/doc

-- <pre>
local p = {}

local yesno = require ("Module:Yesno")

function p.main(frame)
    math.randomseed(os.time())
    local args = frame:getParent().args
    
    local devedev = args.devedev
    local min_hit = tonumber(args.minHit) or 0
    local max_hit = tonumber(args.maxHit) or 0    
    local timeStep = tonumber(args.timeStep) or 0
    local gearLevel20 = yesno(args.level20) or false
    local tDevo = 5 -- devo and enhanced devo have a cooldown of 5 game ticks
    --local proc = {.03,.06,.09}
    local proc = {0,0,0}
    if(devedev == "Enhanced Devoted") then
        proc = {.045,.09,.135}
    end
    if(devedev == "Devoted") then
        proc = {.03,.06,.09}
    end
    if gearLevel20 then
        for perkRank =1,3 do
            proc[perkRank] = proc[perkRank]*1.1
        end
    end
    
    local devoDamage = 0
    local totalDamage = 0
    local averageDamageBetweenProcs = {0,0,0}
    local averageDamageRatioOverTime = {0,0,0}
    
    local pastHits = 0 --hits that failed to proc 
    local noDevoHits = 0 --hits that would have been blocked if perk were on gear
    local nHitsDevo = math.ceil(tDevo/timeStep) -- number of hits that can be done. Intital proc counts
    
    
    local res = ""
    
    if min_hit > max_hit then
        return "The minimum hit must not be higher than the maximum hit."
    end
    
    for perkRank = 1,3 do
        devoDamage=0
        totalDamage=0
        for n = 0,999 do
            pastHits=0
            noDevoHits=0
            for iHitsNoProc = 1,n do
                local randomHit = math.floor(math.random(min_hit,max_hit))
                pastHits = pastHits + randomHit
            end
            for iHitsDevo = 1,nHitsDevo do
                local randomHit = math.floor(math.random(min_hit,max_hit))
                noDevoHits = noDevoHits + randomHit
            end
            
            devoDamage = devoDamage + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits + nHitsDevo))
            totalDamage = totalDamage + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits +noDevoHits))
            
            averageDamageBetweenProcs[perkRank] = averageDamageBetweenProcs[perkRank] + (math.pow(1-proc[perkRank],n)*proc[perkRank] * (pastHits + nHitsDevo) / (pastHits +noDevoHits) )
        end
        averageDamageRatioOverTime[perkRank] = averageDamageRatioOverTime[perkRank] + devoDamage/totalDamage
    end
    
    for perkRank = 1,3 do
        res = res .. "Average damage reduction from " .. devedev .. " " .. perkRank .. " : " .. string.format("%2.1f",(1-averageDamageRatioOverTime[perkRank])*100) .. "%<br/>"
    end
    res = res .. "<br/>"
        for perkRank = 1,3 do
        res = res .. "Average damage reduction between procs from " .. devedev .. " " .. perkRank .. " : " .. string.format("%2.1f",(1-averageDamageBetweenProcs[perkRank])*100) .. "%<br/>"
    end
    
    return res
end

return p