Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (core): Despawn on summoner fix and warning #183

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/server/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}
}
}
}
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(-M_PI / 2));
me->MovePosition(morchokDest, 20.00f, static_cast<float>(M_PI / 2));
me->GetMotionMaster()->MoveJump(morchokDest, 20.00f, 10.00f);
summon->GetMotionMaster()->MoveJump(kohcromDest, 20.00f, 10.00f);
}
Expand Down Expand Up @@ -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<float>(M_PI));
float dist = frand(25.0f, 35.0f);
float tempAngle = me->NormalizeOrientation(angle);
Position pos(*me);
Expand Down Expand Up @@ -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<float>(M_PI));
float dist = frand(30.0f, 40.0f);
float tempAngle = me->NormalizeOrientation(angle);
Position pos(*me);
Expand Down Expand Up @@ -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<float>(M_PI));
float tempAngle = Position::NormalizeOrientation(angle);
bool nearObject = false;
Position pos(*GetCaster());
Expand Down Expand Up @@ -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<float>(M_PI));
float tempAngle = Position::NormalizeOrientation(angle);
bool nearObject = false;
Position pos(*GetCaster());
Expand Down Expand Up @@ -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<float>(M_PI));
float step = float(M_PI) / 16.0f;
for (uint8 i = 0; i < 32; ++i)
{
Expand Down
Loading