You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
6.5 KiB

local _,rematch = ...
local L = rematch.localization
local C = rematch.constants
local settings = rematch.settings
rematch.speciesInfo = {}
--[[
This is for information about species that never changes during a session; such as what expansion each species
is from, each species source, each species moveset, etc.
The list of species is generated by roster while scanning the pet journal:
for speciesID in rematch.roster:AllSpecies() do etc end
]]
-- on-demand table for all species' movesets; indexed by speciesID, its value is the comma-delimited list of abilities
-- in the order they're learned. This generates a ton of garbage, is probably rarely used, and the data never changes,
-- so making this persistent if/when it's used.
local speciesMovesets = rematch.odTable:Create(function(self)
for speciesID in rematch.roster:AllSpecies() do
self[speciesID] = rematch.petInfo:Fetch(speciesID).moveset
end
end,true)
-- sourceIDs is a persistent table indexed by speciesIDs of the source for each species (1=Drop, 2=Quest,
-- 3=Vendor, etc). Because it's computationally expensive to populate this table (need to set 11 different
-- filters and gather results) this is persistent once created.
local sourceIDs = rematch.odTable:Create(function(self)
rematch.roster:StartUpdatingRoster()
rematch.roster:ExpandJournal()
for sourceID=1,C_PetJournal.GetNumPetSources() do -- going through all pet sources
-- set source filter to single category
for i=1,C_PetJournal.GetNumPetSources() do
C_PetJournal.SetPetSourceChecked(i,i==sourceID)
end
-- fill sourceIDs with the source-filtered results
for i=1,C_PetJournal.GetNumPets() do
local _,speciesID = C_PetJournal.GetPetInfoByIndex(i)
if not self[speciesID] then
self[speciesID] = sourceID
end
end
end
rematch.roster:RestoreJournal() -- put everything back how it was
rematch.timer:Start(0,rematch.roster.FinishUpdatingRoster)
end,true)
-- in general, when a pet is added alongside others in an expansion they all clump to a range of speciesIDs
-- (with some outliers listed below). this is a list of expansions and the range of speciesIDs in that
-- expansion: [expansionID] = {firstSpeciesID,lastSpeciesID}
local expansionRanges = {
[0] = {39,128}, -- Classic
[1] = {130,186}, -- Burning Crusade
[2] = {187,258}, -- Wrath of the Lich King
[3] = {259,343}, -- Cataclysm
[4] = {346,1365}, -- Mists of Pandaria
[5] = {1384,1693}, -- Warlords of Draenor
[6] = {1699,2163}, -- Legion
[7] = {2165,2872}, -- Battle for Azeroth
[8] = {2878,3255}, -- Shadowlands
[9] = {3256,9999} -- Dragonflight (next expansion, get max speciesID for Dragonflight and change 9999 to that)
}
-- the majority of pets fall into a range for each expansion above, except for some outliers. these are the
-- species ID and the expansionID they belong to
local expansionOutliers = {
[1563] = 0, -- Bronze Whelpling
[191] = 1, -- Clockwork Rocket Bot
[1073] = 1, -- Terky
[1351] = 2, -- Macabre Marionette
[220] = 3, -- Withers
[255] = 3, -- Celestial Dragon
[231] = 4, -- Jade Tiger
[1386] = 4, -- Dread Hatchling
[1943] = 4, -- Noblegarden Bunny
[115] = 5, -- Land Shark
[1725] = 5, -- Grumpling
[1730] = 5, -- Spectral Spinner
[1740] = 5, -- Ghost Maggot
[1741] = 5, -- Ghastly Rat
[1761] = 5, -- Echo Batling
[1764] = 5, -- Energized Manafiend
[1765] = 5, -- Empyreal Manafiend
[1766] = 5, -- Empowered Manafiend
[1828] = 5, -- Baby Winston
[2143] = 7, -- Tottle
[2157] = 7, -- Dart
[2798] = 8, -- Plagueborn Slime
}
-- small recursive function to get an expansion index without doing a linear check of all ranges; initial call
-- should use an index in/near middle, and it will search up/down ranges until it finds a fit
local function getExpansionIndex(speciesID,index)
if index>=0 and index<=#expansionRanges then
local low = expansionRanges[index][1]
local high = expansionRanges[index][2]
if speciesID<low then -- if speciesID is below low range, then look at previous index
return getExpansionIndex(speciesID,index-1)
elseif speciesID>high then -- if speciesID is above high range, then look at next index
return getExpansionIndex(speciesID,index+1)
else
return index
end
end
return nil -- if we reached here, speciesID didn't fit into any range
end
-- annoyingly, wrong-faction pets canBattle flag can be false for the owned petID and true for the speciesID,
-- making the GetPetInfoByPetID canBattle flag unusable; so collecting speciesIDs that can't battle
local speciesCantBattle = rematch.odTable:Create(function(self)
for speciesID in rematch.roster:AllSpecies() do
local canBattle = select(8,C_PetJournal.GetPetInfoBySpeciesID(speciesID))
if not canBattle then
self[speciesID] = true
end
end
end,true)
-- returns the moveset for a given speciesID
function rematch.speciesInfo:GetMoveset(speciesID)
speciesMovesets:Start()
return speciesMovesets[speciesID]
end
-- returns the table of key,value pairs with speciesID=moveset
function rematch.speciesInfo:GetAllMovesets()
speciesMovesets:Start()
return speciesMovesets
end
-- returns the sourceID (1=Drop, 2=Quest, 3=Vendor, etc.) of a specific speciesID
function rematch.speciesInfo:GetSourceID(speciesID)
sourceIDs:Start()
return sourceIDs[speciesID]
end
-- returns the table of key,value pairs with speciesID=sourceID
function rematch.speciesInfo:GetAllSourceID()
sourceIDs:Start()
return sourceIDs
end
-- gets the expansion a speciesID is from
function rematch.speciesInfo:GetExpansion(speciesID)
if expansionOutliers[speciesID] then
return expansionOutliers[speciesID] -- this speciesID is an outlier, return its expansion without searching
elseif type(speciesID)=="number" and speciesID>0 then
return getExpansionIndex(speciesID,4) -- starting at MoP since it's in middle and most speciesID added then
else
return false
end
end
-- returns true if the speciesID can battle (using cantBattle since it's a shorter list)
function rematch.speciesInfo:CanBattle(speciesID)
if speciesID then
local cantBattle = speciesCantBattle[speciesID]
return not cantBattle
end
end