Closed joevt closed 11 years ago
Really? I had no idea it did this explains why most of the teams it was making were the same haha. I have no idea how this part of the addon works so I wont be able to help much but that would be nice.
Yes, as default the pet list is sorted alphabetically, and MPB will just choose the first available pet matching the conditions for setting the team, this is the most simple way to do it. I could make it check for similar pets and try to avoid them in the team setup, but if you do not have that many pets, it might be a problem.
I will think about it a bit more and put it on the ideas list.
Make a list of all appropriate pets and number them 0 to numAppropriatePets - 1. If the number is 0 then relax the conditions and make a new list. Then choose one of them with math.floor(math.random() * numAppropriatePets).
You may want to have options "Choose different species" and also "Choose different abilities" (since some different species may have the same abilities). If the options aren't selected then allow choosing the same species or pets with the same abilities. You may need to do that anyway if the player doesn't have enough pets (this would be one of the conditions to relax first - then level would be second).
Here's some code I put in PetTracker to cache species abilities which I use in PetJournalEnhanced for filtering purposes (for finding pets with unique abilities, or to show only the best pet of each ability set or to exclude pets that may have equivalents that are available in another zone at a higher level). For example, there's no reason to level a level 1 Rat if you can capture a higher level Rat from a higher level zone.
Journal.SpeciesAbilities = {}
Journal.AbilitiesSpecies = nil
local idTable = {}
local levelTable = {}
function Journal:GetAbilities(speciesID, includePetTypeAbility)
if not Journal.SpeciesAbilities[speciesID] then
local speciesName, _, petType = C_PetJournal.GetPetInfoBySpeciesID(speciesID)
C_PetJournal.GetPetAbilityList(speciesID, idTable, levelTable)
local temp1, temp2
if idTable[1] == nil then idTable[1] = 0 end
if idTable[2] == nil then idTable[2] = 0 end
if idTable[3] == nil then idTable[3] = 0 end
if idTable[4] == nil then idTable[4] = 0 end
if idTable[5] == nil then idTable[5] = 0 end
if idTable[6] == nil then idTable[6] = 0 end
if idTable[4] < idTable[1] then
temp1 = idTable[1]
idTable[1] = idTable[4]
idTable[4] = temp1
end
if idTable[5] < idTable[2] then
temp1 = idTable[2]
idTable[2] = idTable[5]
idTable[5] = temp1
end
if idTable[6] < idTable[3] then
temp1 = idTable[3]
idTable[3] = idTable[6]
idTable[6] = temp1
end
--[[
1 2 3 - no change required
1 3 2 - swap 2 and 3
2 1 3 - swap 1 and 2
2 3 1 - rotate
3 1 2 - rotate
3 2 1 - swap 1 and 3
--]]
if idTable[1] <= idTable[2] and idTable[2] <= idTable[3] then
--[[ handle pets with no abilities
Alliance Balloon
Argent Squire
Chi-ji Kite
Darkmoon Balloon
Guild Herald
Guild Page
Horde Balloon
Yu'lon Kite
Argent Gruntling
Guild Herald
Guild Page
--]]
elseif idTable[1] < idTable[3] and idTable[3] < idTable[2] then
temp1 = idTable[2]
temp2 = idTable[5]
idTable[2] = idTable[3]
idTable[5] = idTable[6]
idTable[3] = temp1
idTable[6] = temp2
elseif idTable[2] < idTable[1] and idTable[1] < idTable[3] then
temp1 = idTable[1]
temp2 = idTable[4]
idTable[1] = idTable[2]
idTable[4] = idTable[5]
idTable[2] = temp1
idTable[5] = temp2
elseif idTable[2] < idTable[3] and idTable[3] < idTable[1] then
temp1 = idTable[3]
temp2 = idTable[6]
idTable[3] = idTable[2]
idTable[6] = idTable[5]
idTable[2] = idTable[1]
idTable[5] = idTable[4]
idTable[1] = temp1
idTable[4] = temp2
elseif idTable[3] < idTable[1] and idTable[1] < idTable[2] then
temp1 = idTable[2]
temp2 = idTable[5]
idTable[2] = idTable[3]
idTable[5] = idTable[6]
idTable[3] = idTable[1]
idTable[6] = idTable[4]
idTable[1] = temp1
idTable[4] = temp2
elseif idTable[3] < idTable[2] and idTable[2] < idTable[1] then
temp1 = idTable[3]
temp2 = idTable[6]
idTable[3] = idTable[1]
idTable[6] = idTable[4]
idTable[1] = temp1
idTable[4] = temp2
else
print("unhandled order", idTable[1], idTable[2], idTable[3], speciesName)
end
local abilities = string.format("%d:%d;%d:%d;%d:%d#%d", idTable[1], idTable[4], idTable[2], idTable[5], idTable[3], idTable[6], PET_BATTLE_PET_TYPE_PASSIVES[petType] or 0)
Journal.SpeciesAbilities[speciesID] = abilities
end
if includePetTypeAbility == false then
return Journal.SpeciesAbilities[speciesID]:match'^([^#]*)#'
else
return Journal.SpeciesAbilities[speciesID]
end
end
function Journal:IsAbilitySetUnique(abilitySet)
if not Journal.AbilitiesSpecies then
Journal.AbilitiesSpecies = {}
local abilities, abilitiesWithoutPetTypeAbility
for i, speciesID in Cache:IterateSpeciesIDs() do
abilities = Journal:GetAbilities(speciesID)
abilitiesWithoutPetTypeAbility = abilities:match'^([^#]*)#'
if not Journal.AbilitiesSpecies[abilities] then
Journal.AbilitiesSpecies[abilities] = {}
end
if not Journal.AbilitiesSpecies[abilitiesWithoutPetTypeAbility] then
Journal.AbilitiesSpecies[abilitiesWithoutPetTypeAbility] = {}
end
tinsert(Journal.AbilitiesSpecies[abilities], speciesID)
tinsert(Journal.AbilitiesSpecies[abilitiesWithoutPetTypeAbility], speciesID)
if PetTrackerDebug == true then
print(i, species, abilities)
end
end
end
if Journal.AbilitiesSpecies[abilitySet] then
return #Journal.AbilitiesSpecies[abilitySet] <= 1
else
return true
end
end
Currently, MyPetBattle creates teams by choosing pets alphabetically. I think the pets should be chosen randomly so that you get a new time every time you click the "Make random team" button.