1,029
edits
m (Fix erroneous calculation of time remainder) |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local MEXP = require('Module:Experience') | local MEXP = require('Module:Experience') | ||
local | local number = require('Module:Number') | ||
local TimeSpan = require('Module:TimeSpan') | |||
function | local function formatTime(seconds) | ||
local timespan = TimeSpan.fromSeconds(seconds) | |||
return timespan:toStringLong() | |||
end | end | ||
function | local function addTableRow(tbl, c1, c2) | ||
tbl:tag("tr") | tbl:tag("tr") | ||
:tag("th"):wikitext(c1) | :tag("th"):wikitext(c1) | ||
Line 25: | Line 18: | ||
end | end | ||
function | 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 38: | Line 30: | ||
:addClass("wikitable sticky-header text-align-right align-left-1") | :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) | return tostring(tbl) | ||
Line 55: | Line 48: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local currentExp = | local currentExp = number.parseNumber(args.currentExp) | ||
local currentLvl = | local currentLvl = number.toNumberOrDefault(args.currentLvl, 0) | ||
local targetLvl = | local targetLvl = number.toNumberOrError(args.targetLvl) | ||
local actionExp = | local actionExp = number.toNumberOrError(args.actionExp) | ||
local actionTime = | local actionTime = number.toNumberOrError(args.actionTime) | ||
-- Check Exp param for validity first, then Lvl | -- Check Exp param for validity first, then Lvl | ||
Line 67: | Line 60: | ||
end | end | ||
return | return calc(currentExp, targetLvl, actionExp, actionTime) | ||
end | end | ||
return p | return p |
edits