Anonymous

Module:Sandbox/AuronTest/SourceTables: Difference between revisions

From Melvor Idle
m
Try to optimise _getItemSources()
(0.21 testing)
m (Try to optimise _getItemSources())
Line 312: Line 312:
   --Alright, time to go through all the ways you can get an item...
   --Alright, time to go through all the ways you can get an item...
   --First up: Can we kill somebody and take theirs?
   --First up: Can we kill somebody and take theirs?
   local killStr = ''
   local killStr = {}
   local dungeonStr = ''
   local dungeonStr = {}
  local count1 = 0
   for i, monster in Shared.skpairs(MonsterData.Monsters) do
   for i, monster in Shared.skpairs(MonsterData.Monsters) do
     local isDrop = false
     local isDrop = false
Line 345: Line 344:
         --If this is a boss then we actually are completing dungeons for this and need to figure out which one
         --If this is a boss then we actually are completing dungeons for this and need to figure out which one
         for j, dung in pairs(areaList) do
         for j, dung in pairs(areaList) do
           if string.len(dungeonStr) > 0 then
           table.insert(dungeonStr, (#dungeonStr > 0 and ',' or 'Completing: ') .. Icons.Icon({dung.name, type="dungeon", notext=true}))
            dungeonStr = dungeonStr..','
          else
            dungeonStr = 'Completing: '
          end
          dungeonStr = dungeonStr..Icons.Icon({dung.name, type="dungeon", notext=true})
         end
         end
       else
       else
         count1 = count1 + 1
         table.insert(killStr, (#killStr > 0 and ',' or 'Killing: ') .. Icons.Icon({monster.name, type="monster", notext="true"}))
        if string.len(killStr) > 0 then
          killStr = killStr..','
          --if count1 % 3 == 1 and count1 > 1 then killStr = killStr..'<br/>' end
          killStr = killStr..Icons.Icon({monster.name, type="monster", notext="true"})
        else
          killStr = killStr..'Killing: '..Icons.Icon({monster.name, type="monster", notext="true"})
        end
       end
       end
     end
     end
Line 366: Line 353:
   -- Special exceptions for Fire/Infernal Cape and first two lore books
   -- Special exceptions for Fire/Infernal Cape and first two lore books
   if sourceOverrides['Dungeon'][item.id] ~= nil then
   if sourceOverrides['Dungeon'][item.id] ~= nil then
     if string.len(dungeonStr) > 0 then
     table.insert(dungeonStr, (#dungeonStr > 0 and ',' or 'Completing: ') .. Icons.Icon({sourceOverrides['Dungeon'][item.id], type="dungeon", notext=true}))
      dungeonStr = dungeonStr .. ','
    else
      dungeonStr = 'Completing: '
    end
    dungeonStr = dungeonStr .. Icons.Icon({sourceOverrides['Dungeon'][item.id], type='dungeon', notext=true})
   end
   end


   if string.len(dungeonStr) > 0 then table.insert(lineArray, dungeonStr) end
   if #dungeonStr > 0 then table.insert(lineArray, table.concat(dungeonStr)) end
   if string.len(killStr) > 0 then table.insert(lineArray, killStr) end
   if #killStr > 0 then table.insert(lineArray, table.concat(killStr)) end


   --Next: Can we find it in a box?
   --Next: Can we find it in a box?
   --While we're here, check for upgrades, cooking, and growing
   --While we're here, check for upgrades, cooking, and growing
   local lootStr = ''
   local lootStr = {}
   local upgradeStr = ''
   local upgradeStr = {}
   local cookStr = ''
   local cookStr = {}
   local burnStr = ''
   local burnStr = {}
   local growStr = ''
   local growStr = {}
  local count2 = 0
  count1 = 0
   for i, item2 in pairs(ItemData.Items) do
   for i, item2 in pairs(ItemData.Items) do
     if item2.dropTable ~= nil then
     if item2.dropTable ~= nil then
       for j, loot in pairs(item2.dropTable) do
       for j, loot in pairs(item2.dropTable) do
         if loot[1] == item.id then
         if loot[1] == item.id then
           count1 = count1 + 1
           table.insert(lootStr, (#lootStr > 0 and ',' or 'Opening: ') .. Icons.Icon({item2.name, type="item", notext="true"}))
          if string.len(lootStr) > 0 then
           break
            lootStr = lootStr..','
            --if count1 % 3 == 1 and count1 > 1 then lootStr = lootStr..'<br/>' end
            lootStr = lootStr..Icons.Icon({item2.name, type="item", notext="true"})
          else
            lootStr = lootStr..'Opening: '..Icons.Icon({item2.name, type="item", notext="true"})
           end
         end
         end
       end
       end
     end
     end
     if item2.trimmedItemID == item.id then
     if item2.trimmedItemID == item.id then
          count2 = count2 + 1
         local pre = ','
         if string.len(upgradeStr) > 0 then
        if #upgradeStr == 0 then
          upgradeStr = upgradeStr..','
          pre = 'Upgrading: '
          --if count2 % 3 == 1 and count2 > 1 then upgradeStr = upgradeStr..'<br/>' end
          upgradeStr = upgradeStr..Icons.Icon({item2.name, type="item", notext="true"})
        else
           table.insert(categoryArray, '[[Category:Upgraded Items]]')
           table.insert(categoryArray, '[[Category:Upgraded Items]]')
          upgradeStr = upgradeStr..'Upgrading: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
        table.insert(upgradeStr, pre .. Icons.Icon({item2.name, type="item", notext="true"}))
     end
     end
     if item2.cookedItemID == item.id then
     if item2.cookedItemID == item.id then
         if string.len(cookStr) > 0 then
        local pre = ','
           cookStr = cookStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         if #cookStr == 0 then
        else
           pre = 'Cooking: '
           table.insert(categoryArray, '[[Category:Cooked Items]]')
           table.insert(categoryArray, '[[Category:Cooked Items]]')
          cookStr = cookStr..'Cooking: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
        table.insert(cookStr, pre .. Icons.Icon({item2.name, type="item", notext="true"}))
     end
     end
     if item2.burntItemID == item.id then
     if item2.burntItemID == item.id then
         if string.len(burnStr) > 0 then
        local pre = ','
           burnStr = burnStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         if #burnstr == 0 then
        else
           pre = 'Burning: '
           table.insert(categoryArray, '[[Category:Burnt Items]]')
           table.insert(categoryArray, '[[Category:Burnt Items]]')
          burnStr = burnStr..'Burning: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
          table.insert(burnStr, pre .. Icons.Icon({item2.name, type="item", notext="true"}))
     end
     end
     if item2.grownItemID == item.id then
     if item2.grownItemID == item.id then
         if string.len(growStr) > 0 then
        local pre = ','
           growStr = growStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         if #growStr == 0 then
        else
           pre = 'Growing: '
           table.insert(categoryArray, '[[Category:Harvestable Items]]')
           table.insert(categoryArray, '[[Category:Harvestable Items]]')
          growStr = growStr..'Growing: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
          table.insert(growStr, pre .. Icons.Icon({item2.name, type="item", notext="true"}))
     end
     end
   end
   end
   if string.len(lootStr) > 0 then table.insert(lineArray, lootStr) end
   if #lootStr > 0 then table.insert(lineArray, table.concat(lootStr)) end
   if string.len(upgradeStr) > 0 then table.insert(lineArray, upgradeStr) end
   if #upgradeStr > 0 then table.insert(lineArray, table.concat(upgradeStr)) end
   if string.len(cookStr) > 0 then table.insert(lineArray, cookStr) end
   if #cookStr > 0 then table.insert(lineArray, table.concat(cookStr)) end
   if string.len(burnStr) > 0 then table.insert(lineArray, burnStr) end
   if #burnStr > 0 then table.insert(lineArray, table.concat(burnStr)) end
   if string.len(growStr) > 0 then table.insert(lineArray, growStr) end
   if #growStr > 0 then table.insert(lineArray, table.concat(growStr)) end


   --Next: Can we take it from somebody else -without- killing them?
   --Next: Can we take it from somebody else -without- killing them?
   local thiefStr = ''
   local thiefStr = {}
   for i, npc in pairs(SkillData.Thieving) do
   for i, npc in pairs(SkillData.Thieving) do
     if npc.lootTable ~= nil then
     if npc.lootTable ~= nil then
       for j, loot in pairs(npc.lootTable) do
       for j, loot in pairs(npc.lootTable) do
         if loot[1] == item.id then
         if loot[1] == item.id then
           if string.len(thiefStr) > 0 then
           table.insert(theifStr, (#thiefStr > 0 and ',' or 'Pickpocketing: ') .. Icons.Icon({npc.name, type="thieving", notext="true"}))
            thiefStr = thiefStr..','..Icons.Icon({npc.name, type="thieving", notext="true"})
           break
          else
            thiefStr = thiefStr..'Pickpocketing: '..Icons.Icon({npc.name, type="thieving", notext="true"})
           end
         end
         end
       end
       end
     end
     end
   end
   end
   if string.len(thiefStr) > 0 then table.insert(lineArray, thiefStr) end
   if #thiefStr > 0 then table.insert(lineArray, table.concat(thiefStr)) end


   --If all else fails, I guess we should check if we can make it ourselves
   --If all else fails, I guess we should check if we can make it ourselves