Module:WeaponDPS: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Converts speed to attacks per second
local function getAttacksPerSecond(speed)
if speed <= 0 then
return 0
end
local attackTimeSeconds = speed * 0.6
return 1 / attackTimeSeconds
end
-- Theoretical DPS formula (accuracy = 1/3 of a damage stat)
function p.dps(frame)
function p.dps(frame)
local args = frame:getParent().args
    local args = frame.args
local accuracy = tonumber(args["accuracy"]) or 0
    local parent = frame:getParent()
local strength = tonumber(args["strength"]) or 0
local magic = tonumber(args["magic"]) or 0
local range = tonumber(args["range"]) or 0
local speed = tonumber(args["speed"]) or 0
 
if speed <= 0 then
return "Invalid speed"
end


local attacksPerSecond = getAttacksPerSecond(speed)
    local str = tonumber(args.Strength or parent.args.Strength) or 0
    local acc = tonumber(args.Accuracy or parent.args.Accuracy) or 0
    local ticks = tonumber(args.Speed or parent.args.Speed)


-- Weight accuracy as one-third of a damage stat
    if (str == 0 and acc == 0) then return "No STR or ACC" end
local weightedStat = (accuracy / 3) + strength + magic + range
    if not ticks then return "No speed" end


-- Scaled DPS calculation
    local effectiveStr = str + acc
local dps = weightedStat * attacksPerSecond * 0.1
    local maxHit = effectiveStr / 14
    local seconds = ticks * 0.6
    local dps = maxHit / seconds


return string.format("%.2f", dps)
    return '<abbr title="Theoretical damage per second">' .. string.format('%.2f', dps) .. '</abbr>'
end
end


return p
return p

Latest revision as of 19:30, 12 June 2025

Documentation for this module may be created at Module:WeaponDPS/doc

local p = {}

function p.dps(frame)
    local args = frame.args
    local parent = frame:getParent()

    local str = tonumber(args.Strength or parent.args.Strength) or 0
    local acc = tonumber(args.Accuracy or parent.args.Accuracy) or 0
    local ticks = tonumber(args.Speed or parent.args.Speed)

    if (str == 0 and acc == 0) then return "No STR or ACC" end
    if not ticks then return "No speed" end

    local effectiveStr = str + acc
    local maxHit = effectiveStr / 14
    local seconds = ticks * 0.6
    local dps = maxHit / seconds

    return '<abbr title="Theoretical damage per second">' .. string.format('%.2f', dps) .. '</abbr>'
end

return p