Module:Items/SourceTables: Difference between revisions

added thieving to item sources
(herbloreLevel -> level to resolve a bunch of script errors)
(added thieving to item sources)
Line 13: Line 13:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local Monsters = require('Module:Monsters')
local Monsters = require('Module:Monsters')
local GatheringSkills = require('Module:Skills/Gathering')


-- Implements overrides for sources which cannot be obtained from game data
-- Implements overrides for sources which cannot be obtained from game data
Line 438: Line 439:


   --Next: Can we take it from somebody else -without- killing them?
   --Next: Can we take it from somebody else -without- killing them?
  local thiefItems = GatheringSkills.getThievingSourcesForItem(item.id)
   local thiefStr = ''
   local thiefStr = ''
   for i, npc in pairs(SkillData.Thieving) do
   if Shared.tableCount(thiefItems) > 0 then
    if npc.lootTable ~= nil then
  thiefStr = 'Pickpocketing: '
      for j, loot in pairs(npc.lootTable) do
  for i, thiefRow in pairs(thiefItems) do
        if loot[1] == item.id then
  if thiefRow.npc == 'all' then
          if string.len(thiefStr) > 0 then
  --if 'any' is the npc, this is a rare item so just say 'Thieving level 1'
            thiefStr = thiefStr..','..Icons.Icon({npc.name, type="thieving", notext="true"})
  thiefStr = Icons._SkillReq('Thieving', 1)
          else
  else
            thiefStr = thiefStr..'Pickpocketing: '..Icons.Icon({npc.name, type="thieving", notext="true"})
  if i > 1 then thiefStr = thiefStr..', ' end
          end
  thiefStr = thiefStr..Icons.Icon({thiefRow.npc, type='thieving', notext='true'})
        end
  end
      end
  end
    end
   end
   end
   if string.len(thiefStr) > 0 then table.insert(lineArray, thiefStr) end
   if string.len(thiefStr) > 0 then table.insert(lineArray, thiefStr) end
Line 526: Line 527:
   if item.type == 'Bar' or Shared.contains(Items.AltMagicProducts, item.name) then
   if item.type == 'Bar' or Shared.contains(Items.AltMagicProducts, item.name) then
     table.insert(lineArray, Icons.Icon({"Alt. Magic", type='skill'}))
     table.insert(lineArray, Icons.Icon({"Alt. Magic", type='skill'}))
  end
  --Chapeau Noir & Bobby's Pocket are special Thieving items
  if item.name == "Chapeau Noir" or item.name == "Bobby's Pocket" then
    table.insert(lineArray, Icons._SkillReq("Thieving", 1))
   end
   end


Line 624: Line 620:
       table.insert(rowPart, '\r\n|colspan="2" ')
       table.insert(rowPart, '\r\n|colspan="2" ')
     else
     else
      table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="' .. chance .. '"| ' .. Shared.fraction(weight, totalWeight) .. '\r\n|')
local fraction = Shared.fraction(weight, totalWeight)
if Shared.contains(fraction, '%.') then
--If fraction contains decimals, something screwy happened so just show only percentage
--(happens sometimes with the rare thieving items)
table.insert(rowPart, '\r\ncolspan="2" ')
else
    table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="' .. chance .. '"| ' .. Shared.fraction(weight, totalWeight) .. '\r\n|')
    end
    end
    if weight == -1 then
    --Weight of -1 means this is a weird row that has a variable percentage
    table.insert(rowPart, 'style="text-align: right;" data-sort-value="0"|Varies (see Thieving page)')
    else
    table.insert(rowPart, 'style="text-align: right;" data-sort-value="'.. chance .. '"|'..chance..'%')
     end
     end
    table.insert(rowPart, 'style="text-align: right;" data-sort-value="'.. chance .. '"|'..chance..'%')
     return table.concat(rowPart)
     return table.concat(rowPart)
   end
   end
Line 716: Line 724:
   --Finally, let's try just stealing it
   --Finally, let's try just stealing it
   local thiefType = Icons.Icon({"Thieving", type='skill'})
   local thiefType = Icons.Icon({"Thieving", type='skill'})
   for i, npc in pairs(SkillData.Thieving) do
  local thiefItems = GatheringSkills.getThievingSourcesForItem(item.id)
    local qty = 1
   for i, thiefRow in pairs(thiefItems) do
    local wt = 0
  local sourceTxt = ''
    local totalWt = 0
     if thiefRow.npc == 'all' then
     if npc.lootTable ~= nil then
    sourceTxt = "Thieving Rare Drop"
      for j, loot in pairs(npc.lootTable) do
    else
        totalWt = totalWt + loot[2]
    sourceTxt = Icons.Icon({thiefRow.npc, type='thieving'})
        if loot[1] == item.id then
end
          wt = loot[2]
    table.insert(dropRows, {source = sourceTxt, type = thiefType, minqty = thiefRow.minQty, qty = thiefRow.maxQty, weight = thiefRow.wt, totalWeight = thiefRow.totalWt})
        end
      end
      if wt > 0 then
        -- There is a constant 75% chance of gaining an item per successful steal attempt
        local sourceTxt = Icons.Icon({npc.name, type='thieving'})
        table.insert(dropRows, {source = sourceTxt, type = thiefType, minqty = 1, qty = qty, weight = wt * 75, totalWeight = totalWt * 100})
      end
    end
   end
   end