From 6fdd2f66dc1e1d8331f0d3e9d26b58f23a26d48f Mon Sep 17 00:00:00 2001 From: M'Dic Date: Fri, 22 Sep 2023 17:08:57 -0400 Subject: [PATCH 1/8] feat (core): Despawn on Summoner Death --- src/server/game/AI/CreatureAI.cpp | 22 +++++++++++----------- src/server/game/Entities/Unit/Unit.cpp | 8 ++------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 5dae3af4..5f3ccc16 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -299,6 +299,17 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) return false; } + if (TempSummon* summon = me->ToTempSummon()) + { + if (SummonPropertiesEntry const* properties = summon->m_Properties) + { // Allied summons, pet summons join a formation unless the following exceptions are being met. + if (properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) + { + me->DespawnOrUnsummon(); + return true; + } + } + } me->RemoveAurasOnEvade(); @@ -313,17 +324,6 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) me->SetTarget(ObjectGuid::Empty); EngagementOver(); - if (TempSummon* summon = me->ToTempSummon()) - { - if (SummonPropertiesEntry const* properties = summon->m_Properties) - { // Allied summons, pet summons join a formation unless the following exceptions are being met. - if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) - { - me->DespawnOrUnsummon(); - return true; - } - } - } return true; } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 1dbd49fb..dbb6bfdb 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -6388,7 +6388,7 @@ Unit* Unit::GetFirstControlled() const // RemoveAllControlled gets called twice - in Unit::setDeathState() & void Unit::RemoveFromWorld() // It removes charming effects, controlled vehicles and unsummons minions. -void Unit::RemoveAllControlled(bool onDeath /*= false*/) +void Unit::RemoveAllControlled() { // possessed pet and vehicle if (GetTypeId() == TYPEID_PLAYER) @@ -6405,10 +6405,6 @@ void Unit::RemoveAllControlled(bool onDeath /*= false*/) // A pet/guardian should continue combat. Since we despawned every other summon type in UnsummonAllTotems(), we can waive on a additional type check and continue with IsSummon(). else if (target->GetOwnerOrCreatorGUID() == GetGUID() && target->IsSummon()) { - if (!(onDeath && !IsPlayer() && target->IsGuardian())) - { - target->ToTempSummon()->UnSummon(); - } if (!target->IsInCombat()) target->ToTempSummon()->UnSummon(); else @@ -6417,7 +6413,7 @@ void Unit::RemoveAllControlled(bool onDeath /*= false*/) } else LOG_ERROR("entities.unit", "Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry()); - + // checking for edge cases if (!controlledKeepsFighting) { From 16ba89e351a5a39c3f4f84a17958d69b86d9fc91 Mon Sep 17 00:00:00 2001 From: M'Dic Date: Fri, 22 Sep 2023 17:15:41 -0400 Subject: [PATCH 2/8] Update Unit.cpp --- src/server/game/Entities/Unit/Unit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index dbb6bfdb..e15d04c6 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -6413,7 +6413,7 @@ void Unit::RemoveAllControlled() } else LOG_ERROR("entities.unit", "Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry()); - + // checking for edge cases if (!controlledKeepsFighting) { From 5a08de3e668ba2d51a938c3c8ef006ccef330aa7 Mon Sep 17 00:00:00 2001 From: M'Dic Date: Sat, 23 Sep 2023 14:32:22 -0400 Subject: [PATCH 3/8] Update CreatureAI.cpp --- src/server/game/AI/CreatureAI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 5f3ccc16..80cce8b1 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -303,7 +303,7 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) { if (SummonPropertiesEntry const* properties = summon->m_Properties) { // Allied summons, pet summons join a formation unless the following exceptions are being met. - if (properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) + if (properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH || (me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive()) { me->DespawnOrUnsummon(); return true; From e60ffd015f99e0249305eaecf1fbdf46466b02a8 Mon Sep 17 00:00:00 2001 From: M'Dic Date: Sat, 23 Sep 2023 14:59:49 -0400 Subject: [PATCH 4/8] Update CreatureAI.cpp --- src/server/game/AI/CreatureAI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 80cce8b1..60b8e284 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -303,7 +303,7 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) { if (SummonPropertiesEntry const* properties = summon->m_Properties) { // Allied summons, pet summons join a formation unless the following exceptions are being met. - if (properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH || (me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive()) + if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) { me->DespawnOrUnsummon(); return true; From ea539888587baf7f82fadc52710db4d5757cfde1 Mon Sep 17 00:00:00 2001 From: M'Dic Date: Sun, 24 Sep 2023 11:41:20 -0400 Subject: [PATCH 5/8] Update CreatureAI.cpp --- src/server/game/AI/CreatureAI.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 60b8e284..5dae3af4 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -299,17 +299,6 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) return false; } - if (TempSummon* summon = me->ToTempSummon()) - { - if (SummonPropertiesEntry const* properties = summon->m_Properties) - { // Allied summons, pet summons join a formation unless the following exceptions are being met. - if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) - { - me->DespawnOrUnsummon(); - return true; - } - } - } me->RemoveAurasOnEvade(); @@ -324,6 +313,17 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) me->SetTarget(ObjectGuid::Empty); EngagementOver(); + if (TempSummon* summon = me->ToTempSummon()) + { + if (SummonPropertiesEntry const* properties = summon->m_Properties) + { // Allied summons, pet summons join a formation unless the following exceptions are being met. + if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) + { + me->DespawnOrUnsummon(); + return true; + } + } + } return true; } From e5b63ae9b68cac8d06b274d057506e3e349ab73b Mon Sep 17 00:00:00 2001 From: M'Dic Date: Sun, 24 Sep 2023 20:24:53 -0400 Subject: [PATCH 6/8] more --- src/server/game/Entities/Unit/Unit.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index e15d04c6..1dbd49fb 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -6388,7 +6388,7 @@ Unit* Unit::GetFirstControlled() const // RemoveAllControlled gets called twice - in Unit::setDeathState() & void Unit::RemoveFromWorld() // It removes charming effects, controlled vehicles and unsummons minions. -void Unit::RemoveAllControlled() +void Unit::RemoveAllControlled(bool onDeath /*= false*/) { // possessed pet and vehicle if (GetTypeId() == TYPEID_PLAYER) @@ -6405,6 +6405,10 @@ void Unit::RemoveAllControlled() // A pet/guardian should continue combat. Since we despawned every other summon type in UnsummonAllTotems(), we can waive on a additional type check and continue with IsSummon(). else if (target->GetOwnerOrCreatorGUID() == GetGUID() && target->IsSummon()) { + if (!(onDeath && !IsPlayer() && target->IsGuardian())) + { + target->ToTempSummon()->UnSummon(); + } if (!target->IsInCombat()) target->ToTempSummon()->UnSummon(); else From 4bd3294ab5971b7fe21220bcec2aec141a5e3171 Mon Sep 17 00:00:00 2001 From: M'Dic Date: Tue, 26 Sep 2023 11:32:49 -0400 Subject: [PATCH 7/8] Update CreatureAI.cpp --- src/server/game/AI/CreatureAI.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 5dae3af4..344caad5 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -299,9 +299,19 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) return false; } + if (TempSummon* summon = me->ToTempSummon()) + { + if (SummonPropertiesEntry const* properties = summon->m_Properties) + { // Allied summons, pet summons join a formation unless the following exceptions are being met. + if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) + { + me->DespawnOrUnsummon(); + return true; + } + } + } me->RemoveAurasOnEvade(); - me->CombatStop(true); me->LoadCreaturesAddon(); me->SetLootRecipient(nullptr); @@ -313,17 +323,6 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/) me->SetTarget(ObjectGuid::Empty); EngagementOver(); - if (TempSummon* summon = me->ToTempSummon()) - { - if (SummonPropertiesEntry const* properties = summon->m_Properties) - { // Allied summons, pet summons join a formation unless the following exceptions are being met. - if ((properties->Flags & SUMMON_PROP_FLAG_DESPAWN_ON_SUMMONER_DEATH) || ((me->IsGuardian() || me->IsPet()) && !me->GetOwner()->IsAlive())) - { - me->DespawnOrUnsummon(); - return true; - } - } - } return true; } From 375be39d336388bebcac389a841e144458af27de Mon Sep 17 00:00:00 2001 From: M'Dic Date: Tue, 26 Sep 2023 12:26:31 -0400 Subject: [PATCH 8/8] fix (core): desoawn on summer change up and warnings --- src/server/game/Entities/Unit/Unit.cpp | 12 ++++++------ src/server/game/Entities/Unit/Unit.h | 2 +- .../CavernsOfTime/DragonSoul/boss_morchok.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 1dbd49fb..afd31ec4 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -6409,8 +6409,6 @@ void Unit::RemoveAllControlled(bool onDeath /*= false*/) { target->ToTempSummon()->UnSummon(); } - if (!target->IsInCombat()) - target->ToTempSummon()->UnSummon(); else // we set this for edge case checks controlledKeepsFighting = true; @@ -6537,7 +6535,7 @@ void Unit::RemoveCharmAuras() // UnsummonAllTotems gets called twice - in Unit::setDeathState() & void Unit::RemoveFromWorld() // It iterates through all summon slots and despawns the summons -void Unit::UnsummonAllTotems() +void Unit::UnsummonAllTotems(bool onDeath /*= false*/) { for (uint8 i = 0; i < MAX_SUMMON_SLOT; ++i) { @@ -6550,8 +6548,10 @@ void Unit::UnsummonAllTotems() // We want to keep guardians and pets alive for now. A InCombat check is not needed here, we do this // in void Unit::RemoveAllControlled() { - if (!OldTotem->IsGuardian() && !OldTotem->IsPet()) + if (!(onDeath && !IsPlayer() && OldTotem->IsGuardian())) + { OldTotem->ToTempSummon()->UnSummon(); + } } } } @@ -9213,8 +9213,8 @@ void Unit::setDeathState(DeathState s) ExitVehicle(); // Exit vehicle before calling RemoveAllControlled // vehicles use special type of charm that is not removed by the next function // triggering an assert - UnsummonAllTotems(); - RemoveAllControlled(); + UnsummonAllTotems(true); + RemoveAllControlled(true); RemoveAllAurasOnDeath(); } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 4ba88df3..6f329e89 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1636,7 +1636,7 @@ class FC_GAME_API Unit : public WorldObject void ModifyAuraState(AuraStateType flag, bool apply); uint32 BuildAuraStateUpdateForTarget(Unit* target) const; bool HasAuraState(AuraStateType flag, SpellInfo const* spellProto = nullptr, Unit const* Caster = nullptr) const; - void UnsummonAllTotems(); + void UnsummonAllTotems(bool onDeath = false); bool IsMagnet() const; Unit* GetMagicHitRedirectTarget(Unit* victim, SpellInfo const* spellInfo); Unit* GetMeleeHitRedirectTarget(Unit* victim, SpellInfo const* spellInfo = nullptr); diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/DragonSoul/boss_morchok.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/DragonSoul/boss_morchok.cpp index 9cc335bc..ed0b77e2 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/DragonSoul/boss_morchok.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/DragonSoul/boss_morchok.cpp @@ -159,8 +159,8 @@ struct boss_morchok : public BossAI oldOrientation = morchokDest.GetOrientation(); summon->SetMaxHealth(me->GetMaxHealth()); summon->SetHealth(me->GetHealth()); - me->MovePosition(kohcromDest, 20.00f, -M_PI / 2); - me->MovePosition(morchokDest, 20.00f, M_PI / 2); + me->MovePosition(kohcromDest, 20.00f, static_cast(-M_PI / 2)); + me->MovePosition(morchokDest, 20.00f, static_cast(M_PI / 2)); me->GetMotionMaster()->MoveJump(morchokDest, 20.00f, 10.00f); summon->GetMotionMaster()->MoveJump(kohcromDest, 20.00f, 10.00f); } @@ -335,7 +335,7 @@ struct boss_morchok : public BossAI case EVENT_RESONATING_CRYSTAL: { Talk(TALK_SUMMON_RESONATING_CRYSTAL); - float angle = frand(0.0f, 2.0f * M_PI); + float angle = frand(0.0f, 2.0f * static_cast(M_PI)); float dist = frand(25.0f, 35.0f); float tempAngle = me->NormalizeOrientation(angle); Position pos(*me); @@ -538,7 +538,7 @@ struct boss_kohcrom : public ScriptedAI case EVENT_RESONATING_CRYSTAL: { Talk(TALK_SUMMON_RESONATING_CRYSTAL); - float angle = frand(0.0f, 2.0f * M_PI); + float angle = frand(0.0f, 2.0f * static_cast(M_PI)); float dist = frand(30.0f, 40.0f); float tempAngle = me->NormalizeOrientation(angle); Position pos(*me); @@ -847,7 +847,7 @@ class spell_ds_falling_fragments_periodic : public AuraScript uint8 maxAttemps = 0; while (maxAttemps < 20) { - float angle = frand(0.0f, 2.0f * M_PI); + float angle = frand(0.0f, 2.0f * static_cast(M_PI)); float tempAngle = Position::NormalizeOrientation(angle); bool nearObject = false; Position pos(*GetCaster()); @@ -877,7 +877,7 @@ class spell_ds_falling_fragments_periodic : public AuraScript uint8 maxAttemps = 0; while (maxAttemps < 20) { - float angle = frand(0.0f, 2.0f * M_PI); + float angle = frand(0.0f, 2.0f * static_cast(M_PI)); float tempAngle = Position::NormalizeOrientation(angle); bool nearObject = false; Position pos(*GetCaster()); @@ -972,7 +972,7 @@ class spell_ds_black_blood_of_the_earth_periodic : public AuraScript if (Unit* caster = GetCaster()) { - float angle = frand(0.0f, 2.0f * M_PI); + float angle = frand(0.0f, 2.0f * static_cast(M_PI)); float step = float(M_PI) / 16.0f; for (uint8 i = 0; i < 32; ++i) {