Module:Sandbox/User:Artoire/1: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
mNo edit summary |
mNo edit summary |
||
Line 4: | Line 4: | ||
target_xp = 37, |
target_xp = 37, |
||
ingot = 'Maloic Adathril Ingot', |
ingot = 'Maloic Adathril Ingot', |
||
ore_buy = 'true', |
|||
pole_buy = 'none', -- 'none'/'logs'/'pole' |
|||
}) |
}) |
||
]] |
]] |
||
Line 10: | Line 12: | ||
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 _ingots |
|||
local function lookup_ingots() |
local function lookup_ingots() |
||
if _ingots then |
|||
if cache.ingots then return cache.ingots end |
|||
return _ingots |
|||
local ingots = { |
|||
⚫ | |||
_ingots = { |
|||
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]]', |
'[[Uses facility::Goblin Smelter||Gnome Smelter]]', |
||
Line 30: | Line 33: | ||
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 37: | Line 40: | ||
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() |
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]]', |
'[[Uses facility::Goblin Forge||Gnome Forge]]', |
||
Line 93: | Line 94: | ||
end |
end |
||
local _lookup_price_cache = {} |
|||
cache.lookup_price = cache.lookup_price or {} |
|||
local function lookup_price(item) |
local function lookup_price(item) |
||
_lookup_price_cache[item] = _lookup_price_cache[item] or _lookup_price_uncached(item) |
|||
return |
return _lookup_price_cache[item] |
||
end |
end |
||
Line 119: | Line 120: | ||
end |
end |
||
local _lookup_pole_cache = {} |
|||
cache.lookup_pole = cache.lookup_pole or {} |
|||
local function lookup_pole(pole) |
local function lookup_pole(pole) |
||
_lookup_pole_cache[pole] = _lookup_pole_cache[pole] or _lookup_pole_uncached(pole) |
|||
return |
return _lookup_pole_cache[pole] |
||
end |
end |
||
Line 136: | Line 137: | ||
end |
end |
||
local _lookup_ore_cache = {} |
|||
cache.lookup_ore = cache.lookup_ore or {} |
|||
local function lookup_ore(ore) |
local function lookup_ore(ore) |
||
_lookup_ore_cache[ore] = _lookup_ore_cache[ore] or _lookup_ore_uncached(ore) |
|||
return |
return _lookup_ore_cache[ore] |
||
end |
end |
||
Line 153: | Line 154: | ||
end |
end |
||
local _lookup_log_cache = {} |
|||
cache.lookup_log = cache.lookup_log or {} |
|||
local function lookup_log(log) |
local function lookup_log(log) |
||
_lookup_log_cache[log] = _lookup_log_cache[log] or _lookup_log_uncached(log) |
|||
return |
return _lookup_log_cache[log] |
||
end |
end |
||
Line 170: | Line 171: | ||
return p._main(frame:getParent().args) |
return p._main(frame:getParent().args) |
||
end |
end |
||
p.w = lookup_weapons |
|||
function p._main(args) |
function p._main(args) |
||
Line 319: | Line 318: | ||
local cost = needed_ores * lookup_price(ingot.ore)[buying_ores and 'buy' or 'sell'] |
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 chopping_logs then |
||
if needed_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 |
cost = cost + needed_logs * lookup_price(pole_info.log).sell |
||
end |
end |
||
elseif buying_logs then |
elseif buying_logs then |
||
if needed_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 |
cost = cost + needed_logs * lookup_price(pole_info.log).buy |
||
end |
end |
||
else |
else |
||
if weapon.pole then |
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 |
cost = cost + needed_poles * lookup_price(weapon.pole.name).buy |
||
end |
end |
||
end |
end |
||
⚫ | |||
if args.debug then |
|||
dbg.cost = cost |
|||
row |
|||
:td{ mw.text.jsonEncode(dbg), attr = { colspan = "10" } } |
|||
else |
|||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |