Módulo:Tcartprice
Revisión del 16:22 30 may 2023 de Margotbean (discusión | contribs.)
Description
This module calculates the price range for an item sold at the Carro Ambulante.
- Note: This module performs special handling of Spanish numbers, inserting a "." instead of a space as a separator for numbers over 1000, in accordance with (most instances of) numbers in the Spanish translation of the game. This differs from the mediawiki standard for displaying numbers in Spanish, which is based on recommendations of the Real Academia Española.
This module can be copy/pasted into all languages without alteration.
Please report any problems or issues with the module on the discussion page for Template:Tprice.
--Not adding a dot to 2nd ES number at all now.
--Math.Max(r.Next(1, 11) * 100, price * r.Next(3, 6))
--Scribunto: math.max(x, ...) Returns the max of all arguments
local p = {}
function p.tprice(frame)
local price = frame.args["price"]
local separator = frame.args["separator"]
local gold = frame.args["gold"]
local space = string.lower(frame.args["spacearoundseparator"])
local ulang = string.upper(mw.language.getContentLanguage():getCode())
local lowprice, highprice, temp, temp2
local formattedprice = "[[File:Gold.png|18px|link=]]"
if (string.lower(price) == "furniture") then
formattedprice = formattedprice .. "250"
if space == "true" then formattedprice = formattedprice .. " " .. separator .. " "
else formattedprice = formattedprice .. separator
end
if (ulang ~= "ES") then
formattedprice = formattedprice .. tostring(mw.language.getContentLanguage():formatNum(2500))
else
formattedprice = formattedprice .. "2.500"
end
else
lowprice = tonumber(price) * 3
highprice = tonumber(price) * 5
if (lowprice <= 100) then
formattedprice = formattedprice .. "100"
elseif (ulang ~= "ES") then
formattedprice = formattedprice .. tostring(mw.language.getContentLanguage():formatNum(lowprice))
else
--Spanish
temp = tostring(mw.language.getContentLanguage():formatNum(lowprice))
if (tonumber(temp) < 10000) then
local length = #(temp)
temp2 = string.sub(temp, -3)
formattedprice = formattedprice .. string.sub(temp, 1, (length-3)) .. "." .. temp2
else
temp2 = {mw.ustring.gsub(tostring(formattedSum), "%s" , ".")}
formattedprice = formattedprice .. temp2[1]
end
if space == "true" then formattedprice = formattedprice .. " " .. separator .. " "
else formattedprice = formattedprice .. separator
end
end
if (highprice <= 1000) then
if (ulang ~= "ES") then
formattedprice = formattedprice .. tostring(mw.language.getContentLanguage():formatNum(1000))
else formattedprice = formattedprice .. "1.000"
end
elseif (ulang ~= "ES") then
formattedprice = formattedprice .. tostring(mw.language.getContentLanguage():formatNum(highprice))
else
--Spanish and highprice > 1000
temp = tostring(mw.language.getContentLanguage():formatNum(highprice))
if (temp < 10000) then
local length = #(tostring(temp))
temp2 = string.sub(tostring(temp), -3)
formattedprice = formattedprice .. string.sub(tostring(temp), 1, (length-3)) .. "." .. temp2
else
temp2 = {mw.ustring.gsub(tostring(formattedSum), "%s" , ".")}
formattedprice = formattedprice .. temp2[1]
end
end
end
return formattedprice .. gold
end
return p