Module:Sandbox/User:Artoire/1: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
 
(12 intermediate revisions by the same user not shown)
Line 3:
current_xp = 24,
target_xp = 37,
ingot = 'MaloicCoarse AdathrilDeathstone Ingot(Etched)',
profession = 'Stonemason', -- 'Bonewright'/'Stonemason'/'Blacksmith'
ore_buy = 'true',
pole_buy = 'none', -- 'none'/'logs'/'pole'
})
]]
Line 10 ⟶ 13:
require('Module:Mw.html extension')
local xp = require('Module:Experience')
local cache = require('Module:Break Isolation').get_module_store('Module:Sandbox/User:Artoire/1')
local currency = require('Module:Currency')
local lang = mw.language.getContentLanguage()
 
local function_ingots lookup_ingots()= {}
local function lookup_ingots(profession)
if cache.ingots then return cache.ingots end
if _ingots[profession] then
local ingots = {
return _ingots[profession]
end
_ingots[profession] = {
recipes = {},
order = {}
}
cache.ingots = ingots
for _, result in ipairs(mw.smw.ask{
({
'[[Uses facility::Goblin Smelter||Gnome Smelter]]',
Blacksmith = '[[Uses facility::Goblin Smelter||Gnome Smelter]]',
Stonemason = '[[Uses facility::T.E.A. Machine]]',
Bonewright = '[[Uses facility::B.R.E.W.S. Vat]]'
})[profession],
['?Recipe JSON'] = '',
mainlabel = '-',
Line 30 ⟶ 38:
result = mw.text.jsonDecode(result[1])
local ingot = result.output[1].name
ingots_ingots[profession].recipes[ingot] = {
xp = result.xp,
facility = result.facility,
Line 37 ⟶ 45:
level = result.level
}
table.insert(ingots_ingots[profession].order, ingot)
end
return ingots_ingots[profession]
end
 
local function lookup_weapons(profession)
local ingots = lookup_ingots(profession)
if cache.weapons then return cache.weapons end
local ingots = lookup_ingots()
local weapons = {}
cache.weapons = weapons
for _, result in ipairs(mw.smw.ask{
({
'[[Uses facility::Goblin Forge||Gnome Forge]]',
Blacksmith = '[[Uses facility::Goblin Forge||Gnome Forge]]',
Stonemason = '[[Category:Stonemason]][[Category:Pages with recipes]][[Uses facility::!T.E.A. Machine]]',
Bonewright = '[[Category:Bonewright]][[Category:Pages with recipes]][[Uses facility::!B.R.E.W.S. Vat]]'
})[profession],
['?Recipe JSON'] = '',
mainlabel = '-',
Line 56 ⟶ 66:
local lvl = result['Profession Level A']
result = mw.text.jsonDecode(result[1])
if not result.passive and result.profession == profession then
local ingot
local poleingot
local pole
for _, material in ipairs(result.materials) do
iffor _, ingots.recipes[material in ipairs(result.name]materials) thendo
if ingots.recipes[material.name] then
assert(not ingot)
assert(not ingot = material)
ingot = material
else
else
assert(not pole)
assert(not pole = material)
pole = material
end
end
weapons[ingot.name] = weapons[ingot.name] or {}
table.insert(weapons[ingot.name], {
facility = result.facility,
level = result.level,
ingot = ingot,
pole = pole,
name = result.output[1].name,
xp = result.xp
})
end
weapons[ingot.name] = weapons[ingot.name] or {}
table.insert(weapons[ingot.name], {
facility = result.facility,
level = result.level,
ingot = ingot,
pole = pole,
name = result.output[1].name,
xp = result.xp
})
end
return weapons
Line 81 ⟶ 93:
 
local function _lookup_price_uncached(item)
local result = tonumber(mw.smw.ask{
('[[Sold item::%s]]'):format(item),
['?Shop buy price'] = 'buy',
['?Shop sell price'] = 'sell',
mainlabel = '-'
}[1][1])
return result or -1{
buy = tonumber(result.buy),
sell = tonumber(result.sell)
}
end
 
local _lookup_price_cache = {}
cache.lookup_price = cache.lookup_price or {}
local function lookup_price(item)
cache.lookup_price_lookup_price_cache[item] = cache.lookup_price_lookup_price_cache[item] or _lookup_price_uncached(item)
return cache.lookup_price_lookup_price_cache[item]
end
 
Line 115 ⟶ 131:
end
 
local _lookup_pole_cache = {}
cache.lookup_pole = cache.lookup_pole or {}
local function lookup_pole(pole)
cache.lookup_pole_lookup_pole_cache[pole] = cache.lookup_pole_lookup_pole_cache[pole] or _lookup_pole_uncached(pole)
return cache.lookup_pole_lookup_pole_cache[pole]
end
 
Line 132 ⟶ 148:
end
 
local _lookup_ore_cache = {}
cache.lookup_ore = cache.lookup_ore or {}
local function lookup_ore(ore)
cache.lookup_ore_lookup_ore_cache[ore] = cache.lookup_ore_lookup_ore_cache[ore] or _lookup_ore_uncached(ore)
return cache.lookup_ore_lookup_ore_cache[ore]
end
 
local function _lookup_log_uncached(log)
local data = mw.smw.ask{
('[[%s]]'):format(orelog),
['?Profession Level A'] = '',
mainlabel = '-'
Line 149 ⟶ 165:
end
 
local _lookup_log_cache = {}
cache.lookup_log = cache.lookup_log or {}
local function lookup_log(log)
cache.lookup_log_lookup_log_cache[log] = cache.lookup_log_lookup_log_cache[log] or _lookup_log_uncached(log)
return cache.lookup_log_lookup_log_cache[log]
end
 
Line 159 ⟶ 175:
local p = {}
 
function p.ingots(frame)
return table.concat(lookup_ingots(frame.args.profession).order, ',')
end
 
Line 166 ⟶ 182:
return p._main(frame:getParent().args)
end
 
p.w = lookup_weapons
 
function p._main(args)
local profession = args.profession
 
local current_xp = tonumber(args.current_xp) or 0
local current_lvl
Line 189 ⟶ 205:
 
local remaining_xp = target_xp - current_xp
 
local buying_ores = args.ore_buy ~= 'false'
 
local buying_poles = args.pole_buy
Line 195 ⟶ 213:
buying_poles = not (buying_logs or chopping_logs)
 
local ingot = lookup_ingots(profession).recipes[args.ingot]
 
local result = mw.html.create()
Line 210 ⟶ 228:
local colspan = 23
if chopping_logs then
colspan = colspan + 41
end
if chopping_logs or buying_logs then
colspan = colspan + 13
end
 
tbl
:tag('tr')
:th(skillclickpic('Miner')):done(){
Blacksmith = 'Miner',
:th{ 'Ore', attr = { colspan = '3' } }:done()
Stonemason = 'Miner',
:th{ 'Ingot', attr = { colspan = '2' } }:done()
Bonewright = 'Gatherer'
})[profession])):done()
:th{ ({
Blacksmith = 'Ore',
Stonemason = 'Rock',
Bonewright = 'Bone'
})[profession], attr = { colspan = '3' } }:done()
:th{ ({
Blacksmith = 'Ingot',
Stonemason = 'Etched',
Bonewright = 'Brewed'
})[profession], attr = { colspan = '2' } }:done()
:IF(chopping_logs)
:th(skillclickpic('Woodcutter')):done()
:th{ 'Log', attr = { colspan = '3' } }:done()
:END()
:IF(chopping_logs or buying_logs)
:th{ 'Log', attr = { colspan = '3' } }:done()
:th(skillclickpic('Carpenter')):done()
:END()
:th{ 'Pole', attr = { colspan = '3' } }:done()
:th(skillclickpic('Blacksmith'profession)):done()
:th{ 'Product', attr = { colspan = '3' } }:done()
:th{ 'Cost', attr = { colspan = '10' } }:done()
:done()
 
for _, weapon in ipairs(lookup_weapons(profession)[ingot.ingot]) do
if not ingot.xp then
tbl
:tr()
:td{
'Missing XP for smeltingpreparing [[' .. ingot.ingot .. ']]; Please [' .. tostring(mw.uri.fullUrl(ingot.ingot, 'action=edit&section=1')) .. ' edit the page] to add the experience earned (after |exp =)',
attr = { colspan = colspan }
}
Line 249 ⟶ 279:
:tr()
:td{
'Missing XP for creating [[' .. weapon.name .. ']]; Please ['.. tostring(mw.uri.fullUrl(weapon.name, 'action=edit&section=1')) .. ' edit the page] to add the experience earned (after |exp =)',
attr = { colspan = colspan }
}
:done()
breakelse
local xp_per = weapon.xp + ingot.xp * weapon.ingot.quantity
end
local needed = math.ceil(remaining_xp / xp_per)
local xp_per = weapon.xp + ingot.xp * weapon.ingot.quantity
local needed = math.ceil(remaining_xp / xp_per)
 
local needed_ores = needed * weapon.ingot.quantity
local row = tbl
:tag('tr')
:td(lookup_ore(ingot.ore).level):done()
:td{ needed_ores .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right', ['data-sort-value'] = needed_ores } }:done()
:td{ ('[[File:%s.png|link=%s|30px]]'):format(ingot.ore, ingot.ore), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' }:done()
:td{ '[[' .. ingot.ore .. ']]', addClass = 'plinkt-link no-border' }:done()
:td{ ('[[File:%s.png|link=%s|30px]]'):format(ingot.ingot, ingot.ingot), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border', ['data-sort-value'] = needed_ores }:done()
:td{ '[[' .. ingot.ingot .. ']]', addClass = 'plinkt-link no-border' }:done()
 
local pole_info
local needed_logs, needed_poles
 
if weapon.pole then
needed_poles = needed * weapon.pole.quantity
if chopping_logs or buying_logs then
pole_info = lookup_pole(weapon.pole.name)
needed_logs = math.ceil(needed_poles / 2)
end
if chopping_logs then
row
:td(lookup_log(pole_info.log).level):done()
end
if chopping_logs or buying_logs then
row
:td{ needed_logs .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_logs } }:done()
:td{ ('[[File:%s.png|link=%s|30px]]'):format(pole_info.log, pole_info.log), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' }:done()
:td{ '[[' .. pole_info.log .. ']]', addClass = 'plinkt-link no-border' }:done()
:td(pole_info.level):done()
end
 
if weapon.pole then
needed_poles = needed * weapon.pole.quantity
if chopping_logs then
pole_info = lookup_pole(weapon.pole.name)
needed_logs = math.ceil(needed_poles / 2)
row
:td{ needed_poles .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_poles } }:done()
:td(lookup_log(pole_info.log).level):done()
:td{ needed_logs ('[[File:%s.png|link=%s|30px]]'):format(weapon.pole.name, '×'weapon.pole.name), css = { ['border-rightleft'] = '0', ['padding-rightleft'] = '0', ['text-align'] = 'right' }, attraddClass = { ['dataplinkt-sortimage no-valueborder'] = needed_logs } }:done()
:td{ ('[[File:%s' .png|link=%s|30px]]'):format(pole_info.log, weapon.pole.log),name css.. = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-imagelink no-border' }:done()
else
:td{ '[[' .. pole_info.log .. ']]', addClass = 'plinkt-link no-border' }:done()
if chopping_logs then
end
row
if chopping_logs or buying_logs then
:na()
pole_info = pole_info or lookup_pole(weapon.pole.name)
end
if chopping_logs or buying_logs then
row
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } }:done()
:na()
end
row
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } }:done()
:td(pole_info.level):done()
end
 
row
:td(weapon.level)
:td{ needed_poles .. '&times;', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_poles } }:done()
:td{ ('[[File:%s.png|link=%s|30px]]'):format(weapon.pole.name,needed weapon.pole.name) '&times;', css = { ['border-leftright'] = '0', ['padding-leftright'] = '0', ['text-align'] = 'right' }, addClassattr = { ['plinktdata-image nosort-bordervalue'] = needed } }:done()
:td{ ('[[' File:%s.png|link=%s|30px]]'):format(weapon.name, weapon.pole.name), ..css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-linkimage no-border' }:done()
:td{ '[[' .. weapon.name .. ']]', addClass = 'plinkt-link no-border' }
else
 
local cost = needed_ores * lookup_price(ingot.ore)[buying_ores and 'buy' or 'sell']
if chopping_logs then
if needed_logs then
row
cost = cost + needed_logs * lookup_price(pole_info.log).sell
:na()
end
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } }:done()
elseif buying_logs then
if needed_logs then
cost = cost + needed_logs * lookup_price(pole_info.log).buy
end
else
if weapon.pole then
cost = cost + needed_poles * lookup_price(weapon.pole.name).buy
end
end
if chopping_logs or buying_logs then
row
:na()
end
row
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } }:done()
end
 
row:node(currency._cell(cost, { html = 'yes' }))
row
:td(weapon.level)
:td{ needed .. '&times;', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed } }:done()
:td{ ('[[File:%s.png|link=%s|30px]]'):format(weapon.name, weapon.name), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' }:done()
:td{ '[[' .. weapon.name .. ']]', addClass = 'plinkt-link no-border' }
 
local cost = needed_ores * lookup_price(ingot.ore)
if chopping_logs then
-- No extra cost
elseif buying_logs then
if needed_logs then
cost = cost + needed_logs * lookup_price(pole_info.log)
end
else
if weapon.pole then
cost = cost + needed_poles * lookup_price(weapon.pole.name)
end
end
 
row:node(currency._cell(cost, { html = 'yes' }))
end
 
697

edits