Editing
Module:PriceCalculator
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} -- Internal function to calculate price function p._calculate(price, priceType) -- Sanitize input: convert to string, remove commas price = tostring(price):gsub(",", "") price = tonumber(price) -- Error handling if not price or price < 0 then return "Invalid price: " .. tostring(price) end -- Lookup conversion factors local percent = { sell = 0.375, minor = 0.333, major = 0.5 } local factor = percent[priceType] if not factor then return "Invalid type: " .. tostring(priceType) end -- Calculate and return rounded result local result = math.floor(price * factor + 0.0) return math.max(result, 1) end -- Entry point for #invoke function p.calculate(frame) local args = frame.args -- Use direct args from #invoke local price = args.price or args[1] local priceType = args.type or args[2] return p._calculate(price, priceType) end function p.renderPrice(frame) local args = frame.args local inputPrice = args.price or args[1] or "1" local priceType = mw.text.trim(args.type or args[2] or "sell") local min = tonumber(args.min or args.MinimumQuantity or "1") or 1 local max = tonumber(args.max or args.MaximumQuantity or "") -- optional local rawPrice = p._calculate(inputPrice, priceType) if type(rawPrice) ~= "number" then return "Error: " .. tostring(rawPrice) end local price = rawPrice local function format(num) return mw.getContentLanguage():formatNum(num) end local coinIcon = frame:preprocess('{{CoinIcon|size=16px}}') if max and max ~= min then if price > 1 then return string.format('<abbr title="%d coins each">%sβ%s</abbr> %s', price, format(price * min), format(price * max), coinIcon) else return string.format('%sβ%s %s', format(price * min), format(price * max), coinIcon) end elseif min == 1 then return string.format('%s %s', format(price), coinIcon) else if price > 1 then return string.format('<abbr title="%d coins each">%s</abbr> %s', price, format(price * min), coinIcon) else return string.format('%s %s', format(price * min), coinIcon) end end end return p
Summary:
Please note that all contributions to HighSpell Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
HighSpell Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Debug console
* The module exports are available as the variable "p", including unsaved modifications. * Precede a line with "=" to evaluate it as an expression or use print(). Use mw.logObject() for tables. * Use mw.log() and mw.logObject() in module code to send messages to this console.
Module:PriceCalculator/doc
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit
View history
More
Purge cache
Search
Discord
HighLite
Navigation
Main page
Wiki policies
Style guide
Browser extension
Recent changes
Random page
Databases
Bestiary
Equipment
Items
Quests
Shops
Skills
Resources
Getting started
World map
Calculators
Game news
Tools
What links here
Related changes
Special pages
Page information
Cargo data