Anonymous

Module:Skills/Gathering: Difference between revisions

From Melvor Idle
Use printError function
(Add TotH icon to Farming & Astrology tables)
(Use printError function)
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
local Skills = require('Module:Skills')
local Skills = require('Module:Skills')
local ItemSourceTables = require('Module:Items/SourceTables')
local ItemSourceTables = require('Module:Items/SourceTables')
-- TODO Move tool tables to Module:Shop
function p.getToolTable(toolName, searchString, modifiers, skillID)
local skillName = Constants.getSkillName(skillID)
local toolArray = Shop.getPurchases(
function(purch)
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, searchString) ~= nil
end)
if skillName == nil or Shared.tableIsEmpty(toolArray) then
return ''
end
if modifiers == nil then
modifiers = {}
end
local modTotal = {}
for i, modDef in ipairs(modifiers) do
modTotal[modDef.name] = 0
end
local headerRowSpan = (Shared.tableIsEmpty(toolArray) and 1) or 2
local resultPart = {}
table.insert(resultPart, '{| class="wikitable"')
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '" colspan="2"| Name')
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '"| ' .. Icons.Icon({skillName, type='skill', notext=true})..' Level')
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '"| Cost')
for i, modDef in ipairs(modifiers) do
modTotal[modDef.name] = 0
table.insert(resultPart, '\r\n!colspan="2"| ' .. modDef.header)
end
if headerRowSpan > 1 then
table.insert(resultPart, '\r\n|-' .. string.rep('\r\n!This ' .. toolName .. '\r\n!Total', Shared.tableCount(modifiers)))
end
for i, tool in ipairs(toolArray) do
local toolName = Shop._getPurchaseName(tool)
local toolCost = Shop.getCostString(tool.cost, false)
local toolCostSort = Shop._getPurchaseSortValue(tool)
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|style="min-width:25px" data-sort-value="' .. toolName .. '"| ' .. Icons.Icon({toolName, type='upgrade', size='50', notext=true}))
table.insert(resultPart, '\r\n| data-sort-value="' .. toolName.. '"|' .. Icons.getExpansionIcon(tool.id) .. toolName)
local level = 1
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then
for i, purchReq in ipairs(tool.purchaseRequirements) do
if purchReq.type == 'SkillLevel' and purchReq.skillID == skillID then
level = purchReq.level
break
end
end
end
table.insert(resultPart, '\r\n|style="text-align:right"| '..level)
table.insert(resultPart, '\r\n|style="text-align:right" data-sort-value="' .. toolCostSort .. '"| ' .. toolCost)
local cellStart = '\r\n|style="text-align:right"| '
if tool.contains ~= nil and tool.contains.modifiers ~= nil then
for j, modDef in ipairs(modifiers) do
local modName = modDef.name
local modVal = tool.contains.modifiers[modName]
if modVal ~= nil then
if type(modVal) == 'table' and type(modVal[1]) == 'table' and modVal[1].skillID ~= nil then
modVal = modVal[1].value
end
modTotal[modName] = modTotal[modName] + modVal
else
modVal = 0
end
table.insert(resultPart, cellStart .. (modVal == 0 and '' or modDef.sign) .. modVal .. modDef.suffix)
table.insert(resultPart, cellStart .. (modTotal[modName] == 0 and '' or modDef.sign) .. modTotal[modName] .. modDef.suffix)
end
end
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
function p.getAxeTable(frame)
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Cut Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', header = 'Double Items Chance', sign = '+', suffix = '%' },
{ name = 'increasedBirdNestDropRate', header = Icons.Icon({'Bird Nest', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' },
{ name = 'increasedChanceForAshInWoodcutting', header = Icons.Icon({'Ash', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' }
}
return p.getToolTable('Axe', '_Axe$', modifiers, 'melvorD:Woodcutting')
end
function p.getPickaxeTable(frame)
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceForQualitySuperiorGem', header = 'Superior Gem Chance', sign = '+', suffix = '%' },
{ name = 'increasedMeteoriteOre', header = 'Increased ' .. Icons.Icon({'Meteorite Ore', type='item', notext=true}), sign = '+', suffix = '' }
}
return p.getToolTable('Pickaxe', '_Pickaxe$', modifiers, 'melvorD:Mining')
end
function p.getRodTable(frame)
local modifiers = {
{ name = 'decreasedSkillIntervalPercent', header = 'Catch Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChanceForOneExtraFish', header = '+1 Fish Chance', sign = '+', suffix = '%' },
{ name = 'increasedChanceToFindLostChest', header = Icons.Icon({'Lost Chest', type='item', notext=true}) .. ' Chance', sign = '+', suffix = '%' },
{ name = 'increasedFishingCookedChance', header = 'Cooked Fish Chance', sign = '+', suffix = '%' }
}
return p.getToolTable('Rod', '_Rod$', modifiers, 'melvorD:Fishing')
end


function p.getRecipeRequirements(skillName, recipe)
function p.getRecipeRequirements(skillName, recipe)
Line 267: Line 157:
local gemDataKey = validTypes[gemType]
local gemDataKey = validTypes[gemType]
if gemDataKey == nil then
if gemDataKey == nil then
return 'ERROR: No such gem type "' .. gemType .. '"[[Category:Pages with script errors]]'
return Shared.printError('No such gem type "' .. gemType .. '"')
end
end
Line 490: Line 380:


--After normal drops, add in rare drops
--After normal drops, add in rare drops
local rareTxt = '===Possible Rare Drops:===\r\nAny of these can be received after a successful pickpocket'
local rareTxt = '===Possible Rare Drops:===\r\nAny of these can be received after a successful pickpocket:'
rareTxt = rareTxt..'\r\n'..p._getThievingGeneralRareTable(npc.id)
rareTxt = rareTxt..'\r\n'..p._getThievingGeneralRareTable(npc.id)
table.insert(sectionTxt, rareTxt)
table.insert(sectionTxt, rareTxt)
Line 516: Line 406:
areaTxt = areaTxt..txt
areaTxt = areaTxt..txt
end
end
areaTxt = areaTxt..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'
areaTxt = areaTxt..'\r\n|style="text-align:right"|'..Shared.fraction(1, 1/(SkillData.Thieving.baseAreaUniqueChance/100))..'||'
areaTxt = areaTxt..'style="text-align:right"|'..Shared.round(SkillData.Thieving.baseAreaUniqueChance, 2, 2)..'%'
areaTxt = areaTxt..'\r\n|}'
areaTxt = areaTxt..'\r\n|}'
table.insert(sectionTxt, areaTxt)
table.insert(sectionTxt, areaTxt)
Line 530: Line 417:
uniqueTxt = uniqueTxt..'\r\nThe unique drop for the '..npc.name..' is '
uniqueTxt = uniqueTxt..'\r\nThe unique drop for the '..npc.name..' is '
if npc.uniqueDrop.quantity > 1 then
if npc.uniqueDrop.quantity > 1 then
uniqueTxt = uniqueTxt..Icons.Icon({thisItem.name, type='item', qty=npc.uniqueDrop.quantity})
uniqueTxt = uniqueTxt..Icons.Icon({thisItem.name, type='item', qty=npc.uniqueDrop.quantity}) .. '.'
else
else
uniqueTxt = uniqueTxt..Icons.Icon({thisItem.name, type='item'})
uniqueTxt = uniqueTxt..Icons.Icon({thisItem.name, type='item'}) .. '.'
end
end
table.insert(sectionTxt, uniqueTxt)
table.insert(sectionTxt, uniqueTxt)
Line 545: Line 432:
local npc = Skills.getThievingNPC(npcName)
local npc = Skills.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 640: Line 527:
local category = GameData.getEntityByName(SkillData.Farming.categories, categoryName)
local category = GameData.getEntityByName(SkillData.Farming.categories, categoryName)
if category == nil then
if category == nil then
return 'ERROR: Invalid farming category. Please choose Allotments, Herbs, or Trees[[Category:Pages with script errors]]'
return Shared.printError('Invalid farming category. Please choose Allotments, Herbs, or Trees')
end
end
local seedList = GameData.getEntities(SkillData.Farming.recipes,
local seedList = GameData.getEntities(SkillData.Farming.recipes,
Line 729: Line 616:
local category = GameData.getEntityByName(SkillData.Farming.categories, areaName)
local category = GameData.getEntityByName(SkillData.Farming.categories, areaName)
if category == nil then
if category == nil then
return 'ERROR: Invalid farming category. Please choose Allotments, Herbs, or Trees[[Category:Pages with script errors]]'
return Shared.printError('Invalid farming category. Please choose Allotments, Herbs, or Trees')
end
end
local patches = GameData.getEntities(SkillData.Farming.plots,
local patches = GameData.getEntities(SkillData.Farming.plots,