FANDOM


--[=[
    dependencies
    [[Module:Addcommas]]
    [[Module:Tables]]
    [[Module:Coins]]
    [[Module:GETotal]]
    [[Module:Number]]
    [[Module:Experience]]
    [[Module:Silverhawks/data]]
    [[Module:Skill_calc/eltGenerator]]
--]=]
-- <nowiki>
 
local p = {}
 
local commas        = require('Module:Addcommas')._add
local tables        = require('Module:Tables')
local coins         = require('Module:Coins')._amount
local gePrice       = require('Module:GETotal')._quantity
local numbers       = require('Module:Number')._round
local level         = require('Module:Experience').level_at_xp
local xp            = require('Module:Experience').xp_at_level
local featherExp    = require('Module:Silverhawks/data')
 
-- This houses most of the processing power
local eltGenerator  = require('Module:Skill_calc/eltGenerator')
 
 
function p.noValue(frame)
    local args = frame:getParent().args
    local expBoost = 0                 -- Account for outfits, avatar, tools, etc
    local currLv, goalLv, currXP, goalXP, remaining
    local icon,links,elts
 
    -- Gather all relative experience boosts to find new base experience
    if not (args.avatar == nil) then 
        expBoost = expBoost + (tonumber(args.avatar)/100) 
    end
    if not (args.extra == nil) then 
        if (tonumber(args.extra)) then 
            expBoost = expBoost + (tonumber(args.extra)/100) 
        end
    end
    if not (args.outfit == nil) then
        if (tonumber(args.outfit)) and (tonumber(args.outfit) == 5) then
            expBoost = expBoost + (6/100) -- Account for set bonus
        else
            expBoost = expBoost + (tonumber(args.outfit)/100)
        end
    end
    if not (args.tool == nil) then 
        if args.tool == "Dwarven army axe" then 
            expBoost = expBoost + 3 
        end
    end
    if not (args.portable == nil) then 
        expBoost = expBoost + (21/100) 
    end
 
    -- Translate goals into experience comparisons
    -- Calculate iterations to goal
    currLv, currXP, goalLv, goalXP, remaining = remainingExp(args.current, args.goal, args.currToggle, args.goalToggle)
 
    -- Try to catch Silverhawk feathers early..
    if args.disp == "Silverhawk Feathers" then
 
        local message = silverhawkFeathers(currLv, goalLv, currXP, goalXP, remaining, expBoost)
        local msgRet = mw.html.create('div'):css({['font-size'] = "16px", ['font-weight'] = "bold"}):wikitext(message)
        return tostring(msgRet)
    end
 
    -- Grab Sub-Category Table Data
    local dataRet = require('Module:Skill calc/' .. args.skill .. '/data')
 
    local data = dataRet(args.disp)
 
    table.sort(data, function(a,b) return a.level < b.level end)
 
    local ret = mw.html.create('table'):addClass('wikitable sortable')
 
    -- Find columns from pool
    -- Some require specific parameters due to common phrases
    local eltsRet = require('Module:Skill calc/elts')
    elts = eltsRet(args.skill)
 
    -- Filter out exceptions
    if (args.disp == "Flatpacks") or (args.disp == "Forging") then
            elts = eltsRet(args.skill .. "-" .. args.disp)
    end
 
    tables._row(ret:tag('tr'), elts, true)
 
    for _, v in ipairs(data) do
 
        --Leave common calculations outside of the function calls
 
        --Total materials to create items
        local mcount = 1
        if v.mcount then
            mcount = v.mcount
        end
 
        --Get total cost of materials
        local cost = 0
        if (v.material) then
            if v.trade ~= 0 then
                cost = gePrice(v.material,mcount)
            end
        end
 
        local productCost = 0
        if (v.raw) then
            --productCost = gePrice(v.name)
            productCost = 0
        end
        if args.skill == "Smithing" and v.trade ~= 0 then
            productCost = gePrice({1,v.name},1)
        end
 
 
        --Establish any experience boosts
        local unitExp = calculateBonus
                {
                    base=v.xp,
                    boost=expBoost
                }
 
        -- Calculate needed iterations
        local needed = tonumber(math.ceil(remaining / unitExp))
 
        -- Decide Label
        local fileName = v.name
        if v.page then fileName = v.page end
        if v.alt then fileName = v.alt end
 
        -- Icon extension
        local ext   = ".png"
        if v.ext then ext = v.ext end
 
        -- File name of Icon
        local icon  = v.icon
        -- Exception for Agility Arena icon (jpg quality)
        if args.disp == "Agility Arena" then 
            icon    = "Brimhaven_Agility_Arena_icon"
            ext     = ".jpg"
        end
 
 
        -- No Profit, No Loss skills 
        if  (args.skill == "Agility" 
         or  args.skill == "Thieving") then
 
            elts = eltGenerator.generate_NoProfitNoLoss({b = {v}, args = {v,unitExp,needed,ext,icon,fileName}})
 
        -- No Loss, Profit skills (Gathering)
        elseif (args.skill == "Mining"
            or  args.skill == "Fishing"
            or  args.skill == "Woodcutting"
            or  args.skill == "Runecrafting") then
 
            elts = ""
 
        -- No Profit, Loss skills (Survival)
        elseif (args.skill == "Firemaking" 
            or  args.skill == "Prayer"
            or  args.skill == "Construction") then
            elts = eltGenerator.generate_NoProfitLoss({b = {v}, args = {v,unitExp,needed,fileName,cost,args}})
 
        -- Profit and Loss skills (Artisan)
    else 
            elts = eltGenerator.generate_ProfitLoss({b = {v}, args = {v,unitExp,cost,productCost,needed,fileName,args}})
        end
 
        if args.skill == "Thieving" then table.insert(elts,v.location) end
 
        local class = 'sg-yellow'
        if v.level > goalLv then
            class = 'sg-red'
        elseif v.level <= currLv then
            class = 'sg-green'
        end
 
        tables._row(ret:tag('tr'):addClass(class), elts, false)
 
    end
 
    local message = displayExp{display=args.disp, skill=args.skill, remaining=remaining, goalLv=goalLv, goalXP=goalXP, currLv = currLv, currXP = currXP}
 
    return tostring(message) .. tostring(ret)
end
 
--[=[ displayExp
-- Creates a text string output for the goal calculations
-- Inputs:
--      params      Incoming parameters to generate string
--          - display   Current set of sub-categorical data
--          - skill     Current skill
--          - remaining Experience needed for goal
--          - goalXP    Expected experience
--          - goalLv    Expected level
--          - currXP    Current experience
--          - currLv    Current level
-- Returns:
--      message     String created from params
--          -   this may be appended with a warning specifically for flatpacks
--]=]
function displayExp(params)
    local message
    local display   = params.display
    local skill     = params.skill
    local remaining = params.remaining
    local goalXP    = params.goalXP
    local goalLv    = params.goalLv
    local currXP    = params.currXP
    local currLv    = params.currLv
 
    message = "To train " .. skill .. " from " .. commas(currXP) .. " experience (level " .. currLv .. ") to " .. commas(goalXP) .. " experience (level " .. goalLv .. "), " .. commas(remaining) .. " experience is required."
 
    if display == "Flatpacks" then
        message = message .. "<div style='color:red; font-size:12px;'>Levels refer to the minimum needed to use the associated workbench if otherwise lower.</div>"
    end
    local ret = mw.html.create('div'):css({['font-size'] = "16px", ['font-weight'] = "bold"}):wikitext(message)
    return tostring(ret)
end
 
--[=[ remainingExp
finds and returns experiences and levels based on inputs
inputs:
	curr	current value
	goal	goal value
	curr_intent		what the current is (level/experience)
	goal_intent		what the goal is (level/experience)
returns
	current level,
	current experience,
	goal level,
	goal experience,
	experience remaining
--]=]
function remainingExp(curr, goal, curr_intent, goal_intent)
    local goalLevel, currLevel, goalXP, currXP
 
    if curr_intent == "Level" and tonumber(curr) <= 120 then
        currLevel = tonumber(curr)
        currXP = xp({args = {curr}})
    else
        currLevel = level({args = {curr}})
        currXP = tonumber(curr)
    end
 
    if goal_intent == "Level" and tonumber(goal) <= 120 then
        goalLevel = tonumber(goal)
        goalXP = xp({args = {goal}})
    else
        goalLevel = level({args = {goal}})
        goalXP = tonumber(goal)
    end
 
    -- Prevent negative values
    local remaining = math.ceil(goalXP - currXP)
    if remaining < 0 then
        remaining = 0
    end
    return currLevel, currXP, goalLevel, goalXP, remaining
end
 
--[=[ calculateBonus
-- Inputs:
--      - source        Incoming data
--          - base      Base experience for item
--          - ava       Avatar bonus
--          - outfit    Outfit bonus
--          - tools     Extra bonuses
-- Returns:
--  Numeric value of new base experience including bonuses
--]=]
function calculateBonus(source) 
        local base  = source.base
        local boost = source.boost
        local total = (base * boost) + base
 
        return numbers(total,1)
end
 
--[=[ silverhawkFeathers
--  Inputs:
--      currlv      Current level
--      goalLv      Goal Level
--      currXP      Current Experience
--      goalXP      Goal Experience
--      remaining   Difference from goal
--      expBoost    Calculated boost to base exp
--  Returns:
--      String including needed feathers, remaining experience, and current GE cost for feathers
--]=]
function silverhawkFeathers(currLv, goalLv, currXP, goalXP, remaining, expBoost)
    local feathers = 0
    local featherXP
    local desc = ""
    local workingXP = currXP
    local workingLv = currLv
    while workingXP < goalXP do
		feathers = feathers + 1
		workingLv = level({args = {workingXP}})
		featherXP = featherExp[workingLv] + (featherExp[workingLv] * expBoost)
 
		workingXP = workingXP + featherXP
	end
	return 'To train from ' .. commas(currXP) .. ' experience (level ' .. currLv .. ') to ' .. commas(goalXP) .. ' experience (level ' .. goalLv .. '), ' .. commas(remaining) .. " experience is needed. This requires '''" .. commas(feathers) .. " [[Silverhawk feathers|feathers]]''' and, at current GE Prices, will cost " .. coins(gePrice({feathers,'Silverhawk feathers'},1)) .. ' coins.'
end
 
function tableToString(t)
    local key
    local value
    local result
 
    result = ''
 
    for key, value in pairs(t) do
        if (tonumber(key) ~= nil) then
            result = result .. ':table[' .. key .. '] is ' .. value .. '\n' 
        else
            result = result .. ':table[\'' .. key .. '\'] is ' .. value .. '\n' 
        end
    end
 
    return result
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.