12,787
edits
(getRequirementString: Fix completion req handling) |
(Use printError function) |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Pets = require('Module:Pets') | |||
-- Overrides for various items, mostly relating to icon overrides | -- Overrides for various items, mostly relating to icon overrides | ||
Line 53: | Line 54: | ||
elseif stat == 'description' then | elseif stat == 'description' then | ||
return p._getPurchaseDescription(purchase) | return p._getPurchaseDescription(purchase) | ||
elseif stat =='expansionicon' then | |||
return p._getPurchaseExpansionIcon(purchase) | |||
else | else | ||
return purchase[stat] | return purchase[stat] | ||
Line 72: | Line 75: | ||
if Shared.tableIsEmpty(purchaseList) then | if Shared.tableIsEmpty(purchaseList) then | ||
return " | return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'") | ||
else | else | ||
local resultPart = {} | local resultPart = {} | ||
Line 96: | Line 99: | ||
end | end | ||
if purch.contains.petID ~= nil then | if purch.contains.petID ~= nil then | ||
local pet = | local pet = Pets.getPetByID(purch.contains.petID) | ||
if pet ~= nil then | if pet ~= nil then | ||
return pet.name | return pet.name | ||
end | end | ||
end | |||
end | |||
return '' | |||
end | |||
function p._getPurchaseExpansionIcon(purch) | |||
if purch.id ~= nil then | |||
return Icons.getExpansionIcon(purch.id) | |||
elseif purch.contains ~= nil then | |||
local item = nil | |||
if purch.contains.items ~= nil and not Shared.tableIsEmpty(purch.contains.items) then | |||
return Icons.getExpansionIcon(purch.contains.items[1].id) | |||
elseif purch.contains.itemCharges ~= nil and not Shared.tableIsEmpty(purch.contains.itemCharges) then | |||
return Icons.getExpansionIcon(purch.contains.itemCharges.id) | |||
end | |||
if purch.contains.petID ~= nil then | |||
return Icons.getExpansionIcon(purch.contains.petID) | |||
end | end | ||
end | end | ||
Line 113: | Line 134: | ||
if purch.contains.modifiers ~= nil then | if purch.contains.modifiers ~= nil then | ||
return Constants.getModifiersText(purch.contains.modifiers, false) | return Constants.getModifiersText(purch.contains.modifiers, false) | ||
elseif purch.contains.petID ~= nil then | |||
local pet = Pets.getPetByID(purch.contains.petID) | |||
return Pets._getPetEffect(pet) | |||
elseif purch.contains.items ~= nil and Shared.tableCount(purch.contains.items) == 1 then | elseif purch.contains.items ~= nil and Shared.tableCount(purch.contains.items) == 1 then | ||
item = Items.getItemByID(purch.contains.items[1].id) | item = Items.getItemByID(purch.contains.items[1].id) | ||
Line 259: | Line 283: | ||
table.insert(reqArray, reqText) | table.insert(reqArray, reqText) | ||
else | else | ||
table.insert(reqArray, ' | table.insert(reqArray, Shared.printError('Unknown requirement: ' .. (req.type or 'nil'))) | ||
end | end | ||
end | end | ||
Line 273: | Line 297: | ||
if purchase.contains == nil then | if purchase.contains == nil then | ||
return 'Unknown' | return 'Unknown' | ||
elseif purchase.contains. | elseif purchase.contains.petID ~= nil then | ||
return 'Pet' | return 'Pet' | ||
elseif purchase.contains.itemCharges ~= nil then | elseif purchase.contains.itemCharges ~= nil then | ||
Line 306: | Line 330: | ||
GPTotal = GPTotal + GPVal | GPTotal = GPTotal + GPVal | ||
table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({item.name, type='item', notext=true, size='25'})) | table.insert(containArray, '|-\r\n| style="min-width:25px"| ' .. Icons.Icon({item.name, type='item', notext=true, size='25'})) | ||
table.insert(containArray, '| ' .. Icons.Icon({item.name, type='item', noicon=true}) .. '\r\n| data-sort-value="' .. itemQty .. '" style="text-align:right" | ' .. Shared.formatnum(itemQty)) | table.insert(containArray, '|data-sort-value="'..item.name..'"|'.. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}) .. '\r\n| data-sort-value="' .. itemQty .. '" style="text-align:right" | ' .. Shared.formatnum(itemQty)) | ||
table.insert(containArray, '| data-sort-value="' .. GPVal .. '"| ' .. Icons.GP(GPVal)) | table.insert(containArray, '| data-sort-value="' .. GPVal .. '"| ' .. Icons.GP(GPVal)) | ||
end | end | ||
Line 340: | Line 364: | ||
if purchase == nil then | if purchase == nil then | ||
return " | return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'") | ||
else | else | ||
return p._getPurchaseContents(purchase, asList) | return p._getPurchaseContents(purchase, asList) | ||
Line 381: | Line 405: | ||
if purchase == nil then | if purchase == nil then | ||
return " | return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'") | ||
else | else | ||
return p._getPurchaseBuyLimit(purchase, asList) | return p._getPurchaseBuyLimit(purchase, asList) | ||
Line 413: | Line 437: | ||
if purchase == nil then | if purchase == nil then | ||
return " | return Shared.printError("Couldn't find purchase with name '" .. tostring(purchaseName) .. "'") | ||
else | else | ||
args[1] = purchase | args[1] = purchase | ||
Line 498: | Line 522: | ||
for i, purchase in ipairs(Purchases) do | for i, purchase in ipairs(Purchases) do | ||
local purchName = p._getPurchaseName(purchase) | local purchName = p._getPurchaseName(purchase) | ||
local purchExpIcon = p._getPurchaseExpansionIcon(purchase) | |||
local purchOverride = nil | local purchOverride = nil | ||
if purchOverrides ~= nil then | if purchOverrides ~= nil then | ||
Line 515: | Line 540: | ||
end | end | ||
local purchSortName = purchName | |||
if iconNoLink == nil or iconNoLink ~= true then purchName = '[[' .. purchLink .. purchName .. ']]' end | if iconNoLink == nil or iconNoLink ~= true then purchName = '[[' .. purchLink .. purchName .. ']]' end | ||
Line 522: | Line 548: | ||
table.insert(resultPart, '|style="min-width:25px"|' .. p._getPurchaseIcon({purchase, notext=true, size='50'})) | table.insert(resultPart, '|style="min-width:25px"|' .. p._getPurchaseIcon({purchase, notext=true, size='50'})) | ||
--table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({iconName, type=iconType, notext=true, nolink=iconNoLink, size='50'})) | --table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({iconName, type=iconType, notext=true, nolink=iconNoLink, size='50'})) | ||
table.insert(resultPart, '| ' .. purchName) | table.insert(resultPart, '| data-sort-value="'..purchSortName..'"|'..purchExpIcon .. purchName) | ||
elseif column == 'Type' then | elseif column == 'Type' then | ||
table.insert(resultPart, '| ' .. purchType) | table.insert(resultPart, '| ' .. purchType) | ||
Line 580: | Line 606: | ||
local shopCat = GameData.getEntityByName('shopCategories', cat) | local shopCat = GameData.getEntityByName('shopCategories', cat) | ||
if shopCat == nil then | if shopCat == nil then | ||
return ' | return Shared.printError('Invalid category ' .. cat) | ||
else | else | ||
local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end) | local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end) | ||
Line 626: | Line 652: | ||
result = result..'\r\n!colspan="2"|'..Icons.Icon({'Shop'})..' Purchase' | result = result..'\r\n!colspan="2"|'..Icons.Icon({'Shop'})..' Purchase' | ||
if purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then | if purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then | ||
result = result..' - '..Icons.Icon({p._getPurchaseName(purchase), type='item'}) | result = result..' - '..p._getPurchaseExpansionIcon(purchase)..Icons.Icon({p._getPurchaseName(purchase), type='item'}) | ||
end | end | ||
Line 657: | Line 683: | ||
local item = Items.getItem(itemName) | local item = Items.getItem(itemName) | ||
if item == nil then | if item == nil then | ||
return | return Shared.printError('No item named ' .. itemName .. ' exists in the data module') | ||
end | end | ||
Line 710: | Line 736: | ||
if capeItem ~= nil then | if capeItem ~= nil then | ||
table.insert(resultPart, '\r\n|-\r\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true})) | table.insert(resultPart, '\r\n|-\r\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true})) | ||
table.insert(resultPart, '\r\n| ' .. Icons.Icon({capeItem.name, type='item', noicon=true})) | table.insert(resultPart, '\r\n| data-sort-value="'..capeItem.name..'"|'..Icons.getExpansionIcon(capeItem.id) .. Icons.Icon({capeItem.name, type='item', noicon=true})) | ||
table.insert(resultPart, '\r\n| ' .. p.getRequirementString(cape.purchaseRequirements)) | table.insert(resultPart, '\r\n| ' .. p.getRequirementString(cape.purchaseRequirements)) | ||
table.insert(resultPart, '\r\n| ' .. p._getPurchaseDescription(cape)) | table.insert(resultPart, '\r\n| ' .. p._getPurchaseDescription(cape)) | ||
Line 786: | Line 812: | ||
local dung = getGodDungeon(upgrade.purchaseRequirements) | local dung = getGodDungeon(upgrade.purchaseRequirements) | ||
local costSortValue = p._getPurchaseSortValue(upgrade) | local costSortValue = p._getPurchaseSortValue(upgrade) | ||
table.insert(resultPart, '|-\r\n|style="min-width:25px; text-align:center;" data-sort-value="' .. upgradeName .. '"| ' .. Icons.Icon({upgradeName, type='upgrade', size=50, notext=true})) | table.insert(resultPart, '|-\r\n|style="min-width:25px; text-align:center;" data-sort-value="' .. upgradeName .. '"| ' ..p._getPurchaseExpansionIcon(upgrade).. Icons.Icon({upgradeName, type='upgrade', size=50, notext=true})) | ||
table.insert(resultPart, '| ' .. Icons.Icon({upgradeName, type='upgrade', noicon=true})) | table.insert(resultPart, '| ' .. Icons.Icon({upgradeName, type='upgrade', noicon=true})) | ||
table.insert(resultPart, '| ' .. p._getPurchaseDescription(upgrade)) | table.insert(resultPart, '| ' .. p._getPurchaseDescription(upgrade)) | ||
Line 797: | Line 823: | ||
end | end | ||
function p. | function p.getToolTable(toolName, searchString, modifiers, skillID) | ||
local | local skillName = nil | ||
if | if type(skillID) == 'string' then | ||
local | skillName = Constants.getSkillName(skillID) | ||
if | end | ||
return ' | local toolArray = p.getPurchases( | ||
function(purch) | |||
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, searchString) ~= nil | |||
end) | |||
if Shared.tableIsEmpty(toolArray) then | |||
return '' | |||
end | |||
if modifiers == nil then | |||
modifiers = {} | |||
end | end | ||
local | local modTotal = {} | ||
for i, modDef in ipairs(modifiers) do | |||
modTotal[modDef.name] = 0 | |||
end | end | ||
local headerRowSpan = (Shared.tableIsEmpty(toolArray) and 1) or 2 | |||
local | |||
local resultPart = {} | local resultPart = {} | ||
table.insert(resultPart, '{| class="wikitable"') | |||
table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '" colspan="2"| Name') | |||
table.insert(resultPart, '{| class="wikitable | table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '"| ' .. (skillName == nil and 'Requirements' or Icons.Icon({skillName, type='skill', notext=true}) .. ' Level')) | ||
table.insert(resultPart, '| | table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '"| Cost') | ||
table.insert(resultPart, '! | for i, modDef in ipairs(modifiers) do | ||
modTotal[modDef.name] = 0 | |||
table.insert(resultPart, '\n!colspan="2"| ' .. modDef.header) | |||
end | |||
if headerRowSpan > 1 then | |||
table.insert(resultPart, '\n|-' .. string.rep('\n!This ' .. toolName .. '\n!Total', Shared.tableCount(modifiers))) | |||
end | |||
for i, tool in ipairs(toolArray) do | |||
local toolName = p._getPurchaseName(tool) | |||
local toolCost = p.getCostString(tool.cost, false) | |||
local toolCostSort = p._getPurchaseSortValue(tool) or 0 | |||
table.insert(resultPart, '\n|-') | |||
table.insert(resultPart, '\n|style="min-width:25px" data-sort-value="' .. toolName .. '"| ' .. Icons.Icon({toolName, type='upgrade', size='50', notext=true})) | |||
table.insert(resultPart, '\n| data-sort-value="' .. toolName.. '"|' .. Icons.getExpansionIcon(tool.id) .. toolName) | |||
local level, levelStyle = nil, nil | |||
if skillID == nil then | |||
level = 'None' | |||
levelStyle = '|class="table-na"' | |||
else | |||
level = 1 | |||
levelStyle = '|style="text-align:right"' | |||
end | |||
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then | |||
if skillID == nil then | |||
-- Return all requirements | |||
level = p.getRequirementString(tool.purchaseRequirements) | |||
if level ~= 'None' then | |||
levelStyle = '' | |||
end | |||
else | |||
-- Return level requirement for just the specified skill | |||
for i, purchReq in ipairs(tool.purchaseRequirements) do | |||
if purchReq.type == 'SkillLevel' and purchReq.skillID == skillID then | |||
level = purchReq.level | |||
break | |||
end | |||
end | |||
end | |||
end | |||
table.insert(resultPart, '\n' .. levelStyle .. '| '..level) | |||
table.insert(resultPart, '\n|style="text-align:right" data-sort-value="' .. toolCostSort .. '"| ' .. toolCost) | |||
local cellStart = '\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 and (modDef.skillID == nil or modDef.skillID == modVal[1].skillID) then | |||
modVal = modVal[1].value | |||
end | end | ||
modTotal[modName] = modTotal[modName] + modVal | |||
else | |||
modVal = 0 | |||
end | end | ||
local cellStartVal = cellStart .. ((modVal == 0 and ' class="table-na"') or '') | |||
local cellStartTot = cellStart .. ((modTotal[modName] == 0 and ' class="table-na"') or '') | |||
table.insert(resultPart, cellStartVal .. '| ' .. (modVal == 0 and '' or modDef.sign) .. modVal .. modDef.suffix) | |||
table.insert(resultPart, cellStartTot .. '| ' .. (modTotal[modName] == 0 and '' or modDef.sign) .. modTotal[modName] .. modDef.suffix) | |||
end | end | ||
end | end | ||
end | |||
table.insert(resultPart, '\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.getCookingUtilityTable(frame) | |||
local category = nil | |||
if frame ~= nil then category = frame.args ~= nil and frame.args[1] or frame end | |||
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'} | |||
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then | |||
return Shared.printError('Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or ')) | |||
end | end | ||
return | local categoryShort = string.match(category, '[^%s]+$') | ||
local modifiers = { | |||
['Cooking Fire'] = { | |||
{ name = 'increasedSkillXP', skillID = 'melvorD:Cooking', header = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP', sign = '+', suffix = '%' }, | |||
{ name = 'increasedChancePerfectCookFire', header = 'Fire Perfect Cook Chance', sign ='+', suffix = '%' }, | |||
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' }, | |||
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' } | |||
}, | |||
['Furnace'] = { | |||
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' }, | |||
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' } | |||
}, | |||
['Pot'] = { | |||
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' }, | |||
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' } | |||
} | |||
} | |||
return p.getToolTable(categoryShort, categoryShort .. '$', modifiers[category], nil) | |||
end | end | ||
return p | return p |