Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Spells: fixed resurrecting pets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovahlord committed Sep 28, 2023
1 parent 31a722b commit 05c6b00
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ bool NewPet::UnlearnSpell(uint32 spellId, bool learnPreviousRank, bool clearActi
if (!RemoveSpell(spellId, learnPreviousRank, clearActionbar))
return false;

if (IsInWorld() && !sSpellMgr->AssertSpellInfo(spellId)->IsPassive())
if (IsInWorld())
SendSpellUnlearnedToSummoner(spellId);

return true;
Expand Down
9 changes: 6 additions & 3 deletions src/server/game/Handlers/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ void HandlePetActionHelper(NewPet* pet, Player* owner, ObjectGuid targetGuid, ui
break;
case COMMAND_MOVE_TO:
printf("COMMAND_MOVE_TO -- %u\n", actionValue);
pet->GetMotionMaster()->Clear(MOTION_SLOT_IDLE);
pet->GetMotionMaster()->MoveIdle();
pet->GetMotionMaster()->MovePoint(0, actionPosition);
if (pet->IsAlive())
{
pet->GetMotionMaster()->Clear(MOTION_SLOT_IDLE);
pet->GetMotionMaster()->MoveIdle();
pet->GetMotionMaster()->MovePoint(0, actionPosition);
}
charmInfo->SetCommandState(COMMAND_MOVE_TO);
charmInfo->SetIsCommandAttack(false);
charmInfo->SetIsAtStay(true);
Expand Down
39 changes: 25 additions & 14 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3644,10 +3644,19 @@ void Spell::_cast(bool skipCheck)
}

if (m_spellInfo->HasAttribute(SPELL_ATTR1_DISMISS_PET_FIRST))
{
if (Unit* unitCaster = m_caster->ToUnit())
{
if (NewPet* pet = unitCaster->GetActivelyControlledSummon())
pet->Unsummon();

{
if (pet->IsClassPet() && unitCaster->IsPlayer())
unitCaster->ToPlayer()->DismissPet(false);
else
pet->Unsummon();
}
}
}

PrepareTriggersExecutedOnHit();

CallScriptOnCastHandlers();
Expand Down Expand Up @@ -6222,19 +6231,21 @@ SpellCastResult Spell::CheckCast(bool strict, uint32* param1 /*= nullptr*/, uint
if (!unitCaster)
break;

SummonPropertiesEntry const* SummonProperties = sSummonPropertiesStore.LookupEntry(m_spellInfo->Effects[i].MiscValueB);
if (!SummonProperties)
break;
switch (SummonProperties->Control)
if (SummonPropertiesEntry const* summonProperties = sSummonPropertiesStore.LookupEntry(m_spellInfo->Effects[i].MiscValueB))
{
case SUMMON_CATEGORY_PET:
if (!m_spellInfo->HasAttribute(SPELL_ATTR1_DISMISS_PET_FIRST) && unitCaster->GetSummonGUID())
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
[[fallthrough]]; // check both GetPetGUID() and GetCharmGUID for SUMMON_CATEGORY_PET*/
case SUMMON_CATEGORY_PUPPET:
if (unitCaster->GetCharmedGUID())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
break;
switch (static_cast<SummonPropertiesControl>(summonProperties->Control))
{
case SummonPropertiesControl::Pet:
if (!m_spellInfo->HasAttribute(SPELL_ATTR1_DISMISS_PET_FIRST) && unitCaster->GetSummonGUID())
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
[[fallthrough]]; // check both GetSummonGUID() and GetCharmGUID for SUMMON_CATEGORY_PET*/
case SummonPropertiesControl::Possessed:
if (unitCaster->GetCharmedGUID())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
break;
default:
break;
}
}
break;
}
Expand Down
48 changes: 10 additions & 38 deletions src/server/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4617,65 +4617,37 @@ void Spell::EffectDispelMechanic(SpellEffIndex effIndex)

void Spell::EffectResurrectPet(SpellEffIndex /*effIndex*/)
{
if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH)
return;

if (damage < 0)
if (damage < 0 || !m_targets.HasDst())
return;

Player* player = m_caster->ToPlayer();
if (!player)
return;

// Maybe player dismissed dead pet or pet despawned?
bool hadPet = true;

/*
if (!player->GetPet())
{
// Position passed to SummonPet is irrelevant with current implementation,
// pet will be relocated without using these coords in Pet::LoadPetData
//player->SummonPet(0, 0.0f, 0.0f, 0.0f, 0.0f, SUMMON_PET, 0);
hadPet = false;
}
// TODO: Better to fail Hunter's "Revive Pet" at cast instead of here when casting ends
Pet* pet = player->GetPet(); // Attempt to get current pet
NewPet* pet = player->GetActivelyControlledSummon();
if (!pet || pet->IsAlive())
return;

// If player did have a pet before reviving, teleport it
if (hadPet)
{
// Reposition the pet's corpse before reviving so as not to grab aggro
Position pos = player->GetPosition();
player->MovePositionToFirstCollision(pos, DEFAULT_FOLLOW_DISTANCE_PET, float(M_PI_2));
pet->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), player->GetOrientation());
pet->Relocate(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), player->GetOrientation()); // This is needed so SaveStayPosition() will get the proper coords.
}
pet->NearTeleportTo(m_targets.GetDstPos()->GetPosition());
pet->Relocate(m_targets.GetDstPos()->GetPosition()); // This is needed so SaveStayPosition() will get the proper coords.
pet->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_NONE);
pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
pet->setDeathState(ALIVE);
pet->ClearUnitState(UNIT_STATE_ALL_ERASABLE);
pet->SetHealth(pet->CountPctFromMaxHealth(damage));

// Reset things for when the AI to takes over
CharmInfo *ci = pet->GetCharmInfo();
if (ci)
if (CharmInfo* charmInfo = pet->GetCharmInfo())
{
// In case the pet was at stay, we don't want it running back
ci->SaveStayPosition();
ci->SetIsAtStay(ci->HasCommandState(COMMAND_STAY));
if (charmInfo->HasCommandState(COMMAND_FOLLOW))
pet->FollowTarget(player);

ci->SetIsFollowing(false);
ci->SetIsCommandAttack(false);
ci->SetIsCommandFollow(false);
ci->SetIsReturning(false);
if (charmInfo->HasCommandState(COMMAND_STAY))
charmInfo->SaveStayPosition();
}
pet->SavePetToDB(PET_SAVE_CURRENT_STATE);
*/
}

static constexpr uint32 SPELL_TOTEMIC_RECALL_ENERGIZE = 39104;
Expand Down

0 comments on commit 05c6b00

Please sign in to comment.