diff options
Diffstat (limited to 'src/server/game/Spells/SpellEffects.cpp')
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 2cdf9006079..edd59647a76 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -2626,26 +2626,34 @@ void Spell::EffectSummonPet() return; } + Optional<PetSaveMode> petSlot; + if (!petentry) + petSlot = PetSaveMode(damage); + float x, y, z; owner->GetClosePoint(x, y, z, owner->GetCombatReach()); - Pet* pet = owner->SummonPet(petentry, x, y, z, owner->GetOrientation(), SUMMON_PET, 0); + bool isNew = false; + Pet* pet = owner->SummonPet(petentry, petSlot, x, y, z, owner->GetOrientation(), 0, &isNew); if (!pet) return; - if (m_caster->GetTypeId() == TYPEID_UNIT) + if (isNew) { - if (m_caster->ToCreature()->IsTotem()) - pet->SetReactState(REACT_AGGRESSIVE); - else - pet->SetReactState(REACT_DEFENSIVE); - } + if (m_caster->GetTypeId() == TYPEID_UNIT) + { + if (m_caster->ToCreature()->IsTotem()) + pet->SetReactState(REACT_AGGRESSIVE); + else + pet->SetReactState(REACT_DEFENSIVE); + } - pet->SetCreatedBySpell(m_spellInfo->Id); + pet->SetCreatedBySpell(m_spellInfo->Id); - // generate new name for summon pet - std::string new_name = sObjectMgr->GeneratePetName(petentry); - if (!new_name.empty()) - pet->SetName(new_name); + // generate new name for summon pet + std::string new_name = sObjectMgr->GeneratePetName(petentry); + if (!new_name.empty()) + pet->SetName(new_name); + } ExecuteLogEffectSummonObject(SpellEffectName(effectInfo->Effect), pet); } @@ -4252,9 +4260,17 @@ void Spell::EffectResurrectPet() if (!player->GetPet()) { + PetStable const* petStable = player->GetPetStable(); + auto deadPetItr = std::find_if(petStable->ActivePets.begin(), petStable->ActivePets.end(), [](Optional<PetStable::PetInfo> const& petInfo) + { + return petInfo && !petInfo->Health; + }); + + PetSaveMode slot = PetSaveMode(std::distance(petStable->ActivePets.begin(), deadPetItr)); + // Position passed to SummonPet is irrelevant with current implementation, // pet will be relocated without using these coords in Pet::LoadPetFromDB - player->SummonPet(0, 0.0f, 0.0f, 0.0f, 0.0f, SUMMON_PET, 0); + player->SummonPet(0, slot, 0.0f, 0.0f, 0.0f, 0.0f, 0); hadPet = false; } |