Module:Gemshop: Difference between revisions

From IdleOn MMO Wiki
m (Undo revision 74739 by Kiokurashi (talk))
Tags: Undo Reverted
mNo edit summary
Tag: Manual revert
Line 43: Line 43:
local section = preprocessArg(args.section)
local section = preprocessArg(args.section)
local tabledata = {}
local tabledata = {}
local ret = {}
local ret = ""
-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
for _, item in pairs(data) do
for _, item in pairs(data) do
Line 51: Line 50:
end
end
end
end
local function rowstr (entry)
local maxPurchases = entry.maxPurchases == 100000 and "∞" or entry.maxPurchases
for _, itemdata in pairs(tabledata) do
local extra = entry.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], entry.costIncrement, entry.cost + entry.costIncrement * (entry.maxPurchases - 1)) or ""
local maxPurchases = itemdata.maxPurchases == 100000 and "∞" or itemdata.maxPurchases
local total = (1 < entry.maxPurchases and entry.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (entry.maxPurchases / 2) * (entry.cost * 2 + entry.costIncrement * (entry.maxPurchases - 1))) or ""
local extra = itemdata.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], itemdata.costIncrement, itemdata.cost + itemdata.costIncrement * (itemdata.maxPurchases - 1)) or ""
local namesub = string.sub(entry.name, 1, 3)
local total = (1 < itemdata.maxPurchases and itemdata.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (itemdata.maxPurchases / 2) * (itemdata.cost * 2 + itemdata.costIncrement * (itemdata.maxPurchases - 1))) or ""
local image = (namesub == "Gem" or namesub == "Pda") and entry.mtxName or entry.itemDisplayName
local namesub = string.sub(itemdata.name, 1, 3)
-- if namesub == "Gem" or namesub == "Pda" then
local image
-- image = entry.mtxName
if namesub == "Gem" then
-- else  
image = itemdata.mtxName
-- image = entry.itemDisplayName
elseif namesub == "Pda" then
-- end
image = itemdata.mtxName --"Daily " .. string.sub(itemdata.name, -1) == "0" and "Teleports" or "Minigame Plays"
else  
image = itemdata.itemDisplayName
end
return string.format(
ret = ret .. string.format(
             ROW_TEMPLATE,
             ROW_TEMPLATE,
             image,
             image,
             entry.mtxName,
             itemdata.mtxName,
             entry.desc,
             itemdata.desc,
             maxPurchases,
             maxPurchases,
             entry.cost,
             itemdata.cost,
             extra,
             extra,
             total
             total
         )
         )
    end
for _, itemdata in pairs(tabledata) do
ret[#ret+1] = rowstr(itemdata)
end
end


return table.concat(ret)
return ret
end
end


return p
return p

Revision as of 13:53, 6 March 2024

Data Here

The data is raw data without any conversion

Maintenance Procedure: simply update the return value of ha.MTXinfo() in N.js


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

-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
local ROW_TEMPLATE = [=[<tr>
<td>[[File:%s.png|50px]]</td>
<td>%s</td>
<td>%s</td>
<td style="text-align:center;">%s</td>
<td>'''Base:''' %d%s%s</td>
</tr>]=]

-- Gemshop data format.
--    {
--        "section": "Hats",
--        "name": "EquipmentHats46",
--        "mtxName": "Strawbiggy",
--        "itemDisplayName": "Strawbiggy",
--        "desc": "This is the ACTUAL strawberry from the Buddhist story about the Tiger and the Strawberry. No wonder the dangling man thought it so tasty!",
--        "cost": 250,
--        "no": 3,
--        "maxPurchases": 100000,
--        "qty": 1,
--        "costIncrement": 0
--    },


-- 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

function p.bySections(frame)
	local args = frame.args
	local section = preprocessArg(args.section)
	local tabledata = {}
	local ret = ""
	
	for _, item in pairs(data) do
		if item.section == section then
			tabledata[#tabledata+1] = item
		end
	end
	
	for _, itemdata in pairs(tabledata) do
		local maxPurchases = itemdata.maxPurchases == 100000 and "∞" or itemdata.maxPurchases
		local extra = itemdata.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], itemdata.costIncrement, itemdata.cost + itemdata.costIncrement * (itemdata.maxPurchases - 1)) or ""
		local total = (1 < itemdata.maxPurchases and itemdata.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (itemdata.maxPurchases / 2) * (itemdata.cost * 2 + itemdata.costIncrement * (itemdata.maxPurchases - 1))) or ""
		local namesub = string.sub(itemdata.name, 1, 3)
		local image
		if namesub == "Gem" then
			image = itemdata.mtxName
		elseif namesub == "Pda" then
			image = itemdata.mtxName --"Daily " .. string.sub(itemdata.name, -1) == "0" and "Teleports" or "Minigame Plays"
		else 
			image = itemdata.itemDisplayName
		end
		
		ret = ret .. string.format(
            ROW_TEMPLATE,
            image,
            itemdata.mtxName,
            itemdata.desc,
            maxPurchases,
            itemdata.cost,
            extra,
            total
        )
	end

	return ret
	
end

return p