Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

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

local p = {}

function p.farming_wisdom(frame)
    local bps = tonumber(frame.args["bps"])
    local wisdom = tonumber(frame.args["wisdom"])
    local xp = tonumber(frame.args["xp"])

    if not bps or not wisdom or not xp then
        return "Error: Missing bps, wisdom, or xp value."
    end

    local answer = bps * 3600 * (1 + wisdom / 100) * xp
    local formatted_answer = string.format("%0.f", answer):reverse():gsub("(%d%d%d)", "%1,"):gsub(",(%-?)$", "%1"):reverse()
    
    return formatted_answer
end


function p.hexFromXP(frame)
    local minVal, maxVal = 550000, 1050000
    local xp = tonumber(frame.args["xp"])

    if not xp then
        return "Error: Missing xp value."
    end

    local value = math.max(minVal, math.min(maxVal, xp))
    
    local ratio = (value - minVal) / (maxVal - minVal)
    
    local brightness_boost = 1.4 -- brightness boost for mid range values (yellow)
    local red = math.floor(255 * (1 - ratio) * (ratio > 0.4 and ratio < 0.6 and brightness_boost or 1))
    local green = math.floor(255 * ratio * (ratio > 0.4 and ratio < 0.6 and brightness_boost or 1))

    red = math.min(red, 255)
    green = math.min(green, 255)
    
    return string.format("#%02X%02X%02X", red, green, 0)
end


function p.getFarmingWisdomHex(frame)
    local bps = tonumber(frame.args["bps"])
    local wisdom = tonumber(frame.args["wisdom"])
    local basexp = tonumber(frame.args["basexp"])

    local xp = bps * 3600 * (1 + wisdom / 100) * basexp

    return p.hexFromXP({ args = { xp = xp } })
end


function p.mooshroom(frame)
	local strength = frame.args["strength"]
	
	local answer = math.floor(strength / 20 * .7)

	return answer
end

	
function p.pb(frame)
    local score = tonumber((string.gsub(frame.args["score"], ",", "")))
    local max_score = tonumber((string.gsub(frame.args["max"], ",", "")))

    local answer = math.floor((score / max_score) * 100 * 100 + 0.5) / 100
    answer = math.min(100, answer)

    return answer
end

	
function p.rates(frame)
	local ff = frame.args["ff"]
	local base = frame.args["base"]
	local bps = frame.args["bps"]
	local multiplier = (ff + 100)*0.01
	
	local answer = base * bps * multiplier * 3600
	mw.log(multiplier)
	local formatted_answer = mw.ustring.format("%0.0f", answer):reverse():gsub("(%d%d%d)", "%1,"):gsub(",%s*$", ""):reverse()

	return formatted_answer	
end


function p.trex(frame)
	--[[local args = getArgs(frame)
	local bandana, dae, chim = tonumber(args.bandana), args.dae, tonumber(args.chim)]]--
	local bandanabonus = tonumber(frame.args["bandana"])
	local dae = frame.args["dae"]
	local chimera = tonumber(frame.args["chim"])
	local pet = frame.args["pet"]
	
	if chimera > 5 or chimera < 0 then
		answer = "Invalid Chimera Level"
		return answer
	end
	

	local multiplier = 1 + (chimera * 0.2) + dae
	
	if pet == "slug" or pet == "Slug" then
		answer = (bandanabonus * multiplier) + 40
	elseif pet == "trex" or pet == "Trex" or pet == "t-rex" or pet == "T-rex" then
		answer = (2 * bandanabonus) * multiplier
	else
		answer = "Error with pet selection"
	end
	
	return answer
end

return p