Module:WeaponDPS: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
Created page with "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 function p.dps(frame) local args = frame:getParent().args local accuracy = tonumber(args["accuracy"]) or 0 local strength = tonumber(args["strength"]) or 0 local speed = tonumber(args["speed"]) or 0 -- Prevent division by zero or invali..."
 
No edit summary
Line 15: Line 15:
local accuracy = tonumber(args["accuracy"]) or 0
local accuracy = tonumber(args["accuracy"]) or 0
local strength = tonumber(args["strength"]) or 0
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
local speed = tonumber(args["speed"]) or 0


-- Prevent division by zero or invalid speed
-- Prevent invalid speed
if speed <= 0 then
if speed <= 0 then
return "Invalid speed"
return "Invalid speed"
Line 24: Line 26:
local attacksPerSecond = getAttacksPerSecond(speed)
local attacksPerSecond = getAttacksPerSecond(speed)


-- Pseudo-DPS: simple product of stats
-- Combined offensive stat
local dps = accuracy * strength * attacksPerSecond
local offensiveStat = strength + magic + range
 
-- Theoretical DPS
local dps = accuracy * offensiveStat * attacksPerSecond


return string.format("%.2f", dps)
return string.format("%.2f", dps)

Revision as of 12:15, 22 May 2025

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

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
function p.dps(frame)
	local args = frame:getParent().args
	local accuracy = tonumber(args["accuracy"]) or 0
	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

	-- Prevent invalid speed
	if speed <= 0 then
		return "Invalid speed"
	end

	local attacksPerSecond = getAttacksPerSecond(speed)

	-- Combined offensive stat
	local offensiveStat = strength + magic + range

	-- Theoretical DPS
	local dps = accuracy * offensiveStat * attacksPerSecond

	return string.format("%.2f", dps)
end

return p