Anonymous

Module:Skills: Difference between revisions

From Melvor Idle
Use printError function
(getFiremakingTable: Fix reference to non-existent attribute)
(Use printError function)
(13 intermediate revisions by 2 users not shown)
Line 15: Line 15:


local p = {}
local p = {}
local ItemData = mw.loadData('Module:Items/data')


local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
Line 70: Line 68:
local npc = p.getThievingNPC(npcName)
local npc = p.getThievingNPC(npcName)
if npc == nil then
if npc == nil then
return "ERROR: Invalid Thieving NPC "..npcName.."[[Category:Pages with script errors]]"
return Shared.printError('Invalid Thieving NPC ' .. npcName)
end
end


Line 85: Line 83:
for j, drop in pairs(area.uniqueDrops) do
for j, drop in pairs(area.uniqueDrops) do
if drop.id == itemID then
if drop.id == itemID then
for k, npcID in pairs(area.npcs) do
for k, npcID in ipairs(area.npcIDs) do
areaNPCs[npcID] = drop.quantity
areaNPCs[npcID] = drop.quantity
end
end
Line 106: Line 104:
end
end
if dropWt > 0 then
if dropWt > 0 then
table.insert(resultArray, {npc = npc.name, minQty = dropQty.min, maxQty = dropQty.max, wt = dropWt * SkillData.Thieving.itemChance, totalWt = totalWt * 100, level = npc.level})
table.insert(resultArray, {npc = npc.name, minQty = dropQty.min, maxQty = dropQty.max, wt = dropWt * SkillData.Thieving.itemChance, totalWt = totalWt * 100, level = npc.level, npcID = npc.id})
end
end


--Chance of -1 on unique drops is to indicate variable chance
--Chance of -1 on unique drops is to indicate variable chance
if npc.uniqueDrop ~= nil and npc.uniqueDrop.id == itemID then
if npc.uniqueDrop ~= nil and npc.uniqueDrop.id == itemID then
table.insert(resultArray, {npc = npc.name, minQty = npc.uniqueDrop.quantity, maxQty = npc.uniqueDrop.quantity, wt = -1, totalWt = -1, level = npc.level})
table.insert(resultArray, {npc = npc.name, minQty = npc.uniqueDrop.quantity, maxQty = npc.uniqueDrop.quantity, wt = -1, totalWt = -1, level = npc.level, npcID = npc.id})
end
end


if areaNPCs[npc.id] ~= nil then
if areaNPCs[npc.id] ~= nil then
table.insert(resultArray, {npc = npc.name, minQty = areaNPCs[npc.id], maxQty = areaNPCs[npc.id], wt = SkillData.Thieving.baseAreaUniqueChance, totalWt = 100, level = npc.level})
table.insert(resultArray, {npc = npc.name, minQty = areaNPCs[npc.id], maxQty = areaNPCs[npc.id], wt = SkillData.Thieving.baseAreaUniqueChance, totalWt = 100, level = npc.level, npcID = npc.id})
end
end
end
end
Line 122: Line 120:
if drop.itemID == itemID then
if drop.itemID == itemID then
if drop.npcs == nil then
if drop.npcs == nil then
table.insert(resultArray, {npc = 'all', minQty = 1, maxQty = 1, wt = 1, totalWt = Shared.round2(1/(drop.chance/100), 0), level = 1})
table.insert(resultArray, {npc = 'all', minQty = 1, maxQty = 1, wt = 1, totalWt = Shared.round2(1/(drop.chance/100), 0), level = 1, npcID = itemID})
else
else
for j, npcID in ipairs(drop.npcs) do
for j, npcID in ipairs(drop.npcs) do
local npc = p.getThievingNPCByID(npcID)
local npc = p.getThievingNPCByID(npcID)
if npc ~= nil then
if npc ~= nil then
table.insert(resultArray, {npc = npc.name, minQty = 1, maxQty = 1, wt = 1, totalWt = Shared.round2(1/(drop.chance/100), 0), level = npc.level})
table.insert(resultArray, {npc = npc.name, minQty = 1, maxQty = 1, wt = 1, totalWt = Shared.round2(1/(drop.chance/100), 0), level = npc.level, npcID = npc.id})
end
end
end
end
Line 190: Line 188:
local modArray = {}
local modArray = {}
local isSkillMod = {}
local isSkillMod = {}
--Adding a Group Number to hold together different bonuses from the same modifier [Falterfire 22/10/27]
local groupNum = 0


for _, modType in ipairs(modTypes) do
for _, modType in ipairs(modTypes) do
for i, modTypeData in ipairs(cons[modType]) do
for i, modTypeData in ipairs(cons[modType]) do
groupNum = groupNum + 1
local modVal = nil
local modVal = nil
if modValue ~= nil then
if modValue ~= nil then
Line 200: Line 201:
end
end
for j, modifier in ipairs(modTypeData.modifiers) do
for j, modifier in ipairs(modTypeData.modifiers) do
local modEntry = (modifier.skill ~= nil and {modifier.skill, modVal}) or modVal
local modEntry = (modifier.skill ~= nil and { skillID = modifier.skill, value = modVal }) or modVal
addToArray(modArray, {modifier.key, modEntry})
addToArray(modArray, {modifier.key, modEntry, group = groupNum})
end
end
end
end
Line 210: Line 211:
for i, modDefn in ipairs(modArray) do
for i, modDefn in ipairs(modArray) do
local modName, modVal = modDefn[1], modDefn[2]
local modName, modVal = modDefn[1], modDefn[2]
local isSkill = type(modVal) == 'table' and type(modVal[1]) == 'string'
local isSkill = type(modVal) == 'table' and modVal.skillID ~= nil
if modArrayKV[modName] == nil then
if modArrayKV[modName] == nil then
modArrayKV[modName] = (isSkill and { modVal } or modVal)
modArrayKV[modName] = (isSkill and { modVal } or modVal)
Line 230: Line 231:
local skillID = Constants.getSkillID(skillName)
local skillID = Constants.getSkillID(skillName)
if skillID == nil then
if skillID == nil then
return "ERROR: Failed to find a skill ID for "..skillName
return Shared.printError('Failed to find a skill ID for ' .. skillName)
end
end


local unlockTable = SkillData[skillID].masteryLevelUnlocks
local _, localSkillID = GameData.getLocalID(skillID)
-- Clone so that we can sort by level
local unlockTable = Shared.clone(SkillData[localSkillID].masteryLevelUnlocks)
if unlockTable == nil then
if unlockTable == nil then
return 'ERROR: Failed to find Mastery Unlock data for '..skillName
return Shared.printError('Failed to find Mastery Unlock data for ' .. skillName)
end
end
table.sort(unlockTable, function(a, b) return (a.level == b.level and a.descriptionID < b.descriptionID) or a.level < b.level end)


local result = '{|class="wikitable"\r\n!Level!!Unlock'
local result = '{|class="wikitable"\r\n!Level!!Unlock'
Line 251: Line 255:
local skillID = Constants.getSkillID(skillName)
local skillID = Constants.getSkillID(skillName)
if skillID == nil then
if skillID == nil then
return "ERROR: Failed to find a skill ID for "..skillName
return Shared.printError('Failed to find a skill ID for ' .. skillName)
end
end


local checkpoints = SkillData[skillID].masteryCheckpoints
local _, localSkillID = GameData.getLocalID(skillID)
local checkpoints = SkillData[localSkillID].masteryCheckpoints
if checkpoints == nil then
if checkpoints == nil then
return 'ERROR: Failed to find Mastery Unlock data for '..skillName
return Shared.printError('Failed to find Mastery Unlock data for ' .. skillName)
end
end


local totalPoolXP = SkillData[skillID].baseMasteryPoolCap
local totalPoolXP = SkillData[localSkillID].baseMasteryPoolCap
local checkpointPct = GameData.rawData.masteryCheckpoints
local result = '{|class="wikitable"\r\n!Pool %!!style="width:100px"|Pool XP!!Bonus'
local result = '{|class="wikitable"\r\n!Pool %!!style="width:100px"|Pool XP!!Bonus'
for i, checkpointDesc in ipairs(checkpoints) do
for i, checkpointDesc in ipairs(checkpoints) do
result = result..'\r\n|-'
result = result..'\r\n|-'
result = result..'\r\n|'..GameData.masteryCheckpoints[i]..'%||'
result = result..'\r\n|'..checkpointPct[i]..'%||'
result = result..Shared.formatnum(math.floor(totalPoolXP * GameData.masteryCheckpoints[i] / 100))..' xp||'..checkpointDesc
result = result..Shared.formatnum(math.floor(totalPoolXP * checkpointPct[i] / 100))..' xp||'..checkpointDesc
end
end
result = result..'\r\n|-\r\n!colspan="2"|Total Mastery Pool XP'
result = result..'\r\n|-\r\n!colspan="2"|Total Mastery Pool XP'
Line 321: Line 327:
local advMode = GameData.getEntityByID('gamemodes', 'melvorF:Adventure')
local advMode = GameData.getEntityByID('gamemodes', 'melvorF:Adventure')
if advMode ~= nil then
if advMode ~= nil then
local unlockCount = Shared.tableCount(GameData.skillData) - Shared.tableCount(advMode.startingSkills)
local costLength = Shared.tableCount(advMode.skillUnlockCost)
local returnPart = {}
local returnPart = {}
table.insert(returnPart, '{| class="wikitable stickyHeader"\r\n|- class="headerRow-0"\r\n!Unlock!!Cost!!Cumulative Cost')
table.insert(returnPart, '{| class="wikitable stickyHeader"\r\n|- class="headerRow-0"\r\n!Unlock!!Cost!!Cumulative Cost')


local accCost = 0
local accCost = 0
for i, cost in ipairs(advMode.skillUnlockCost) do
for i = 1, unlockCount, 1 do
local cost = advMode.skillUnlockCost[math.min(i, costLength)]
accCost = accCost + cost
accCost = accCost + cost
table.insert(returnPart, '|-')
table.insert(returnPart, '|-')
Line 337: Line 346:


-- Accepts 1 parameter, being either:
-- Accepts 1 parameter, being either:
--  'Smelting', for which a table of all bars is generated, or
--  'Bars', for which a table of all bars is generated, or
--  A bar or tier name, which if valid generates a table of all smithing recipes using that bar/tier
--  A bar or tier name, which if valid generates a table of all smithing recipes using that bar/tier
function p.getSmithingTable(frame)
function p.getSmithingTable(frame)
local tableType = frame.args ~= nil and frame.args[1] or frame
local tableType = frame.args ~= nil and frame.args[1] or frame
tableType = Shared.splitString(tableType, ' ')[1]


-- Has a valid category been passed (by name)?
-- Has a valid category been passed (by name)?
local category = GameData.getEntityByName(SkillData.Smithing.categories, tableType)
local category = GameData.getEntityByName(SkillData.Smithing.categories, tableType)
if category == nil then
if category == nil then
return 'ERROR: Invalid Smithing category: "' .. tableType .. '"[[Category:Pages with script errors]]'
return Shared.printError('Invalid Smithing category: "' .. tableType .. '"')
end
end


Line 356: Line 364:
local recipeItem = Items.getItemByID(recipe.productID)
local recipeItem = Items.getItemByID(recipe.productID)
if recipeItem ~= nil then
if recipeItem ~= nil then
table.insert(recipeList, { id = i, level = recipe.level, itemName = recipeItem.name, itemValue = recipeItem.sellsFor })
table.insert(recipeList, { id = i, level = recipe.level, itemName = recipeItem.name, itemValue = recipeItem.sellsFor, expIcon = Icons.getExpansionIcon(recipeItem.id) })
end
end
elseif recipe.categoryID == 'melvorD:Bars' then
elseif recipe.categoryID == 'melvorD:Bars' then
Line 399: Line 407:
table.insert(resultPart, '\r\n| ' .. Icons.Icon({recipeDef.itemName, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n| ' .. Icons.Icon({recipeDef.itemName, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n| ')
table.insert(resultPart, '\r\n| ')
table.insert(resultPart, recipeDef.expIcon)
if recipe.baseQuantity > 1 then
if recipe.baseQuantity > 1 then
table.insert(resultPart, recipe.baseQuantity .. 'x ')
table.insert(resultPart, recipe.baseQuantity .. 'x ')
Line 444: Line 453:
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='item', size='50', notext=true}))
table.insert(resultPart, '\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='item', size='50', notext=true}))
table.insert(resultPart, '||[['..name..']]')
table.insert(resultPart, '||'..Icons.getExpansionIcon(logs.id)..Icons.Icon({name, type='item', noicon=true}))
table.insert(resultPart, '||style ="text-align: right;"|'..logData.level)
table.insert(resultPart, '||style ="text-align: right;"|'..logData.level)
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..burnTime..'"|'..Shared.timeString(burnTime, true))
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..burnTime..'"|'..Shared.timeString(burnTime, true))