FANDOM


-- <pre>
local commas        = require('Module:Addcommas')._add
local tables        = require('Module:Tables')
local coins         = require('Module:Coins')._amount
local numbers       = require('Module:Number')._round
 
local eltData = {}
 
--[=[ 
-- Input
--  v           data from caller
--  unitExp     experience per iteration
--  needed      required iterations for goal
--  fileName    page location
--  cost        cost per iteration
--  args        additional parameters from caller
--]=]
function eltData.generate_NoProfitLoss(frame)
 
    local T         = frame.args[1]
    local unitExp   = frame.args[2]
    local needed    = frame.args[3]
    local fileName  = frame.args[4]
    local cost      = frame.args[5]
    local eltArgs   = frame.args[6]
    local images, links
 
    -- Check for multiple images
    -- This occurs when multiple materials are required
    if T.multi then
        images  = 
                    imageLink{file=mw.text.split(T.multi[1], "<")[1],image=T.multi[1]},
                    imageLink{file=mw.text.split(T.multi[2], "<")[1],image=T.multi[2]}
        links   =
                    '[[' .. mw.text.split(T.multi[1], "<")[1] .. ']]',
                    '[[' .. mw.text.split(T.multi[2], "<")[1] .. ']]'
 
    -- Single images only at then
    else
        -- Set the image location
        -- Default with using our page for the icon
        local ourIcon = mw.text.split(fileName, "<")[1]
 
        -- Check for flatpacks and adjust
        if eltArgs.disp == "Flatpacks" then ourIcon = ourIcon .. " (flatpack)" end
 
        -- Check if we specified an image location and make adjustments
        if T.image then ourIcon = mw.text.split(T.image, "<")[1] end
 
        images = imageLink{file=mw.text.split(T.name, "<")[1],image=ourIcon}
 
        -- Set the item's [link]
        -- Default with using the item's name
        local ourTitle = mw.text.split(T.name, "<")[1]
 
        -- Check if we specified a page location
        if T.title then ourTitle = T.title end
 
        links  = '[[' .. mw.text.split(T.name, "<")[1] .. '|' .. ourTitle .. ']]'
 
    end
 
    elts =
    {
        images,
        links,
        T.level,
        numbers(unitExp,1),
        coins(string.format("%.2f", cost / unitExp),1),
        commas(needed),
        "<div style='text-align:left'>" .. createList(T.material,needed) .. "</div>",
        coins(cost),
        coins(cost * needed)
    }
 
 
    -- Check for flatpack exception
    -- Add bench image
    if eltArgs.disp == "Flatpacks" then
        table.insert(elts, 3, 
            imageLink{
                file=mw.text.split(T.bench, "<")[1],
                image=mw.text.split(T.bench, "<")[1],
                alt=T.bench})
    end
 
    return elts
end -- generate_NoProfitLoss
 
--[=[
Generates a No Profit, No Loss skill table
inputs:
    T           Data being processed from 'Module:Skill calc/' .. args.skill .. '/data'
    unitExp     Generated unit exp including bonuses
    needed      Required iterations for goal
    ext         Image/Icon extension
    icon        File name of icon
    altName     Page name
returns:
    Table of data using proper elts based on skill
--]=]
function eltData.generate_NoProfitNoLoss(frame)
 
    local T         = frame.args[1]
    local unitExp   = frame.args[2]
    local needed    = frame.args[3]
    local ext       = frame.args[4]
    local icon      = frame.args[5]
    local altName   = frame.args[6]
    local images, links
 
    icon    =   imageLink
                {
                    file=T.page,
                    image=icon,
                    ext=ext
                }
    links   =   '[[' .. T.page .. '|' .. altName .. ']]'
    elts    = 
    {
        icon,
        numbers(T.level),
        links,
        numbers(unitExp,1),
        commas(needed)
    }
    return elts
end -- generate_NoProfitNoLoss
 
--[=[
Generates a potential Profit, potential Loss skill table
inputs:
    T           Data being processed from 'Module:Skill calc/' .. args.skill .. '/data'
--  unitExp     experience per iteration
--  needed      required iterations for goal
--  fileName    page location
--  rawCost     ingredient cost per iteration
--  productCost product value per iteration
--  args        additional parameters from caller
returns:
    Table of data using proper elts based on skill
--]=]
function eltData.generate_ProfitLoss(frame)
 
    local T             = frame.args[1]
    local unitExp       = frame.args[2]
    local rawCost       = frame.args[3]
    local productCost   = frame.args[4]
    local needed        = frame.args[5]
    local fileName      = frame.args[6]
    local eltArgs       = frame.args[7]
    local images, links
 
        -- Check for multiple images
    -- This occurs when multiple materials are required
    if T.multi then
        images  = 
                    imageLink{file=mw.text.split(T.multi[1], "<")[1],image=T.multi[1]},
                    imageLink{file=mw.text.split(T.multi[2], "<")[1],image=T.multi[2]}
        links   =
                    '[[' .. mw.text.split(T.multi[1], "<")[1] .. ']]',
                    '[[' .. mw.text.split(T.multi[2], "<")[1] .. ']]'
 
    -- Single images only at then
    else
        -- Set the image location
 
        -- Default with using our page for the icon
        local ourIcon = mw.text.split(fileName, "<")[1]
 
        -- Check for farming and make adjustments
        if eltArgs.skill == "Farming" then 
            if eltArgs.disp ~= "Arc" then
            ourIcon = mw.text.split(T.name, "<")[1] .. " seed 5"
            end
            if T.seed then 
                ourIcon = mw.text.split(T.name, "<")[1] ..  "_" .. mw.text.split(T.seed, "<")[1] 
            end
        end
 
        -- Check if we specified an image location and make adjustments
        if T.image then ourIcon = mw.text.split(T.image, "<")[1] end
 
        images = imageLink{file=mw.text.split(T.name, "<")[1],image=ourIcon}
 
        -- Set the item's [link]
        -- Default with using the item's name
        local ourTitle = mw.text.split(T.name, "<")[1]
 
        -- Check if we specified a page location
        if T.title then ourTitle = T.title end
 
        links  = '[[' .. mw.text.split(T.name, "<")[1] .. '|' .. ourTitle .. ']]'
 
end
 
    if eltArgs.skill == "Farming" then
        elts =
        {
            images,
            T.level,
            links,
            commas(unitExp,1),
            commas(needed)
        }
    elseif eltArgs.disp == "Forging" then
        elts =
        {
            images,
            links,
            T.level,
            numbers(unitExp,1),
            commas(needed),
            coins(productCost*needed,1),
            coins(string.format("%.2f", (productCost) / unitExp),1)
        }
    else
 
        elts =
        {
            images,
            links,
            T.level,
            "<div style='text-align:left'>" .. createList(T.material,needed) .. "</div>",
            numbers(unitExp,1),
            commas(needed),
            coins(rawCost*needed,1),
            coins(productCost*needed,1),
            coins(string.format("%.2f", (productCost - rawCost)*needed),1),
            coins(string.format("%.2f", (productCost - rawCost) / unitExp),1)
        }
    end
 
    return elts
end -- generate_ProfitLoss
 
function imageLink(params)
    local ext = ".png"
    if params.ext then ext = params.ext end
 
    if params.alt then
        if params.image == "Bench with lathe" then
            return '[[File:Bench with lathe icon' .. ext .. '|link=' .. params.file .. '|' .. params.file .. ']]'
        else
            return '[[File:' .. params.image .. ext .. '|link=' .. params.file .. '|' .. params.alt .. ']]'
        end
    else
        return '[[File:' .. params.image .. ext .. '|link=' .. params.file .. '|' .. params.file .. ']]'
    end
end -- imageLink
 
function createList(mess,a)
    local sentence = ""
    for i, v in ipairs(mess) do
 
        if (i%2) > 0 then
            sentence = "" .. sentence .. " " .. commas( v * a ) 
        else
            if i == table.getn(mess) then
                sentence = sentence .. " " .. pLink(v)
            else
                sentence = sentence .. " " .. pLink(v) .. "<br />"
            end
        end
    end
 
    return sentence
end -- createList
 
-- This is an implementation of Template:Plink
function pLink(a)
    return "[[File:" .. a .. ".png|link=" .. a .. "]]&nbsp;[[" .. a .. "|" .. a .. "]]"
end -- plink
 
function explain(message)
    local ret = mw.html.create('span'):css({['color'] = "#15f", ['border-bottom'] = "dotted 1px black", ['cursor'] = 'help'}):attr("title", message):wikitext("?")
    return "[" .. tostring(ret) .. "]"
end -- explain
 
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 eltData

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.