Diferencia entre revisiones de «Módulo:Calcedibility»
Ir a la navegación
Ir a la búsqueda
m (Margotbean trasladó la página Módulo:Test a Módulo:Calcedibility sin dejar una redirección: I think I've settled on its final name) |
|||
(No se muestran 3 ediciones intermedias del mismo usuario) | |||
Línea 1: | Línea 1: | ||
local p = {} | local p = {} | ||
− | --ceh = calculate energy | + | --ceh = calculate edibility (energy/health) |
− | function p. | + | function p.ce(frame) |
local item = string.lower(frame.args.im) | local item = string.lower(frame.args.im) | ||
local edibility = tonumber(frame.args.ed) | local edibility = tonumber(frame.args.ed) | ||
Línea 12: | Línea 12: | ||
if item == "energy" then | if item == "energy" then | ||
− | result = | + | result = math.floor(math.ceil(edibility*2.5) + edibility*quality) |
else | else | ||
− | result = | + | result = math.floor(math.floor(math.ceil(edibility*2.5) + edibility*quality)*0.45) |
end | end | ||
+ | |||
formattedresult = mw.language.getContentLanguage():formatNum(result) | formattedresult = mw.language.getContentLanguage():formatNum(result) | ||
Línea 26: | Línea 27: | ||
length = #(tostring(result)) | length = #(tostring(result)) | ||
temp = string.sub(tostring(result), -3) | temp = string.sub(tostring(result), -3) | ||
− | return string.sub( | + | return string.sub(tostring(result), 1, (length-3)) .. "." .. temp |
else | else | ||
temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , ".")} | temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , ".")} | ||
return temp[1] | return temp[1] | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
return p | return p |
Revisión actual del 16:53 27 feb 2023
Description
This module calculates the Energy and Health values for an edible item. It can return a raw, unformatted number to be used as the data-sort-value in a table, or a number formatted appropriately for the language where it's used.
- 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:EdibilityGrid.
local p = {}
--ceh = calculate edibility (energy/health)
function p.ce(frame)
local item = string.lower(frame.args.im)
local edibility = tonumber(frame.args.ed)
local quality = tonumber(frame.args.q)
local ulang = string.upper(frame.args.ll)
local result, formattedresult, temp, length
if edibility == 0 then return 0 end
if item == "energy" then
result = math.floor(math.ceil(edibility*2.5) + edibility*quality)
else
result = math.floor(math.floor(math.ceil(edibility*2.5) + edibility*quality)*0.45)
end
formattedresult = mw.language.getContentLanguage():formatNum(result)
if ((result < 1000) or (ulang ~= "ES")) then return formattedresult end
--replace space with dot
--Problem: ES doesn't add a space for 4 digits, only for 5+
if (result < 10000) then
length = #(tostring(result))
temp = string.sub(tostring(result), -3)
return string.sub(tostring(result), 1, (length-3)) .. "." .. temp
else
temp = {mw.ustring.gsub(tostring(formattedresult), "%s" , ".")}
return temp[1]
end
end
return p