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

m
no edit summary
mNo edit summary
mNo edit summary
Line 4:
target_xp = 37,
ingot = 'Maloic Adathril Ingot',
ore_buy = 'true',
pole_buy = 'none', -- 'none'/'logs'/'pole'
})
]]
Line 10 ⟶ 12:
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 _ingots
local function lookup_ingots()
if _ingots then
if cache.ingots then return cache.ingots end
return _ingots
local ingots = {
end
_ingots = {
recipes = {},
order = {}
}
cache.ingots = ingots
for _, result in ipairs(mw.smw.ask{
'[[Uses facility::Goblin Smelter||Gnome Smelter]]',
Line 30 ⟶ 33:
result = mw.text.jsonDecode(result[1])
local ingot = result.output[1].name
ingots_ingots.recipes[ingot] = {
xp = result.xp,
facility = result.facility,
Line 37 ⟶ 40:
level = result.level
}
table.insert(ingots_ingots.order, ingot)
end
return ingots_ingots
end
 
local function lookup_weapons()
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]]',
Line 93 ⟶ 94:
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 ⟶ 120:
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 ⟶ 137:
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 ⟶ 154:
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 170 ⟶ 171:
return p._main(frame:getParent().args)
end
 
p.w = lookup_weapons
 
function p._main(args)
Line 319 ⟶ 318:
 
local cost = needed_ores * lookup_price(ingot.ore)[buying_ores and 'buy' or 'sell']
local dbg = { args = args, needed_ores = needed_ores, lookup_ore = lookup_price(ingot.ore) }
if chopping_logs then
if needed_logs then
dbg.needed_logs = needed_logs
dbg.lookup_chop_log = lookup_price(pole_info.log)
cost = cost + needed_logs * lookup_price(pole_info.log).sell
end
elseif buying_logs then
if needed_logs then
dbg.needed_logs = needed_logs
dbg.lookup_buy_log = lookup_price(pole_info.log)
cost = cost + needed_logs * lookup_price(pole_info.log).buy
end
else
if weapon.pole then
dbg.needed_poles = needed_poles
dbg.lookup_buy_poles = lookup_price(weapon.pole.name)
cost = cost + needed_poles * lookup_price(weapon.pole.name).buy
end
end
 
row:node(currency._cell(cost, { html = 'yes' }))
if args.debug then
dbg.cost = cost
row
:td{ mw.text.jsonEncode(dbg), attr = { colspan = "10" } }
else
row:node(currency._cell(cost, { html = 'yes' }))
end
end
end
697

edits