12,810
edits
(getPet: Amend to (hopefully) avoid errors with ampersands) |
(getPetNavbox: Migrate to Module:Navboxes) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
local GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local areaDataKeys = { 'combatAreas', 'dungeons', 'slayerAreas' } | |||
-- Compute combat pet sources once for use later | -- Compute combat pet sources once for use later | ||
local function getCombatPetSources() | local function getCombatPetSources() | ||
local result = {} | local result = {} | ||
local areas = | for _, key in ipairs(areaDataKeys) do | ||
local areas = GameData.getEntities(key, function(area) return area.pet ~= nil end) | |||
for i, area in ipairs(areas) do | |||
result[area.pet.petID] = { | |||
id = area.id, | |||
name = area.name, | |||
type = area.type, | |||
weight = area.pet.weight, | |||
fixedChance = (area.fixedPetClears ~= nil and area.fixedPetClears) or area.pet.weight == 1 | |||
} | |||
end | |||
end | end | ||
return result | return result | ||
Line 30: | Line 38: | ||
function p.getPets(checkFunc) | function p.getPets(checkFunc) | ||
return GameData.getEntities('pets', checkFunc) | return GameData.getEntities('pets', checkFunc) | ||
end | |||
--Returns the expansion icon for the pet if it has one | |||
function p.getExpansionIcon(frame) | |||
local petName = frame.args ~= nil and frame.args[1] or frame | |||
local pet = p.getPet(petName) | |||
if pet == nil then | |||
return Shared.printError('No pet named "' .. petName .. '" exists in the data module') | |||
end | |||
return Icons.getExpansionIcon(pet.id) | |||
end | end | ||
Line 49: | Line 68: | ||
['Festive Cool Rock'] = { text = '[[Holiday Event 2021]]', useIcon = false }, | ['Festive Cool Rock'] = { text = '[[Holiday Event 2021]]', useIcon = false }, | ||
['Jerry the Giraffe'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false }, | ['Jerry the Giraffe'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false }, | ||
['Preston the Platypus'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false } | ['Preston the Platypus'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false }, | ||
['Ty'] = { text = 'Mastery', useIcon = true }, | |||
['Golden Golbin'] = { text = Icons.Icon({'Golbin', type='monster'}) .. ' kills', useIcon = false}, | |||
['Saki'] = { text = 'Mastery', useIcon = true } | |||
} | } | ||
local petSourceText = nil | local petSourceText = nil | ||
Line 102: | Line 124: | ||
if source ~= nil and source.weight ~= nil then | if source ~= nil and source.weight ~= nil then | ||
-- Pet is from a dungeon or combat/slayer area | -- Pet is from a dungeon or combat/slayer area | ||
if source.fixedChance then | |||
if source. | return 'Guaranteed after ' .. Shared.formatnum(source.weight) .. (source.weight == 1 and ' clear' or ' clears') | ||
return 'Guaranteed after ' .. Shared.formatnum(source.weight) .. ' clears' | |||
else | else | ||
return '1 in ' .. Shared.formatnum(source.weight) .. ' (' .. Shared.round(100 / source.weight, 2, 2) .. '%)' | return '1 in ' .. Shared.formatnum(source.weight) .. ' (' .. Shared.round(100 / source.weight, 2, 2) .. '%)' | ||
Line 138: | Line 159: | ||
table.insert(resultPart, '|-') | table.insert(resultPart, '|-') | ||
table.insert(resultPart, '|style="text-align: center;"|' .. Icons.Icon({pet.name, type='pet', size=60, notext=true})) | table.insert(resultPart, '|style="text-align: center;"|' .. Icons.Icon({pet.name, type='pet', size=60, notext=true})) | ||
table.insert(resultPart, '|' .. Icons.Icon({pet.name, type='pet', noicon=true})) | table.insert(resultPart, '|' .. Icons.getExpansionIcon(pet.id) .. Icons.Icon({pet.name, type='pet', noicon=true})) | ||
table.insert(resultPart, '| ' .. p._getPetEffect(pet)) | table.insert(resultPart, '| ' .. p._getPetEffect(pet)) | ||
end | end | ||
Line 168: | Line 189: | ||
local pet = p.getPet(name) | local pet = p.getPet(name) | ||
if pet == nil then | if pet == nil then | ||
return ' | return Shared.printError('No pet named "' .. (name or 'Unknown') .. '" exists in the data module') | ||
end | end | ||
local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet) | local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet) | ||
Line 174: | Line 195: | ||
local dropChance = p._getPetChance(pet) | local dropChance = p._getPetChance(pet) | ||
result = '{| class="wikitable infobox | result = '{| class="wikitable infobox"\r\n|-\r\n' | ||
result = result..'! '..name..'\r\n|-\r\n| ' | result = result..'! ' .. Icons.getExpansionIcon(pet.id) .. name .. '\r\n|-\r\n| ' | ||
result = result..'style="text-align: center;"|' .. Icons.Icon({name, type='pet', size='250', notext=true}) | result = result..'style="text-align: center;"|' .. Icons.Icon({name, type='pet', size='250', notext=true}) | ||
result = result.."\r\n|-\r\n|'''Pet ID:''' "..pet.id | result = result.."\r\n|-\r\n|'''Pet ID:''' "..pet.id | ||
Line 192: | Line 213: | ||
result = '{|class="wikitable sortable lighttable stickyHeader"' | result = '{|class="wikitable sortable lighttable stickyHeader"' | ||
result = result..'\r\n|- class="headerRow-0"\r\n! | result = result..'\r\n|- class="headerRow-0"\r\n! colspan="2"| Pet !! Acquired From !! Effect' | ||
for i, thisPet in ipairs(GameData.rawData.pets) do | for i, thisPet in ipairs(GameData.rawData.pets) do | ||
result = result..'\r\n|-\r\n|'..Icons.Icon({thisPet.name, type='pet', | result = result..'\r\n|-\r\n|class="table-img" data-sort-value="' .. thisPet.name .. '"| ' .. Icons.Icon({thisPet.name, size='60', type='pet', notext=true}) | ||
result = result..'| | result = result..'||' .. Icons.getExpansionIcon(thisPet.id) ..Icons.Icon({thisPet.name, type='pet', noicon=true}) | ||
result = result..'||'..p._getPetSourceText(thisPet) | result = result..'||'..p._getPetSourceText(thisPet) | ||
result = result..'||'..p._getPetEffect(thisPet) | result = result..'||'..p._getPetEffect(thisPet) | ||
Line 207: | Line 228: | ||
function p.getDungeonBoxPetText(frame) | function p.getDungeonBoxPetText(frame) | ||
local dungeonName = frame.args ~= nil and frame.args[1] or frame | local dungeonName = frame.args ~= nil and frame.args[1] or frame | ||
local dung = | local dung = nil | ||
for i, key in ipairs(areaDataKeys) do | |||
dung = GameData.getEntityByName(key, dungeonName) | |||
if dung ~= nil then | |||
break | |||
end | |||
end | |||
if dung == nil then | if dung == nil then | ||
return ' | return Shared.printError('No dungeon named "' .. dungeonName .. '" exists in the data module') | ||
end | end | ||
Line 221: | Line 248: | ||
end | end | ||
end | end | ||
end | end | ||
return p | return p |