Gem Shop

From IdleOn MMO Wiki
Revision as of 06:12, 29 July 2024 by Jasaj (talk | contribs)

local mtxinfo = mw.loadJsonData('Module:Gemshop/MTXinfo.json') local p = {}

-- Gemshop/data.json is return value of ha.MTXinfo() in N.js without any conversion

-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff

local ROW_TEMPLATE = [=[ File:%s.png %s %s %s Base: %d%s%s ]=] -- Trim whitespace from args, and treat blank args as nil local function preprocessArg(s) if not s then return nil end s = s:match('^%s*(.-)%s*$') -- trim whitespace if s == then return nil else return s end end -- Convert underscores to spaces local function underscore_to_space(s) return s:gsub('_+', ' ') end -- Convert to title capitalization local function toTitleCase(str) return (str:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end)) end -- Convert raw 4d MTXinfo to 2d table local function mtxinfo_to_2dtable(mtxinfo) local data = {} local index = 1 for tabno, tab in ipairs(mtxinfo) do for sectionno, section in ipairs(tab) do for itemno, item in ipairs(section) do data[index] = { tabno = tabno, sectionno = sectionno, itemno = itemno, display = item[1], name = toTitleCase(underscore_to_space(item[2])), description = underscore_to_space(item[3]), cost = tonumber(item[4]), no = tonumber(item[5]), maxPurchases = tonumber(item[6]), qty = tonumber(item[7]), costIncrement = tonumber(item[8]) } index = index + 1 end end end return data end function p.bySections(frame) local args = frame.args local tab_number = tonumber(preprocessArg(args.tab_number)) + 1 local section_number = tonumber(preprocessArg(args.section_number)) local ret = "" local data = mtxinfo_to_2dtable(mtxinfo) -- TODO for _, item in pairs(data) do if item.tabno == tab_number and item.sectionno == section_number and item.display ~= "Blank" then local maxPurchases = item.maxPurchases == 100000 and "∞" or item.maxPurchases local extra = item.costIncrement > 0 and string.format([[
Increment: %d
Final: %d]], item.costIncrement, item.cost + item.costIncrement * (item.maxPurchases - 1)) or "" local total = (1 < item.maxPurchases and item.maxPurchases < 100000) and string.format([[
Total: %d]], (item.maxPurchases / 2) * (item.cost * 2 + item.costIncrement * (item.maxPurchases - 1))) or "" ret = ret .. string.format( ROW_TEMPLATE, item.display, item.name, item.description, maxPurchases, item.cost, extra, total ) end end return ret end return p