Módulo:Calcedibility

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 energy or health
function p.ceh(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 formattedresult

	if edibility == 0 then return 0 end

	if item == "energy" then
		formattedresult = mw.language.getContentLanguage():formatNum(calcenergy(edibility, quality))
	else
		formattedresult = mw.language.getContentLanguage():formatNum(calchealth(edibility, quality))
	end

	if tonumber(formattedresult) < 1000 then return formattedresult end
	if ulang ~= "ES" then return formattedresult end

	--replace space with dot
	--Problem: ES doesn't add a space for 4 digits
	local temp = string.sub(formattedresult, -3)	
	return string.sub(formattedresult, 1, #formattedresult-3) .. "." .. temp	
end

function calcenergy(edib, qualmult)
	return math.floor(math.ceil(edib*2.5) + edib*qualmult)
end

function calchealth(edib, qualmult)
	return math.floor(math.floor(math.ceil(edib*2.5) + edib*qualmult) * 0.45)
end

return p