Module:SourcesQuery: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary Tag: Manual revert |
Kiokurashi (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local fullList = {} | |||
function p.Main( frame ) | function p.Main( frame ) | ||
local item = frame.args.item | local item = frame.args.item | ||
local result = '' | local result = '' | ||
SmithingSources(item) | |||
DropTableSources(item) | |||
QuestSources(item) | |||
VendorSources(item) | |||
PostOfficeSources(item) | |||
CustomSources(item) | |||
if | if #fullList == 0 then | ||
result = 'Unobtainable' | result = 'Unobtainable' | ||
else | else | ||
result = fullList.concat(', ') | |||
end | end | ||
mw.ext.VariablesLua.vardefine('Sources', | mw.ext.VariablesLua.vardefine('Sources', result) -- Set LuaVar variable Sources so that we don't need to re-query on the same page. | ||
return result | return result | ||
Line 88: | Line 26: | ||
local tables = 'AnvilCraft' | local tables = 'AnvilCraft' | ||
local fields = 'RecipeFrom' | local fields = 'RecipeFrom' | ||
local args = { | local args = { | ||
where = 'AnvilCraft.Item="'.. item ..'"', | where = 'AnvilCraft.Item="'.. item ..'"', | ||
Line 95: | Line 31: | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local from | |||
for r = 1, #results do | for r = 1, #results do | ||
from = 'Start' ~= result[r].RecipeFrom and string.format(' (%)', results[r].RecipeFrom) or '' | |||
fullList[#fullList+1] = '[[Smithing]]' .. from | |||
end | end | ||
end | end | ||
Line 111: | Line 42: | ||
local tables = 'DropTables' | local tables = 'DropTables' | ||
local fields = 'DropSourceEntity' | local fields = 'DropSourceEntity' | ||
local args = { | local args = { | ||
where = 'DropTables.DropItem="'.. item ..'" AND NOT DropTables.DropSourceEntity LIKE "%DropTable%"', | where = 'DropTables.DropItem="'.. item ..'" AND NOT DropTables.DropSourceEntity LIKE "%DropTable%"', | ||
Line 119: | Line 48: | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local source = '' | |||
for r = 1, #results do | for r = 1, #results do | ||
source = results[r].DropSourceEntity | |||
fullList[#fullList+1] = string.format('[[%s]]', source) | |||
end | end | ||
end | end | ||
Line 132: | Line 59: | ||
local tables = 'Quests' | local tables = 'Quests' | ||
local fields = '_pageName' | local fields = '_pageName' | ||
local args = { | local args = { | ||
where = 'Quests.Rewards HOLDS LIKE "%>'.. item ..'<%"', | where = 'Quests.Rewards HOLDS LIKE "%>'.. item ..'<%"', | ||
Line 139: | Line 64: | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local source = '' | |||
for r = 1, #results do | for r = 1, #results do | ||
source = results[r]._pageName | |||
fullList[#fullList+1] = string.format('[[%s]]', source) | |||
end | end | ||
end | end | ||
Line 152: | Line 76: | ||
local tables = 'VendorItems' | local tables = 'VendorItems' | ||
local fields = 'Vendor' | local fields = 'Vendor' | ||
local args = { | local args = { | ||
where = 'VendorItems.Item="'.. item ..'"', | where = 'VendorItems.Item="'.. item ..'"', | ||
Line 159: | Line 81: | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local vendor = '' | |||
for r = 1, #results do | for r = 1, #results do | ||
vendor = results[r].Vendor | |||
fullList[#fullList+1] = string.format('[[Vendors#%s|%s]] (Shop)', vendor, vendor) | |||
end | end | ||
end | end | ||
Line 175: | Line 95: | ||
local tables = 'PORewards' | local tables = 'PORewards' | ||
local fields = 'Company' | local fields = 'Company' | ||
local args = { | local args = { | ||
where = 'PORewards.Item="'.. item ..'"', | where = 'PORewards.Item="'.. item ..'"', | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local company = '' | |||
for r = 1, #results do | for r = 1, #results do | ||
company = results[r].Company | |||
for c = 1, #companies do | for c = 1, #companies do | ||
if company == companies[c] then boolTracker[c] = 1 end | if company == companies[c] then boolTracker[c] = 1 end | ||
Line 188: | Line 108: | ||
end | end | ||
temp = temp .. '[[Post Office#Companies & Rewards|Post Office]] (' | temp = temp .. '[[Post Office#Companies & Rewards|Post Office]] (' | ||
local | local compTable = {} | ||
for b = 1, #boolTracker do | for b = 1, #boolTracker do | ||
if boolTracker[b] == 1 then | if boolTracker[b] == 1 then | ||
compTable[#compTable+1] = string.format('<span class="simple-tooltip simple-tooltip-inline tooltipstered" style="color: #b847cb;" data-simple-tooltip="%s">[[Post Office#%s|%s]]</span>', companies[b], companies[b], shortNames[b]) | |||
end | end | ||
end | end | ||
fullList[#fullList+1] = string.format('[[Post Office#Companies & Rewards|Post Office]] (%s)', compTable.concat(", ")) | |||
end | end | ||
Line 205: | Line 120: | ||
local tables = 'Sources' | local tables = 'Sources' | ||
local fields = 'Link, SpecialText, EventRules' | local fields = 'Link, SpecialText, EventRules' | ||
local args = { | local args = { | ||
where = 'Sources.Item="'.. item ..'"', | where = 'Sources.Item="'.. item ..'"', | ||
Line 212: | Line 125: | ||
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
if #results == 0 then return | if #results == 0 then return end -- if no results, return original string and continue. | ||
local EventRulesCounter = 0 | local EventRulesCounter = 0 | ||
local link = '' | |||
local sText = '' | |||
for r = 1, #results do | for r = 1, #results do | ||
link = results[r].Link | |||
sText = results[r].SpecialText | |||
EventRulesCounter = EventRulesCounter + results[r].EventRules | EventRulesCounter = EventRulesCounter + results[r].EventRules | ||
fullList[#fullList+1] = string.format('[[%s]]%s', link, sText ~= 'None' and string.format(' (%s)', sText) or '') | |||
end | end | ||
if EventRulesCounter > 0 then | -- If item is a special drop then append the following to the last entry so it isn't split by commas later. | ||
if EventRulesCounter > 0 then fullList[#fullList] = fullList[#fullList] .. "<br/>''Additional Event drop.''" end | |||
end | end | ||
Revision as of 03:27, 19 March 2024
Documentation for this module may be created at Module:SourcesQuery/doc
local p = {}
local cargo = mw.ext.cargo
local fullList = {}
function p.Main( frame )
local item = frame.args.item
local result = ''
SmithingSources(item)
DropTableSources(item)
QuestSources(item)
VendorSources(item)
PostOfficeSources(item)
CustomSources(item)
if #fullList == 0 then
result = 'Unobtainable'
else
result = fullList.concat(', ')
end
mw.ext.VariablesLua.vardefine('Sources', result) -- 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 args = {
where = 'AnvilCraft.Item="'.. item ..'"',
orderBy = 'AnvilCraft.Item'
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end -- if no results, return original string and continue.
local from
for r = 1, #results do
from = 'Start' ~= result[r].RecipeFrom and string.format(' (%)', results[r].RecipeFrom) or ''
fullList[#fullList+1] = '[[Smithing]]' .. from
end
end
function DropTableSources(item)
local tables = 'DropTables'
local fields = 'DropSourceEntity'
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 end -- if no results, return original string and continue.
local source = ''
for r = 1, #results do
source = results[r].DropSourceEntity
fullList[#fullList+1] = string.format('[[%s]]', source)
end
end
function QuestSources(item)
local tables = 'Quests'
local fields = '_pageName'
local args = {
where = 'Quests.Rewards HOLDS LIKE "%>'.. item ..'<%"',
groupBy = 'Quests._pageName',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end -- if no results, return original string and continue.
local source = ''
for r = 1, #results do
source = results[r]._pageName
fullList[#fullList+1] = string.format('[[%s]]', source)
end
end
function VendorSources(item)
local tables = 'VendorItems'
local fields = 'Vendor'
local args = {
where = 'VendorItems.Item="'.. item ..'"',
orderBy = 'VendorItems.Vendor',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end -- if no results, return original string and continue.
local vendor = ''
for r = 1, #results do
vendor = results[r].Vendor
fullList[#fullList+1] = string.format('[[Vendors#%s|%s]] (Shop)', vendor, vendor)
end
end
function PostOfficeSources(item)
local companies = {'Simple Shippin', 'Plan-it Express', 'Dudes Next Door', 'Down Undelivery', 'Alpine Suppliers', 'Cosmic Carrier'}
local shortNames = {'SS', 'PE', 'DND', 'DU', 'AS', 'CC'} -- Handling it this way so we can control the order.
local boolTracker = {0, 0, 0, 0, 0, 0} --Used to track which Company offers the same item as a reward.
local tables = 'PORewards'
local fields = 'Company'
local args = {
where = 'PORewards.Item="'.. item ..'"',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end -- if no results, return original string and continue.
local company = ''
for r = 1, #results do
company = results[r].Company
for c = 1, #companies do
if company == companies[c] then boolTracker[c] = 1 end
end
end
temp = temp .. '[[Post Office#Companies & Rewards|Post Office]] ('
local compTable = {}
for b = 1, #boolTracker do
if boolTracker[b] == 1 then
compTable[#compTable+1] = string.format('<span class="simple-tooltip simple-tooltip-inline tooltipstered" style="color: #b847cb;" data-simple-tooltip="%s">[[Post Office#%s|%s]]</span>', companies[b], companies[b], shortNames[b])
end
end
fullList[#fullList+1] = string.format('[[Post Office#Companies & Rewards|Post Office]] (%s)', compTable.concat(", "))
end
function CustomSources(item)
local tables = 'Sources'
local fields = 'Link, SpecialText, EventRules'
local args = {
where = 'Sources.Item="'.. item ..'"',
orderBy = 'Sources.Source',
}
local results = cargo.query( tables, fields, args )
if #results == 0 then return end -- if no results, return original string and continue.
local EventRulesCounter = 0
local link = ''
local sText = ''
for r = 1, #results do
link = results[r].Link
sText = results[r].SpecialText
EventRulesCounter = EventRulesCounter + results[r].EventRules
fullList[#fullList+1] = string.format('[[%s]]%s', link, sText ~= 'None' and string.format(' (%s)', sText) or '')
end
-- If item is a special drop then append the following to the last entry so it isn't split by commas later.
if EventRulesCounter > 0 then fullList[#fullList] = fullList[#fullList] .. "<br/>''Additional Event drop.''" end
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 = 'DropItem, DropRate'
-- DropItem="{{{1|{{PAGENAME}}}}}" AND NOT DropSourceEntity LIKE "%DropTable%"
local args = {
where = 'DropTables.DropItem = "'.. item ..'" AND NOT DropSourceEntity LIKE "%DropTable%"',
orderBy = 'DropTables.DropRate DESC'
}
local results = cargo.query( tables, fields, args )
if #results == 0 then result = 0 else result = '' .. results[1].DropRate end -- Gets the highest drop rate.
mw.ext.VariablesLua.vardefine('Chance', result)
return result
end
return p