Module:Item spawns: Difference between revisions

From The Cycle: Frontier Wiki
mNo edit summary
mNo edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {} --p stands for package
local p = {} --p stands for package


p.items = mw.loadJsonData( "User:VeryGreatFrog/sandbox2" )
p.items = mw.loadJsonData( "Module:Item infobox/itemData.json" )
p.lootPools = mw.loadJsonData( "User:VeryGreatFrog/sandbox3" )
p.lootPools = mw.loadJsonData( "Module:Item spawns/lootPoolData.json" )
p.containers = mw.loadJsonData( "User:VeryGreatFrog/sandbox4" )
p.containers = mw.loadJsonData( "Module:Item spawns/containerData.json" )


local args = mw.getCurrentFrame().args
local args = mw.getCurrentFrame().args
Line 15: Line 15:


function p.main( frame )
function p.main( frame )
local output = ""
local encodedName = mw.uri.encode(p.items[p.item]["inGameName"])
local par = nil;
if args[2] == 'hide text' then
par = ''
else
par = mw.html.create( "p" )
par:wikitext("\'\'\'" .. p.items[p.item]["inGameName"] .. "\'\'\' can be found in many locations of [[Fortuna III]]. Find all of its spawns on our Interactive Map: " .. mw.text.nowiki( "[" ) .. "[https://tools.thecyclefrontier.wiki/map?map=1&item="..encodedName.." BS]" ..mw.text.nowiki( "] [" ) .."[https://tools.thecyclefrontier.wiki/map?map=2&item="..encodedName.." CF]".. mw.text.nowiki( "] [" ) .. "[https://tools.thecyclefrontier.wiki/map?map=3&item="..encodedName.." TI]" .. mw.text.nowiki( "]") .. ".<br> Specifically, it can be found in the following [[Loot Container]]s, depending on the tier. This list does not include non-container or special spawns." )
  :addClass( "plainlinks")
end
 
local tab = "<table class=\"wikitable sortable\"><caption>Spawn chance per container</caption><tr><th>Container</th><th>Max spawn chance</th></tr>"
 
for container, pools in pairs(p.containers) do
for container, pools in pairs(p.containers) do
local firstOccuranceOfContainer = true
for _, pool in ipairs(pools) do
for _, pool in ipairs(pools) do
local curPools = p.lootPools[pool]
local curPools = p.lootPools[pool]
Line 22: Line 34:
-- check if this item (the key) is in the spawns
-- check if this item (the key) is in the spawns
if curPools["items"][p.item] ~= nil then
if curPools["items"][p.item] ~= nil then
output = output .. pool .. " " .. tostring(curPools["items"][p.item]["chance"]) .. " <br>"
local nameOfContainer = ''
if firstOccuranceOfContainer == true then
nameOfContainer = "[[" .. tostring(container) .. "]]"
else
nameOfContainer = container
end
tab = tab .. "<tr><td>" .. nameOfContainer .. " Tier " .. tonumber(curPools["tier"]) .. "</td><td>" .. tostring(round(curPools["items"][p.item]["chance"], 2)) .. "% </td></tr>"
firstOccuranceOfContainer = false
end
end
end
end
end
end
end
end
return tostring (output)  
tab = tab .. "</table>"
return tostring(par) .. tostring (tab)
end
 
-- thanks http://lua-users.org/wiki/SimpleRound
function round(num, numDecimalPlaces)
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end
end


return p
return p

Latest revision as of 21:08, 31 May 2023

This module spits out the containers that specific item can spawn in, including chances. Does not show other special spawns or ground spawns.

Parameters

Must always call the main function. The second argument must be the exact name of an item.

Example

{{#invoke:Item spawns|main|Pure Veltecite}}

local p = {} --p stands for package

p.items = mw.loadJsonData( "Module:Item infobox/itemData.json" )
p.lootPools = mw.loadJsonData( "Module:Item spawns/lootPoolData.json" )
p.containers = mw.loadJsonData( "Module:Item spawns/containerData.json" )

local args = mw.getCurrentFrame().args

for k, v in pairs(p.items) do
    if args[1] == v["inGameName"] then
        p.item = k
        break
    end
end

function p.main( frame )
	local encodedName = mw.uri.encode(p.items[p.item]["inGameName"])
	local par = nil;
	if args[2] == 'hide text' then
		par = ''	
	else 
		par = mw.html.create( "p" )
		par:wikitext("\'\'\'" .. p.items[p.item]["inGameName"] .. "\'\'\' can be found in many locations of [[Fortuna III]]. Find all of its spawns on our Interactive Map: " .. mw.text.nowiki( "[" ) .. "[https://tools.thecyclefrontier.wiki/map?map=1&item="..encodedName.." BS]" ..mw.text.nowiki( "] [" ) .."[https://tools.thecyclefrontier.wiki/map?map=2&item="..encodedName.." CF]".. mw.text.nowiki( "] [" ) .. "[https://tools.thecyclefrontier.wiki/map?map=3&item="..encodedName.." TI]" .. mw.text.nowiki( "]") .. ".<br> Specifically, it can be found in the following [[Loot Container]]s, depending on the tier. This list does not include non-container or special spawns." )
		   :addClass( "plainlinks")
	end
	   
	local tab = "<table class=\"wikitable sortable\"><caption>Spawn chance per container</caption><tr><th>Container</th><th>Max spawn chance</th></tr>"

	for container, pools in pairs(p.containers) do
		local firstOccuranceOfContainer = true
		for _, pool in ipairs(pools) do
			local curPools = p.lootPools[pool]
			if curPools then
				-- check if this item (the key) is in the spawns
				if curPools["items"][p.item] ~= nil then
					local nameOfContainer = ''
					if firstOccuranceOfContainer == true then
						nameOfContainer = "[[" .. tostring(container) .. "]]"
					else
						nameOfContainer = container
					end
					tab = tab .. "<tr><td>" .. nameOfContainer .. " Tier " .. tonumber(curPools["tier"]) .. "</td><td>" .. tostring(round(curPools["items"][p.item]["chance"], 2)) .. "% </td></tr>"
					firstOccuranceOfContainer = false
				end
			end
		end

	end
	tab = tab .. "</table>"
	return tostring(par) .. tostring (tab) 
end

-- thanks http://lua-users.org/wiki/SimpleRound
function round(num, numDecimalPlaces)
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.