17,101
edits
m (_getPetEffect(): Fix new lines) |
(Create _getPetSource() & apply source/effect overrides consistently, resolves exception with getPetSidebar() for Golbin Raid pets) |
||
Line 49: | Line 49: | ||
end | end | ||
return result | return result | ||
end | |||
function p._getPetSource(pet) | |||
local sourceOverrides = { | |||
-- Format: ['PetName'] = {'Source', UseIcon} | |||
-- UseIcon = true if Source has an associated icon, false otherwise | |||
['Asura'] = {'Slayer', true}, | |||
['Ripper the Reindeer'] = {'[[Events#Christmas_Event_2020|Christmas Event 2020]]', false}, | |||
['Jerry the Giraffe'] = {'[[Golbin Raid|Golbin Raid Shop]]', false}, | |||
['Preston the Platypus'] = {'[[Golbin Raid|Golbin Raid Shop]]', false} | |||
} | |||
local petSource = '' | |||
local useIcon = true | |||
local override = sourceOverrides[pet.name] | |||
if override ~= nil then | |||
petSource = override[1] ~= nil and override[1] or pet.acquiredBy | |||
useIcon = override[2] | |||
elseif pet.acquiredBy ~= nil then | |||
petSource = pet.acquiredBy | |||
end | |||
-- Determine icon type (if any) | |||
local iconType = nil | |||
if Skills.getSkillID(petSource) ~= nil then | |||
iconType = 'skill' | |||
else | |||
local combatArea = Zones.getArea(petSource) | |||
if combatArea ~= nil then | |||
iconType = combatArea.type | |||
end | |||
end | |||
if useIcon then | |||
petSource = Icons.Icon({petSource, type=iconType}) | |||
end | |||
return petSource | |||
end | end | ||
function p._getPetEffect(pet) | function p._getPetEffect(pet) | ||
if pet.modifiers ~= nil then | local effectOverrides = { | ||
['Ripper the Reindeer'] = 'None', | |||
} | |||
if effectOverrides[pet.name] ~= nil then | |||
return effectOverrides[pet.name] | |||
elseif pet.modifiers ~= nil then | |||
local effects = {} | local effects = {} | ||
for effectName, effectValue in pairs(pet.modifiers) do | for effectName, effectValue in pairs(pet.modifiers) do | ||
Line 69: | Line 110: | ||
result = result..'!Pet!!Name!!Effect' | result = result..'!Pet!!Name!!Effect' | ||
result = result..'\r\n|-\r\n|'..Icons.Icon({pet.name, type='pet', size='60', notext=true}) | result = result..'\r\n|-\r\n|'..Icons.Icon({pet.name, type='pet', size='60', notext=true}) | ||
result = result..'||[['..pet.name..']]||'..pet | result = result..'||[['..pet.name..']]||'..p._getPetEffect(pet) | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
return result | return result | ||
Line 87: | Line 128: | ||
local pet = p.getPet(name) | local pet = p.getPet(name) | ||
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) | ||
local dropChance = nil | local dropChance = nil | ||
Line 105: | Line 134: | ||
dropChance = '1 in '..odds..' ('..Shared.round(100 / odds, 2, 2)..'%)' | dropChance = '1 in '..odds..' ('..Shared.round(100 / odds, 2, 2)..'%)' | ||
end | end | ||
result = '{| class="wikitable" style="float:right; clear:right;"\r\n|-\r\n' | result = '{| class="wikitable" style="float:right; clear:right;"\r\n|-\r\n' | ||
Line 112: | Line 140: | ||
result = result..'\r\n|-\r\n| Pet ID: '..pet.id | result = result..'\r\n|-\r\n| Pet ID: '..pet.id | ||
result = result..'\r\n|-\r\n| Source: '.. | result = result..'\r\n|-\r\n| Source: '..p._getPetSource(pet) | ||
if dropChance ~= nil then | if dropChance ~= nil then | ||
result = result..'\r\n|-\r\n| Drop Chance: '..dropChance | result = result..'\r\n|-\r\n| Drop Chance: '..dropChance | ||
Line 124: | Line 152: | ||
function p.getPetPageTable() | function p.getPetPageTable() | ||
local result = '' | local result = '' | ||
local petList = Shared.clone(PetData.Pets) | |||
result = '{|class="wikitable lighttable"' | |||
result = | |||
result = result..'\r\n|-\r\n! Name !! Image !! Acquired From !! Effect' | result = result..'\r\n|-\r\n! Name !! Image !! Acquired From !! Effect' | ||
Line 167: | Line 164: | ||
result = result..'\r\n|-\r\n|[['..thisPet.name..']]' | result = result..'\r\n|-\r\n|[['..thisPet.name..']]' | ||
result = result..'||'..Icons.Icon({thisPet.name, size='60', type='pet', notext=true}) | result = result..'||'..Icons.Icon({thisPet.name, size='60', type='pet', notext=true}) | ||
result = result..'||'..p._getPetSource(thisPet) | |||
result = result..'||'..p._getPetEffect(thisPet) | result = result..'||'..p._getPetEffect(thisPet) | ||
end | end |