Editing Module:Sandbox/User:Artoire/1
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
current_xp = 24, |
current_xp = 24, |
||
target_xp = 37, |
target_xp = 37, |
||
ingot = ' |
ingot = 'Maloic Adathril Ingot', |
||
profession = 'Stonemason', -- 'Bonewright'/'Stonemason'/'Blacksmith' |
|||
ore_buy = 'true', |
|||
pole_buy = 'none', -- 'none'/'logs'/'pole' |
|||
}) |
}) |
||
]] |
]] |
||
Line 13: | Line 10: | ||
require('Module:Mw.html extension') |
require('Module:Mw.html extension') |
||
local xp = require('Module:Experience') |
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 currency = require('Module:Currency') |
||
local lang = mw.language.getContentLanguage() |
local lang = mw.language.getContentLanguage() |
||
local |
local function lookup_ingots() |
||
if cache.ingots then return cache.ingots end |
|||
local function lookup_ingots(profession) |
|||
local ingots = { |
|||
if _ingots[profession] then |
|||
return _ingots[profession] |
|||
end |
|||
_ingots[profession] = { |
|||
recipes = {}, |
recipes = {}, |
||
order = {} |
order = {} |
||
} |
} |
||
cache.ingots = ingots |
|||
for _, result in ipairs(mw.smw.ask{ |
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'] = '', |
['?Recipe JSON'] = '', |
||
mainlabel = '-', |
mainlabel = '-', |
||
Line 38: | Line 30: | ||
result = mw.text.jsonDecode(result[1]) |
result = mw.text.jsonDecode(result[1]) |
||
local ingot = result.output[1].name |
local ingot = result.output[1].name |
||
ingots.recipes[ingot] = { |
|||
xp = result.xp, |
xp = result.xp, |
||
facility = result.facility, |
facility = result.facility, |
||
Line 45: | Line 37: | ||
level = result.level |
level = result.level |
||
} |
} |
||
table.insert( |
table.insert(ingots.order, ingot) |
||
end |
end |
||
return |
return ingots |
||
end |
end |
||
local function lookup_weapons( |
local function lookup_weapons() |
||
if cache.weapons then return cache.weapons end |
|||
local ingots = lookup_ingots(profession) |
|||
local ingots = lookup_ingots() |
|||
local weapons = {} |
local weapons = {} |
||
cache.weapons = weapons |
|||
for _, result in ipairs(mw.smw.ask{ |
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'] = '', |
['?Recipe JSON'] = '', |
||
mainlabel = '-', |
mainlabel = '-', |
||
Line 66: | Line 56: | ||
local lvl = result['Profession Level A'] |
local lvl = result['Profession Level A'] |
||
result = mw.text.jsonDecode(result[1]) |
result = mw.text.jsonDecode(result[1]) |
||
local ingot |
|||
if not result.passive and result.profession == profession then |
|||
local pole |
|||
for _, material in ipairs(result.materials) do |
|||
local pole |
|||
if ingots.recipes[material.name] then |
|||
assert(not ingot) |
|||
if ingots.recipes[material.name] then |
|||
ingot = material |
|||
else |
|||
ingot = material |
|||
assert(not pole) |
|||
else |
|||
pole = material |
|||
pole = material |
|||
end |
|||
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 |
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 |
end |
||
return weapons |
return weapons |
||
Line 93: | Line 81: | ||
local function _lookup_price_uncached(item) |
local function _lookup_price_uncached(item) |
||
local result = mw.smw.ask{ |
local result = tonumber(mw.smw.ask{ |
||
('[[Sold item::%s]]'):format(item), |
('[[Sold item::%s]]'):format(item), |
||
['?Shop buy price'] = ' |
['?Shop buy price'] = '', |
||
['?Shop sell price'] = 'sell', |
|||
mainlabel = '-' |
mainlabel = '-' |
||
}[1] |
}[1][1]) |
||
return |
return result or -1 |
||
buy = tonumber(result.buy), |
|||
sell = tonumber(result.sell) |
|||
} |
|||
end |
end |
||
cache.lookup_price = cache.lookup_price or {} |
|||
local _lookup_price_cache = {} |
|||
local function lookup_price(item) |
local function lookup_price(item) |
||
cache.lookup_price[item] = cache.lookup_price[item] or _lookup_price_uncached(item) |
|||
return |
return cache.lookup_price[item] |
||
end |
end |
||
Line 131: | Line 115: | ||
end |
end |
||
cache.lookup_pole = cache.lookup_pole or {} |
|||
local _lookup_pole_cache = {} |
|||
local function lookup_pole(pole) |
local function lookup_pole(pole) |
||
cache.lookup_pole[pole] = cache.lookup_pole[pole] or _lookup_pole_uncached(pole) |
|||
return |
return cache.lookup_pole[pole] |
||
end |
end |
||
Line 148: | Line 132: | ||
end |
end |
||
cache.lookup_ore = cache.lookup_ore or {} |
|||
local _lookup_ore_cache = {} |
|||
local function lookup_ore(ore) |
local function lookup_ore(ore) |
||
cache.lookup_ore[ore] = cache.lookup_ore[ore] or _lookup_ore_uncached(ore) |
|||
return |
return cache.lookup_ore[ore] |
||
end |
end |
||
local function _lookup_log_uncached(log) |
local function _lookup_log_uncached(log) |
||
local data = mw.smw.ask{ |
local data = mw.smw.ask{ |
||
('[[%s]]'):format( |
('[[%s]]'):format(ore), |
||
['?Profession Level A'] = '', |
['?Profession Level A'] = '', |
||
mainlabel = '-' |
mainlabel = '-' |
||
Line 165: | Line 149: | ||
end |
end |
||
cache.lookup_log = cache.lookup_log or {} |
|||
local _lookup_log_cache = {} |
|||
local function lookup_log(log) |
local function lookup_log(log) |
||
cache.lookup_log[log] = cache.lookup_log[log] or _lookup_log_uncached(log) |
|||
return |
return cache.lookup_log[log] |
||
end |
end |
||
Line 175: | Line 159: | ||
local p = {} |
local p = {} |
||
function p.ingots( |
function p.ingots() |
||
return table.concat(lookup_ingots( |
return table.concat(lookup_ingots().order, ',') |
||
end |
end |
||
Line 183: | Line 167: | ||
end |
end |
||
p.w = lookup_weapons |
|||
function p._main(args) |
|||
local profession = args.profession |
|||
function p._main(args) |
|||
local current_xp = tonumber(args.current_xp) or 0 |
local current_xp = tonumber(args.current_xp) or 0 |
||
local current_lvl |
local current_lvl |
||
Line 205: | Line 189: | ||
local remaining_xp = target_xp - current_xp |
local remaining_xp = target_xp - current_xp |
||
local buying_ores = args.ore_buy ~= 'false' |
|||
local buying_poles = args.pole_buy |
local buying_poles = args.pole_buy |
||
Line 213: | Line 195: | ||
buying_poles = not (buying_logs or chopping_logs) |
buying_poles = not (buying_logs or chopping_logs) |
||
local ingot = lookup_ingots( |
local ingot = lookup_ingots().recipes[args.ingot] |
||
local result = mw.html.create() |
local result = mw.html.create() |
||
result:wikitext(('To get from %s xp (level %s) to %s xp (level %s) requires %s experience'):format |
result:wikitext(('To get from %s xp (level %s) to %s xp (level %s) requires %s experience'):format(current_xp, current_lvl, target_xp, target_lvl, remaining_xp)) |
||
local tbl = result:tag('table') |
local tbl = result:tag('table') |
||
Line 226: | Line 208: | ||
end |
end |
||
local colspan = |
local colspan = 24 |
||
if chopping_logs then |
if chopping_logs then |
||
colspan = colspan + |
colspan = colspan + 4 |
||
end |
end |
||
if chopping_logs or buying_logs then |
if chopping_logs or buying_logs then |
||
colspan = colspan + |
colspan = colspan + 1 |
||
end |
end |
||
tbl |
tbl |
||
: |
:tr() |
||
:th(skillclickpic(( |
:th(skillclickpic('Miner')):done() |
||
:th{ 'Ore', attr = { colspan = '3' } }:done() |
|||
Blacksmith = 'Miner', |
|||
:th(skillclickpic('Blacksmith')):done() |
|||
Stonemason = 'Miner', |
|||
:th{ 'Ingot', attr = { colspan = '3' } }: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) |
:IF(chopping_logs) |
||
:th(skillclickpic('Woodcutter') |
:th(skillclickpic('Woodcutter')) |
||
:END() |
|||
:IF(chopping_logs or buying_logs) |
|||
:th{ 'Log', attr = { colspan = '3' } }:done() |
:th{ 'Log', attr = { colspan = '3' } }:done() |
||
:th() |
|||
:th(skillclickpic('Carpenter')):done() |
|||
:IF(chopping_logs or buying_logs) |
|||
:END() |
|||
:th(skillclickpic('Carpenter')) |
|||
:DONE() |
|||
:th{ 'Pole', attr = { colspan = '3' } }:done() |
:th{ 'Pole', attr = { colspan = '3' } }:done() |
||
:th(skillclickpic(profession)):done() |
|||
:th{ 'Product', attr = { colspan = '3' } }:done() |
:th{ 'Product', attr = { colspan = '3' } }:done() |
||
:th{ 'Cost', attr = { colspan = '10' } }:done() |
:th{ 'Cost', attr = { colspan = '10' } }:done() |
||
:done() |
:done() |
||
for _, weapon in |
for _, weapon in lookup_weapons()[ingot.name] do |
||
if not ingot.xp then |
if not ingot.xp then |
||
tbl |
tbl |
||
:tr() |
:tr() |
||
:td{ |
:td{ |
||
'Missing XP for |
'Missing XP for smelting [[' .. ingot.name .. ']]; Please [' .. mw.uri.fullUrl(ingot.name, 'action=edit§ion=1') .. ' edit the page] to add the experience earned (after |exp =)', |
||
attr = { colspan = colspan } |
attr = { colspan = colspan } |
||
} |
} |
||
Line 279: | Line 249: | ||
:tr() |
:tr() |
||
:td{ |
:td{ |
||
'Missing XP for creating [[' .. weapon.name .. ']]; Please ['.. |
'Missing XP for creating [[' .. weapon.name .. ']]; Please ['.. mw.uri.fullUrl(weapon.name, 'action=edit§ion=1') .. ' edit the page] to add the experience earned (after |exp =)', |
||
attr = { colspan = colspan } |
attr = { colspan = colspan } |
||
} |
} |
||
:done() |
:done() |
||
break |
|||
end |
|||
local xp_per = weapon.xp + ingot.xp * weapon.ingot.quantity |
|||
local xp_per = weapon.xp + ingot.xp * weapon.ingot.quantity |
|||
local needed = math.ceil(remaining_xp / xp_per) |
|||
local needed = math.ceil(remaining_xp / xp_per) |
|||
local needed_ores = needed * weapon.ingot.quantity |
|||
local row = tbl |
|||
:tr() |
|||
:td(lookup_ore(ingot.ore).level) |
|||
:td{ needed_ores .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right', ['data-sort-value'] = needed_ores } } |
|||
:td{ ('[[File:%s.png|link=%s|30px]]'):format(ingot.ore), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' } |
|||
:td{ '[[' .. ingot.ore .. ']]', addClass = 'plinkt-link no-border' } |
|||
: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 |
row |
||
:td(lookup_log(pole_info.log).level) |
|||
:td{ needed_poles .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_poles } }:done() |
|||
:td{ |
:td{ needed_logs .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_logs } } |
||
:td{ '[[' |
:td{ ('[[File:%s.png|link=%s|30px]]'):format(pole_info.log), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' } |
||
:td{ '[[' .. pole_info.log .. ']]', addClass = 'plinkt-link no-border' } |
|||
else |
|||
end |
|||
if chopping_logs then |
|||
if chopping_logs or buying_logs then |
|||
row |
|||
pole_info = pole_info or lookup_pole(weapon.pole.name) |
|||
:na() |
|||
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 |
row |
||
:td(pole_info.level) |
|||
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } }:done() |
|||
end |
end |
||
row |
row |
||
:td{ needed_poles .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed_poles } } |
|||
:td(weapon.level) |
|||
:td{ |
:td{ ('[[File:%s.png|link=%s|30px]]'):format(weapon.pole.name), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' } |
||
:td{ |
:td{ '[[' .. weapon.pole.name .. ']]', addClass = 'plinkt-link no-border' } |
||
else |
|||
:td{ '[[' .. weapon.name .. ']]', addClass = 'plinkt-link no-border' } |
|||
local cost = needed_ores * lookup_price(ingot.ore)[buying_ores and 'buy' or 'sell'] |
|||
if chopping_logs then |
if chopping_logs then |
||
row |
|||
if needed_logs then |
|||
:na() |
|||
cost = cost + needed_logs * lookup_price(pole_info.log).sell |
|||
:td{ '<small>N/A</small>', addClass = 'table-na', attr = { ['data-sort-value'] = '0', colspan = '3' } } |
|||
end |
|||
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 |
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' } } |
|||
end |
|||
row |
|||
row:node(currency._cell(cost, { html = 'yes' })) |
|||
:td{ needed .. '×', css = { ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }, attr = { ['data-sort-value'] = needed } } |
|||
:td{ ('[[File:%s.png|link=%s|30px]]'):format(weapon.name), css = { ['border-left'] = '0', ['padding-left'] = '0' }, addClass = 'plinkt-image no-border' } |
|||
: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 |
end |
||
row:node(currency._cell(amount, { html = 'yes' })) |
|||
end |
end |
||