Anonymous

Module:Items/SourceTables: Difference between revisions

From Melvor Idle
Fix various issues
(Fix openable item sources)
(Fix various issues)
Line 47: Line 47:
-- Gathering skills
-- Gathering skills
-- All follow a similar data structure
-- All follow a similar data structure
for localSkillID, dataProp in ipairs(skillIDs.Gathering) do
for localSkillID, dataProp in pairs(skillIDs.Gathering) do
local skillData = SkillData[localSkillID]
local skillData = SkillData[localSkillID]
local skill = skillData.name
local skill = skillData.name
Line 56: Line 56:
xp = recipe.baseExperience
xp = recipe.baseExperience
qty = recipe.baseQuantity or 1
qty = recipe.baseQuantity or 1
if localSkillID == 'Farming' then
req = { recipe.seedCost }
end
-- Action time
-- Action time
if recipe.baseMinInterval ~= nil then
if recipe.baseMinInterval ~= nil then
Line 80: Line 83:
-- Artisan skills
-- Artisan skills
-- Allow follow a similar data structure
-- Allow follow a similar data structure
for localSkillID, dataProp in ipairs(skillIDs.Artisan) do
for localSkillID, dataProp in pairs(skillIDs.Artisan) do
local skillData = SkillData[localSkillID]
local skillData = SkillData[localSkillID]
local skill = skillData.name
local skill = skillData.name
local lvl, xp, qty, req, time, maxTime = 0, 0, 0, nil, 0, nil
local lvl, xp, qty, req, time, maxTime = 0, 0, 0, nil, 0, nil
for i, recipe in ipairs(skillData.recipes) do
for i, recipe in ipairs(skillData.recipes) do
if recipe.productID == itemID or (localSkillID == 'Cooking' and recipe.perfectCookID == itemID) then
if recipe.productID == itemID or
(localSkillID == 'Cooking' and recipe.perfectCookID == itemID) or
(localSkillID == 'Herblore' and Shared.contains(recipe.potionIDs, itemID)) then
lvl = recipe.level
lvl = recipe.level
xp = recipe.baseExperience
xp = recipe.baseExperience
Line 137: Line 142:
req = table.concat(shardCostArray, ', ')
req = table.concat(shardCostArray, ', ')
if not Shared.tableIsEmpty(otherCostArray) then
if not Shared.tableIsEmpty(otherCostArray) then
req = req .. '<br/>and one of the following:<br/>' .. table.concat(otherCostArray, "<br/>'''OR''' ")
local costLen = Shared.tableCount(otherCostArray)
req = req .. '<br/>' .. (costLen == 1 and '' or 'and one of the following:<br/>') .. table.concat(otherCostArray, "<br/>'''OR''' ")
end
end
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
table.insert(tables, p.buildCreationTable(skill, lvl, xp, req, qty, time))
Line 148: Line 154:
local reqItem = Items.getItemByID(itemCost.id)
local reqItem = Items.getItemByID(itemCost.id)
if reqItem == nil then
if reqItem == nil then
table.insert(reqSubPart, itemCost.qty .. 'x ?????')
table.insert(reqSubPart, itemCost.quantity .. 'x ?????')
else
else
table.insert(reqSubPart, Icons.Icon({reqItem.name, type='item', qty=itemCost.qty}))
table.insert(reqSubPart, Icons.Icon({reqItem.name, type='item', qty=itemCost.quantity}))
end
end
end
end
Line 162: Line 168:
table.insert(qtyPart, Shared.formatnum(qty * altCost.quantityMultiplier))
table.insert(qtyPart, Shared.formatnum(qty * altCost.quantityMultiplier))
end
end
local sep = "<br/>'''OR'''"
local sep = "<br/>'''OR''' "
req = table.concat(reqPart, sep)
req = table.concat(reqPart, sep)
local qtyText = table.concat(qtyPart, sep)
local qtyText = table.concat(qtyPart, sep)
Line 202: Line 208:
function p._buildAltMagicTable(spell)
function p._buildAltMagicTable(spell)
local resultPart = {}
local resultPart = {}
local imgType = p._getSpellIconType(spell)
local imgType = Magic._getSpellIconType(spell)
table.insert(resultPart, '{|class="wikitable"\r\n|-')
table.insert(resultPart, '{|class="wikitable"\r\n|-')
table.insert(resultPart, '\r\n!colspan="2"|'..Icons.Icon({spell.name, type=imgType}))
table.insert(resultPart, '\r\n!colspan="2"|'..Icons.Icon({spell.name, type=imgType}))
Line 208: Line 214:
table.insert(resultPart, '\r\n|'..Icons._SkillReq('Magic', spell.level))
table.insert(resultPart, '\r\n|'..Icons._SkillReq('Magic', spell.level))


local costText = p._getAltSpellCostText(spell)
local costText = Magic._getAltSpellCostText(spell)
if costText ~= nil then
if costText ~= nil then
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Materials')
table.insert(resultPart, '\r\n|-\r\n!style="text-align:right;"|Materials')
Line 237: Line 243:
table.insert(resultPart, '\r\n|-\r\n!style="text-align: right;"|Materials\r\n|')
table.insert(resultPart, '\r\n|-\r\n!style="text-align: right;"|Materials\r\n|')
if type(req) == 'table' then
if type(req) == 'table' then
for i, mat in pairs(req) do
for i, mat in ipairs(req) do
if i > 1 then table.insert(resultPart, '<br/>') end
if i > 1 then table.insert(resultPart, '<br/>') end
local matItem = Items.getItemByID(mat.id)
local matItem = Items.getItemByID(mat.id)
if matItem == nil then
if matItem == nil then
table.insert(resultPart, mat.qty..'x ?????')
table.insert(resultPart, mat.quantity..'x ?????')
else
else
table.insert(resultPart, Icons.Icon({matItem.name, type='item', qty=mat.qty}))
table.insert(resultPart, Icons.Icon({matItem.name, type='item', qty=mat.quantity}))
end
end
end
end
Line 319: Line 325:
local event = GameData.getEntityByID('combatEvents', dungeon.eventID)
local event = GameData.getEntityByID('combatEvents', dungeon.eventID)
if type(event) == 'table' and type(event.itemRewardIDs) == 'table' then
if type(event) == 'table' and type(event.itemRewardIDs) == 'table' then
for j, itemRewardID in ipairs(event.itemRewardIDs) do
for eventCycle, itemRewardID in ipairs(event.itemRewardIDs) do
if item.id == itemRewardID then
if item.id == itemRewardID then
local dungPrefix = (i == Shared.tableCount(event.itemRewardIDs) and '' or (i == 1 and 'cycle' or 'cycles') .. ' of ')
local dungPrefix = (eventCycle == Shared.tableCount(event.itemRewardIDs) and '' or eventCycle .. (eventCycle == 1 and ' cycle' or ' cycles') .. ' of ')
table.insert(dungeonStrPart, dungPrefix .. Icons.Icon({dungeon.name, type='dungeon', notext=true}))
table.insert(dungeonStrPart, dungPrefix .. Icons.Icon({dungeon.name, type='dungeon', notext=true}))
break
break
Line 369: Line 375:


local upgradeCat = false
local upgradeCat = false
for k, parts in pairs(upgradePart) do
for catName, parts in pairs(upgradePart) do
if not Shared.tableIsEmpty(parts) then
if not Shared.tableIsEmpty(parts) then
if not upgradeCat then
if not upgradeCat then
Line 375: Line 381:
upgradeCat = true
upgradeCat = true
end
end
local typeText = (k == '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, ','))
end
end
Line 417: Line 423:


-- Gathering skills
-- Gathering skills
for localSkillID, dataProp in ipairs(skillIDs.Gathering) do
for localSkillID, dataProp in pairs(skillIDs.Gathering) do
local skillData = SkillData[localSkillID]
local skillData = SkillData[localSkillID]
local skill = skillData.name
local skill = skillData.name
for i, recipe in ipairs(skillData[dataProp.recipeKey]) do
for i, recipe in ipairs(skillData[dataProp.recipeKey]) do
if recipe.productId == item.id then
if recipe.productId == item.id then
table.insert(lineArray, Icons._SkillReq(skill, recipe.level))
if localSkillID == 'Farming' and recipe.seedCost ~= nil then
local seedItem = Items.getItemByID(recipe.seedCost.id)
if seedItem ~= nil then
table.insert(lineArray, 'Growing: ' .. Icons.Icon({seedItem.name, type='item', notext='true'}))
end
else
table.insert(lineArray, Icons._SkillReq(skill, recipe.level))
end
break
break
end
end
Line 429: Line 442:


-- Artisan skills
-- Artisan skills
for localSkillID, dataProp in ipairs(skillIDs.Artisan) do
for localSkillID, dataProp in pairs(skillIDs.Artisan) do
local skillData = SkillData[localSkillID]
local skillData = SkillData[localSkillID]
local skill = skillData.name
local skill = skillData.name
for i, recipe in ipairs(skillData.recipes) do
for i, recipe in ipairs(skillData.recipes) do
if recipe.productID == item.id or (localSkillID == 'Cooking' and recipe.perfectCookID == item.id) then
if recipe.productID == item.id or
(localSkillID == 'Cooking' and recipe.perfectCookID == item.id) or
(localSkillID == 'Herblore' and Shared.contains(recipe.potionIDs, item.id)) then
table.insert(lineArray, Icons._SkillReq(skill, recipe.level))
table.insert(lineArray, Icons._SkillReq(skill, recipe.level))
break
break
Line 511: Line 526:
--Tokens are from the appropriate skill
--Tokens are from the appropriate skill
if item.modifiers ~= nil and item.modifiers.masteryToken ~= nil then
if item.modifiers ~= nil and item.modifiers.masteryToken ~= nil then
for localSkillID, skillData in ipairs(SkillData) do
for localSkillID, skillData in pairs(SkillData) do
if skillData.masteryTokenID ~= nil and skillData.masteryTokenID == item.id then
if skillData.masteryTokenID ~= nil and skillData.masteryTokenID == item.id then
table.insert(lineArray, Icons._SkillReq(skillData.name, 1))
table.insert(lineArray, Icons._SkillReq(skillData.name, 1))
Line 624: Line 639:
local monster = GameData.getEntityByID('monsters', drop.id)
local monster = GameData.getEntityByID('monsters', drop.id)
if monster ~= nil then
if monster ~= nil then
table.insert(dropRows, {source = Icons.Icon({monster.name, type='monster'}), type = '[[Monster]]', minqty = drop.minQty, drop.maxQty, weight = drop.dropWt, totalWeight = drop.totalWt})
table.insert(dropRows, {source = Icons.Icon({monster.name, type='monster'}), type = '[[Monster]]', minqty = drop.minQty, qty = drop.maxQty, weight = drop.dropWt, totalWeight = drop.totalWt})
end
end
end
end
Line 637: Line 652:
local event = GameData.getEntityByID('combatEvents', dungeon.eventID)
local event = GameData.getEntityByID('combatEvents', dungeon.eventID)
if type(event) == 'table' and type(event.itemRewardIDs) == 'table' then
if type(event) == 'table' and type(event.itemRewardIDs) == 'table' then
for j, itemRewardID in ipairs(event.itemRewardIDs) do
for eventCycle, itemRewardID in ipairs(event.itemRewardIDs) do
if item.id == itemRewardID then
if item.id == itemRewardID then
local sourceTxt = Icons.Icon({dungeon.name, type='dungeon', notext=true}) .. (i == Shared.tableCount(event.itemRewardIDs) and '' or ', Cycle ' .. i)
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, type = '[[Dungeon]]', minqty = 1, qty = 1, weight = 1, totalWeight = 1})
break
break
Line 706: Line 721:
for i, gemKey in ipairs(gemKeys) do
for i, gemKey in ipairs(gemKeys) do
local thisGem, totalGemWeight = nil, 0
local thisGem, totalGemWeight = nil, 0
for j, gem in ipairs(GameData[gemKey]) do
for j, gem in ipairs(GameData.rawData[gemKey]) do
totalGemWeight = totalGemWeight + gem.weight
totalGemWeight = totalGemWeight + gem.weight
if gem.itemID == item.id then
if gem.itemID == item.id then
Line 721: Line 736:
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=p._getSpellIconType(spell)}), type = magicType, minqty = thisGem.minQuantity, qty = thisGem.maxQuantity, weight = thisGem.weight, totalWeight = totalGemWeight})
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})
end
end
end
end
Line 730: Line 745:
--Make sure to return nothing if there are no drop sources
--Make sure to return nothing if there are no drop sources
if Shared.tableIsEmpty(dropRows) then return '' end
if Shared.tableIsEmpty(dropRows) then return '' end
 
table.sort(dropRows, function(a, b)
table.sort(dropRows, function(a, b)
if a.weight / a.totalWeight == b.weight / b.totalWeight then
if a.weight / a.totalWeight == b.weight / b.totalWeight then
Line 796: Line 811:


function p._getSuperheatSmithRecipe(item)
function p._getSuperheatSmithRecipe(item)
local smithRecipe = GameData.getEntityByID(SkillData.Smithing.recipes, 'productID', item.id)
local smithRecipe = GameData.getEntityByProperty(SkillData.Smithing.recipes, 'productID', item.id)
if smithRecipe ~= nil and smithRecipe.category == 'melvorD:Bars' then
if smithRecipe ~= nil and smithRecipe.categoryID == 'melvorD:Bars' then
return smithRecipe
return smithRecipe
end
end
Line 805: Line 820:
--Manually build the Superheat Item table
--Manually build the Superheat Item table
-- Validate that the item can be superheated
-- Validate that the item can be superheated
local smithRecipe = p._getSuperheatSmithRecipe(item.id)
local smithRecipe = p._getSuperheatSmithRecipe(item)
if smithRecipe == nil then
if smithRecipe == nil then
return 'ERROR: The item "' .. item.name .. '" cannot be superheated[[Category:Pages with script errors]]'
return 'ERROR: The item "' .. item.name .. '" cannot be superheated[[Category:Pages with script errors]]'
Line 833: Line 848:
for i, spell in ipairs(spells) do
for i, spell in ipairs(spells) do
if spell.specialCost ~= nil and Shared.contains({ 'BarIngredientsWithCoal', 'BarIngredientsWithoutCoal' }, spell.specialCost.type) then
if spell.specialCost ~= nil and Shared.contains({ 'BarIngredientsWithCoal', 'BarIngredientsWithoutCoal' }, spell.specialCost.type) then
local imgType = p._getSpellIconType(spell)
local imgType = Magic._getSpellIconType(spell)
table.insert(superheatTable, '\r\n|-\r\n|'..Icons.Icon({spell.name, type=imgType, notext=true, size=50}))
table.insert(superheatTable, '\r\n|-\r\n|'..Icons.Icon({spell.name, type=imgType, notext=true, size=50}))
table.insert(superheatTable, '||'..Icons.Icon({spell.name, type=imgType, noicon=true})..'||style="text-align:right;"|'..smithRecipe.level)
table.insert(superheatTable, '||'..Icons.Icon({spell.name, type=imgType, noicon=true})..'||style="text-align:right;"|'..smithRecipe.level)
Line 881: Line 896:
end
end


if p._getSuperheatSmithRecipe(item.id) ~= nil then
if p._getSuperheatSmithRecipe(item) ~= nil then
table.insert(resultPart, '\r\n==='..Icons.Icon({'Alt. Magic', type='skill'})..'===\r\n'..p._getItemSuperheatTable(item))
table.insert(resultPart, '\r\n==='..Icons.Icon({'Alt. Magic', type='skill'})..'===\r\n'..p._getItemSuperheatTable(item))
end
end