FANDOM


-- <pre>
local p = {}
local commas = require('Module:Addcommas')._add
-- Parameter syntax:
-- <bonusname>::<bonusvalue>::<priority>::<constant|>
-- e.g.:
-- Outfit::6%::5
-- will create a variable displayed as "Outfit" that gives +6% bonus XP
-- this 6% bonus will be calculated 5th, if there are 4 other variables, prioritized as 1,2,3, and 4
-- both 6 and 6% are valid as a value, and both will equate to .06
-- if constant is defined, then the value will not be treated as a percent, even if a percent sign is used
 
-- any bonus can be suppressed on a case-by-case basis by setting its name as a parameter to "DISABLED"
-- the name comparison will be case insensitive
 
local behaviours = {
	BASE = 1,
	BONUS = 2,
	RAW = 3
}
function p.main(frame)
	local args = frame:getParent().args
 
	local xph = args.xph
 
	xph = string.gsub(xph,',','')
	xph = tonumber(xph) or 0
 
	local bonuses = {}
	local disabled = {}
	-- allow values to be suppressed when an action cannot benefit from the bonus
 
	for n, v in pairs(args) do
		if string.lower(v) == 'disabled' then
			disabled[string.lower(n)] = true
		end
	end
 
	for _, v in ipairs(args) do
		local _v = {}
		-- split
		local t = mw.text.split(v,'::')
		-- name
		_v.n = t[1]
		-- value
		local val = t[2]
		val = string.gsub(val,'[,%%]','')
		val = tonumber(val)
		_v.x = val
 
		-- priortity
		_v.p = tonumber(t[3])
 
		-- constant?
		local const = string.lower(t[4] or '')
 
		if const == 'constant' or const == 'const' then
			_v.c = true
		else
			_v.c = false
		end
 
		-- if val was a number and the bonus isn't disabled
		if val and not disabled[string.lower(_v.n or '')] then
			table.insert(bonuses,_v)
		end
	end
 
	return p._main(xph, bonuses)
end
 
function p._main(xph, bonuses)
	local ret = mw.html.create('table')
					:addClass('wikitable sortable align-right-2 align-right-3')
					:tag('tr')
						:tag('th'):wikitext('Effect'):done()
						:tag('th'):wikitext('Increase'):done()
						:tag('th'):wikitext('XP/H'):done()
					:done()
	ret	:tag('tr')
			:tag('td'):wikitext('No bonus'):done()
			:tag('td'):wikitext('0'):done()
			:tag('td'):wikitext(commas(xph)):done()
		:done()
 
	local total_bonus = 0
	-- sort bonuses by priority
	table.sort(bonuses, function(a,b) return a.p < b.p end)
 
	for _, v in ipairs(bonuses) do
		local bonus = 0
		local plus_bonus = xph
		if v.c then
			bonus = v.x
		else
			bonus = (v.x / 100) * xph
			-- round to .10
			bonus = math.floor(bonus * 10 + .009) / 10
		end
 
		-- add to totals
		total_bonus = total_bonus + bonus
		plus_bonus = plus_bonus + bonus
 
		-- add .0 to integers
		bonus = commas(add0(bonus))	
		plus_bonus = commas(add0(plus_bonus))
 
		ret	:tag('tr')
				:tag('td'):wikitext(v.n):done()
				:tag('td'):wikitext('+'..bonus):done()
				:tag('td'):wikitext(plus_bonus):done()
			:done()
	end
 
	local total_plus = xph + total_bonus
	-- add .0 to integers
	total_bonus = commas(add0(total_bonus))
	total_plus = commas(add0(total_plus))
 
	ret	:tag('tr')
			:tag('th'):css('text-align','right'):wikitext('Max'):done()
			:tag('th'):css('text-align','right'):wikitext('+'..total_bonus):done()
			:tag('th'):css('text-align','right'):wikitext(total_plus):done()
		:done()
	return ret
end
 
function add0(x)
	local _x = tonumber(x)
	if not _x then
		return x
	end
 
	if _x == math.floor(_x) then
		_x = _x .. '.0'
	end
 
	return _x
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.