Core/Pet: Attempt to fix assertions triggered when summoning pets
Port From (https://github.com/TrinityCore/TrinityCore/commit/40d882b7544cff556f5e2dc6ac570c3fee5b9659)
This commit is contained in:
@@ -155,6 +155,10 @@ namespace Game.Entities
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't try to reload the current pet
|
||||
if (petStable.CurrentPet != null && owner.GetPet() != null && petStable.CurrentPet.PetNumber == petInfo.PetNumber)
|
||||
return false;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(petInfo.CreatedBySpellId, owner.GetMap().GetDifficultyID());
|
||||
|
||||
bool isTemporarySummon = spellInfo != null && spellInfo.GetDuration() > 0;
|
||||
@@ -274,7 +278,11 @@ namespace Game.Entities
|
||||
// PET_SAVE_NOT_IN_SLOT(100) = not stable slot (summoning))
|
||||
if (slot == PetSaveMode.NotInSlot)
|
||||
{
|
||||
var unslottedPetInfo = petStable.UnslottedPets.Find(unslottedPet => unslottedPet.PetNumber == petInfo.PetNumber);
|
||||
uint petInfoNumber = petInfo.PetNumber;
|
||||
if (petStable.CurrentPet != null)
|
||||
owner.RemovePet(null, PetSaveMode.NotInSlot);
|
||||
|
||||
var unslottedPetInfo = petStable.UnslottedPets.Find(unslottedPet => unslottedPet.PetNumber == petInfoNumber);
|
||||
Cypher.Assert(petStable.CurrentPet == null);
|
||||
Cypher.Assert(unslottedPetInfo != null);
|
||||
|
||||
@@ -284,6 +292,18 @@ namespace Game.Entities
|
||||
// old petInfo is no longer valid, refresh it
|
||||
petInfo = petStable.CurrentPet;
|
||||
}
|
||||
else if (PetSaveMode.FirstStableSlot <= slot && slot <= PetSaveMode.LastStableSlot)
|
||||
{
|
||||
var index = Array.FindIndex(petStable.StabledPets, pet => pet?.PetNumber == petnumber);
|
||||
var stabledPet = petStable.StabledPets[index];
|
||||
Cypher.Assert(index != -1);
|
||||
|
||||
petStable.StabledPets[index] = petStable.CurrentPet;
|
||||
petStable.CurrentPet = stabledPet;
|
||||
|
||||
// old petInfo pointer is no longer valid, refresh it
|
||||
petInfo = petStable.CurrentPet;
|
||||
}
|
||||
|
||||
// Send fake summon spell cast - this is needed for correct cooldown application for spells
|
||||
// Example: 46584 - without this cooldown (which should be set always when pet is loaded) isn't set clientside
|
||||
|
||||
@@ -4744,6 +4744,9 @@ namespace Game.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
if (petType == PetType.Summon && petStable.CurrentPet != null)
|
||||
RemovePet(null, PetSaveMode.NotInSlot);
|
||||
|
||||
PhasingHandler.InheritPhaseShift(pet, this);
|
||||
|
||||
pet.SetCreatorGUID(GetGUID());
|
||||
@@ -4836,7 +4839,7 @@ namespace Game.Entities
|
||||
|
||||
if (pet == null)
|
||||
{
|
||||
if (mode == PetSaveMode.NotInSlot && m_petStable.CurrentPet != null)
|
||||
if (mode == PetSaveMode.NotInSlot && m_petStable?.CurrentPet != null)
|
||||
{
|
||||
// Handle removing pet while it is in "temporarily unsummoned" state, for example on mount
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_PET_SLOT_BY_ID);
|
||||
|
||||
Reference in New Issue
Block a user