mNo edit summary |
mNo edit summary |
||
Line 814: | Line 814: | ||
if income ~= 0 then |
if income ~= 0 then |
||
if currency == "Chimes" then |
if currency == "Chimes" then |
||
− | value = value .. " : " .. |
+ | value = value .. " : " .. currency(income * needed, "chimes") |
else |
else |
||
value = value .. " : " .. coins(income * needed, 1) |
value = value .. " : " .. coins(income * needed, 1) |
Revision as of 08:19, 15 December 2017
Documentation for this module may be created at Module:Skill calc/eltGenerator/doc
-- <pre>
local commas = require('Module:Addcommas')._add
local tables = require('Module:Tables')
local coins = require('Module:Coins')._amount
local currency = require('Module:Currency')._amount
local numbers = require('Module:Number')._round
local eltData = {}
--[=[
Note: Once all existing calculators have been converted, this Module will be cleaned
up to remove any spaghetti code.
--]=]
--[=[
Generates a No profit, Purely Loss skill table
skills: Construction, Firemaking, Prayer
Inputs:
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
returns:
Table of data using proper elts based on skill
--]=]
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
if T.icon then ourIcon = mw.text.split(T.icon, "<")[1] end
images = imageLink{file=mw.text.split(T.name, "<")[1],image=ourIcon,iconSize=T.iconSize}
-- 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
}
if eltArgs.disp == "Rooms" then
table.insert(elts, 4, coins(T.coins))
elseif eltArgs.disp == "Milestones" then
table.insert(elts, 4,
"<div style='text-align:left'>" .. checkValue(unitExp,0) .. "</div>")
table.insert(elts, 5,
"<div style='text-align:center'>" .. checkValue(T.coins,1) .. "</div>")
else
elts =
{
-- Are the first 3 needed here?
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)
}
end
-- 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
skills: Agility, Thieving
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 eltArgs = frame.args[7]
local remaining = frame.args[8]
local currLv = frame.args[9]
local images, links, sLink, eLink, cLv
icon = imageLink
{
file=T.page,
image=icon,
ext=ext,
iconSize=T.iconSize
}
-- Determine link
local sLink = ""
local eLink = ""
local linkTitle = T.page
-- Check if an override was provided
if T.sLink then sLink = T.sLink end
if altName then linkTitle = altName end
if T.eLink then eLink = T.eLink end
links = sLink .. ' [[' .. T.page .. '|' .. linkTitle .. ']] ' .. eLink
-- Check for Members only
if (T.mem) then
links = links .. T.mem
end
elts =
{
icon,
numbers(T.level),
links
}
if eltArgs.skill == "Slayer" then
if eltArgs.disp == "Assignments" then
elts =
{
icon,
links,
numbers(T.level),
T.level2
}
else
elts =
{
icon,
links,
numbers(T.level)
}
end
elseif eltArgs.skill == "Agility" then
if eltArgs.disp == "Wilderness Agility Course"
or (T.page == "Wilderness Agility Course" and eltArgs.disp ~= "Milestones") then
if (eltArgs.disp == "Wilderness Agility Course") then cLv = T.level
else cLv = currLv end
if eltArgs.wild == "Demonic Skull" then
unitExp = unitExp + 498.9
if (cLv > 50) then unitExp = (((cLv-21)*0.04)*(unitExp)) end
elseif eltArgs.wild == "Both" then
unitExp = ((unitExp*((cLv-21)*0.04))+((((cLv-21)*0.04)+0.05)*498.9))
elseif eltArgs.wild == "Wilderness Sword 2+" then
unitExp = unitExp + (498.9*1.05)
else unitExp = unitExp + 498.9
end
table.insert(elts, 4, commas(numbers(unitExp,1)))
elseif (eltArgs.disp == "Milestones" or eltArgs.disp == "Multiples"
or eltArgs.disp == "Other") then
elts =
{
icon,
links,
numbers(T.level)
}
else
table.insert(elts, 4, numbers(unitExp,1))
end
if unitExp == 0 then needed = 0 else
needed = tonumber(math.ceil(remaining / unitExp))
end
table.insert(elts, 5, commas(needed))
else
if unitExp == 0 then needed = 0 end
table.insert(elts, 4, numbers(unitExp,1))
table.insert(elts, 5, commas(needed))
end
return elts
end -- generate_NoProfitNoLoss
--[=[
Generates a potential Profit, potential Loss skill table
skills: Fletching, Cooking, Farming, Smithing, Herblore, Summoning
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
-- If alternative currencies are used, the Grand Exchange will not have information
local materials = ""
if not (T.currency == nil) and T.material then
materials = "<div style='text-align:left'>" .. expandedList(T.material,needed) .. "</div>"
elseif T.material then
materials = "<div style='text-align:left'>" .. createList(T.material,needed) .. "</div>"
end
-- Set default currency settings, then determine if alternative used
local displayCurrency = "int"
if T.currency then
displayCurrency = T.currency end
-- 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 for seed icons
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 an image location was specified
if T.image then ourIcon = mw.text.split(T.image, "<")[1] end
if T.icon then ourIcon = mw.text.split(T.icon, "<")[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,
commas(unitExp, 1),
commas(needed)
}
if eltArgs.disp == "Forging" then
table.insert(elts, 6, printCoins( productCost * needed, "int" ))
table.insert(elts, 7, printCoins( productCost / unitExp, "dec"))
elseif string.find(eltArgs.disp,"Dungeoneering - ") then
table.insert(elts, 6, materials)
else
table.insert(elts, 6, materials)
table.insert(elts, 7, printCoins( rawCost * needed, displayCurrency ))
table.insert(elts, 8, printCoins( productCost * needed, displayCurrency ))
table.insert(elts, 9, printCoins( (productCost - rawCost) * needed, displayCurrency ))
if T.currency then
table.insert(elts, 10,
printCoins( (productCost - rawCost) / unitExp, T.currency .. "-dec" ))
else
table.insert(elts, 10, printCoins( (productCost - rawCost) / unitExp, "dec" ))
end
end
return elts
end -- generate_ProfitLoss
--[=[
Generates a Purely Profit, No Loss skill table
skills:
Fishing, Mining, Woodcutting, Runecrafting, Hunter
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_ProfitNoLoss(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 fileName = frame.args[6]
local income = frame.args[7]
local rawCost = frame.args[8]
local eltArgs = frame.args[9]
local remaining = frame.args[10]
local images, links
-- Default with using item's name for the icon
local ourIcon = mw.text.split(fileName, "<")[1]
-- Check if an icon image was specified
if T.icon then ourIcon = mw.text.split(T.icon, "<")[1] end
-- Hunter is a little different
if T.title and not T.icon then ourIcon = mw.text.split(T.title, "<")[1] end
-- Set the item's [link]
-- Default with using the item's name
local ourLink = mw.text.split(T.name, "<")[1]
local ourTitle = mw.text.split(T.name, "<")[1]
local equipmentLink = ""
local ourIconSize = 0
-- Check if a page location was specified
if T.link then ourLink = mw.text.split(T.link, "<")[1] end
-- Check if a title was specified
if T.title then ourTitle = mw.text.split(T.title, "<")[1] end
if T.equipment then
equipmentLink = mw.text.split(T.equipment, "<")[1]
-- Check if an equipment link was specified
if T.eLink then equipmentLink = mw.text.split(T.eLink, "<")[1] end
end
if T.iconSize then ourIconSize = T.iconSize end
-- Set the actual icon image
images = imageLink{file = ourLink, image = ourIcon, iconSize = ourIconSize}
links = '[[' .. ourLink .. '|' .. ourTitle .. ']]'
-- Check if there are materials and create a list
local materialList = "-"
if T.material then
materialList = "<div style='text-align:left'>" .. createList(T.material,needed) .. "</div>"
end
-- Put it all together
if eltArgs.disp == "Urns" then
elts =
{
images,
links,
commas(unitExp,1),
commas(needed),
printCoins( (rawCost * needed), "int" )
}
elseif eltArgs.skill == "Fishing" then
elts =
{
images,
links,
imageLink{
file=equipmentLink,
image=mw.text.split(T.equipment, "<")[1],
alt=equipmentLink},
materialList,
T.level,
commas(unitExp,1),
commas(needed)
}
if not (eltArgs.disp == "Dungeoneering") then
table.insert(elts, 8, printCoins( income * needed, "int" ))
table.insert(elts, 9, printCoins( rawCost * needed, "int" ))
table.insert(elts, 10, printCoins( (income - rawCost) * needed, "int" ))
end
-- This section also accounts for base rune production multipliers
elseif eltArgs.skill == "Runecrafting" then
if eltArgs.disp == "Tiaras" then
elts =
{
images,
links,
materialList,
commas(unitExp,1),
commas(needed),
printCoins( rawCost * needed, "int" ),
printCoins( (income * needed), "int" ),
printCoins( (income - rawCost ) * needed, "int" )
}
elseif eltArgs.disp == "Runespan - Free" or eltArgs.disp == "Runespan - Members" then
elts =
{
images,
links,
T.level,
commas(unitExp,1),
commas(needed)
}
else
elts =
{
images,
links,
T.level,
materialList,
commas(unitExp,1),
commas(needed),
printCoins( rawCost * needed, "int" ),
printCoins(
(income * needed) * levelMultiplier(ourIcon, tonumber(eltArgs.current)), "int" ),
printCoins(
( (income * levelMultiplier(ourIcon, tonumber(eltArgs.current))) - rawCost )
* needed, "int" )
}
end
elseif eltArgs.skill == "Divination" then
-- These allow for Cursed modification (tiered experience)
local modifyExp = 1
local modifyNeeded = needed
if T.name == "Cursed wisp" or T.name == "Cursed memory" then
modifyExp = levelMultiplier(T.name, tonumber(eltArgs.current))
modifyNeeded = tonumber(math.ceil(remaining / (unitExp * modifyExp))) end
if eltArgs.disp == "Harvest" then
elts =
{
images,
links,
T.level,
commas(unitExp * modifyExp, 1),
commas(modifyNeeded, 1),
printCoins(
(income * levelMultiplier(ourIcon, tonumber(eltArgs.current)))
* modifyNeeded, "int" )
}
else
elts =
{
images,
links,
T.level,
materialList,
commas(unitExp * modifyExp, 1),
commas(modifyNeeded, 1),
printCoins( (0 - rawCost) * modifyNeeded, "int" )
}
end
else
elts =
{
images,
links,
T.level,
commas(unitExp,1),
commas(needed)
}
if not (eltArgs.disp == "Dungeoneering" or
(eltArgs.skill == "Woodcutting" and eltArgs.disp == "Other") or (eltArgs.skill == "Hunter")) then
table.insert(elts, 6, printCoins(income * needed, "int")) end
if eltArgs.skill == "Hunter" then
local targetElt = 6
if (eltArgs.disp == "Nets and Sprites" or
eltArgs.disp == "Deadfall and Pitfall" or
eltArgs.disp == "Box Trapping") then
if T.bait then
table.insert(elts, targetElt, pLink(T.bait))
else
table.insert(elts, targetElt, "-")
end
targetElt = targetElt + 1
end
if T.product then
local currency = "Coins"
if T.currency then currency = T.currency end
table.insert(elts, targetElt, inlineProfit(income, needed, T.product, currency))
else
table.insert(elts, targetElt, "-")
end
end
end
return elts
end -- generate_ProfitNoLoss
--------------------------------------
-------- Helper Functions ------------
--------------------------------------
function imageLink(params)
local ext = ".png"
local iconSize = nil
if params.iconSize and params.iconSize > 0 then iconSize = params.iconSize end
if params.ext then ext = params.ext end
-- param.iconSize sets icon size if using a non-icon sized image.
-- Replace this if you'd like to set all images to the same size (eg: 30px) without all the extra coding
if params.alt then
if params.image == "Bench with lathe" then
return '[[File:Bench with lathe icon' .. ext .. '|link=' .. params.file .. '|' .. params.file .. ']]'
elseif (iconSize) then
return '[[File:' .. params.image .. ext .. '|' .. iconSize .. '|link=' .. params.file .. '|' .. params.alt .. ']]'
else
return '[[File:' .. params.image .. ext .. '|link=' .. params.file .. '|' .. params.alt .. ']]'
end
elseif not (iconSize == nil) then
return '[[File:' .. params.image .. ext .. '|' .. iconSize .. 'px|link=' .. params.file .. '|' .. params.file .. ']]'
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 function is used for alternative currencies
function expandedList(mess, a)
local sentence = ""
local follower = 0
for i, v in ipairs(mess) do
if type(v) == "number" then
if follower == 0 then
sentence = "" .. sentence .. " " .. commas( v * a )
follower = 1
else follower = 0 end
else
local parts = explode(",", v)
local image = v
local link = v
if table.getn(parts) > 1 then
image = parts[1]
link = parts[2] end
if i == table.getn(mess) then
sentence = sentence .. " " .. peLink(image,link,link)
else
sentence = sentence .. " " .. peLink(image,link,link) .. "<br />"
end
end
end
return sentence
end
-- This will display a "-" if the assigned value is not set or 0
function checkValue(notEmpty,xc)
local newValue = ""
if (notEmpty) then
if xc == 1 then -- Returns the coin value
newValue = coins(notEmpty)
elseif (notEmpty > 0) then -- Returns any other value greater than 0 (eg: xp)
newValue = commas(numbers(notEmpty,1))
else
newValue = "-"
end
else -- Returns a "-" if there is no value set
newValue = "-"
end
return newValue
end
-- This is a simplified implementation of Template:Plink
function pLink(a)
return "[[File:" .. a .. ".png|link=" .. a .. "]] [[" .. a .. "|" .. a .. "]]"
end -- plink
-- An extended implementation of pLink
function peLink(file, link, title)
return "[[File:" .. file .. ".png|link=" .. link .. "]] [[" .. link .. "|" .. title .. "]]"
end -- pelink
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
-- This takes the amount of coins needed to display in table,
-- but filters out 0s to make untradeables look better
function printCoins(amount, category)
if amount ~= 0 then
if category == "dec" then
return coins(string.format("%.2f", amount, 1))
elseif category == "int" then
return coins(amount, 1)
elseif category == "chimes-dec" then
return currency(string.format("%.2f", amount, 1), "chimes")
elseif category == "chimes" then
return currency(amount, "chimes")
end
else
return "-"
end
end
-- This takes an item and the player's level to find the base multiplier where applicable
function levelMultiplier(item, level)
local ret = 1
if item == "Air rune" then
if level >= 99 then ret = 10
elseif level >= 88 then ret = 9
elseif level >= 77 then ret = 8
elseif level >= 66 then ret = 7
elseif level >= 55 then ret = 6
elseif level >= 44 then ret = 5
elseif level >= 33 then ret = 4
elseif level >= 22 then ret = 3
elseif level >= 11 then ret = 2 end
elseif item == "Mind rune" then
if level >= 112 then ret = 9
elseif level >= 98 then ret = 8
elseif level >= 84 then ret = 7
elseif level >= 70 then ret = 6
elseif level >= 56 then ret = 5
elseif level >= 42 then ret = 4
elseif level >= 28 then ret = 3
elseif level >= 14 then ret = 2 end
elseif item == "Water rune" then
if level >= 114 then ret = 7
elseif level >= 95 then ret = 6
elseif level >= 76 then ret = 5
elseif level >= 57 then ret = 4
elseif level >= 38 then ret = 3
elseif level >= 19 then ret = 2 end
elseif item == "Earth rune" then
if level >= 104 then ret = 5
elseif level >= 78 then ret = 4
elseif level >= 52 then ret = 3
elseif level >= 26 then ret = 2 end
elseif item == "Fire rune" then
if level >= 105 then ret = 4
elseif level >= 70 then ret = 3
elseif level >= 35 then ret = 2 end
elseif item == "Body rune" then
if level >= 92 then ret = 3
elseif level >= 46 then ret = 2 end
elseif item == "Cosmic rune" and level >= 118 then ret = 2
elseif item == "Chaos rune" and level >= 74 then ret = 2
elseif item == "Astral rune" and level >= 82 then ret = 2
elseif item == "Nature rune" and level >= 91 then ret = 2
elseif item == "Law rune" and level >= 110 then ret = 2
elseif item == "Death rune" and level >= 131 then ret = 2
elseif item == "Armadyl rune" then
if level >= 99 then ret = 10
elseif level >= 88 then ret = 9
elseif level >= 77 then ret = 8
elseif level >= 72 then ret = 7 end
elseif item == "Blood rune" and level >= 154 then ret = 2
elseif item == "Cursed wisp" then
if level >= 95 then ret = 12
elseif level >= 90 then ret = 11
elseif level >= 85 then ret = 10
elseif level >= 80 then ret = 9
elseif level >= 70 then ret = 8
elseif level >= 60 then ret = 7
elseif level >= 50 then ret = 6
elseif level >= 40 then ret = 5
elseif level >= 30 then ret = 4
elseif level >= 20 then ret = 3
elseif level >= 10 then ret = 2 end
elseif item == "Cursed memory" then
if level >= 95 then ret = 64
elseif level >= 90 then ret = 53
elseif level >= 85 then ret = 46
elseif level >= 80 then ret = 41
elseif level >= 70 then ret = 36
elseif level >= 60 then ret = 29
elseif level >= 50 then ret = 22
elseif level >= 40 then ret = 13
elseif level >= 30 then ret = 8
elseif level >= 20 then ret = 6
elseif level >= 10 then ret = 5
else ret = 4 end
end
return ret
end
-- From http://lua-users.org/wiki/SplitJoin
function explode(d,p)
local t, ll
t={}
ll=0
if(#p == 1) then
return {p}
end
while true do
l = string.find(p, d, ll, true) -- find the next d in the string
if l ~= nil then -- if "not not" found then..
table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array.
ll = l + 1 -- save just after where we found it for searching next time.
else
table.insert(t, string.sub(p,ll)) -- Save what's left in our array.
break -- Break at end, as it should be, according to the lua manual.
end
end
return t
end
function inlineProfit(income, needed, item, currency)
local sentence = ""
local value = ""
local parts = explode(",", item)
local image = item
local link = item
if income ~= 0 then
if currency == "Chimes" then
value = value .. " : " .. currency(income * needed, "chimes")
else
value = value .. " : " .. coins(income * needed, 1)
end
end
if table.getn(parts) > 1 then
image = parts[1]
link = parts[2] end
sentence = sentence .. " " .. peLink(image,link,link) .. value
return sentence
end
return eltData