Anonymous

Module:Items/SourceTables: Difference between revisions

From Melvor Idle
m
Add custom separator for ItemSources
(_getCreationTable: Amend to show XP harvested per quantity for Farming)
m (Add custom separator for ItemSources)
 
(2 intermediate revisions by 2 users not shown)
Line 292: Line 292:
end
end


function p._getItemSources(item, asList, addCategories)
function p._getItemSources(item, asList, addCategories, separator)
local lineArray = {}
local lineArray = {}
local categoryArray = {}
local categoryArray = {}
local sep = separator or ','


--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...
Line 303: Line 304:
if monster.bones ~= nil and monster.bones.itemID == item.id and Monsters._getMonsterBones(monster) ~= nil then
if monster.bones ~= nil and monster.bones.itemID == 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
-- 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.barrierPercent ~= nil and 'melvorAoD:Barrier_Dust' == item.id and not Monsters._isDungeonOnlyMonster(monster) then
-- Item is Barrier Dust and is not a dungeon exclusive monster
isDrop = true
isDrop = true
elseif monster.lootTable ~= nil then
elseif monster.lootTable ~= nil then
Line 347: Line 351:


if not Shared.tableIsEmpty(dungeonStrPart) then
if not Shared.tableIsEmpty(dungeonStrPart) then
table.insert(lineArray, 'Completing: ' .. table.concat(dungeonStrPart, ','))
table.insert(lineArray, 'Completing: ' .. table.concat(dungeonStrPart, sep))
end
end
if not Shared.tableIsEmpty(killStrPart) then
if not Shared.tableIsEmpty(killStrPart) then
table.insert(lineArray, 'Killing: ' .. table.concat(killStrPart, ','))
table.insert(lineArray, 'Killing: ' .. table.concat(killStrPart, sep))
end
end


Line 367: Line 371:


if not Shared.tableIsEmpty(lootPart) then
if not Shared.tableIsEmpty(lootPart) then
table.insert(lineArray, 'Opening: ' .. table.concat(lootPart, ','))
table.insert(lineArray, 'Opening: ' .. table.concat(lootPart, sep))
end
end


Line 392: Line 396:
end
end
local typeText = (catName == 'up' and 'Upgrading') or 'Downgrading'
local typeText = (catName == 'up' and 'Upgrading') or 'Downgrading'
table.insert(lineArray, typeText .. ': ' .. table.concat(parts, ','))
table.insert(lineArray, typeText .. ': ' .. table.concat(parts, sep))
end
end
end
end
Line 411: Line 415:
end
end
if not Shared.tableIsEmpty(thiefPart) then
if not Shared.tableIsEmpty(thiefPart) then
table.insert(lineArray, 'Pickpocketing: ' .. table.concat(thiefPart, ','))
table.insert(lineArray, 'Pickpocketing: ' .. table.concat(thiefPart, sep))
end
end
end
end
Line 421: Line 425:
end
end
if not Shared.tableIsEmpty(castPart) then
if not Shared.tableIsEmpty(castPart) then
table.insert(lineArray, 'Casting: ' .. table.concat(castPart, ','))
table.insert(lineArray, 'Casting: ' .. table.concat(castPart, sep))
end
end


Line 786: Line 790:
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!Source!!Source Type!!Quantity!!colspan="2"|Chance')
table.insert(resultPart, '\r\n!Source!!Level!!Quantity!!colspan="2"|Chance')


--Set up function for adding rows
--Set up function for adding rows
local buildRow = function(source, type, minqty, qty, weight, totalWeight, expIcon)
local buildRow = function(source, level, levelNum, minqty, qty, weight, totalWeight, expIcon)
if minqty == nil then minqty = 1 end
if minqty == nil then minqty = 1 end
if expIcon == nil then expIcon = '' end
if expIcon == nil then expIcon = '' end
if level == nil then level = 'N/A' end
local rowPart = {}
local rowPart = {}
table.insert(rowPart, '\r\n|-')
table.insert(rowPart, '\r\n|-')
table.insert(rowPart, '\r\n|style="text-align: left;"|'..source)
table.insert(rowPart, '\r\n|style="text-align: left;"|'..source)
--Weeding out brackets since they don't play nice with data-sort-value
-- Retrieve numeric level value for sorting, or remove anything between [[]]
local _, _, typeText = string.find(type, "%|([%a%s]+)%]")
local levelValue = ''
if typeText == nil then _, _, typeText = string.find(type, "%[%[([%a%s]+)%]") end
if levelNum ~= nil then
if typeText == nil then typeText = type end
levelValue = tostring(levelNum)
table.insert(rowPart, '\r\n|style="text-align: left;" data-sort-value="'..typeText..'"|'..expIcon..type)
else
 
levelValue = level:match('%[%[.-%]%]%s*(%w+)$') or ''
end
table.insert(rowPart, '\r\n|style="text-align: left;" data-sort-value="'..levelValue..'"|'..expIcon.. level)
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="'..qty..'"|'..Shared.formatnum(minqty))
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="'..qty..'"|'..Shared.formatnum(minqty))
if qty ~= minqty then table.insert(rowPart, ' - '..Shared.formatnum(qty)) end
if qty ~= minqty then table.insert(rowPart, ' - '..Shared.formatnum(qty)) end
Line 839: Line 846:
iconName = SourceOverrides[drop.id]
iconName = SourceOverrides[drop.id]
end
end
if monster ~= nil then
if monster ~= nil then
table.insert(dropRows, {source = Icons.Icon({iconName, type='monster'}), type = '[[Monster]]', minqty = drop.minQty, qty = drop.maxQty, weight = drop.dropWt, totalWeight = drop.totalWt, expIcon = Icons.getExpansionIcon(drop.id)})
local monsterLevel = Monsters._getMonsterCombatLevel(monster)
table.insert(dropRows, {
source = Icons.Icon({iconName, type='monster'}),  
level = Icons.Icon({'Monsters', img='Combat', notext=true}) .. ' Level ' .. Shared.formatnum(monsterLevel),
levelNum = monsterLevel,
minqty = drop.minQty,  
qty = drop.maxQty,  
weight = drop.dropWt,  
totalWeight = drop.totalWt,  
expIcon = Icons.getExpansionIcon(drop.id)})
end
end
end
end
Line 848: Line 865:
for i, drop in ipairs(p._getItemArchSources(item)) do
for i, drop in ipairs(p._getItemArchSources(item)) do
if drop.name ~= nil then
if drop.name ~= nil then
table.insert(dropRows, {source = Icons.Icon({drop.name, type='poi'}), type = '[[Archaeology|Dig Site]] ('..drop.size..')', minqty = drop.minQty, qty = drop.maxQty, weight = drop.dropWt, totalWeight = drop.totalWt, expIcon = Icons.getExpansionIcon(drop.id)})
table.insert(dropRows, {
source = Icons.Icon({drop.name, type='poi'}),  
level = Icons._SkillReq('Archaeology', drop.level) .. ' ('..drop.size..')',
levelNum = drop.level,
minqty = drop.minQty,  
qty = drop.maxQty,  
weight = drop.dropWt,  
totalWeight = drop.totalWt,  
expIcon = Icons.getExpansionIcon(drop.id)})
end
end
end
end
Line 856: Line 881:
if (dungeon.oneTimeRewardID ~= nil and item.id == dungeon.oneTimeRewardID) or
if (dungeon.oneTimeRewardID ~= nil and item.id == dungeon.oneTimeRewardID) or
(type(dungeon.rewardItemIDs) == 'table' and Shared.contains(dungeon.rewardItemIDs, item.id)) then
(type(dungeon.rewardItemIDs) == 'table' and Shared.contains(dungeon.rewardItemIDs, item.id)) then
table.insert(dropRows, {source = Icons.Icon({dungeon.name, type='dungeon'}), type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1, expIcon = Icons.getExpansionIcon(dungeon.id)})
table.insert(dropRows, {
source = Icons.Icon({dungeon.name, type='dungeon'}),  
level = '[[Dungeon]]',
minqty = 1,  
qty = 1,  
weight = 1,  
totalWeight = 1,  
expIcon = Icons.getExpansionIcon(dungeon.id)})
elseif dungeon.eventID ~= nil then
elseif dungeon.eventID ~= nil then
-- Is the item dropped from a combat event (e.g. Impending Darkness event)?
-- Is the item dropped from a combat event (e.g. Impending Darkness event)?
Line 864: Line 896:
if item.id == itemRewardID then
if item.id == itemRewardID then
local sourceTxt = Icons.Icon({dungeon.name, type='dungeon'}) .. (eventCycle == Shared.tableCount(event.itemRewardIDs) and '' or ', Cycle ' .. eventCycle)
local sourceTxt = Icons.Icon({dungeon.name, type='dungeon'}) .. (eventCycle == Shared.tableCount(event.itemRewardIDs) and '' or ', Cycle ' .. eventCycle)
table.insert(dropRows, {source = sourceTxt, type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1})
table.insert(dropRows, {
source = sourceTxt,  
level = '[[Dungeon]]',
minqty = 1,  
qty = 1,  
weight = 1,  
totalWeight = 1})
break
break
end
end
Line 887: Line 925:
if wt > 0 then
if wt > 0 then
local sourceTxt = Icons.Icon({item2.name, type='item'})
local sourceTxt = Icons.Icon({item2.name, type='item'})
table.insert(dropRows, {source = sourceTxt, type = '[[Chest]]', minqty = minQty, qty = maxQty, weight = wt, totalWeight = totalWt, expIcon = Icons.getExpansionIcon(item2.id)})
table.insert(dropRows, {
source = sourceTxt,  
level = '[[Chest]]',
minqty = minQty,  
qty = maxQty,  
weight = wt,  
totalWeight = totalWt,  
expIcon = Icons.getExpansionIcon(item2.id)})
end
end
end
end
Line 901: Line 946:
sourceTxt = Icons.Icon({thiefRow.npc, type='thieving'})
sourceTxt = Icons.Icon({thiefRow.npc, type='thieving'})
end
end
table.insert(dropRows, {source = sourceTxt, type = Icons.Icon({SkillData.Thieving.name, type='skill'}), minqty = thiefRow.minQty, qty = thiefRow.maxQty, weight = thiefRow.wt, totalWeight = thiefRow.totalWt, expIcon = Icons.getExpansionIcon(thiefRow.npcID)})
table.insert(dropRows, {
source = sourceTxt,  
level = Icons._SkillReq("Thieving", thiefRow.level),
levelNum = thiefRow.level,
minqty = thiefRow.minQty,  
qty = thiefRow.maxQty,  
weight = thiefRow.wt,  
totalWeight = thiefRow.totalWt,  
expIcon = Icons.getExpansionIcon(thiefRow.npcID)})
end
end


Line 909: Line 962:
local fishType = Icons.Icon({'Fishing', type='skill'})
local fishType = Icons.Icon({'Fishing', type='skill'})
local fishTotWeight = Shared.tableCount(SkillData.Fishing.JunkItems)
local fishTotWeight = Shared.tableCount(SkillData.Fishing.JunkItems)
table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, weight = 1, totalWeight = fishTotWeight})
table.insert(dropRows, {
source = fishSource,  
level = Icons._SkillReq("Fishing", 1),
levelNum = 1,
minqty = 1,  
qty = 1,  
weight = 1,  
totalWeight = fishTotWeight})
else
else
local fishTotWeight, fishItem = 0, nil
local fishTotWeight, fishItem = 0, nil
Line 921: Line 981:
local fishSource = '[[Fishing#Special|Special]]'
local fishSource = '[[Fishing#Special|Special]]'
local fishType = Icons.Icon({SkillData.Fishing.name, type='skill'})
local fishType = Icons.Icon({SkillData.Fishing.name, type='skill'})
table.insert(dropRows, {source = fishSource, type = fishType, minqty = fishItem.minQuantity, qty = fishItem.maxQuantity, weight = fishItem.weight, totalWeight = fishTotWeight})
table.insert(dropRows, {
source = fishSource,  
level = Icons._SkillReq("Fishing", 1),
levelNum = 1,
minqty = fishItem.minQuantity,  
qty = fishItem.maxQuantity,  
weight = fishItem.weight,  
totalWeight = fishTotWeight})
end
end
end
end
Line 937: Line 1,004:
end
end
if thisGem ~= nil then
if thisGem ~= nil then
local mineType = Icons.Icon({SkillData.Mining.name, type='skill'})
local expIcon = ''
local expIcon = ''
local sourceTxt
local sourceTxt
local lv = nil
if item.type == 'Superior Gem' then
if item.type == 'Superior Gem' then
expIcon = Icons.TotH()
expIcon = Icons.TotH()
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
-- Superior gems can only be found with Mining 100 or above
lv = 100
else
else
sourceTxt = '[[Mining#Gems|Gem]]'
sourceTxt = '[[Mining#Gems|Gem]]'
-- Gems can only be found with any Mining level
lv = 1
end
end
table.insert(dropRows, {source = sourceTxt, type = mineType, minqty = thisGem.minQuantity, qty = thisGem.maxQuantity, weight = thisGem.weight, totalWeight = totalGemWeight, expIcon = expIcon})
table.insert(dropRows, {
source = sourceTxt,  
level = Icons._SkillReq('Mining', lv),
levelNum = lv,
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,  
weight = thisGem.weight,  
totalWeight = totalGemWeight,  
expIcon = expIcon})
-- Check for Alt. Magic spells also
-- Check for Alt. Magic spells also
local magicType = Icons.Icon({SkillData.Magic.name, type = 'skill'})
local producesKey = (gemKey == 'randomGems' and 'RandomGem') or 'RandomSuperiorGem'
local producesKey = (gemKey == 'randomGems' and 'RandomGem') or 'RandomSuperiorGem'
for j, spell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
for j, spell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
if spell.produces ~= nil and spell.produces == producesKey then
if spell.produces ~= nil and spell.produces == producesKey then
table.insert(dropRows, {source = Icons.Icon({spell.name, type=Magic._getSpellIconType(spell)}), type = magicType, minqty = thisGem.minQuantity, qty = thisGem.maxQuantity, weight = thisGem.weight, totalWeight = totalGemWeight, expIcon = Icons.getExpansionIcon(spell.id)})
table.insert(dropRows, {
source = Icons.Icon({spell.name, type=Magic._getSpellIconType(spell)}),
level = Icons.Icon({'Alternative Magic', type='skill', img='Magic', notext=true}) .. ' Level ' .. spell.level,
levelNum = spell.level,
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,
weight = thisGem.weight,  
totalWeight = totalGemWeight,
expIcon = Icons.getExpansionIcon(spell.id)})
end
end
end
end
Line 966: Line 1,052:
if a.weight / a.totalWeight == b.weight / b.totalWeight then
if a.weight / a.totalWeight == b.weight / b.totalWeight then
if a.minqty + a.qty == b.minqty + b.qty then
if a.minqty + a.qty == b.minqty + b.qty then
return (a.type == b.type and a.source < b.source) or a.type < b.type
return (a.level == b.level and a.source < b.source) or a.level < b.level
else
else
return a.minqty + a.qty > b.minqty + b.qty
return a.minqty + a.qty > b.minqty + b.qty
Line 975: Line 1,061:
end)
end)
for i, data in ipairs(dropRows) do
for i, data in ipairs(dropRows) do
table.insert(resultPart, buildRow(data.source, data.type, data.minqty, data.qty, data.weight, data.totalWeight, data.expIcon))
table.insert(resultPart, buildRow(data.source, data.level, data.levelNum, data.minqty, data.qty, data.weight, data.totalWeight, data.expIcon))
end
end


Line 1,199: Line 1,285:
chance = 1
chance = 1
weight = 1
weight = 1
elseif monster.barrierPercent ~= nil and 'melvorAoD:Barrier_Dust' == item.id and not Monsters._isDungeonOnlyMonster(monster) then
-- Item is Barrier Dust and is not a dungeon exclusive monster
maxQty = math.max(math.floor(Monsters._getMonsterStat(monster, 'Barrier') / 10 / 20), 1)
minQty = maxQty
chance = 1
elseif monster.lootTable ~= nil and not Monsters._isDungeonOnlyMonster(monster) then
elseif monster.lootTable ~= nil and not Monsters._isDungeonOnlyMonster(monster) then
-- If the monster has a loot table, check if the item we are looking for is in there
-- If the monster has a loot table, check if the item we are looking for is in there
Line 1,250: Line 1,341:
local min = found.minQuantity
local min = found.minQuantity
local max = found.maxQuantity
local max = found.maxQuantity
table.insert(resultArray, {id = digSite.id, name = digSite.name, size = sizeName, minQty = min, maxQty = max, dropWt = found.weight, totalWt = sizeWeight})
table.insert(resultArray, {
id = digSite.id,  
name = digSite.name,  
level = digSite.level,
size = sizeName,  
minQty = min,  
maxQty = max,  
dropWt = found.weight,  
totalWt = sizeWeight})
end
end
end
end
Line 1,309: Line 1,408:
"Paper",
"Paper",
"Lemon",
"Lemon",
"Aranite Brush"
"Aranite Brush",
"Barrier Dust"
}
}
local checkFuncs = {
local checkFuncs = {
914

edits