Module:NHVillagerItemOutput

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

function tableEmpty(s) return next(s) == nil end

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

function p.HHPOutput( frame, typeItem ) local print = '' local currency

-- Cargo query for hhp_villager (without facilities) local tables1 = 'hhp_villager' local fields1 = "hhp_villager.name=name,hhp_villager._pageTitle=pageName,hhp_villager.icon=icon" local args1 = { where = "hhp_villager.facility=0 AND (hhp_villager.unlocked_items LIKE '%\"" .. frame.args['1'] .. "\"%' OR hhp_villager.item1 = \"" .. frame.args['1'] .. "\" OR hhp_villager.item2 = \"" .. frame.args['1'] .. "\" OR hhp_villager.item3 = \"" .. frame.args['1'] .. "\")", orderBy = 'hhp_villager.name_sort', groupBy = 'hhp_villager.name_sort', limit = 500, default = '' }   local resultsHHP = cargo.query( tables1, fields1, args1 ) -- Cargo query for hhp_villager (only facilities) local tables2 = 'hhp_villager' local fields2 = "hhp_villager.name=name,hhp_villager._pageTitle=pageName" local args2 = { where = "hhp_villager.facility=1 AND hhp_villager.unlocked_items LIKE '%\"" .. frame.args['1'] .. "\"%'", orderBy = 'hhp_villager.name_sort', groupBy = 'hhp_villager.name_sort', limit = 500, default = '' }   local resultsHHP_Facility = cargo.query( tables2, fields2, args2 ) -- Cargo query for hhp_villager (required items) local tables3 = 'hhp_villager' local fields3 = "hhp_villager.name=name,hhp_villager._pageTitle=pageName,hhp_villager.icon=icon" local args3 = { where = "hhp_villager.facility=0 AND (hhp_villager.item1 = \"" .. frame.args['1'] .. "\" OR hhp_villager.item2 = \"" .. frame.args['1'] .. "\" OR hhp_villager.item3 = \"" .. frame.args['1'] .. "\")", orderBy = 'hhp_villager.name_sort', groupBy = 'hhp_villager.name_sort', limit = 500, default = '' }   local resultsHHP_Required = cargo.query( tables3, fields3, args3 ) -- Cargo query for hhp_villager (required item under category for facilities) local tables4 = 'hhp_facility_category' local fields4 = "hhp_facility_category.category=category,hhp_facility_category.room=room,hhp_facility_category._pageTitle=pageName,hhp_facility_category.facility=facility" local args4 = { where = "hhp_facility_category.items LIKE '%\"" .. frame.args['1'] .. "\"%'", orderBy = 'hhp_facility_category.facility,hhp_facility_category.room', groupBy = 'hhp_facility_category._pageTitle', limit = 500, default = '' }   local resultsHHP_Category = cargo.query( tables4, fields4, args4 ) local tables5 local fields5 local args5 local resultsHHP_Wardell if typeItem == "furniture" then -- Cargo query for nh_furniture (Wardell price) tables5 = 'nh_furniture' fields5 = "nh_furniture.buy2_price=price,nh_furniture.availability2=availability2,nh_furniture.buy2_currency=currency" args5 = { where = "nh_furniture._pageName = \"Item:" .. frame.args['1'] .. " (New Horizons)\"", limit = 2000, groupBy = 'nh_furniture._pageName', default = '', }	   resultsHHP_Wardell = cargo.query( tables5, fields5, args5 ) elseif typeItem == "interior" then -- Cargo query for nh_interior (Wardell price) tables5 = 'nh_interior' fields5 = "nh_interior.buy2_price=price,nh_interior.availability2=availability2,nh_interior.buy2_currency=currency" args5 = { where = "nh_interior._pageName = \"Item:" .. frame.args['1'] .. " (New Horizons)\"", limit = 2000, groupBy = 'nh_interior._pageName', default = '', }	   resultsHHP_Wardell = cargo.query( tables5, fields5, args5 ) end

-- Cargo query for nh_clothing (equipable items) local tables6 = 'nh_clothing' local fields6 = "nh_clothing.vill_equip=equip" local args6 = { where = "nh_clothing._pageName = \"Item:" .. frame.args['1'] .. " (New Horizons)\"", limit = 2000, groupBy = 'nh_clothing._pageName', default = '', }   local resultsVill_Equip = cargo.query( tables6, fields6, args6 ) -- Cargo query for nh_clothing (handbags) local tables7 = 'nh_clothing' local fields7 = "nh_clothing.handbag=handbag" local args7 = { where = "nh_clothing._pageName = \"Item:" .. frame.args['1'] .. " (New Horizons)\"", limit = 2000, groupBy = 'nh_clothing._pageName', default = '', }   local resultsHandbags = cargo.query( tables7, fields7, args7 )

print = print .. "In " .. frame:preprocess('') if (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "starter") then print = print .. ", this item is available from the start for usage in house designing" if not isEmpty(frame.args['clothing']) and not (not isEmpty(resultsHandbags[1].handbag) and resultsHandbags[1].handbag == "1") then print = print .. " and for changing the clothes of" if not isEmpty(resultsVill_Equip[1].equip) and resultsVill_Equip[1].equip == "1" then print = print .. " a villager or" end print = print .. " the player" end print = print .. "."		if not tableEmpty(resultsHHP) then for r = 1, #resultsHHP do		   	if r == #resultsHHP then print = print .. 'and ' end print = print .. " " .. resultsHHP[r].name .. "" if r == #resultsHHP then print = print .. '.'		       else print = print .. ', '		       end end print = print .. " feature this item when doing their vacation home request." end elseif (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "hybrid") then print = print .. ", this item is unlocked for usage in house designing after listening to Leif's lecture at the school regarding hybrid flowers." elseif (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "plant") then print = print .. ", this item is unlocked for usage in house designing when designing the second villager's house." elseif (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "partition") then print = print .. ", this item is unlocked for usage in house designing when designing the eighth villager's house." elseif (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "party") then print = print .. ", this item is unlocked for usage in house designing" if not isEmpty(frame.args['clothing']) and not (not isEmpty(resultsHandbags[1].handbag) and resultsHandbags[1].handbag == "1") then print = print .. " and for changing the clothes of" if not isEmpty(resultsVill_Equip[1].equip) and resultsVill_Equip[1].equip == "1" then print = print .. " a villager or" end print = print .. " the player" end print = print .. " after attending the first party hosted by Lottie for designing ten houses." elseif (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "niko") then print = print .. ", this item is unlocked for usage in house designing after listening to Niko's lecture at the school regarding wooden pillars and counters." else if not tableEmpty(resultsHHP) then print = print .. ", this item is unlocked for usage in house designing" if not isEmpty(frame.args['clothing']) and not (not isEmpty(resultsHandbags[1].handbag) and resultsHandbags[1].handbag == "1") then print = print .. " and for changing the clothes of" if not isEmpty(resultsVill_Equip[1].equip) and resultsVill_Equip[1].equip == "1" then print = print .. " a villager or" end print = print .. " the player" end print = print .. " when doing a vacation home request for " for r = 1, #resultsHHP do		   	if r == #resultsHHP and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsHHP[r].name .. "" if r == #resultsHHP then print = print .. '.'		       elseif r-1 == 0 and r+1 == #resultsHHP then print = print .. ' '		       else print = print .. ', '		       end end end end if not tableEmpty(resultsHHP_Facility) then if not tableEmpty(resultsHHP) then if (not isEmpty(frame.args['hhpstatus']) and frame.args['hhpstatus']:lower == "starter") then print = print .. " The item is also featured in the order list" else print = print .. " The item can also be unlocked" end print = print .. " when designing " for r = 1, #resultsHHP_Facility do		   	if r == #resultsHHP_Facility and r-1 ~= 0 then print = print .. 'and ' end print = print .. "the " .. resultsHHP_Facility[r].name:lower .. "" if r == #resultsHHP_Facility then print = print .. '.'		       elseif r-1 == 0 and r+1 == #resultsHHP_Facility then print = print .. ' '		       else print = print .. ', '		       end end else print = print .. "In " .. frame:preprocess('') .. ", this item is unlocked for usage in house designing" if not isEmpty(frame.args['clothing']) and not (not isEmpty(resultsHandbags[1].handbag) and resultsHandbags[1].handbag == "1") then print = print .. " and for changing the clothes of" if not isEmpty(resultsVill_Equip[1].equip) and resultsVill_Equip[1].equip == "1" then print = print .. " a villager or" end print = print .. " the player" end print = print .. " when tasked with designing " for r = 1, #resultsHHP_Facility do		   	if r == #resultsHHP_Facility and r-1 ~= 0 then print = print .. 'and ' end print = print .. "the " .. resultsHHP_Facility[r].name:lower .. "" if r == #resultsHHP_Facility then print = print .. '.'		       elseif r-1 == 0 and r+1 == #resultsHHP_Facility then print = print .. ' '		       else print = print .. ', '		       end end end end if not tableEmpty(resultsHHP_Required) then if (not tableEmpty(resultsHHP)) or (not tableEmpty(resultsHHP_Facility)) then print = print .. "\n\n" for r = 1, #resultsHHP_Required do		   	if r == #resultsHHP_Required and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsHHP_Required[r].name .. "" if r == #resultsHHP_Required or (r-1 == 0 and r+1 == #resultsHHP_Required) then print = print .. ' '		       else print = print .. ', '		       end end print = print .. "require" if #resultsHHP_Required == 1 then print = print .. "s" end print = print .. " this item to be placed in their vacation home." end end if not tableEmpty(resultsHHP_Category) then if (not tableEmpty(resultsHHP)) or (not tableEmpty(resultsHHP_Facility)) then if not tableEmpty(resultsHHP_Required) then print = print .. ' '			else print = print .. '\n\n' end print = print .. "This item is " if not tableEmpty(resultsHHP_Required) then print = print .. "also " else print = print .. ''			end print = print .. "required " for r = 1, #resultsHHP_Category do		   	if r == #resultsHHP_Category and r-1 ~= 0 then print = print .. 'and ' end print = print .. "as one of the " .. resultsHHP_Category[r].category:lower .. " for the " .. resultsHHP_Category[r].room:lower .. " at the " .. resultsHHP_Category[r].facility:lower .. "" if r == #resultsHHP_Category then print = print .. '.'		       elseif r-1 == 0 and r+1 == #resultsHHP_Category then print = print .. ' '		       else print = print .. ', '		       end end end end if (typeItem == "furniture" or typeItem == "interior") and (not isEmpty(resultsHHP_Wardell[1].price) and resultsHHP_Wardell[1].currency == "Poki") then currency = require("Module:Currency") print = print .. '\n\n' print = print .. "After unlocking this item, the item can be purchased from Wardell's catalog" if (resultsHHP_Wardell[1].availability2 == "Paradise Planning office" or resultsHHP_Wardell[1].availability2 == "Café") then print = print .. ''		else print = print .. " for " .. currency.outputCurrency("Poki", resultsHHP_Wardell[1].price,"","","","") end print = print .. "."	end if (tableEmpty(resultsHHP)) and (tableEmpty(resultsHHP_Facility) and isEmpty(frame.args['hhpstatus'])) then print = print .. ", no villagers unlock this item for usage in designing a vacation home" if not isEmpty(frame.args['clothing']) and not (not isEmpty(resultsHandbags[1].handbag) and resultsHandbags[1].handbag == "1") then print = print .. " and as a clothing item to use on" if not isEmpty(resultsVill_Equip[1].equip) and resultsVill_Equip[1].equip == "1" then print = print .. " villagers and" end print = print .. " the player" end print = print .. ", and it can only be used once the player's catalog is unlocked after completing the 27th vacation home." if not tableEmpty(resultsHHP_Category) then print = print .. '\n\nThe item is however required ' for r = 1, #resultsHHP_Category do		   	if r == #resultsHHP_Category and r-1 ~= 0 then print = print .. 'and ' end print = print .. "as one of the " .. resultsHHP_Category[r].category:lower .. " for the " .. resultsHHP_Category[r].room:lower .. " at the " .. resultsHHP_Category[r].facility:lower .. "" if r == #resultsHHP_Category then print = print .. '.'		       elseif r-1 == 0 and r+1 == #resultsHHP_Category then print = print .. ' '		       else print = print .. ', '		       end end end end return print end

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

-- Cargo query for nh_house local tables = 'nh_house' local fields = "nh_house.villager=villager,nh_house._pageTitle=pageName" local args = { where = "nh_house.items LIKE '%\"" .. frame.args['1'] .. "\"%'", orderBy = 'nh_house.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) if not tableEmpty(results) then print = print .. "This item " if not isEmpty(frame.args['disable-clothing']) then print = print .. ""   	else print = print .. "also " end print = print .. "appears in the homes of " 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 if not isEmpty(frame.args['not-purchasable']) then print = print .. ''	   else print = print .. " As a result, this item has a chance to be purchasable by the player if they were invited by any of the following villagers." end if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] end else print = print .. "No villagers have this item in their home." end print = print .. '\n\n' .. p.HHPOutput(frame,"furniture") return print end

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

-- Cargo query for nh_villager local tables = 'nh_villager' local fields = "nh_villager.icon=icon,nh_villager.name=villager,nh_villager._pageTitle=pageName" local args = { where = "nh_villager.clothing = '" .. frame.args['1'] .. "'",       orderBy = 'nh_villager.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) if not tableEmpty(results) then print = print .. "This item is worn 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 outfit." if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] end else print = print .. "No villagers wear this item as their default outfit." end print = print .. '\n\n' .. p.HHPOutput(frame,"") return print end

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

-- Cargo query for nh_villager local tables = 'nh_villager' local fields = "nh_villager.icon=icon,nh_villager.name=villager,nh_villager._pageTitle=pageName" local args = { where = "nh_villager.umbrella = '" .. frame.args['1'] .. "' AND species<>'Frog'", orderBy = 'nh_villager.name_sort', 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." if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] end else print = print .. "No villagers use this item as their default umbrella during periods of rain." end print = print .. '\n\n' .. p.HHPOutput(frame,"") return print end

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

-- Cargo query for nh_house local tables local fields local args local results if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then tables = 'nh_house' fields = "nh_house.villager=villager,nh_house._pageTitle=pageName" args = { where = "nh_house.wallpaper = '" .. frame.args['1'] .. "'",	       orderBy = 'nh_house.name_sort', limit = 300, default = '' }	   results = cargo.query( tables, fields, args ) elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "flooring" then tables = 'nh_house' fields = "nh_house.villager=villager,nh_house._pageTitle=pageName" args = { where = "nh_house.flooring = '" .. frame.args['1'] .. "'",	       orderBy = 'nh_house.name_sort', limit = 300, default = '' }	   results = cargo.query( tables, fields, args ) end if not tableEmpty(results) then print = print .. "This item appears in the homes of " 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 if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] end else print = print .. "No villagers have this item in their home." end print = print .. '\n\n' .. p.HHPOutput(frame,"interior") return print end

return p