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

m
no edit summary
mNo edit summary
Tag: Manual revert
mNo edit summary
 
(4 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 ingots =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{
})({
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{
({
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 ingotpole
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 = ingot,material
else
assert(not pole)
assert(not pole = material)
pole = pole,material
end
end
weapons[ingot.name] = weapons[ingot.name] or {}
table.insert(weapons[ingot.name], {
facility = result.facility,
level = result.level,
assert(notingot = ingot),
assert(notpole = 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 93 ⟶ 105:
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 119 ⟶ 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 136 ⟶ 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
 
Line 153 ⟶ 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 163 ⟶ 175:
local p = {}
 
function p.ingots(frame)
return table.concat(lookup_ingots(frame.args.profession).order, ',')
end
 
Line 170 ⟶ 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 194 ⟶ 206:
local remaining_xp = target_xp - current_xp
 
local buying_ores = args.ore_buy ~= 'nofalse'
 
local buying_poles = args.pole_buy
Line 201 ⟶ 213:
buying_poles = not (buying_logs or chopping_logs)
 
local ingot = lookup_ingots(profession).recipes[args.ingot]
 
local result = mw.html.create()
Line 224 ⟶ 236:
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'
:th{ 'Ore'})[profession], attr = { colspan = '3' } }:done()
:th{ ({
Blacksmith = 'Ingot',
Stonemason = 'Etched',
Bonewright = 'Brewed'
:th{ 'Ingot'})[profession], attr = { colspan = '2' } }:done()
:IF(chopping_logs)
:th(skillclickpic('Woodcutter')):done()
Line 235 ⟶ 259:
: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 }
}
697

edits