Anonymous

Module:Sandbox/AuronTest/SourceTables: Difference between revisions

From Melvor Idle
Testing Items/SourceTables for 1.0.2
m (Fix header)
(Testing Items/SourceTables for 1.0.2)
Line 1: Line 1:
local p = {}
local p = {}
local MonsterData = mw.loadData('Module:Monsters/data')
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:AuronTest/data')


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Areas = require('Module:CombatAreas')
local Magic = require('Module:AuronTest/Magic')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Shop = require('Module:Shop')
local Monsters = require('Module:Monsters')
local Monsters = require('Module:Monsters')
local Magic = require('Module:Magic')
local GatheringSkills = require('Module:Skills/Gathering')
local Attacks = require('Module:AuronTest')
 
-- Implements overrides for sources which cannot be obtained from game data
-- Currently only overrides for dungeon sources are implemented here
local sourceOverrides = {
['Dungeon'] = {
[950] = 'Volcanic Cave', -- A Tale of the Past, a future's prophecy
[951] = 'Fire God Dungeon', -- The First Hero and an Unknown Evil
[1116] = 'Into the Mist' -- Beginning of the End
}
}
 
local SkillEnum = {}
for i, skill in pairs(SkillData.Skills) do
SkillEnum[skill.name] = Constants.getSkillID(skill.name)
end
 
function p._getCreationTable(item)
local skill = ''
local specialReq = nil
local time = 0
local maxTime = nil
local lvl = 0
local xp = 0
local qty = nil
local req = nil
 
local tables = {}
--First figure out what skill is used to make this...
if type(item.masteryID) == 'table' then
local skillID, masteryID = item.masteryID[1], item.masteryID[2]
skill = Constants.getSkillName(skillID)
if skillID == SkillEnum.Fishing then
-- Fishing
lvl = item.fishingLevel
xp = item.fishingXP
qty = 1
time = item.minFishingInterval / 1000
maxTime = item.maxFishingInterval / 1000
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time, maxTime))
elseif skillID == SkillEnum.Cooking then
-- Cooking
for i, reqSet in pairs(item.recipeRequirements) do
lvl = item.cookingLevel
xp = item.cookingXP
req = reqSet
qty = item.cookingQty
time = item.cookingInterval / 1000
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
end
elseif skillID == SkillEnum.Mining then
-- Mining
local rock = SkillData.Mining.Rocks[masteryID + 1]
if rock ~= nil then
lvl = rock.levelRequired
xp = rock.baseExperience
qty = rock.baseQuantity
time = 3
if item.name == 'Dragonite Ore' then
specialReq = Icons.Icon({"Mastery", notext='true'})..' 271 total [[Mining]] [[Mastery]]'
end
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time, nil, specialReq))
end
elseif skillID == SkillEnum.Smithing then
-- Smithing
local recipe = SkillData.Smithing.Recipes[masteryID + 1]
if recipe ~= nil then
lvl = recipe.level
xp = recipe.baseXP
req = recipe.itemCosts
qty = recipe.baseQuantity
time = 2
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
end
elseif skillID == SkillEnum.Fletching then
-- Fletching
lvl = item.fletchingLevel
xp = item.fletchingXP
if item.name == 'Arrow Shafts' then
--Arrow Shafts get special (weird) treatment
req = '1 of any [[Log]]'
qty = '15 - 135'
else
req = item.fletchReq
qty = item.fletchQty
end
time = 2
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
elseif skillID == SkillEnum.Crafting then
-- Crafting
lvl = item.craftingLevel
xp = item.craftingXP
req = item.craftReq
qty = item.craftQty
time = 3
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
elseif skillID == SkillEnum.Runecrafting then
-- Runecrafting
lvl = item.runecraftingLevel
xp = item.runecraftingXP
req = item.runecraftReq
qty = item.runecraftQty
time = 2
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
elseif skillID == SkillEnum.Herblore then
-- Herblore
local potion = SkillData.Herblore.Potions[masteryID + 1]
if potion ~= nil then
lvl = potion.level
xp = potion.baseXP
req = potion.itemCosts
qty = 1
time = 2
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
end
elseif skillID == SkillEnum.Summoning then
-- Summoning
lvl = item.summoningLevel
--Summoning uses a formula to calculate XP for creation instead of referring to the item's XP data directly
xp = (5 + 2 * math.floor(item.summoningLevel / 5))
local ShardCostArray = {}
for j, cost in Shared.skpairs(item.summoningReq[1]) do
if cost.id >= 0 then
local item = Items.getItemByID(cost.id)
if item.type == 'Shard' then
table.insert(ShardCostArray, Icons.Icon({item.name, type='item', notext=true, qty=cost.qty}))
end
end
end
req = table.concat(ShardCostArray, ', ')
req = req..'<br/>\r\nand one of the following<br/>\r\n'
local OtherCostArray = {}
local recipeGPCost = SkillData.Summoning.Settings.recipeGPCost
for j, altCost in Shared.skpairs(item.summoningReq) do
local nonShardArray = {}
for k, cost in Shared.skpairs(altCost) do
if cost.id >= 0 then
local item = Items.getItemByID(cost.id)
if item.type ~= 'Shard' then
local sellPrice = math.max(item.sellsFor, 20)
table.insert(nonShardArray, Icons.Icon({item.name, type='item', notext=true, qty=math.max(1, math.floor(recipeGPCost / sellPrice))}))
end
elseif cost.id == -4 then
table.insert(nonShardArray, Icons.GP(recipeGPCost))
elseif cost.id == -5 then
table.insert(nonShardArray, Icons.SC(recipeGPCost))
end
end
table.insert(OtherCostArray, table.concat(nonShardArray, ', '))
end
req = req..table.concat(OtherCostArray, "<br/>'''OR''' ")
qty = item.summoningQty
time = 5
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
end
end
 
-- Woodcutting
if item.type == "Logs" then
-- Determine which tree (if any) the log is from
for i, tree in ipairs(SkillData.Woodcutting.Trees) do
if tree.logID == item.id then
skill = 'Woodcutting'
lvl = tree.levelRequired
time = tree.baseInterval / 1000
xp = tree.baseExperience
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
break
end
end
end
 
--had to add cooking to the list of valid categories here to account for cherries/apples
if item.category == 'Cooking' or item.type == "Harvest" or item.type == "Herb" or item.type == "Logs" or Shared.contains(item.name, '(Perfect)') then
--Harvest/Herb means farming
--Logs might mean farming or might not. Depends on the logs
for i, item2 in pairs(ItemData.Items) do
if item2.grownItemID == item.id then
skill = 'Farming'
lvl = item2.farmingLevel
xp = item2.farmingXP
time = item2.timeToGrow
if item.type == 'Logs' then
qty = 35
else
qty = 15
end
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
end
 
--If this is a perfect item, need to find the original
if item2.perfectItem == item.id and item2.recipeRequirements ~= nil then
for j, reqSet in pairs(item2.recipeRequirements) do
skill = 'Cooking'
lvl = item2.cookingLevel
xp = item2.cookingXP
req = reqSet
qty = item2.cookingQty
time = item2.cookingInterval / 1000
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
end
end
end
end
 
-- Alt. Magic, excludes Gems and Bars
-- Bars are handled by getItemSuperheatTable()
-- Gems are handled by _getItemLootSourceTable()
-- TODO Should be able to iterate AltMagic.spells, checking the produces property
if item.name == 'Rune Essence' then
table.insert(tables, p.buildAltMagicTable('Just Learning'))
elseif item.name == 'Bones' then
table.insert(tables, p.buildAltMagicTable('Bone Offering'))
elseif item.name == 'Holy Dust' then
table.insert(tables, p.buildAltMagicTable('Blessed Offering'))
end
 
if Shared.tableCount(tables) == 0 then
return ""
else
return table.concat(tables, '\r\n')
end
end
 
-- Used by various Alt. Magic tables
function getRuneText(spell)
local formatRuneList = function(runes)
local runeList = {}
for i, req in ipairs(runes) do
local rune = Items.getItemByID(req.id)
if rune ~= nil then
table.insert(runeList, Icons.Icon({rune.name, type='item', notext=true, qty=req.qty}))
end
end
return table.concat(runeList, ', ')
end
if type(spell.runesRequired) == 'table' then
local resultPart  = {}
table.insert(resultPart, formatRuneList(spell.runesRequired))
if spell.runesRequiredAlt ~= nil and not Shared.tablesEqual(spell.runesRequired, spell.runesRequiredAlt) then
table.insert(resultPart, "<br/>'''OR'''<br/>" .. formatRuneList(spell.runesRequiredAlt))
end
return table.concat(resultPart)
else
return ''
end
end
 
function p.buildAltMagicTable(spellName)
local spell = Magic.getSpell(spellName, 'AltMagic')
local resultPart = {}
table.insert(resultPart, '{|class="wikitable"\r\n|-')
table.insert(resultPart, '\r\n!colspan="2"|'..Icons.Icon({spell.name, type='spell'}))
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Requirements')
table.insert(resultPart, '\r\n|'..Icons._SkillReq('Magic', spell.level))
 
-- The produces property of Alt magic spells is as follows:
-- -3 = A random gem, using the same weights as Mining
-- -2 = A bar of the type being created (Superheat)
-- -1 = GP (Alchemy)
--  0 = Undefined
-- >0 = Item ID of the item being produced
-- The amount produced is determined by the productionRatio property
 
-- The consumes property of Alt Magic spells is as follows:
-- 0 = Any item
-- 1 = Junk item
-- 2 = Superheat/ores with Coal
-- 3 = Superheat/ores without Coal
-- 4 = Nothing
-- 5 = Coal ore
-- Superheat (2, 3) is handled by _getItemSuperheatTable()
--
if spell.consumes ~= nil then
local consumeText = {
'1 of any item',
'1 of any [[Fishing#Junk|Junk]] item',
'1 x required ores for the chosen bar',
'1 x required ores (except ' .. Icons.Icon({'Coal Ore', type='item'}) .. ') for the chosen bar',
nil,
Icons.Icon({'Coal Ore', type='item', qty=1})
}
local consumeStr = consumeText[spell.consumes + 1]
if consumeStr ~= nil then
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Materials')
table.insert(resultPart, '\r\n| ' .. consumeStr)
end
end
 
--Add runes
local formatRuneList = function(runes)
local runeList = {}
for i, req in ipairs(runes) do
local rune = Items.getItemByID(req.id)
if rune ~= nil then
table.insert(runeList, Icons.Icon({rune.name, type='item', notext=true, qty=req.qty}))
end
end
return table.concat(runeList, ', ')
end
 
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Runes\r\n| ' .. getRuneText(spell))
 
--Now just need the output quantity, xp, and casting time (which is always 2)
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Base Quantity\r\n|'..spell.productionRatio)
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Base XP\r\n|'..spell.baseExperience)
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Cast Time\r\n|2s')
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
 
function p.buildCreationTable(skill, lvl, xp, req, qty, time, maxTime, specialReq, gpCost)
if qty == nil then qty = 1 end
local resultPart = {}
table.insert(resultPart, '{|class="wikitable"')
if req ~= nil then
table.insert(resultPart, '\r\n!colspan="2"|Item Creation')
else
table.insert(resultPart, '\r\n!colspan="2"|Item Production')
end
table.insert(resultPart, '\r\n|-\r\n!style="text-align: right;"|Requirements')
table.insert(resultPart, '\r\n|'..Icons._SkillReq(skill, lvl))
if specialReq ~= nil then table.insert(resultPart, '<br/>'..specialReq) end
 
if req ~= nil then
table.insert(resultPart, '\r\n|-\r\n!style="text-align: right;"|Materials\r\n|')
if type(req) == 'table' then
for i, mat in pairs(req) do
if i > 1 then table.insert(resultPart, '<br/>') end
local matItem = Items.getItemByID(mat.id)
if matItem == nil then
table.insert(resultPart, mat.qty..'x ?????')
else
table.insert(resultPart, Icons.Icon({matItem.name, type='item', qty=mat.qty}))
end
end
if gpCost ~= nil and gpCost > 0 then
table.insert(resultPart, '<br/>')
table.insert(resultPart, Icons.GP(gpCost))
end
else
table.insert(resultPart, req)
end
end
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Base Quantity')
table.insert(resultPart, '\r\n|'..qty)
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Base Experience')
table.insert(resultPart, '\r\n|'..Shared.formatnum(xp)..' XP')
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Base Creation Time')
table.insert(resultPart, '\r\n|'..Shared.formatnum(Shared.round(time, 2, 0))..'s')
if maxTime ~= nil then table.insert(resultPart, ' - '..Shared.formatnum(Shared.round(maxTime, 2, 0))..'s') end
table.insert(resultPart, '\r\n|}')
 
return table.concat(resultPart)
end
 
function p.getCreationTable(frame)
local itemName = frame.args ~= nil and frame.args[1] or frame
local item = Items.getItem(itemName)
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
end
 
return p._getCreationTable(item)
end
 
function p._getItemSources(item, asList, addCategories)
local lineArray = {}
local categoryArray = {}
 
--Alright, time to go through all the ways you can get an item...
--First up: Can we kill somebody and take theirs?
local killStrPart = {}
for i, monster in ipairs(MonsterData.Monsters) do
local isDrop = false
if monster.bones == item.id and Monsters._getMonsterBones(monster) ~= nil then
-- Item is a bone, and is either a shard from God dungeons or dropped by a non-boss monster with a loot table
isDrop = true
elseif monster.lootTable ~= nil then
-- If the monster has a loot table, check if the item we are looking for is in there
-- Dungeon exclusive monsters don't count as they are either:
--  - A monster before the boss, which doesn't drop anything except shards (checked above)
--  - A boss monster, whose drops are accounted for in data from Areas instead
for j, loot in ipairs(monster.lootTable) do
if loot[1] == item.id and not Monsters._isDungeonOnlyMonster(monster) then
isDrop = true
break
end
end
end
if isDrop then
-- Item drops when the monster is killed
table.insert(killStrPart, Icons.Icon({monster.name, type='monster', notext=true}))
end
end
-- Is the item dropped from any dungeon?
local dungeonStrPart = {}
local dungeonList = Areas.getAreas(function(area) return area.type == 'dungeon' and type(area.rewards) == 'table' and Shared.contains(area.rewards, item.id) end)
if dungeonList ~= nil then
for i, dungeon in ipairs(dungeonList) do
table.insert(dungeonStrPart, Icons.Icon({dungeon.name, type='dungeon', notext=true}))
end
end
-- Is the item dropped from a cycle of the Impending Darkness event?
for i, eventItemID in ipairs(Areas.eventData.rewards) do
if item.id == eventItemID then
local dungPrefix = (i == Shared.tableCount(Areas.eventData.rewards) and '' or i .. ' ' .. (i == 1 and 'cycle' or 'cycles') .. ' of ')
table.insert(dungeonStrPart, dungPrefix .. Icons.Icon({'Impending Darkness Event', type='dungeon', notext=true}))
break
end
end
-- Special exceptions for lore books
if sourceOverrides['Dungeon'][item.id] ~= nil then
table.insert(dungeonStrPart, Icons.Icon({sourceOverrides['Dungeon'][item.id], type='dungeon', notext=true}))
end
 
if Shared.tableCount(dungeonStrPart) > 0 then
table.insert(lineArray, 'Completing: ' .. table.concat(dungeonStrPart, ','))
end
if Shared.tableCount(killStrPart) > 0 then
table.insert(lineArray, 'Killing: ' .. table.concat(killStrPart, ','))
end
 
--Next: Can we find it in a box?
--While we're here, check for upgrades, originals (for perfect items), and growing
local lootStr = ''
local upgradeStr = ''
local cookStr = ''
local growStr = ''
local count1 = 0
local count2 = 0
for i, item2 in pairs(ItemData.Items) do
if item2.dropTable ~= nil then
for j, loot in pairs(item2.dropTable) do
if loot[1] == item.id then
count1 = count1 + 1
if string.len(lootStr) > 0 then
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
if item2.trimmedItemID == item.id then
count2 = count2 + 1
if string.len(upgradeStr) > 0 then
upgradeStr = upgradeStr..','
--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]]')
upgradeStr = upgradeStr..'Upgrading: '..Icons.Icon({item2.name, type="item", notext="true"})
end
end
if item2.grownItemID == item.id then
-- Farming
if string.len(growStr) > 0 then
growStr = growStr..','..Icons.Icon({item2.name, type="item", notext="true"})
else
table.insert(categoryArray, '[[Category:Harvestable Items]]')
growStr = growStr..'Growing: '..Icons.Icon({item2.name, type="item", notext="true"})
end
end
if item2.perfectItem == item.id and item2.cookingLevel ~= nil then
-- Cooking (Perfect items)
table.insert(lineArray, Icons._SkillReq('Cooking', item2.cookingLevel))
end
end
if string.len(lootStr) > 0 then table.insert(lineArray, lootStr) end
if string.len(upgradeStr) > 0 then table.insert(lineArray, upgradeStr) end
if string.len(cookStr) > 0 then table.insert(lineArray, cookStr) end
if string.len(growStr) > 0 then table.insert(lineArray, growStr) end
 
--Next: Can we take it from somebody else -without- killing them?
local thiefItems = GatheringSkills.getThievingSourcesForItem(item.id)
local thiefStr = ''
if Shared.tableCount(thiefItems) > 0 then
thiefStr = 'Pickpocketing: '
for i, thiefRow in pairs(thiefItems) do
if thiefRow.npc == 'all' then
--if 'any' is the npc, this is a rare item so just say 'Thieving level 1'
thiefStr = Icons._SkillReq('Thieving', 1)
else
if i > 1 then thiefStr = thiefStr..', ' end
thiefStr = thiefStr..Icons.Icon({thiefRow.npc, type='thieving', notext='true'})
end
end
end
if string.len(thiefStr) > 0 then table.insert(lineArray, thiefStr) end
 
--If all else fails, I guess we should check if we can make it ourselves
--AstrologyCheck
--(Just a brute force for now because only two items and I'm lazy)
if item.name == 'Stardust' or item.name == 'Golden Stardust' then
table.insert(lineArray, Icons.Icon({"Astrology", type="skill"}))
end
 
-- Sources discoverable through mastery IDs
if type(item.masteryID) == 'table' then
local skillID, masteryID = item.masteryID[1], item.masteryID[2]
local skill, levelReq = Constants.getSkillName(skillID), nil
if skillID == SkillEnum.Fishing then
-- Fishing (less Junk & Special items)
levelReq = item.fishingLevel
elseif skillID == SkillEnum.Cooking then
-- Cooking (less Perfect items)
levelReq = item.cookingLevel
elseif skillID == SkillEnum.Mining then
-- Mining
local rock = SkillData.Mining.Rocks[masteryID + 1]
if rock ~= nil then
levelReq = rock.levelRequired
end
elseif skillID == SkillEnum.Smithing then
-- Smithing
local recipe = SkillData.Smithing.Recipes[masteryID + 1]
if recipe ~= nil then
levelReq = recipe.level
end
elseif skillID == SkillEnum.Fletching then
-- Fletching
levelReq = item.fletchingLevel
elseif skillID == SkillEnum.Crafting then
-- Crafting
levelReq = item.craftingLevel
elseif skillID == SkillEnum.Runecrafting then
-- Runecrafting
levelReq = item.runecraftingLevel
elseif skillID == SkillEnum.Herblore then
-- Herblore
local potion = SkillData.Herblore.Potions[masteryID + 1]
if potion ~= nil then
levelReq = potion.level
end
elseif skillID == SkillEnum.Summoning then
-- Summoning
levelReq = item.summoningLevel
end
if levelReq ~= nil then
table.insert(lineArray, Icons._SkillReq(skill, levelReq))
end
end
 
-- Woodcutting
for i, tree in ipairs(SkillData.Woodcutting.Trees) do
if tree.logID == item.id then
table.insert(lineArray, Icons._SkillReq('Woodcutting', tree.levelRequired))
break
end
end
 
-- Woodcutting (Nests)
if item.name == 'Bird Nest' then
table.insert(lineArray, Icons._SkillReq('Woodcutting', 1))
end
 
-- Fishing (Junk & Special items)
if (item.category == "Fishing" and (item.type == "Junk" or item.type == "Special")) then
table.insert(lineArray, Icons.Icon({"Fishing", type='skill', notext=true})..' [[Fishing#'..item.type..'|'..item.type..']]')
end
 
--Finally there are some weird exceptions:
--Coal can be acquired via firemaking
if item.name == "Coal Ore" then
table.insert(lineArray, Icons._SkillReq("Firemaking", 1))
end
 
--Gems can be acquired from mining, fishing, and alt. magic
if item.type == 'Gem' and item.name ~= 'Jadestone' then
table.insert(lineArray, Icons.Icon({"Fishing", type='skill', notext=true})..' [[Fishing#Special|Special]]')
table.insert(lineArray, Icons.Icon({"Mining", type='skill', notext=true})..' [[Mining#Gems|Gem]]')
table.insert(lineArray, Icons.Icon({"Alt. Magic", type='skill'}))
end
 
--Bars and some other stuff can also be acquired via Alt. Magic
if item.type == 'Bar' or Shared.contains(Items.AltMagicProducts, item.name) then
table.insert(lineArray, Icons.Icon({"Alt. Magic", type='skill'}))
end
 
--Rhaelyx pieces are also special
if Shared.contains({'Circlet of Rhaelyx', 'Jewel of Rhaelyx', 'Mysterious Stone'}, item.name) then
local rhaSkills = {
Circlet = {'Woodcutting', 'Fishing', 'Mining', 'Thieving', 'Farming', 'Agility', 'Astrology'},
Jewel = {'Firemaking', 'Cooking', 'Smithing', 'Fletching', 'Crafting', 'Runecrafting', 'Herblore', 'Summoning'}
}
local rhaSkList = {}
if item.name == 'Circlet of Rhaelyx' then
rhaSkList = rhaSkills.Circlet
elseif item.name == 'Jewel of Rhaelyx' then
rhaSkList = rhaSkills.Jewel
elseif item.name == 'Mysterious Stone' then
rhaSkList = rhaSkills.Jewel
for i, v in ipairs(rhaSkills.Circlet) do
table.insert(rhaSkList, v)
end
end
 
local rhaStrPart = {}
for i, skillName in ipairs(rhaSkList) do
table.insert(rhaStrPart, Icons.Icon({skillName, type='skill', notext=true}))
end
local rhaStr = 'Any action in: ' .. table.concat(rhaStrPart, ', ')
if item.name == 'Mysterious Stone' then rhaStr = rhaStr .. '<br/>after finding ' .. Icons.Icon({'Crown of Rhaelyx', type='item'}) end
table.insert(lineArray, rhaStr)
end
 
--Tokens are from the appropriate skill
if item.isToken and item.skill ~= nil then
table.insert(lineArray, Icons._SkillReq(Constants.getSkillName(item.skill), 1))
end


function p._getSpecialAttackTable(effectDefn, categories, sourceHeaderLabel, includeSource)
--Shop items (including special items like gloves that aren't otherwise listed)
    local spAttTable = {}
local shopSources = Shop.getItemSourceArray(item.id)
    local attacks = Attacks.getAttacks(function(attack)
if Shared.tableCount(shopSources) > 0 then
                                          if effectDefn == nil then
table.insert(lineArray, Icons.Icon({'Shop'}))
                                              return true
end
                                          else
                                              return Attacks.attackHasEffect(attack, effectDefn)
                                          end
                                      end)
    local includeCat = {}
    for i, category in ipairs(categories) do
        includeCat[category] = true
    end


    -- Compile a list of monsters, items, spells, etc. for each included attack
--Easter Eggs (manual list 'cause don't have a better way to do that)
    for i, spAtt in ipairs(attacks) do
if Shared.contains(Items.EasterEggs, item.name) then
        -- Monsters
table.insert(lineArray, '[[Easter Eggs]]')
        if includeCat['Monster'] then
end
            for j, monsterID in ipairs(spAtt.monsters) do
-- Event exclusive items (also a manual list)
                local monster = Monsters.getMonsterByID(monsterID)
if Shared.contains(Items.EventItems, item.name) then
                local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)
table.insert(lineArray, '[[Events]]')
                local attChance = spAtt.defaultChance
end
                if overrideChance then
                    local attIdx = nil
                    for k, monsterAttack in ipairs(monster.specialAttacks) do
                        local attID = (type(monsterAttack) == 'table' and monsterAttack.id) or monsterAttack
                        if spAtt.id == attID then
                            attIdx = k
                            break
                        end
                    end
                    if attIdx ~= nil then
                        attChance = monster.overrideSpecialChances[attIdx]
                    end
                end


                table.insert(spAttTable, { idx = i, source = 'Monster', sourceSort = monster.name, sourceText = Icons.Icon({ monster.name, type = 'monster' }), chance = attChance, descType = 'monster' })
--Gold Topaz Ring drops from any action (when not wearing a Gold Topaz Ring)
            end
--Also handling Signet Ring things here
        end
if item.name == 'Gold Topaz Ring' then
table.insert(lineArray, 'Any non-combat action if not worn (Instead of '..Icons.Icon({"Signet Ring Half (a)", type="item"})..')')
table.insert(lineArray, 'Killing any monster if not worn (Instead of '..Icons.Icon({"Signet Ring Half (b)", type="item"})..')')
elseif item.name == 'Signet Ring Half (a)' then
table.insert(lineArray, 'Any non-combat action while wearing '..Icons.Icon({'Gold Topaz Ring', type='item'}))
elseif item.name == 'Signet Ring Half (b)' then
table.insert(lineArray, 'Killing any monster while wearing '..Icons.Icon({'Gold Topaz Ring', type='item'}))
end


        -- Items/Weapons
local resultPart = {}
        if includeCat['Item'] then
if asList then
            for j, itemID in ipairs(spAtt.items) do
table.insert(resultPart, '* '..table.concat(lineArray, "\r\n* "))
                local item = Items.getItemByID(itemID)
else
                table.insert(spAttTable, { idx = i, source = 'Weapon', sourceSort = item.name, sourceText = Icons.Icon({ item.name, type = 'item' }), chance = spAtt.defaultChance, descType = 'player' })
table.insert(resultPart, '<div style="max-width:180px;text-align:right">' .. table.concat(lineArray, "<br/>") .. '</div>')
            end
end
        end
if addCategories then table.insert(resultPart, table.concat(categoryArray, '')) end
return table.concat(resultPart)
end


        -- Spells
function p.getItemSources(frame)
        if includeCat['Spell'] then
local itemName = frame.args ~= nil and frame.args[1] or frame
            for j, spellID in ipairs(spAtt.spells) do
local item = Items.getItem(itemName)
                local spell = Magic.getSpellByID(spellID[1], spellID[2])
local asList = false
                table.insert(spAttTable, { idx = i, source = 'Spell', sourceSort = spell.name, sourceText = Icons.Icon({ spell.name, type = 'spell' }), chance = spAtt.defaultChance, descType = 'player' })
local addCategories = false
            end
if frame.args ~= nil then
        end
asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
    end
addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
end
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
end


    -- Summoning familiars. Any effects inflicted by combat familiars aren't actually special
return p._getItemSources(item, asList, addCategories)
    -- attacks, therefore the handling here is a bit different and outside of the above attack loop
end
    if includeCat['Familiar'] then
        local famIdx = Shared.tableCount(attacks) + 1
        local familiars = Items.getItems(function(item)
                                            if item.type == 'Familiar' and Items._getItemStat(item, 'summoningMaxhit') ~= nil and item.modifiers ~= nil then
                                                local famAttack = { prehitEffects = {}, onhitEffects = { { type = 'Modifier', subtype = 'Familiar', modifiers = item.modifiers } } }
                                                if effectDefn == nil then
                                                    return Shared.tableCount(Attacks.getAttackEffects(famAttack)) > 0
                                                else
                                                    return Attacks.attackHasEffect(famAttack, effectDefn)
                                                end
                                            end
                                            return false
                                        end)
        for j, familiar in ipairs(familiars) do
            -- For chance, assume the first modifier we come across has the chance, which is pretty lazy
            local famChance, famDesc = 0, ''
            for modName, modVal in pairs(familiar.modifiers) do
                if type(modVal) == 'table' and type(modVal[1]) == 'number' then
                    famChance = modVal[1]
                elseif type(modVal) == 'number' then
                    famChance = modVal
                else
                    famChance = 0
                end
                famDesc = Constants._getModifierText(modName, modVal, false)
                break
            end


            table.insert(spAttTable, { idx = famIdx, source = 'Familiar', sourceSort = familiar.name, sourceText = Icons.Icon({ familiar.name, type = 'item' }), chance = famChance or 0, descType = 'player' })
function p._getItemLootSourceTable(item)
            -- Slap a dummy entry into the attacks table for this familiar
local resultPart = {}
            attacks[famIdx] = { name = familiar.name .. ' (Familiar)', description = { player = famDesc } }
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
            famIdx = famIdx + 1
table.insert(resultPart, '\r\n|- class="headerRow-0"')
        end
table.insert(resultPart, '\r\n!Source!!Source Type!!Quantity!!colspan="2"|Chance')
    end


    -- Nothing to output if there are no row definitions
--Set up function for adding rows
    if Shared.tableCount(spAttTable) == 0 then
local buildRow = function(source, type, minqty, qty, weight, totalWeight)
    return ''
if minqty == nil then minqty = 1 end
    end
local rowPart = {}
table.insert(rowPart, '\r\n|-')
table.insert(rowPart, '\r\n|style="text-align: left;"|'..source)
table.insert(rowPart, '\r\n|style="text-align: left;"|'..type)


    -- Sort entries into desired order and generate stats to determine row spans:
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="'..qty..'"|'..minqty)
    -- By attack index, description type (monster/player), chance, source, then source name (weapon/item/etc.)
if qty ~= minqty then table.insert(rowPart, ' - '..qty) end
    table.sort(spAttTable, function (a, b)
local chance = weight / totalWeight * 100
                              local sortKeys = { 'idx', 'descType', 'chance', 'source', 'sourceSort' }
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places
                              for i, key in ipairs(sortKeys) do
local fmt = (chance < 0.10 and '%.2g') or '%.2f'
                                  if a[key] ~= b[key] then
chance = string.format(fmt, chance)
                                      return a[key] < b[key]
if weight >= totalWeight then
                                  end
-- Fraction would be 1/1, so only show the percentage
                              end
chance = 100
                              return false
table.insert(rowPart, '\r\n|colspan="2" ')
                          end)
else
    -- Determine row counts for grouping/rowspans
local fraction = Shared.fraction(weight, totalWeight)
    local rowCounts = {}
if Shared.contains(fraction, '%.') then
    for i, rowDefn in ipairs(spAttTable) do
--If fraction contains decimals, something screwy happened so just show only percentage
        local idx, dt, chance = rowDefn.idx, rowDefn.descType, rowDefn.chance
--(happens sometimes with the rare thieving items)
        if rowCounts[idx] == nil then
table.insert(rowPart, '\r\n|colspan="2" ')
            rowCounts[idx] = { rows = 0 }
else
        end
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="' .. chance .. '"| ' .. Shared.fraction(weight, totalWeight) .. '\r\n|')
        if rowCounts[idx][dt] == nil then
end
            rowCounts[idx][dt] = { rows = 0 }
end
        end
if weight == -1 then
        if rowCounts[idx][dt][chance] == nil then
--Weight of -1 means this is a weird row that has a variable percentage
            rowCounts[idx][dt][chance] = 0
table.insert(rowPart, 'style="text-align: right;" data-sort-value="0"|Varies (see Thieving page)')
        end
else
        rowCounts[idx]['rows'] = rowCounts[idx]['rows'] + 1
table.insert(rowPart, 'style="text-align: right;" data-sort-value="'.. chance .. '"|'..chance..'%')
        rowCounts[idx][dt]['rows'] = rowCounts[idx][dt]['rows'] + 1
end
        rowCounts[idx][dt][chance] = rowCounts[idx][dt][chance] + 1
return table.concat(rowPart)
    end
end
local dropRows = {}


    -- Generate output table
--Alright, time to go through a few ways to get the item
    local resultPart = {}
--First up: Can we kill somebody and take theirs?
    table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')
for i, monster in ipairs(MonsterData.Monsters) do
    table.insert(resultPart, '\r\n|- class="headerRow-0"')
local minqty = 1
    table.insert(resultPart, '\r\n!Name!!style="min-width:225px"| ' .. sourceHeaderLabel .. (includeSource and '!!Type' or '') .. '!!Chance!!Effect')
local qty = 1
local wt = 0
local totalWt = 0
--Only add bones if this monster has loot (ie appears outside a dungeon) and isn't a boss
--... unless we're looking for Shards of course, at which point we'll take any monster with the right bones
if monster.bones == item.id and Monsters._getMonsterBones(monster) ~= nil then
qty = monster.boneQty ~= nil and monster.boneQty or 1
minqty = qty
wt = 1
totalWt = 1
elseif monster.lootTable ~= nil then
-- If the monster has a loot table, check if the item we are looking for is in there
-- Dungeon exclusive monsters don't count as they are either:
--   - A monster before the boss, which doesn't drop anything except shards (checked above)
--  - A boss monster, whose drops are accounted for in data from Areas instead
for j, loot in ipairs(monster.lootTable) do
totalWt = totalWt + loot[2]
if loot[1] == item.id and not Monsters._isDungeonOnlyMonster(monster) then
wt = loot[2]
qty = loot[3]
end
end
end
local lootChance = monster.lootChance ~= nil and monster.bones ~= item.id and monster.lootChance or 100


    local firstRow = { idx = true, descType = true, chance = true }
if wt > 0 and lootChance > 0 then
    local prevRowVal = { idx = 0, descType = '', chance = 0 }
-- Item drops when the monster is killed
    local resetOnChange = {
table.insert(dropRows, {source = Icons.Icon({monster.name, type='monster'}), type = '[[Monster]]', minqty = minqty, qty = qty, weight = wt * lootChance, totalWeight = totalWt * 100})
        idx = { 'idx', 'descType', 'chance' },
end
        descType = { 'descType', 'chance' },
end
        chance = { 'chance' }
-- Is the item dropped from any dungeon?
    }
local dungeonList = Areas.getAreas(function(area) return area.type == 'dungeon' and type(area.rewards) == 'table' and Shared.contains(area.rewards, item.id) end)
    local rowSuffix = ''
if dungeonList ~= nil then
    for i, spAttRow in ipairs(spAttTable) do
for i, dungeon in ipairs(dungeonList) do
        local spIdx = spAttRow.idx
table.insert(dropRows, {source = Icons.Icon({dungeon.name, type='dungeon'}), type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1})
        local spAtt = attacks[spIdx]
end
        -- Determine if it's the first row for any of our groupings
end
        local resetKeys = {}
-- Is the item dropped from a cycle of the Impending Darkness event?
        for key, val in pairs(prevRowVal) do
for i, eventItemID in ipairs(Areas.eventData.rewards) do
            if spAttRow[key] ~= prevRowVal[key] then
if item.id == eventItemID then
                for j, keyName in ipairs(resetOnChange[key]) do
sourceTxt = Icons.Icon({'Impending Darkness Event', type='dungeon'}) .. (i == Shared.tableCount(Areas.eventData.rewards) and '' or ', Cycle ' .. i)
                    resetKeys[keyName] = true
table.insert(dropRows, {source = sourceTxt, type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1})
                end
break
            end
end
            prevRowVal[key] = spAttRow[key]
end
        end
--Special exception for the Fire/Infernal Cape and first two lore books as bonus dungeon drops
        for key, val in pairs(firstRow) do
if sourceOverrides['Dungeon'][item.id] ~= nil then
            firstRow[key] = (resetKeys[key] ~= nil)
local sourceTxt = Icons.Icon({sourceOverrides['Dungeon'][item.id], type='dungeon'})
        end
table.insert(dropRows, {source = sourceTxt, type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1})
end


        table.insert(resultPart, '\r\n|-')
--Next: Can we find it by rummaging around in another item?
        if firstRow.idx then
for i, item2 in pairs(ItemData.Items) do
            rowSuffix = (rowCounts[spIdx]['rows'] > 1 and '|rowspan="' .. rowCounts[spIdx]['rows'] .. '"') or ''
if item2.dropTable ~= nil then
            table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)
local qty = 1
        end
local wt = 0
        table.insert(resultPart, '\r\n|data-sort-value="' .. spAttRow.sourceSort .. '"| ' .. spAttRow.sourceText)
local totalWt = 0
        if includeSource then
for j, loot in pairs(item2.dropTable) do
            table.insert(resultPart, '\r\n| ' .. spAttRow.source)
totalWt = totalWt + loot[2]
        end
if loot[1] == item.id then
        if firstRow.chance then
wt = loot[2]
            rowSuffix = (rowCounts[spIdx][spAttRow.descType][spAttRow.chance] > 1 and 'rowspan="' .. rowCounts[spIdx][spAttRow.descType][spAttRow.chance] .. '" ') or ''
if item2.dropQty ~= nil then qty = item2.dropQty[j] end
            table.insert(resultPart, '\r\n|' .. rowSuffix .. 'data-sort-value="' .. spAttRow.chance .. '" style="text-align:right;"| ' .. Shared.round(spAttRow.chance, 2, 0) .. '%')
end
        end
end
        if firstRow.descType then
            rowSuffix = (rowCounts[spIdx][spAttRow.descType]['rows'] > 1 and '|rowspan="' .. rowCounts[spIdx][spAttRow.descType]['rows'] .. '"') or ''
            table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt['description'][spAttRow.descType])
        end
    end
    table.insert(resultPart, '\r\n|}')


    return table.concat(resultPart)
if wt > 0 then
local sourceTxt = Icons.Icon({item2.name, type='item'})
table.insert(dropRows, {source = sourceTxt, type = '[[Chest]]', minqty = 1, qty = qty, weight = wt, totalWeight = totalWt})
end
end
end
 
--Finally, let's try just stealing it
local thiefType = Icons.Icon({"Thieving", type='skill'})
local thiefItems = GatheringSkills.getThievingSourcesForItem(item.id)
for i, thiefRow in pairs(thiefItems) do
local sourceTxt = ''
if thiefRow.npc == 'all' then
sourceTxt = "Thieving Rare Drop"
else
sourceTxt = Icons.Icon({thiefRow.npc, type='thieving'})
end
table.insert(dropRows, {source = sourceTxt, type = thiefType, minqty = thiefRow.minQty, qty = thiefRow.maxQty, weight = thiefRow.wt, totalWeight = thiefRow.totalWt})
end
 
--Bonus overtime: Special Fishing table & mining gem table. Also Rags to Riches
--Jadestone is special and doesn't count
if item.type == 'Gem' and item.name ~= 'Jadestone' then
local mineType = Icons.Icon({'Mining', type='skill'})
local thisGemChance = Items.GemTable[item.name].chance
local totalGemChance = 0
for i, gem in pairs(Items.GemTable) do
totalGemChance = totalGemChance + gem.chance
end
table.insert(dropRows, {source = '[[Mining#Gems|Gem]]', type = mineType, minqty = 1, qty = 1, weight = thisGemChance, totalWeight = totalGemChance})
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, weight = thisGemChance, totalWeight = totalGemChance})
table.insert(dropRows, {source = Icons.Icon({"Rags to Riches II", type="spell"}), type = magicType, minqty = 1, qty = 1, weight = thisGemChance, totalWeight = totalGemChance})
end
 
if item.fishingCatchWeight ~= nil then
local fishSource = '[[Fishing#Special|Special]]'
local fishType = Icons.Icon({'Fishing', type='skill'})
table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, weight = item.fishingCatchWeight, totalWeight = Items.specialFishWt})
end
 
if item.type == 'Junk' then
local fishSource = '[[Fishing#Junk|Junk]]'
local fishType = Icons.Icon({'Fishing', type='skill'})
table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, weight = 1, totalWeight = Items.junkCount})
end
 
--Make sure to return nothing if there are no drop sources
if Shared.tableCount(dropRows) == 0 then return '' end
 
table.sort(dropRows, function(a, b)
if a.weight / a.totalWeight == b.weight / b.totalWeight then
return a.minqty + a.qty > b.minqty + b.qty
else
return a.weight / a.totalWeight > b.weight / b.totalWeight
end
end)
for i, data in pairs(dropRows) do
table.insert(resultPart, buildRow(data.source, data.type, data.minqty, data.qty, data.weight, data.totalWeight))
end
 
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
 
function p.getItemLootSourceTable(frame)
local itemName = frame.args ~= nil and frame.args[1] or frame
local item = Items.getItem(itemName)
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
end
 
return p._getItemLootSourceTable(item)
end
 
function p._getItemUpgradeTable(item)
local resultPart = {}
if item.itemsRequired ~= nil then
--First, get details on all the required materials
local upgradeFrom = {}
local materials = {}
for i, row in pairs(item.itemsRequired) do
local mat = Items.getItemByID(row[1])
--Check to see if the source item can trigger the upgrade
if mat.canUpgrade or (mat.type == 'Armour' and mat.canUpgrade == nil) then
table.insert(upgradeFrom, Icons.Icon({mat.name, type='item'}))
end
table.insert(materials, Icons.Icon({mat.name, type='item', qty=row[2]}))
end
if item.trimmedGPCost ~= nil then
table.insert(materials, Icons.GP(item.trimmedGPCost))
end
table.insert(resultPart, '{| class="wikitable"\r\n|-\r\n!colspan="2"|[[Upgrading Items|Item Upgrade]]')
--[[result = result..'\r\n|-\r\n!style="text-align:right;"|Upgrades From\r\n|'
result = result..table.concat(upgradeFrom, '<br/>')--]]
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Materials\r\n|')
table.insert(resultPart, table.concat(materials, '<br/>'))
table.insert(resultPart, '\r\n|}')
end
return table.concat(resultPart)
end
end


function p.getSpecialAttackTable(frame)
function p.getItemUpgradeTable(frame)
    local args = frame.args ~= nil and frame.args or frame
local itemName = frame.args ~= nil and frame.args[1] or frame
    local tableCategories = {'Monster', 'Item', 'Spell', 'Familiar'}
local item = Items.getItem(itemName)
    if args[1] ~= nil and args[1] ~= '' then
if item == nil then
        tableCategories = Shared.splitString(args[1], ',')
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
    end
end
    local effectName = args['effect']
    local sourceHeaderLabel = (args['sourceHeader'] ~= '' and args['sourceHeader']) or 'Source'
    local includeSource = true
    if args['includeSource'] ~= nil and string.lower(args['includeSource']) == 'false' then
        includeSource = false
    end
    local effectDefn = nil


    if effectName ~= nil and effectName ~= '' then
return p._getItemUpgradeTable(item)
        effectDefn = Attacks.effectDefinition[effectName]
end
        if effectDefn == nil then
            local validEffectNames = {}
            for k, v in pairs(Attacks.effectDefinition) do
                table.insert(validEffectNames, k)
            end
            table.sort(validEffectNames, function(a, b) return a < b end)


            return 'ERROR: Invalid effect name "' .. effectName .. '", must be one of: ' .. table.concat(validEffectNames, ', ') .. '[[Category:Pages with script errors]]'
function p._getItemSuperheatTable(item)
        end
--Manually build the Superheat Item table
    end
-- Validate that the item can be superheated
local canSuperheat, smithRecipe = true, nil
if type(item.masteryID) ~= 'table' then
canSuperheat = false
elseif item.masteryID[1] ~= SkillEnum.Smithing then
canSuperheat = false
else
smithRecipe = SkillData.Smithing.Recipes[item.masteryID[2] + 1]
if smithRecipe == nil or smithRecipe.category ~= 0 then
canSuperheat = false
end
end
if not canSuperheat then
return 'ERROR: The item "' .. item.name .. '" cannot be superheated[[Category:Pages with script errors]]'
end
 
local oreStringPart, coalString = {}, ''
for i, mat in ipairs(item.smithReq) do
local thisMat = Items.getItemByID(mat.id)
if thisMat.name == 'Coal Ore' then
coalString = Icons.Icon({thisMat.name, type='item', notext='true', qty=mat.qty})
else
table.insert(oreStringPart, Icons.Icon({thisMat.name, type='item', notext='true', qty=mat.qty}))
end
end
--Set up the header
local superheatTable = {}
table.insert(superheatTable, '{|class="wikitable"\r\n!colspan="2"|Spell')
table.insert(superheatTable, '!!'..Icons.Icon({'Smithing', type='skill', notext='true'})..' Level')
table.insert(superheatTable, '!!'..Icons.Icon({'Magic', type='skill', notext='true'})..' Level')
table.insert(superheatTable, '!!'..Icons.Icon({'Magic', type='skill', notext='true'})..' XP')
table.insert(superheatTable, '!!'..Icons.Icon({item.name, type='item', notext='true'})..' Bars')
table.insert(superheatTable, '!!Ore!!Runes')
--Loop through all the variants
local spellNames = {'Superheat I', 'Superheat II', 'Superheat III', 'Superheat IV'}
for i, sName in pairs(spellNames) do
local spell = Magic.getSpell(sName, 'AltMagic')
table.insert(superheatTable, '\r\n|-\r\n|'..Icons.Icon({spell.name, type='spell', notext=true, size=50}))
table.insert(superheatTable, '||'..Icons.Icon({spell.name, type='spell', noicon=true})..'||style="text-align:right;"|'..smithRecipe.level)
table.insert(superheatTable, '||style="text-align:right;"|'..spell.level..'||style="text-align:right;"|'..spell.baseExperience)
table.insert(superheatTable, '||style="text-align:right;"|'..spell.productionRatio)
table.insert(superheatTable, '|| '..table.concat(oreStringPart, ', '))
if spell.consumes == 2 then
-- 2 = Superheat with coal, 3 = Superheat without coal
table.insert(superheatTable, (Shared.tableCount(oreStringPart) > 0 and ', ' or '') .. coalString)
end
table.insert(superheatTable, '||style="text-align:center"| ' .. getRuneText(spell))
end
--Add the table end and add the table to the result string
table.insert(superheatTable, '\r\n|}')
return table.concat(superheatTable)
end
 
function p.getItemSuperheatTable(frame)
local itemName = frame.args ~= nil and frame.args[1] or frame
local item = Items.getItem(itemName)
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
end
 
return p._getItemSuperheatTable(item)
end
 
function p._getItemSourceTables(item)
local resultPart = {}
local shopTable = Shop._getItemShopTable(item)
if string.len(shopTable) > 0 then
table.insert(resultPart, '===Shop===\r\n'..shopTable)
end
 
local creationTable = p._getCreationTable(item)
if string.len(creationTable) > 0 then
if #resultPart > 0 then table.insert(resultPart, '\r\n') end
table.insert(resultPart, '===Creation===\r\n'..creationTable)
end
 
local upgradeTable = p._getItemUpgradeTable(item)
if string.len(upgradeTable) > 0 then
if #resultPart > 0 then table.insert(resultPart, '\r\n') end
if string.len(creationTable) == 0 then table.insert(resultPart, '===Creation===\r\n') end
table.insert(resultPart, upgradeTable)
end
 
if type(item.masteryID) == 'table' and item.masteryID[1] == SkillEnum.Smithing then
local recipe = SkillData.Smithing.Recipes[item.masteryID[2] + 1]
if recipe ~= nil and recipe.category == 0 then
table.insert(resultPart, '\r\n==='..Icons.Icon({'Alt Magic', type='skill'})..'===\r\n'..p._getItemSuperheatTable(item))
end
end
 
local lootTable = p._getItemLootSourceTable(item)
if string.len(lootTable) > 0 then
if #resultPart > 0 then table.insert(resultPart, '\r\n') end
table.insert(resultPart, '===Loot===\r\n'..lootTable)
end
return table.concat(resultPart)
end
 
function p.getItemSourceTables(frame)
local itemName = frame.args ~= nil and frame.args[1] or frame
local item = Items.getItem(itemName)
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
end
 
return p._getItemSourceTables(item)
end
 
function p.getCombatPassiveSlotItems(frame)
local resultPart = {}
table.insert(resultPart, '{| class="wikitable"\r\n')
table.insert(resultPart, '|-\r\n')
table.insert(resultPart, '!colspan="2"|Item\r\n! Passive\r\n')
 
local itemArray = Items.getItems(function(item) return item.validSlots ~= nil and Shared.contains(item.validSlots, 'Passive') end)
 
table.sort(itemArray, function(a, b) return a.id < b.id end)
 
for i, item in ipairs(itemArray) do
table.insert(resultPart, '|-\r\n')
table.insert(resultPart, '! '..Icons.Icon({item.name, type='item', notext='true'})..'\r\n! '..Icons.Icon({item.name, type='item', noicon=true})..'\r\n')
table.insert(resultPart, '| '..item.description..'\r\n')
end
 
table.insert(resultPart, '|}')
 
return table.concat(resultPart)
end
 
function p._getItemMonsterSources(item)
local resultArray = {}
for i, monster in ipairs(MonsterData.Monsters) do
local chance = 0
local weight = 0
local minQty = 1
local maxQty = 1
if monster.bones == item.id and Monsters._getMonsterBones(monster) ~= nil then
-- Item is a bone, and is either a shard from God dungeons or dropped by a non-boss monster with a loot table
chance = 1
weight = 1
if monster.boneQty ~= nil then
minQty = monster.boneQty
maxQty = monster.boneQty
end
elseif monster.lootTable ~= nil then
-- If the monster has a loot table, check if the item we are looking for is in there
-- Dungeon exclusive monsters don't count as they are either:
--  - A monster before the boss, which doesn't drop anything except shards (checked above)
--  - A boss monster, whose drops are accounted for in data from Areas instead
local monsterWeight
for j, loot in ipairs(monster.lootTable) do
weight = weight + loot[2]
if loot[1] == item.id and not Monsters._isDungeonOnlyMonster(monster) then
chance = loot[2]
maxQty = loot[3]
end
end
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
chance = chance * lootChance
weight = weight * 100
chance, weight = Shared.fractionpair(chance, weight)
end
if chance > 0 then
-- Item drops when the monster is killed
table.insert(resultArray, {id = monster.id, dropWt = chance, totalWt = weight, minQty = minQty, maxQty = maxQty})
end
end
return resultArray
end


    return p._getSpecialAttackTable(effectDefn, tableCategories, sourceHeaderLabel, includeSource)
function p.getItemMonsterSources(itemName)
local item = Items.getItem(itemName)
return p._getItemMonsterSources(item)
end
end


return p
return p