Module:SourcesQuery: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary |
Kiokurashi (talk | contribs) mNo edit summary |
||
Line 4: | Line 4: | ||
function p.Main( frame ) | function p.Main( frame ) | ||
local item = frame.args.item | local item = frame.args.item | ||
local result = '' | local result, fullresult, recipe, drops, quests, shops, other = '' | ||
recipe = SmithingSources(item) | |||
drops = DropTableSources(item) | |||
quests = QuestSources(item) | |||
shops = VendorSources(item) | |||
other = CustomSources(item) | |||
mw.ext.VariablesLua.vardefine('Sources', | if (#recipe + #drops + #quests + #shops + #other) == 0 then | ||
result, fullresult = 'Unobtainable' | |||
else | |||
if #recipe > 0 then | |||
result = result .. recipe | |||
fullresult = fullresult .. recipe | |||
end | |||
if #drops > 0 then | |||
if #result > 0 then | |||
result = result .. ', ' | |||
fullresult = fullresult .. ', ' | |||
end -- If there was other sources, then insert divider. | |||
if #drops < 150 then | |||
result = result .. drops | |||
else | |||
result = result .. "Many Drop Tables (Check Item Page)" | |||
end | |||
fullresult = fullresult .. drops | |||
end | |||
if #quests > 0 then | |||
if #result > 0 then | |||
result = result .. ', ' | |||
fullresult = fullresult .. ', ' | |||
end -- If there was other sources, then insert divider. | |||
if #quests < 150 then | |||
result = result .. quests | |||
else | |||
result = result .. "Many Quest Rewards (Check Item Page)" | |||
end | |||
fullresult = fullresult .. quests | |||
end | |||
if #shops > 0 then | |||
if #result > 0 then | |||
result = result .. ', ' | |||
fullresult = fullresult .. ', ' | |||
end -- If there was other sources, then insert divider. | |||
result = result .. shops | |||
fullresult = fullresult .. shops | |||
end | |||
if #other > 0 then | |||
if #result > 0 then | |||
result = result .. ', ' | |||
fullresult = fullresult .. ', ' | |||
end -- If there was other sources, then insert divider. | |||
if #other < 200 then | |||
result = result .. other | |||
else | |||
result = result .. "A lot of other sources (Check Item Page)" | |||
end | |||
fullresult = fullresult .. other | |||
end | |||
end | |||
mw.ext.VariablesLua.vardefine('Sources', fullresult) -- Set LuaVar variable Sources so that we don't need to re-query on the same page. | |||
return result | return result | ||
end | end | ||
function SmithingSources(item | function SmithingSources(item) | ||
local tables = 'AnvilCraft' | local tables = 'AnvilCraft' | ||
local fields = 'RecipeFrom' | local fields = 'RecipeFrom' | ||
local temp = | local temp = '' | ||
-- _pageName LIKE "{{{1|{{PAGENAME}}}}}" | -- _pageName LIKE "{{{1|{{PAGENAME}}}}}" | ||
local args = { | local args = { | ||
Line 39: | Line 91: | ||
end | end | ||
function DropTableSources(item | function DropTableSources(item) | ||
local tables = 'DropTables' | local tables = 'DropTables' | ||
local fields = 'DropSourceEntity' | local fields = 'DropSourceEntity' | ||
local temp = | local temp = '' | ||
-- DropItem="{{{1|{{PAGENAME}}}}}" AND NOT DropSourceEntity LIKE "%DropTable%" | -- DropItem="{{{1|{{PAGENAME}}}}}" AND NOT DropSourceEntity LIKE "%DropTable%" | ||
local args = { | local args = { | ||
Line 51: | Line 103: | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return temp end -- if no results, return original string and continue. | if #results == 0 then return temp end -- if no results, return original string and continue. | ||
for r = 1, #results do | for r = 1, #results do | ||
if r > 1 then temp = temp .. ', ' end | if r > 1 then temp = temp .. ', ' end | ||
Line 61: | Line 112: | ||
end | end | ||
function QuestSources(item | function QuestSources(item) | ||
local tables = 'Quests' | local tables = 'Quests' | ||
local fields = '_pageName' | local fields = '_pageName' | ||
local temp = | local temp = '' | ||
-- Rewards HOLDS LIKE "%>{{{1|{{PAGENAME}}}}}<%" | -- Rewards HOLDS LIKE "%>{{{1|{{PAGENAME}}}}}<%" | ||
local args = { | local args = { | ||
Line 72: | Line 123: | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return temp end -- if no results, return original string and continue. | if #results == 0 then return temp end -- if no results, return original string and continue. | ||
for r = 1, #results do | for r = 1, #results do | ||
if r > 1 then temp = temp .. ', ' end | if r > 1 then temp = temp .. ', ' end | ||
Line 82: | Line 132: | ||
end | end | ||
function VendorSources(item | function VendorSources(item) | ||
local tables = 'VendorItems' | local tables = 'VendorItems' | ||
local fields = 'Vendor' | local fields = 'Vendor' | ||
local temp = | local temp = '' | ||
-- Item="{{{1|{{PAGENAME}}}}}" | -- Item="{{{1|{{PAGENAME}}}}}" | ||
local args = { | local args = { | ||
Line 93: | Line 143: | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return temp end -- if no results, return original string and continue. | if #results == 0 then return temp end -- if no results, return original string and continue. | ||
for r = 1, #results do | for r = 1, #results do | ||
if r > 1 then temp = temp .. ', ' end | if r > 1 then temp = temp .. ', ' end | ||
Line 103: | Line 152: | ||
end | end | ||
function CustomSources(item | function CustomSources(item) | ||
local tables = 'Sources' | local tables = 'Sources' | ||
local fields = 'Link, SpecialText, EventRules' | local fields = 'Link, SpecialText, EventRules' | ||
local temp = | local temp = '' | ||
-- Item="{{{1|{{PAGENAME}}}}}" | -- Item="{{{1|{{PAGENAME}}}}}" | ||
local args = { | local args = { | ||
Line 114: | Line 163: | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return temp end -- if no results, return original string and continue. | if #results == 0 then return temp end -- if no results, return original string and continue. | ||
local EventRulesCounter = 0 | local EventRulesCounter = 0 | ||
for r = 1, #results do | for r = 1, #results do | ||
Line 124: | Line 172: | ||
if sText ~= 'None' then temp = temp .. ' (' .. sText .. ')' end | if sText ~= 'None' then temp = temp .. ' (' .. sText .. ')' end | ||
end | end | ||
if EventRulesCounter > 0 then temp = temp .. "<br/>'' | if EventRulesCounter > 0 then temp = temp .. "<br/>''Additional Event drop.''" end | ||
return temp | return temp |
Revision as of 18:54, 2 March 2023
Documentation for this module may be created at Module:SourcesQuery/doc
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
local item = frame.args.item
local result, fullresult, recipe, drops, quests, shops, other = ''
recipe = SmithingSources(item)
drops = DropTableSources(item)
quests = QuestSources(item)
shops = VendorSources(item)
other = CustomSources(item)
if (#recipe + #drops + #quests + #shops + #other) == 0 then
result, fullresult = 'Unobtainable'
else
if #recipe > 0 then
result = result .. recipe
fullresult = fullresult .. recipe
end
if #drops > 0 then
if #result > 0 then
result = result .. ', '
fullresult = fullresult .. ', '
end -- If there was other sources, then insert divider.
if #drops < 150 then
result = result .. drops
else
result = result .. "Many Drop Tables (Check Item Page)"
end
fullresult = fullresult .. drops
end
if #quests > 0 then
if #result > 0 then
result = result .. ', '
fullresult = fullresult .. ', '
end -- If there was other sources, then insert divider.
if #quests < 150 then
result = result .. quests
else
result = result .. "Many Quest Rewards (Check Item Page)"
end
fullresult = fullresult .. quests
end
if #shops > 0 then
if #result > 0 then
result = result .. ', '
fullresult = fullresult .. ', '
end -- If there was other sources, then insert divider.
result = result .. shops
fullresult = fullresult .. shops
end
if #other > 0 then
if #result > 0 then
result = result .. ', '
fullresult = fullresult .. ', '
end -- If there was other sources, then insert divider.
if #other < 200 then
result = result .. other
else
result = result .. "A lot of other sources (Check Item Page)"
end
fullresult = fullresult .. other
end
end
mw.ext.VariablesLua.vardefine('Sources', fullresult) -- Set LuaVar variable Sources so that we don't need to re-query on the same page.
return result
end
function SmithingSources(item)
local tables = 'AnvilCraft'
local fields = 'RecipeFrom'
local temp = ''
-- _pageName LIKE "{{{1|{{PAGENAME}}}}}"
local args = {
where = 'AnvilCraft.Item="'.. item ..'"',
orderBy = 'AnvilCraft.Item'
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return temp end -- if no results, return original string and continue.
for r = 1, #results do
if r > 1 then temp = temp .. ', ' end
local from = ' '
if 'Start' ~= results[r].RecipeFrom then
from = ' (' .. results[r].RecipeFrom .. ')'
end
temp = temp .. '[[Smithing]]' .. from
end
return temp
end
function DropTableSources(item)
local tables = 'DropTables'
local fields = 'DropSourceEntity'
local temp = ''
-- DropItem="{{{1|{{PAGENAME}}}}}" AND NOT DropSourceEntity LIKE "%DropTable%"
local args = {
where = 'DropTables.DropItem="'.. item ..'" AND NOT DropTables.DropSourceEntity LIKE "%DropTable%"',
groupBy = 'DropTables.DropSourceEntity',
orderBy = 'DropTables.DropSourceEntity ASC'
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return temp end -- if no results, return original string and continue.
for r = 1, #results do
if r > 1 then temp = temp .. ', ' end
local source = results[r].DropSourceEntity
temp = temp .. '[[' .. source .. ']]'
end
return temp
end
function QuestSources(item)
local tables = 'Quests'
local fields = '_pageName'
local temp = ''
-- Rewards HOLDS LIKE "%>{{{1|{{PAGENAME}}}}}<%"
local args = {
where = 'Quests.Rewards HOLDS LIKE "%>'.. item ..'<%"',
groupBy = 'Quests._pageName',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return temp end -- if no results, return original string and continue.
for r = 1, #results do
if r > 1 then temp = temp .. ', ' end
local source = results[r]._pageName
temp = temp .. '[[' .. source .. ']]'
end
return temp
end
function VendorSources(item)
local tables = 'VendorItems'
local fields = 'Vendor'
local temp = ''
-- Item="{{{1|{{PAGENAME}}}}}"
local args = {
where = 'VendorItems.Item="'.. item ..'"',
orderBy = 'VendorItems.Vendor',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return temp end -- if no results, return original string and continue.
for r = 1, #results do
if r > 1 then temp = temp .. ', ' end
local vendor = results[r].Vendor
temp = temp .. '[[Vendors#' .. vendor .. '|' .. vendor .. ']]'
end
return temp
end
function CustomSources(item)
local tables = 'Sources'
local fields = 'Link, SpecialText, EventRules'
local temp = ''
-- Item="{{{1|{{PAGENAME}}}}}"
local args = {
where = 'Sources.Item="'.. item ..'"',
orderBy = 'Sources.Source',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return temp end -- if no results, return original string and continue.
local EventRulesCounter = 0
for r = 1, #results do
if r > 1 then temp = temp .. ', ' end
local link = results[r].Link
local sText = results[r].SpecialText
EventRulesCounter = EventRulesCounter + results[r].EventRules
temp = temp .. '[[' .. link .. ']]'
if sText ~= 'None' then temp = temp .. ' (' .. sText .. ')' end
end
if EventRulesCounter > 0 then temp = temp .. "<br/>''Additional Event drop.''" end
return temp
end
-- This one is just to get the Drop Chance value for an Item.
function p.DropChance(frame)
local item = frame.args.item
local result = ''
local tables = 'DropTables'
local fields = 'DropRate'
-- DropItem="{{{1|{{PAGENAME}}}}}" AND NOT DropSourceEntity LIKE "%DropTable%"
local args = {
where = 'DropTables.DropItem LIKE "'.. item ..'"',
groupBy = 'DropTables.DropItem',
orderBy = 'DropTables.DropRate DESC' -- For any item with multiple drop sources, get the highest one.
}
local results = cargo.query( tables, fields, args )
if #results == 0 then result = 0 else result = results[1].DropRate end
mw.ext.VariablesLua.vardefine('Chance', result)
return result
end
return p