Module:Sandbox/User:Microbrews/Wilderness agility calculator

From RuneRealm Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Microbrews/Wilderness agility calculator requires Module:Addcommas.
Module:Sandbox/User:Microbrews/Wilderness agility calculator requires Module:Coins.
Module:Sandbox/User:Microbrews/Wilderness agility calculator requires Module:Exchange.
Module:Sandbox/User:Microbrews/Wilderness agility calculator requires Module:Yesno.

This module is a sandbox for Microbrews. It can be used to test changes to existing modules, prototype new modules, or just experimenting with lua features.

Invocations of this sandbox should be kept in userspace; if the module is intended for use in other namespaces, it should be moved out of the sandbox into a normal module and template.

This default documentation can be overridden by creating the /doc subpage of this module, as normal.

local gePrice = require('Module:Exchange')._price
local yesNo = require('module:Yesno')
local coins = require('module:Coins')._amount
local addCommas = require('module:Addcommas')._add

local p = {}

local lapRanges = {{1, 15}, {16, 30}, {31, 60}, {61, 65536}}

local angler = gePrice('Blighted anglerfish')
angler = angler - math.floor(0.01 * angler)
local manta = gePrice('Blighted manta ray')
manta = manta - math.floor(0.01 * angler)
local kbwan = gePrice('Blighted karambwan')
kbwan = kbwan - math.floor(0.01 * kbwan)
local restore = gePrice('Blighted super restore(4)')
restore = restore - math.floor(0.01 * restore)

local steelBody = gePrice('Steel platebody')
steelBody = steelBody - math.floor(0.01 * steelBody)

local mithChain = gePrice('Mithril chainbody')
mithChain = mithChain - math.floor(0.01 * mithChain)
local mithLegs = gePrice('Mithril platelegs')
mithLegs = mithLegs - math.floor(0.01 * mithLegs)
local mithSkirt = gePrice('Mithril plateskirt')
mithSkirt = mithSkirt - math.floor(0.01 * mithSkirt)

local addyFull = gePrice('Adamant full helm')
addyFull = addyFull - math.floor(0.01 * addyFull)
local addyLegs = gePrice('Adamant platelegs')
addyLegs = addyLegs - math.floor(0.01 * addyLegs)
local addyBody = gePrice('Adamant platebody')
addyBody = addyBody - math.floor(0.01 * addyBody)

local runeChain = gePrice('Rune chainbody')
runeChain = runeChain - math.floor(0.01 * runeChain)
local runeKite = gePrice('Rune kiteshield')
runeKite = runeKite - math.floor(0.01 * runeKite)
local runeMed = gePrice('Rune med helm')
runeMed = runeMed - math.floor(0.01 * runeMed)


function lapGroupValue(lowerLap, sellNoted)
	local sellNoted = yesNo(sellNoted)
	local lapVal = 0
	
	if lowerLap == 1 then
		if sellNoted then
			lapVal = lapVal + (8 * 4.5 * (angler + manta + kbwan) + 7 * 1.5 * restore) / 31
		end
		
		lapVal = lapVal + (2 * addyBody + 2 * runeMed + addyFull + addyLegs + mithChain + mithLegs + mithSkirt + steelBody) / 10
	
	elseif lowerLap == 16 then
		if sellNoted then
			lapVal = lapVal + (8 * 8.5 * (angler + manta + kbwan) + 7 * 2.5 * restore) / 31
		end
		
		lapVal = lapVal + (addyFull + addyBody + addyLegs + mithChain + mithLegs + mithSkirt + runeChain + runeKite + runeMed) / 9

	elseif lowerLap == 31 then
		if sellNoted then
			lapVal = lapVal + (8 * 13 * (angler + manta + kbwan) + 7 * 4.5 * restore) / 31
		end
		
		lapVal = lapVal + (2 * runeChain + 2 * runeKite + addyFull + addyBody + addyLegs + mithLegs + mithSkirt + runeMed) / 10

	else
		if sellNoted then
			lapVal = lapVal + (8 * 17 * (angler + manta + kbwan) + 7 * 6 * restore) / 31
		end
		
		lapVal = lapVal + (6 * runeChain + 6 * runeKite + 2 * addyBody + 2 * runeMed + addyFull + addyLegs + mithLegs + mithSkirt) / 20
	end

	return lapVal
end


function getXp(laps)
	local nonTicketXp = 571.4 * laps
	if laps <= 10 then
		return nonTicketXp + 200 * laps
	elseif laps <= 50 then
		return nonTicketXp + 210 * laps
	elseif laps <= 100 then
		return nonTicketXp + 220 * laps
	else
		return nonTicketXp + 230 * laps
	end
end


function p.main(frame)
	local args = frame.args
	local laps = tonumber(args.laps or 80)
	local sellNoted = yesNo(args.sellNoted or true)
	
	return p.calc(laps, sellNoted)
end


function p.calc(laps, sellNoted)
	local totalVal = -150000
	for i, lapRange in ipairs(lapRanges) do
		local lowerLap = lapRange[1]
		local upperLap = lapRange[2]
		local lapsInRange = upperLap - lowerLap + 1
		if laps < lowerLap then
			break
		end
		
		local groupVal = lapGroupValue(lowerLap, sellNoted)
		if laps > upperLap then
			totalVal = totalVal + groupVal * lapsInRange
		else
			totalVal = totalVal + groupVal * (laps - lowerLap + 1)
		end
	end

	totalXp = addCommas(getXp(laps))
	return string.format("Completing <b>%s</b> consecutive laps earns a profit of %s and <b>%s</b> experience (after tax, not including clues and un-noted supplies).", laps, coins(totalVal), totalXp)
end

return p