Anonymous

Module:Sandbox/AuronTest/UseTables: Difference between revisions

From Melvor Idle
0.21 testing
(Clone live module)
 
(0.21 testing)
Line 2: Line 2:


local MonsterData = mw.loadData('Module:Monsters/data')
local MonsterData = mw.loadData('Module:Monsters/data')
local ItemData = mw.loadData('Module:Items/data')
local ItemData = mw.loadData('Module:AuronTest/data')
local SkillData = mw.loadData('Module:Skills/data')
local SkillData = mw.loadData('Module:Skills/data')


Line 9: Line 9:
local Magic = require('Module:Magic')
local Magic = require('Module:Magic')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
local Items = require('Module:Items')
local Items = require('Module:AuronTest')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Agility = require('Module:Skills/Agility')
local Agility = require('Module:Skills/Agility')
Line 77: Line 77:


   --Before anything else, if this is a potion add it to the appropriate override section
   --Before anything else, if this is a potion add it to the appropriate override section
   if item.herbloreMasteryID ~= nil then
   if item.masteryID ~= nil and item.masteryID[1] == 19 then
     table.insert(itemUseArray[potionUseArray[item.herbloreMasteryID]], item.name)
     table.insert(itemUseArray[potionUseArray[item.masteryID[2]]], item.name)
   end
   end


Line 101: Line 101:
   if item.dropTable ~= nil then
   if item.dropTable ~= nil then
     table.insert(categoryArray, '[[Category:Openable Items]]')
     table.insert(categoryArray, '[[Category:Openable Items]]')
     table.insert(useArray, chr..'[[Chest Drop Tables|Can Be Opened]]')  
     table.insert(useArray, chr..'[[Chest Drop Tables|Can Be Opened]]')
  end
 
  -- Check if the item is an entry requirement for any Slayer area
  local isSlayerAreaReq = false
  if item.isEquipment then
    local slayerAreas = Areas.getAreas(function(area) return area.type == 'slayer' end)
    for i, area in pairs(slayerAreas) do
      if area.entryRequirements ~= nil and type(area.entryRequirements) == 'table' then
        for j, req in pairs(area.entryRequirements) do
          if req.type == "SlayerItem" and req.itemID == item.id then
            isSlayerAreaReq = true
            break
          end
        end
        if isSlayerAreaReq then break end
      end
    end
   end
   end


Line 160: Line 177:
       end
       end
     end
     end
   
 
     if item2.summoningReq ~= nil then
     if item2.summoningReq ~= nil then
       for j, reqSet in pairs(item2.summoningReq) do
       for j, reqSet in pairs(item2.summoningReq) do
Line 175: Line 192:
   --Check if Agility applies here
   --Check if Agility applies here
   canAgile = Shared.tableCount(Agility.getObstaclesForItem(item.id)) > 0
   canAgile = Shared.tableCount(Agility.getObstaclesForItem(item.id)) > 0
 
 
   --Agility
   --Agility
   if canAgile or Shared.contains(itemUseArray.Agility, item.name) then
   if canAgile or Shared.contains(itemUseArray.Agility, item.name) then
Line 193: Line 210:
   end
   end
   --Firemaking
   --Firemaking
   if SkillData.Firemaking[item.id + 1] ~= nil or Shared.contains(itemUseArray.Firemaking, item.name) then
   if item.firemakingID ~= nil or Shared.contains(itemUseArray.Firemaking, item.name) then
     table.insert(useArray, chr..Icons.Icon({'Firemaking', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Firemaking', type='skill'}))
   end
   end
Line 222: Line 239:
   end
   end
   --Slayer
   --Slayer
   if item.slayerCost ~= nil or Shared.contains(itemUseArray.Slayer, item.name) then
   if isSlayerAreaReq or Shared.contains(itemUseArray.Slayer, item.name) then
     table.insert(useArray, chr..Icons.Icon({'Slayer', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Slayer', type='skill'}))
   end
   end
Line 241: Line 258:
     table.insert(useArray, chr..Icons.Icon({'Woodcutting', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Woodcutting', type='skill'}))
   end
   end
 
 
   --Other odds and ends:
   --Other odds and ends:


   --Mastery Tokens are tied to 'Mastery'
   --Mastery Tokens are tied to 'Mastery'
   if item.type == 'Token' then
   if item.isToken and item.skill ~= nil then
     table.insert(useArray, chr..Icons.Icon({'Mastery'}))
     table.insert(useArray, chr..Icons.Icon({'Mastery'}))
   end
   end
Line 252: Line 269:
   --Except Max Skillcape, which is tied to all skills. (And so is the Signet Ring)
   --Except Max Skillcape, which is tied to all skills. (And so is the Signet Ring)
   --And combat skillcapes, since combat skills don't get special treatment
   --And combat skillcapes, since combat skills don't get special treatment
 
 
   local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'Hitpoints Skillcape', 'Defence Skillcape'}
   local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'Hitpoints Skillcape', 'Defence Skillcape'}
   if item.name == 'Max Skillcape' or item.name == 'Aorpheat's Signet Ring' or item.name == 'Cape of Completion' then
   if Shared.contains({'Max Skillcape', 'Aorpheat's Signet Ring', 'Cape of Completion'}, item.name) then
     table.insert(useArray, chr..'All skills')
     table.insert(useArray, chr..'All skills')
   elseif item.name == 'Magic Skillcape' then
   elseif item.name == 'Magic Skillcape' then
Line 287: Line 304:
   end
   end


   local result = asList and table.concat(useArray,'\r\n') or table.concat(useArray, '<br/>')
   local resultPart = {}
   if addCategories then result = result..table.concat(categoryArray, '') end
  table.insert(resultPart, asList and table.concat(useArray,'\r\n') or table.concat(useArray, '<br/>'))
   return result
   if addCategories then table.insert(resultPart, table.concat(categoryArray, '')) end
   return table.concat(resultPart)
end
end


Line 297: Line 315:
   local addCategories = false
   local addCategories = false
   local asList = true
   local asList = true
   if frame.args ~= nil then  
   if frame.args ~= nil then
     addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
     addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
     asList = frame.args.addCategories == nil or frame.args.addCategories == '' or frame.args.addCategories == 'true'
     asList = frame.args.addCategories == nil or frame.args.addCategories == '' or frame.args.addCategories == 'true'
Line 385: Line 403:
       for j, req in pairs(item2.herbloreReq) do
       for j, req in pairs(item2.herbloreReq) do
         if req.id == item.id then
         if req.id == item.id then
           local potionData = SkillData.Herblore.ItemData[item2.herbloreMasteryID + 1]
           local potionData = SkillData.Herblore.ItemData[item2.masteryID[2] + 1]
           local mat = item2.herbloreReq
           local mat = item2.herbloreReq
           local xp = potionData.herbloreXP
           local xp = potionData.herbloreXP
Line 408: Line 426:
             mat[k].qty = math.max(math.floor(1000 / math.max(item.sellsFor, 20)), 1)
             mat[k].qty = math.max(math.floor(1000 / math.max(item.sellsFor, 20)), 1)
             local xp = 5 + 2 * math.floor(item2.summoningLevel * 0.2)
             local xp = 5 + 2 * math.floor(item2.summoningLevel * 0.2)
             local rowReq = Icons._SkillReq('Summoning', item2.summoningLevel)
             local rowReq = item2.summoningLevel
             table.insert(useArray, {item = item2, qty = 25, mats = mat, skill = 'Summoning', reqVal = item2.summoningLevel, req = rowReq, xp = xp})
             table.insert(useArray, {item = item2, qty = 25, mats = mat, skill = 'Summoning', req = rowReq, xp = xp})
           end
           end
         end
         end
Line 466: Line 484:


   local spellUseTable = p._getSpellUseTable(item)
   local spellUseTable = p._getSpellUseTable(item)
   local result = ''
   local resultPart = {}
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
     if string.len(spellUseTable) > 0 then
     if string.len(spellUseTable) > 0 then
Line 474: Line 492:
     end
     end
   end
   end
   result = result..'{| class="wikitable sortable"'
   table.insert(resultPart, '{| class="wikitable sortable"')
   result = result..'\r\n!colspan=2|Item Created!!Type!!Requirements!!XP!!Ingredients'
   table.insert(resultPart, '\r\n!colspan=2|Item Created!!Type!!Requirements!!XP!!Ingredients')
   for i, row in pairs(useArray) do
   for i, row in pairs(useArray) do
     local qty = row.qty ~= nil and row.qty or 1
     local qty = row.qty ~= nil and row.qty or 1
     local iconType = row.type ~= nil and row.type or 'item'
     local iconType = row.type ~= nil and row.type or 'item'
     result = result..'\r\n|-\r\n|data-sort-value="'..row.item.name..'"|'
     table.insert(resultPart, '\r\n|-\r\n|data-sort-value="'..row.item.name..'"|')
     result = result..Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||'
     table.insert(resultPart, Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||')
     if qty > 1 then result = result.."'''"..qty.."x''' " end
     if qty > 1 then table.insert(resultPart, "'''"..qty.."x''' ") end
     result = result..'[['..row.item.name..']]'
     table.insert(resultPart, '[['..row.item.name..']]')
     if row.skill == 'Upgrade' then
     if row.skill == 'Upgrade' then
       result = result..'||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]'
       table.insert(resultPart, '||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]')
     elseif row.skill == 'Shop' then
     elseif row.skill == 'Shop' then
       result = result..'||data-sort-value="Shop"|'..Icons.Icon({'Shop'})
       table.insert(resultPart, '||data-sort-value="Shop"|'..Icons.Icon({'Shop'}))
     else
     else
       result = result..'||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'})
       table.insert(resultPart, '||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'}))
     end
     end
     if type(row.req) == 'number' then
     if type(row.req) == 'number' then
       result = result..'|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req)
       table.insert(resultPart, '|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req))
     elseif row.reqVal ~= nil then
     elseif row.reqVal ~= nil then
       result = result..'|| data-sort-value="'..row.reqVal..'"|'..row.req
       table.insert(resultPart, '|| data-sort-value="'..row.reqVal..'"|'..row.req)
     else
     else
       result = result..'||'..row.req
       table.insert(resultPart, '||'..row.req)
     end
     end
     if type(row.xp) == 'string' then
     if type(row.xp) == 'string' then
       result = result..'||data-sort-value="0"|'..row.xp
       table.insert(resultPart, '||data-sort-value="0"|'..row.xp)
     else
     else
       result = result..'||data-sort-value="'..row.xp..'"|'..row.xp..' '..Icons.Icon({row.skill, type='skill', notext=true})..' XP'
       table.insert(resultPart, '||data-sort-value="'..row.xp..'"|'..row.xp..' '..Icons.Icon({row.skill, type='skill', notext=true})..' XP')
     end
     end
     result = result..'||'
     table.insert(resultPart, '||')
     for i, mat in Shared.skpairs(row.mats) do
     for i, mat in Shared.skpairs(row.mats) do
       local matID = mat.id ~= nil and mat.id or mat[1]
       local matID = mat.id ~= nil and mat.id or mat[1]
       local matQty = mat.qty ~= nil and mat.qty or mat[2]
       local matQty = mat.qty ~= nil and mat.qty or mat[2]
       local matText = ''
       local matText = ''
     
 
       if i > 1 then result = result..'<br/>' end
       if i > 1 then table.insert(resultPart, '<br/>') end
       if matID >= 0 then
       if matID >= 0 then
         -- Item
         -- Item
Line 526: Line 544:
         matText = 'ERROR: Unknown item ID: ' .. matID .. ' [[Category:Pages with Script Errors]]'
         matText = 'ERROR: Unknown item ID: ' .. matID .. ' [[Category:Pages with Script Errors]]'
       end
       end
       result = result .. matText
       table.insert(resultPart, matText)
     end
     end
     if row.gp ~= nil then result = result..'<br/>'..Icons.GP(row.gp) end
     if row.gp ~= nil then table.insert(resultPart, '<br/>'..Icons.GP(row.gp)) end
   end
   end


   --Agility obstacles are weird and get their own section
   --Agility obstacles are weird and get their own section
   for i, obst in Shared.skpairs(obstacles) do
   for i, obst in Shared.skpairs(obstacles) do
     result = result..'\r\n|-\r\n|'
     table.insert(resultPart, '\r\n|-\r\n|')
     result = result..Icons.Icon({"Agility", type="skill", size="50", notext=true})
     table.insert(resultPart, Icons.Icon({"Agility", type="skill", size="50", notext=true}))
     result = result..'||[[Agility#Obstacles|'..obst.name..']]'
     table.insert(resultPart, '||[[Agility#Obstacles|'..obst.name..']]')
     result = result..'||'..Icons.Icon({"Agility", type="skill"})
     table.insert(resultPart, '||'..Icons.Icon({"Agility", type="skill"}))


     --Adding the requirements for the Agility Obstacle
     --Adding the requirements for the Agility Obstacle
Line 551: Line 569:
       end
       end
     end
     end
     result = result..'||'..table.concat(reqArray, '<br/>')
     table.insert(resultPart, '||'..table.concat(reqArray, '<br/>'))


     --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
     --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
     result = result..'||N/A'
     table.insert(resultPart, '||N/A')


     --Finally the cost
     --Finally the cost
Line 569: Line 587:
       table.insert(costArray, Icons.Icon({item.name, type="item", qty=mat[2]}))
       table.insert(costArray, Icons.Icon({item.name, type="item", qty=mat[2]}))
     end
     end
   
 
     result = result..'||'..table.concat(costArray, '<br/>')
     table.insert(resultPart, '||'..table.concat(costArray, '<br/>'))


   end
   end


   result = result..'\r\n|}'
   table.insert(resultPart, '\r\n|}')
   if string.len(spellUseTable) > 0 then
   if string.len(spellUseTable) > 0 then
     result = result..'\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable
     table.insert(resultPart, '\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable)
   end
   end
   return '==Uses==\r\n'..result
   return '==Uses==\r\n'..table.concat(resultPart)
end
end


Line 598: Line 616:
   end
   end


   local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
   local resultPart = {}
   result = result..'!!Requirements'
  table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"|Spell')
   result = result..'!!Type!!style="width:275px"|Description'
   table.insert(resultPart, '!!Requirements')
   result = result..'!!Runes'
   table.insert(resultPart, '!!Type!!style="width:275px"|Description')
   table.insert(resultPart, '!!Runes')
   for i, spell in pairs(spellList) do
   for i, spell in pairs(spellList) do
     local rowTxt = '\r\n|-\r\n|data-sort-value="'..spell.name..'"|'
     local rowPart = {}
     if spell.type == 'Auroras' then
    table.insert(rowPart, '\r\n|-\r\n|data-sort-value="'..spell.name..'"|')
      rowTxt = rowTxt..Icons.Icon({spell.name, type='aurora', notext=true, size=50})
     local iconType = (spell.type == 'Auroras' and 'aurora') or (spell.type == 'Curses' and 'curse') or 'spell'
    elseif spell.type == 'Curses' then
     table.insert(rowPart, Icons.Icon({spell.name, type=iconType, notext=true, size=50}))
      rowTxt = rowTxt..Icons.Icon({spell.name, type='curse', notext=true, size=50})
     table.insert(rowPart, '||[['..spell.name..']]')
     else
     table.insert(rowPart, '||data-sort-value="'..spell.magicLevelRequired..'"|'..Icons._SkillReq('Magic', spell.magicLevelRequired))
      rowTxt = rowTxt..Icons.Icon({spell.name, type='spell', notext=true, size=50})
     end
    rowTxt = rowTxt..'||[['..spell.name..']]'
     rowTxt = rowTxt..'||data-sort-value="'..spell.magicLevelRequired..'"|'..Icons._SkillReq('Magic', spell.magicLevelRequired)
     --Handle required items/dungeon clears
     --Handle required items/dungeon clears
     if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
     if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
       local reqItem = Items.getItemByID(spell.requiredItem)
       local reqItem = Items.getItemByID(spell.requiredItem)
       rowTxt = rowTxt..'<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped'
       table.insert(rowPart, '<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped')
     end
     end
     if spell.requiredDungeonCompletion ~= nil then
     if spell.requiredDungeonCompletion ~= nil then
       local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
       local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
       rowTxt = rowTxt..'<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears'
       table.insert(rowPart, '<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears')
     end
     end
     rowTxt = rowTxt..'||data-sort-value="'..Magic.getSpellTypeIndex(spell.type)..'"|'
     table.insert(rowPart, '||data-sort-value="'..Magic.getSpellTypeIndex(spell.type)..'"|')
     rowTxt = rowTxt..Magic.getSpellTypeLink(spell.type)
     table.insert(rowPart, Magic.getSpellTypeLink(spell.type))
     rowTxt = rowTxt..'||'..Magic._getSpellStat(spell, 'description')
     table.insert(rowPart, '||'..Magic._getSpellStat(spell, 'description'))
     rowTxt = rowTxt..'||style="text-align:center"|'
     table.insert(rowPart, '||style="text-align:center"|')
     rowTxt = rowTxt..Magic._getSpellRunes(spell)
     table.insert(rowPart, Magic._getSpellRunes(spell))
     result = result..rowTxt
     table.insert(resultPart, table.concat(rowPart))
   end
   end
   --Add the table end and add the table to the result string
   --Add the table end and add the table to the result string
   result = result..'\r\n|}'
   table.insert(resultPart, '\r\n|}')
   return result
   return table.concat(resultPart)
end
end