Module:Treasure Trails reward points calculator

Revision as of 21:23, 4 November 2021 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Treasure Trails reward points calculator/doc

-- <pre>
local p = {}

local yesno = require("Module:Yesno")
local lang = mw.getContentLanguage()

function p.main(frame)
    local args = frame:getParent().args

    local easyCounter = tonumber(args.easy) or 0
    local mediumCounter = tonumber(args.medium) or 0
    local hardCounter = tonumber(args.hard) or 0
    local eliteCounter = tonumber(args.elite) or 0
    local masterCounter = tonumber(args.master) or 0
    local pointsDesired = tonumber(args.pointsDesired) or 0
    local unlockGlobetrotter = yesno(args.unlockGlobetrotter) or false
    local unlockAllAtShop = yesno(args.unlockAll) or false
    local unlockJacket = yesno(args.unlockJacket) or false
    local unlockShorts = yesno(args.unlockShorts) or false
    local unlockBoots = yesno(args.unlockBoots) or false
    local unlockArmguards = yesno(args.unlockArmguards) or false
    local unlockBackpack = yesno(args.unlockBackpack) or false
    local unlockFootShapedKey = yesno(args.unlockFootShapedKey) or false
    local unlockBlue = yesno(args.unlockBlue) or false
    local unlockExplorerTitle = yesno(args.unlockExplorerTitle) or false
    local unlockGlobetrotterTitle = yesno(args.unlockGlobetrotterTitle) or false
    local unlockEnigmatologistTitle = yesno(args.unlockEnigmatologistTitle) or false
    local unlockCapacityUpgrade = yesno(args.unlockCapacityUpgrade) or false
    
    --Counters must be 0 or positive
    easyCounter = math.max(0,easyCounter)
    mediumCounter = math.max(0,mediumCounter)
    hardCounter = math.max(0,hardCounter)
    eliteCounter = math.max(0,eliteCounter)
    masterCounter = math.max(0,masterCounter)
    
    local pointTotal = 0
    local clueCounter = {easyCounter, mediumCounter, hardCounter, eliteCounter, masterCounter}
    local clue = {"easy", "medium", "hard", "elite", "master"}
	local fClueCounter = {}
	for i,v in ipairs(clueCounter) do
		if v < 0 then
			v = 0
			clueCounter[i] = 0
		end
		table.insert(fClueCounter, lang:formatNum(v))
	end

    local res = ""

    -- Calc current points
    for clueTier = 1,5 do
        pointTotal = pointTotal + math.pow(2, clueTier - 1) * 
            ( (math.floor(clueCounter[clueTier]/500) * math.pow(2,5)) + 
            (math.floor(clueCounter[clueTier]/250) - math.floor(clueCounter[clueTier]/500)) * math.pow(2,4) + 
			(math.floor(clueCounter[clueTier]/100) - math.floor(clueCounter[clueTier]/500)) * math.pow(2,3) + 
			(math.floor(clueCounter[clueTier]/50) - math.floor(clueCounter[clueTier]/100) - math.floor(clueCounter[clueTier]/250) + math.floor(clueCounter[clueTier]/500)) * math.pow(2,2) + 
			(math.floor(clueCounter[clueTier]/10) - math.floor(clueCounter[clueTier]/50)) * math.pow(2,1) + 
			(clueCounter[clueTier]-math.floor(clueCounter[clueTier]/10)) * math.pow(2,0) )
	end

	table.insert(fClueCounter, lang:formatNum(pointTotal) )
    res = { string.format("Total points from ([[File:Sealed clue scroll (easy).png|link=Sealed clue scroll (easy)]] %s, [[File:Sealed clue scroll (medium).png|link=Sealed clue scroll (medium)]] %s, [[File:Sealed clue scroll (hard).png|link=Sealed clue scroll (hard)]] %s, [[File:Sealed clue scroll (elite).png|link=Sealed clue scroll (elite)]] %s, [[File:Sealed clue scroll (master).png|link=Sealed clue scroll (master)]] %s) is : %s<br/>", unpack(fClueCounter) ) }

    -- Calc #needed clues for requested points
    local pointsJacket = 0; if unlockJacket then pointsJacket = 1500 end
    local pointsShorts = 0; if unlockShorts then pointsShorts = 1000 end
    local pointsBoots = 0; if unlockBoots then pointsBoots = 500 end
    local pointsArmguards = 0; if unlockArmguards then pointsArmguards = 750 end
    local pointsBackpack = 0; if unlockBackpack then pointsBackpack = 1200 end
    local pointsGlobetrotter = 4950
    local pointsFootShapedKey = 0; if unlockFootShapedKey then pointsFootShapedKey = 500 end
    local pointsBlue = 0; if unlockBlue then pointsBlue = 2500 end
    local pointsExplorerTitle = 0; if unlockExplorerTitle then pointsExplorerTitle = 750 end
    local pointsGlobetrotterTitle = 0; if unlockGlobetrotterTitle then pointsGlobetrotterTitle = 750 end
    local pointsEnigmatologistTitle = 0; if unlockEnigmatologistTitle then pointsEnigmatologistTitle = 750 end
    local pointsClueCapacityUpgrade = 0; if unlockCapacityUpgrade then pointsClueCapacityUpgrade = 750 end
    local pointsUnlockAllAtShop = 10950
    
    local pointTotalFromGlobetrotterOutfit = pointsJacket + pointsShorts + pointsBoots + pointsArmguards + pointsBackpack
    if unlockGlobetrotter then pointTotalFromGlobetrotterOutfit = pointsGlobetrotter end
    
    local pointsFromCombinedRewards = pointTotalFromGlobetrotterOutfit + pointsFootShapedKey + pointsBlue + pointsExplorerTitle + pointsGlobetrotterTitle + pointsEnigmatologistTitle + pointsClueCapacityUpgrade
    if unlockAllAtShop then pointsFromCombinedRewards = pointsUnlockAllAtShop end
    	
    nPointsRequested = pointsFromCombinedRewards - pointTotal
    
    --manual inputted values override tick boxes
    if (pointsDesired > 0 ) then nPointsRequested = pointsDesired end
    
    --Determine number of clues needed per tier for number of requested points
    if nPointsRequested > 0 then
        for clueTier = 1,5 do
            local nClue = clueCounter[clueTier]
            local currentPointTotal = pointTotal
            while (currentPointTotal < pointTotal+nPointsRequested) do
				nClue = nClue + 1
				if(nClue%500 == 0) then
					currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,5);
				elseif(nClue%250 == 0) then
					currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,4);
				elseif(nClue%100 == 0) then
					currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,3);
				elseif(nClue%50 == 0) then
					currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,2);
				elseif(nClue%10 == 0) then
					currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,1);
				else
                    currentPointTotal = currentPointTotal + math.pow(2,clueTier - 1) * math.pow(2,0);
                end
            end

            table.insert(res,  string.format( "To get %s additional points, another %s %s clues need to be completed.<br/>", lang:formatNum(nPointsRequested), lang:formatNum(nClue-clueCounter[clueTier]), clue[clueTier] ))
        end
    end

    return table.concat(res, '')
end

return p