Jump to content

Module:StepHarvest

From StepHarvest Wiki

Documentation for this module may be created at Module:StepHarvest/doc

-- Shared helpers for StepHarvest templates.
-- Keeps palette logic and economy math in one place so templates stay thin.
local p = {}

-- Renders a comma separated season list ("spring, fall") as Season tags.
function p.seasons( frame )
	local arg = frame.args[1] or ''
	local out = {}
	for season in mw.text.gsplit( arg, ',' ) do
		season = mw.text.trim( season )
		if season ~= '' then
			table.insert( out, frame:expandTemplate{ title = 'Season', args = { season } } )
		end
	end
	if #out == 0 then
		return ''
	end
	return table.concat( out, ' ' )
end

-- Store payout for selling an item, before any temporary price dips.
-- Mirrors the server formula: floor(base_value x quality_mult x store_rate),
-- minimum 1. The store rate and quality multipliers are universal, they
-- apply to every item and are not configured per crop. If the live config
-- changes, update the two constants below and every page follows.
local STORE_RATE = 0.6
local QUALITY_MULT = {
	regular = 1.0,
	silver = 1.25,
	gold = 1.5,
	pristine = 2.0,
}

function p.storePayout( frame )
	local base = tonumber( frame.args[1] )
	local quality = mw.text.trim( frame.args[2] or 'regular' ):lower()
	local mult = QUALITY_MULT[quality]
	if not base or not mult then
		return ''
	end
	local payout = math.floor( base * mult * STORE_RATE )
	if payout < 1 then
		payout = 1
	end
	return tostring( payout )
end

return p