Module:Items: Difference between revisions

3,984 bytes added ,  27 September 2020
Various improvements to both getCreationTable and getItemLootSources
(Added more item creation/production tables)
(Various improvements to both getCreationTable and getItemLootSources)
Line 11: Line 11:
local EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon'}
local EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon'}
local OtherShopItems = {'Cooking Gloves', 'Mining Gloves', 'Gem Gloves', 'Smithing Gloves', 'Thieving Gloves'}
local OtherShopItems = {'Cooking Gloves', 'Mining Gloves', 'Gem Gloves', 'Smithing Gloves', 'Thieving Gloves'}
--This is hardcoded, so there's no easy way to scrape it. Hopefully it doesn't change
local GemTable = {["Topaz"] = {name = 'Topaz', id = 128, chance = 50},
                  ["Sapphire"] = {name = "Sapphire", id = 129, chance = 17.5},
                  ["Ruby"] = {name = "Ruby", id = 130, chance = 17.5},
                  ["Emerald"] = {name = "Emerald", id = 131, chance = 10},
                  ["Diamond"] = {name = "Diamond", id = 132, chance = 5}}
--The base chance to receive a gem while mining
local GemChance = .01
--The number of different fishing junk items
local junkCount = 8
local specialFishWt = 6721
local specialFishLoot = {{129, 2000}, {130, 1600}, {131, 1400}, {132, 1000}, {133, 400}, {668, 10}, {669, 10}, {671, 1}, {670, 50}, {121, 250}}
function p.buildSpecialFishingTable()
  --This shouldn't ever be included in a page
  --This is for generating the above 'specialFishLoot' variable if it ever needs to change
  --To re-run, edit the module, type in "console.log(p.buildSpecialFishingTable())" and copy+paste the result as the new value of the variable
  --Also gives you the total fishing weight for saving time later
  local lootArray = {}
  local totalWt = 0
  for i, item in pairs(ItemData.Items) do
    if item.fishingCatchWeight ~= nil then
      totalWt = totalWt + item.fishingCatchWeight
      table.insert(lootArray, '{'..i..', '..item.fishingCatchWeight..'}')
    end
  end
  local result = 'local specialFishWt = '..totalWt..'\r\n'
  result = result..'local specialFishLoot = {'..table.concat(lootArray, ', ')..'}'
  return result
end


function p.getItemByID(ID)
function p.getItemByID(ID)
Line 135: Line 168:
   local qty = nil
   local qty = nil
   local req = nil
   local req = nil
  local result = ''
  local tables = {}
   --First figure out what skill is used to make this...
   --First figure out what skill is used to make this...
   if item.smithingLevel ~= nil then
   if item.smithingLevel ~= nil then
Line 143: Line 179:
     qty = item.smithingQty
     qty = item.smithingQty
     time = 2
     time = 2
   elseif item.craftingLevel ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.craftingLevel ~= nil then
     skill = 'Crafting'
     skill = 'Crafting'
     lvl = item.craftingLevel
     lvl = item.craftingLevel
Line 150: Line 188:
     qty = item.craftQty
     qty = item.craftQty
     time = 3
     time = 3
   elseif item.runecraftingLevel ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.runecraftingLevel ~= nil then
     skill = 'Runecrafting'
     skill = 'Runecrafting'
     lvl = item.runecraftingLevel
     lvl = item.runecraftingLevel
Line 157: Line 197:
     qty = item.runecraftQty
     qty = item.runecraftQty
     time = 2
     time = 2
   elseif item.fletchingLevel ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.fletchingLevel ~= nil then
     skill = 'Fletching'
     skill = 'Fletching'
     lvl = item.fletchingLevel
     lvl = item.fletchingLevel
Line 164: Line 206:
     qty = item.fletchQty
     qty = item.fletchQty
     time = 2
     time = 2
   elseif item.herbloreReq ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.herbloreReq ~= nil then
     skill = 'Herblore'
     skill = 'Herblore'
     req = item.herbloreReq
     req = item.herbloreReq
Line 173: Line 217:
     xp = potionData.herbloreXP
     xp = potionData.herbloreXP
     time = 2
     time = 2
   elseif item.miningLevel ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.miningLevel ~= nil then
     skill = 'Mining'
     skill = 'Mining'
     lvl = item.miningLevel
     lvl = item.miningLevel
Line 181: Line 227:
       specialReq = Icons.Icon({"Mastery", notext='true'})..' 271 total [[Mining]] [[Mastery]]'
       specialReq = Icons.Icon({"Mastery", notext='true'})..' 271 total [[Mining]] [[Mastery]]'
     end
     end
   elseif item.type == "Logs" then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time, nil, specialReq))
   end
  if item.type == "Logs" then
     --Well this feels like cheating, but for as long as logs are the first items by ID it works
     --Well this feels like cheating, but for as long as logs are the first items by ID it works
     local treeData = SkillData.Woodcutting[item.id + 1]
     local treeData = SkillData.Woodcutting[item.id + 1]
Line 188: Line 236:
     time = treeData.interval / 1000
     time = treeData.interval / 1000
     xp = treeData.xp
     xp = treeData.xp
   elseif item.fishingLevel ~= nil then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
   end
  if item.fishingLevel ~= nil then
     skill = 'Fishing'
     skill = 'Fishing'
     lvl = item.fishingLevel
     lvl = item.fishingLevel
Line 194: Line 244:
     time = item.minFishingInterval/1000
     time = item.minFishingInterval/1000
     maxTime = item.maxFishingInterval/1000
     maxTime = item.maxFishingInterval/1000
   elseif item.type == "Havest" or type == "Herb" then
    table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time, maxTime))
  end
   if item.type == "Havest" or item.type == "Herb" or item.type == "Logs" then
     --Havest/Herb means farming
     --Havest/Herb means farming
    --Logs might mean farming or might not. Depends on the logs
     --Yes, Havest. The typos are coming from inside the source code
     --Yes, Havest. The typos are coming from inside the source code
     for i, item2 in pairs(ItemData.Items) do
     for i, item2 in pairs(ItemData.Items) do
Line 205: Line 258:
         qty = 5
         qty = 5
         req = {{id = i - 1, qty = (item2.seedsRequired ~= nil and item2.seedsRequired or 1)}}
         req = {{id = i - 1, qty = (item2.seedsRequired ~= nil and item2.seedsRequired or 1)}}
        table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
         break
         break
       end
       end
     end
     end
    if skill == '' then
  end
      return "Failed to find source item for herb/fruit/vegetable"
   if item.type == "Food" or item.type == "Cooked Fish" then
    end
   elseif item.type == "Food" or item.type == "Cooked Fish" then
     --Food/Cooked Fish is Fishing, need to figure out source item
     --Food/Cooked Fish is Fishing, need to figure out source item
     for i, item2 in pairs(ItemData.Items) do
     for i, item2 in pairs(ItemData.Items) do
Line 227: Line 279:
       end
       end
     end
     end
     if skill == '' then
     if skill ~= '' then
       return "Failed to find source item for cooked/burnt fish"
       table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
     end
     end
  end
  if Shared.tableCount(tables) == 0 then
    return "Failed to find creation requirements for this (Possibly the module isn't properly updated for this skill)"
   else
   else
     return "Failed to find creation requirements for this (Possibly the module isn't properly updated for this skill)"
     return table.concat(tables, '\r\n<br/>')
   end
   end
end
function p.buildCreationTable(skill, lvl, xp, req, qty, time, maxTime, specialReq)
   if qty == nil then qty = 1 end
   if qty == nil then qty = 1 end
   local result = '{|class="wikitable"'
   local result = '{|class="wikitable"'
   if req ~= nil then
   if req ~= nil then
Line 260: Line 318:
   result = result..'\r\n|'..qty
   result = result..'\r\n|'..qty
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Experience'
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Experience'
   result = result..'\r\n|'..xp..' XP'
   result = result..'\r\n|'..Shared.formatnum(xp)..' XP'
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Creation Time'
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Creation Time'
   result = result..'\r\n|'..Shared.formatnum(Shared.round(time, 2, 1))..'s'
   result = result..'\r\n|'..Shared.formatnum(Shared.round(time, 2, 0))..'s'
   if maxTime ~= nil then result = result..' - '..Shared.formatnum(Shared.round(maxTime, 2, 1))..'s' end
   if maxTime ~= nil then result = result..' - '..Shared.formatnum(Shared.round(maxTime, 2, 0))..'s' end
   result = result..'\r\n|}'
   result = result..'\r\n|}'


Line 459: Line 517:
   --Set up function for adding rows
   --Set up function for adding rows
   local buildRow = function(source, type, minqty, qty, chance)
   local buildRow = function(source, type, minqty, qty, chance)
    if minqty == nil then minqty = 1 end
     local rowTxt = '\r\n|-'
     local rowTxt = '\r\n|-'
     rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..source
     rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..source
Line 547: Line 606:
     end
     end
   end
   end
  --Bonus overtime: Special Fishing table & mining gem table. Also Rags to Riches
  if item.type == 'Gem' then
    local mineType = Icons.Icon({'Mining', type='skill'})
    local thisGemChance = GemTable[item.name].chance
    table.insert(dropRows, {source = 'Special Drop', type = mineType, minqty = 1, qty = 1, chance = (thisGemChance * GemChance)})
    local magicType = Icons.Icon({'Magic', type = 'skill'})
    table.insert(dropRows, {source = Icons.Icon({"Rags to Riches I", type="spell"}), type = magicType, minqty = 1, qty = 1, chance = thisGemChance})
    table.insert(dropRows, {source = Icons.Icon({"Rags to Riches II", type="spell"}), type = magicType, minqty = 1, qty = 1, chance = thisGemChance})
  end
  if item.fishingCatchWeight ~= nil then
    local fishSource = '[[Fishing#Special|Special]]'
    local fishType = Icons.Icon({'Fishing', type='skill'})
    local thisChance = (item.fishingCatchWeight / specialFishWt) * 100
    table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, chance = thisChance})
  end
  if item.type == 'Junk' then
    local fishSource = '[[Fishing#Junk|Junk]]'
    local fishType = Icons.Icon({'Fishing', type='skill'})
    local thisChance = 100 / junkCount
    table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, chance = thisChance})
  end
 
    
    
   table.sort(dropRows, function(a, b) return a.qty * a.chance > b.qty * b.chance end)
   table.sort(dropRows, function(a, b) return a.qty * a.chance > b.qty * b.chance end)