Module:Calculator/ETA: Difference between revisions
From Melvor Idle
m (Allow currentExp to be entered with a suffix) |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
local MEXP = require('Module:Experience') | local MEXP = require('Module:Experience') | ||
local number = require('Module:Number') | local number = require('Module:Number') | ||
local TimeSpan = require('Module:TimeSpan') | |||
local function formatTime( | local function formatTime(seconds) | ||
local timespan = TimeSpan.fromSeconds(seconds) | |||
return timespan:toStringLong() | |||
end | end | ||
Line 26: | Line 19: | ||
local function calc(currentExp, targetLvl, expPerAction, actionTime) | local function calc(currentExp, targetLvl, expPerAction, actionTime) | ||
local actionsPerHour = math.floor(3600 / actionTime) | |||
local actionsPerHour = math.floor( | |||
local targetExp = MEXP.expForLevel(targetLvl) | local targetExp = MEXP.expForLevel(targetLvl) | ||
local expRemaining = math.max(targetExp - currentExp, 0) | local expRemaining = math.max(targetExp - currentExp, 0) | ||
local expPerHour = math.floor(3600 / actionTime * expPerAction) | |||
local actionsToTarget = math.ceil(expRemaining / expPerAction) | local actionsToTarget = math.ceil(expRemaining / expPerAction) | ||
Line 42: | Line 34: | ||
addTableRow(tbl, "Target Experience", number.formatnum(targetExp)) | addTableRow(tbl, "Target Experience", number.formatnum(targetExp)) | ||
addTableRow(tbl, "Experience Remaining", number.formatnum(expRemaining)) | addTableRow(tbl, "Experience Remaining", number.formatnum(expRemaining)) | ||
addTableRow(tbl, "Experience Per Hour", number.formatnum(expPerHour)) | |||
addTableRow(tbl, "Actions Left", number.formatnum(actionsToTarget)) | addTableRow(tbl, "Actions Left", number.formatnum(actionsToTarget)) | ||
addTableRow(tbl, "Time Left", formatTime(timeToTarget)) | addTableRow(tbl, "Time Left", formatTime(timeToTarget)) |
Latest revision as of 21:23, 13 April 2024
Documentation for this module may be created at Module:Calculator/ETA/doc
local p = {}
local MEXP = require('Module:Experience')
local number = require('Module:Number')
local TimeSpan = require('Module:TimeSpan')
local function formatTime(seconds)
local timespan = TimeSpan.fromSeconds(seconds)
return timespan:toStringLong()
end
local function addTableRow(tbl, c1, c2)
tbl:tag("tr")
:tag("th"):wikitext(c1)
:tag("td"):wikitext(c2)
return tbl
end
local function calc(currentExp, targetLvl, expPerAction, actionTime)
local actionsPerHour = math.floor(3600 / actionTime)
local targetExp = MEXP.expForLevel(targetLvl)
local expRemaining = math.max(targetExp - currentExp, 0)
local expPerHour = math.floor(3600 / actionTime * expPerAction)
local actionsToTarget = math.ceil(expRemaining / expPerAction)
local timeToTarget = actionsToTarget * actionTime
local tbl = mw.html.create("table")
:addClass("wikitable sticky-header text-align-right align-left-1")
addTableRow(tbl, "Current Experience", number.formatnum(currentExp))
addTableRow(tbl, "Target Level", targetLvl)
addTableRow(tbl, "Target Experience", number.formatnum(targetExp))
addTableRow(tbl, "Experience Remaining", number.formatnum(expRemaining))
addTableRow(tbl, "Experience Per Hour", number.formatnum(expPerHour))
addTableRow(tbl, "Actions Left", number.formatnum(actionsToTarget))
addTableRow(tbl, "Time Left", formatTime(timeToTarget))
return tostring(tbl)
end
function p.main(frame)
return p._main(frame)
end
function p._main(frame)
local args = frame:getParent().args
local currentExp = number.parseNumber(args.currentExp)
local currentLvl = number.toNumberOrDefault(args.currentLvl, 0)
local targetLvl = number.toNumberOrError(args.targetLvl)
local actionExp = number.toNumberOrError(args.actionExp)
local actionTime = number.toNumberOrError(args.actionTime)
-- Check Exp param for validity first, then Lvl
if(currentExp == 0) then
currentExp = MEXP.expForLevel(currentLvl)
end
return calc(currentExp, targetLvl, actionExp, actionTime)
end
return p