Module:Items

local p = {}; local cargo = mw.ext.cargo; local utils = require( "Module:Utils" );

function p.items(frame) local tf_r = { ['0'] = ' data-sort-value="0" |Common', ['1'] = ' data-sort-value="1" |Rare', ['2'] = ' data-sort-value="2" |Legendary', ['3'] = ' data-sort-value="3" |Special', ['4'] = ' data-sort-value="4" |Mythical' };   setmetatable(tf_r,{__index = function(tab, index) return ' data-sort-value="5" |Unknown' end}); local tf_at = { ['0'] = 'None', ['1'] = 'Basic', ['2'] = 'Cleave', ['3'] = 'Swing', ['4'] = 'Pierce', ['5'] = 'Unable', ['6'] = 'Ranged' };   local unknw = function(tab, index) return 'Unknown' end; setmetatable(tf_at,{__index = unknw}); local tf_dt = { ['0'] = 'None', ['1'] = 'Basic', ['2'] = 'Slashing', ['3'] = 'Fire', ['4'] = 'Water', ['5'] = 'Ice', ['6'] = 'Electric', ['7'] = 'Poison', ['8'] = 'Bleeding', ['9'] = 'True', ['10'] = 'Light', ['11'] = 'Shadow' };   setmetatable(tf_dt,{__index = unknw}); local tf_t = { ['1'] = 'Weapon', ['2'] = 'Armor', ['3'] = 'Misc', ['4'] = 'Consumable' };   setmetatable(tf_t,{__index = unknw}); local tf_use = { ['111'] = 'Everywhere', ['110'] = 'Overworld and Town', ['101'] = 'Overworld and Battle', ['100'] = 'Overworld Only', ['011'] = 'Town and Battle', ['010'] = 'Town Only', ['001'] = 'Battle Only', ['000'] = 'Nowhere' };   setmetatable(tf_use,{__index = unknw}); local temp_res = {}; local fstr = utils.toNumberedTable(frame.args[2]); local results = cargo.query(frame.args[1], utils.trimBrackets(frame.args[3]), utils.toTable(utils.trimBrackets(frame.args[4]))); for _, result in ipairs(results) do   	local temp_item = {'|-\n'}; for r, fv in ipairs( fstr ) do local v = result["'" .. tostring(r) .. "'"];		   temp_item[#temp_item+1] = '|'; if (v ~= nil) then if fv == 'name' then temp_item[#temp_item+1] = ' id="' .. v .. '" |' .. v;		   elseif fv == 'text' then temp_item[#temp_item+1] = v;		   elseif fv == 'rarity' then temp_item[#temp_item+1] = tf_r[v]; elseif fv == 'atkType' then temp_item[#temp_item+1] = tf_at[v]; elseif fv == 'damageType' then temp_item[#temp_item+1] = tf_dt[v]; elseif fv == 'mod' then local modif = utils.toNumberedTable(v); if modif[1] ~= '0' then temp_item[#temp_item+1] = 'HP: ' .. modif[1] .. ' ';	    		end if modif[2] ~= '0' then temp_item[#temp_item+1] = 'Mana: ' .. modif[2] .. ' ';	    		end if modif[3] ~= '0' then temp_item[#temp_item+1] = 'Speed: ' .. modif[3] .. ' ';	    		end if modif[4] ~= '0' then temp_item[#temp_item+1] = 'Strength: ' .. modif[4] .. ' ';	    		end if modif[5] ~= '0' then temp_item[#temp_item+1] = 'Armor: ' .. modif[5] .. ' ';	    		end if modif[6] ~= '0' then temp_item[#temp_item+1] = 'Lust damage: ' .. modif[6] .. ' ';	    		end if modif[7] ~= '0' then temp_item[#temp_item+1] = 'Lust resistance: ' .. modif[7] .. ' ';	    		end if modif[8] ~= '0' then temp_item[#temp_item+1] = 'Magic strength: ' .. modif[8] .. ' ';	    		end elseif fv == 'aSkill' then local aSkill = utils.toNumberedTable(v); if aSkill[1] ~= '' then temp_item[#temp_item+1] = aSkill[1] .. ' ';	    		end if aSkill[2] ~= '' then temp_item[#temp_item+1] = 'Range: ' .. aSkill[2] .. ' ';	    		end if aSkill[3] ~= '' then temp_item[#temp_item+1] = 'Mana cost: ' .. aSkill[3] .. ' ';	    		end if aSkill[4] ~= '' then temp_item[#temp_item+1] = 'Ap cost: ' .. aSkill[4] .. ' ';	    		end if aSkill[5] ~= '' then temp_item[#temp_item+1] = 'Uses: ' .. aSkill[5] .. ' ';	    		end if aSkill[6] ~= '' then temp_item[#temp_item+1] = string.gsub(aSkill[6],"&lt;br&gt;",' '); end elseif fv == 'material' then local materials = utils.toNumberedTable(v); if materials[1] ~=  and materials[2] ~=  then local material = utils.toNumberedTable(materials[1],','); local count = utils.toNumberedTable(materials[2],','); local prev_material = nil; for i=1,#material do     	 				if (material[i] ~= nil and count[i] ~= nil and prev_material ~= material[i]) then prev_material = material[i]; temp_item[#temp_item+1] = 'x'..count[i]..' '..material[i]..' '; end end end elseif fv == 'use' then temp_item[#temp_item+1] = tf_use[v]; elseif fv == 'type' then temp_item[#temp_item+1] = tf_t[v]; else temp_item[#temp_item+1] = v;		   end end temp_item[#temp_item+1] = '\n'; end temp_res[#temp_res+1] = table.concat(temp_item,""); end local restbl = table.concat(temp_res,""); return restbl; end

return p