FANDOM


--
-- Implements [[Calculator:Silverhawks]]
--
local p = {}
 
local feather_exp = require('Module:Silverhawks/data')
local XPAtLevel = require('Module:Experience/data')
local commas = require('Module:Addcommas')
 
function p.feathers_for_level(frame)
	local target_level = frame.args.level
	local current_xp = frame.args.xp
	local bonus_xp = frame.args.bonusxp
 
	if type(current_xp) == 'string' then
		 current_xp = commas._strip(current_xp)
		 current_xp = tonumber(current_xp)
	end
 
	if type(bonus_xp) == 'string' then
		 bonus_xp = commas._strip(bonus_xp)
		 bonus_xp = tonumber(bonus_xp)
	end
 
	if bonus_xp == nil then
		bonus_xp = 0
	end
 
	if type(target_level) == 'string' then
		 target_level = commas._strip(target_level)
		 target_level = tonumber(target_level)
	end
 
	local current_lvl
	local function level_at_xp(xp)
		local level
		for i=120,1,-1 do
		   if XPAtLevel[i] <= xp then
				level = i
				break
		   end
		end
		return level
	end
 
    if current_xp == 0 then
    	current_level = 1
    elseif current_xp > 120 then
        current_level = level_at_xp(current_xp)
    else
        current_level = current_xp
        current_xp = XPAtLevel[current_level]
    end
    local initial_xp = current_xp
    local initial_level = current_level
 
    local target_xp
    if target_level > 120 then
        target_xp = target_level
        target_level = level_at_xp(target_xp)
    else
	    target_xp = XPAtLevel[target_level]
    end
 
	local feathers = 0
 
	while current_xp < target_xp do
		feathers = feathers + 1
		current_level = level_at_xp(current_xp)
		local xp_per_feather = feather_exp[current_level]
		local bonus_xp_per
		if bonus_xp >= xp_per_feather then
			bonus_xp_per = xp_per_feather
			bonus_xp = bonus_xp - xp_per_feather
		elseif bonus_xp > 0 then
			bonus_xp_per = bonus_xp
			bonus_xp = 0
		else
			bonus_xp_per = 0
		end
 
		current_xp = current_xp + xp_per_feather + bonus_xp_per
	end
 
    return 'To train from ' .. commas._add(initial_xp) .. ' experience (level ' .. initial_level .. ') to ' .. commas._add(target_xp) .. ' experience (level ' .. target_level .. '), you will need ' .. commas._add(feathers) .. ' feathers.'
end
 
--
-- Module access point
--
function p._feathers_for_level(args)
    return p.feathers_for_level(args)
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.