Module:PGVillagerItemOutput

local p = {} local cargo = mw.ext.cargo

function tableEmpty(s) if s == nil then return s == nil or s == '' else return next(s) == nil end end

function isEmpty(s) return s == nil or s == '' end

function p.furnitureOutput( frame ) local print = ''

-- Cargo query for pg_house and pg_villager (Doubutsu no Mori) local tables1 = 'pg_house,pg_villager' local fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" local args1 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'pg_house.villager', limit = 300, default = '' }   local resultsDnM = cargo.query( tables1, fields1, args1 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+) local tables2 = 'pg_house,pg_villager' local fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" local args2 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'pg_house.villager', limit = 300, default = '' }   local resultsDnMplus = cargo.query( tables2, fields2, args2 ) -- Cargo query for pg_house and pg_villager (Animal Crossing) local tables3 = 'pg_house,pg_villager' local fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" local args3 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'PG' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'pg_house.villager', limit = 300, default = '' }   local resultsPG = cargo.query( tables3, fields3, args3 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+) local tables4 = 'pg_house,pg_villager' local fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" local args4 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DmMe+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'pg_house.villager', limit = 300, default = '' }   local resultsDnMeplus = cargo.query( tables4, fields4, args4 ) if not tableEmpty(resultsDnM) then print = print .. "In Doubutsu no Mori, this item appears in the homes of " for r = 1, #resultsDnM do	   	if r == #resultsDnM and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnM[r].villager .. "" if r == #resultsDnM then print = print .. '.'	       elseif r-1 == 0 and r+1 == #resultsDnM then print = print .. ' '	       else print = print .. ', '	       end end if not tableEmpty(resultsDnMplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMplus) then print = print .. "In Doubutsu no Mori+, this item appears in the homes of " for r = 1, #resultsDnMplus do	   	if r == #resultsDnMplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMplus[r].villager .. "" if r == #resultsDnMplus then print = print .. '.'	       elseif r-1 == 0 and r+1 == #resultsDnMplus then print = print .. ' '	       else print = print .. ', '	       end end if not tableEmpty(resultsPG) then print = print .. "\n\n" end end if not tableEmpty(resultsPG) then print = print .. "In Animal Crossing, this item appears in the homes of " for r = 1, #resultsPG do	   	if r == #resultsPG and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsPG[r].villager .. "" if r == #resultsPG then print = print .. '.'	       elseif r-1 == 0 and r+1 == #resultsPG then print = print .. ' '	       else print = print .. ', '	       end end if not tableEmpty(resultsDnMeplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMeplus) then print = print .. "In Doubutsu no Mori e+, this item appears in the homes of " for r = 1, #resultsDnMeplus do	   	if r == #resultsDnMeplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMeplus[r].villager .. "" if r == #resultsDnMeplus then print = print .. '.'	       elseif r-1 == 0 and r+1 == #resultsDnMeplus then print = print .. ' '	       else print = print .. ', '	       end end end if not tableEmpty(resultsDnM) or not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then print = print .. "\n\nFor villagers who have the " .. frame.args['1'] .. " placed on the floor in their house, there is a chance that the villager will gift it to the player." end if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then print = print .. "No villagers have this item in their home." end return print end

function p.clothingOutput( frame ) local print = ''

-- Cargo query for pg_villager (Doubutsu no Mori) local tables1 = 'pg_villager' local fields1 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName" local args1 = { where = "pg_villager.clothing_dnm = '" .. frame.args['1']:gsub("\'","\\'").. "'",       orderBy = 'pg_villager.romanized_name', limit = 300, default = '' }   local resultsDnM = cargo.query( tables1, fields1, args1 ) -- Cargo query for pg_villager (Doubutsu no Mori+) local tables2 = 'pg_villager' local fields2 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName" local args2 = { where = "pg_villager.clothing_plus = '" .. frame.args['1']:gsub("\'","\\'").. "'",       orderBy = 'pg_villager.romanized_name', limit = 300, default = '' }   local resultsDnMplus = cargo.query( tables2, fields2, args2 ) -- Cargo query for pg_villager (Animal Crossing) local tables3 = 'pg_villager' local fields3 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName" local args3 = { where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=1", orderBy = 'pg_villager.romanized_name', limit = 300, default = '' }   local resultsPG = cargo.query( tables3, fields3, args3 ) -- Cargo query for pg_villager (Doubutsu no Mori e+) local tables4 = 'pg_villager' local fields4 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName" local args4 = { where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=0", orderBy = 'pg_villager.romanized_name', limit = 300, default = '' }   local resultsDnMeplus = cargo.query( tables4, fields4, args4 ) if not tableEmpty(resultsDnM) then print = print .. "In Doubutsu no Mori, this item is worn by " for r = 1, #resultsDnM do	   	if r == #resultsDnM and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnM[r].villager .. "" if r == #resultsDnM then print = print .. ' '	       elseif r-1 == 0 and r+1 == #resultsDnM then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default outfit." if not tableEmpty(resultsDnMplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMplus) then print = print .. "In Doubutsu no Mori+, this item is worn by " for r = 1, #resultsDnMplus do	   	if r == #resultsDnMplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMplus[r].villager .. "" if r == #resultsDnMplus then print = print .. ' '	       elseif r-1 == 0 and r+1 == #resultsDnMplus then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default outfit." if not tableEmpty(resultsPG) then print = print .. "\n\n" end end if not tableEmpty(resultsPG) then print = print .. "In Animal Crossing, this item is worn by " for r = 1, #resultsPG do	   	if r == #resultsPG and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsPG[r].villager .. "" if r == #resultsPG then print = print .. ' '	       elseif r-1 == 0 and r+1 == #resultsPG then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default outfit." if not tableEmpty(resultsDnMeplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMeplus) then print = print .. "In Doubutsu no Mori e+, this item is worn by " for r = 1, #resultsDnMeplus do	   	if r == #resultsDnMeplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMeplus[r].villager .. "" if r == #resultsDnMeplus then print = print .. ' '	       elseif r-1 == 0 and r+1 == #resultsDnMeplus then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default outfit." end if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then print = print .. "No villagers wear this item as their default outfit." end return print end

function p.umbrellaOutput( frame ) local print = ''

-- Cargo query for pg_villager local tables = 'pg_villager' local fields = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName" local args = { where = "pg_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "'",       orderBy = 'pg_villager.romanized_name', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) if not tableEmpty(results) then print = print .. "This item is used by " for r = 1, #results do	   	if r == #results and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results[r].villager .. "" if r == #results then print = print .. ' '	       elseif r-1 == 0 and r+1 == #results then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default umbrella during periods of rain." else print = print .. "No villagers use this item as their default umbrella during periods of rain." end return print end

function p.interiorOutput( frame ) local print = ''

-- Declare variables local tables1 local fields1 local args1 local resultsDnM local tables2 local fields2 local args2 local resultsDnMplus local tables3 local fields3 local args3 local resultsPG local tables4 local fields4 local args4 local resultsDnMeplus -- Switch between wallpaper and flooring if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then -- Cargo query for pg_house and pg_villager (Doubutsu no Mori) tables1 = 'pg_house,pg_villager' fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args1 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnM = cargo.query( tables1, fields1, args1 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+) tables2 = 'pg_house,pg_villager' fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args2 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnMplus = cargo.query( tables2, fields2, args2 ) -- Cargo query for pg_house and pg_villager (Animal Crossing) tables3 = 'pg_house,pg_villager' fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args3 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'PG' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsPG = cargo.query( tables3, fields3, args3 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+) tables4 = 'pg_house,pg_villager' fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args4 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DmMe+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnMeplus = cargo.query( tables4, fields4, args4 ) elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then -- Cargo query for pg_house and pg_villager (Doubutsu no Mori) tables1 = 'pg_house,pg_villager' fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args1 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnM = cargo.query( tables1, fields1, args1 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+) tables2 = 'pg_house,pg_villager' fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args2 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DnM+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnMplus = cargo.query( tables2, fields2, args2 ) -- Cargo query for pg_house and pg_villager (Animal Crossing) tables3 = 'pg_house,pg_villager' fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args3 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'PG' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsPG = cargo.query( tables3, fields3, args3 ) -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+) tables4 = 'pg_house,pg_villager' fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName" args4 = { join = 'pg_villager.romanized_name = pg_house.villager', where = "pg_house.game HOLDS 'DmMe+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'pg_house.villager', limit = 300, default = '' }	   resultsDnMeplus = cargo.query( tables4, fields4, args4 ) end

if not tableEmpty(resultsDnM) then print = print .. "In Doubutsu no Mori, this item appears in the homes of " for r = 1, #resultsDnM do	   	if r == #resultsDnM and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnM[r].villager .. "" if r == #resultsDnM then print = print .. ''	       elseif r-1 == 0 and r+1 == #resultsDnM then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then print = print .. ' as the default wallpaper.' elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then print = print .. ' as the default flooring.' end if not tableEmpty(resultsDnMplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMplus) then print = print .. "In Doubutsu no Mori+, this item appears in the homes of " for r = 1, #resultsDnMplus do	   	if r == #resultsDnMplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMplus[r].villager .. "" if r == #resultsDnMplus then print = print .. ''	       elseif r-1 == 0 and r+1 == #resultsDnMplus then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then print = print .. ' as the default wallpaper.' elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then print = print .. ' as the default flooring.' end if not tableEmpty(resultsPG) then print = print .. "\n\n" end end if not tableEmpty(resultsPG) then print = print .. "In Animal Crossing, this item appears in the homes of " for r = 1, #resultsPG do	   	if r == #resultsPG and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsPG[r].villager .. "" if r == #resultsPG then print = print .. ''	       elseif r-1 == 0 and r+1 == #resultsPG then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then print = print .. ' as the default wallpaper.' elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then print = print .. ' as the default flooring.' end if not tableEmpty(resultsDnMeplus) then print = print .. "\n\n" end end if not tableEmpty(resultsDnMeplus) then print = print .. "In Doubutsu no Mori e+, this item appears in the homes of " for r = 1, #resultsDnMeplus do	   	if r == #resultsDnMeplus and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsDnMeplus[r].villager .. "" if r == #resultsDnMeplus then print = print .. ''	       elseif r-1 == 0 and r+1 == #resultsDnMeplus then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then print = print .. ' as the default wallpaper.' elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then print = print .. ' as the default flooring.' end end if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then print = print .. "No villagers have this item in their home." end return print end

return p