Skip to content

Commit

Permalink
[Core/Spell] Fix Casting Earth, Wind and Fire (Monk spell) Crashes (#363
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leelf00 authored Oct 15, 2024
1 parent 4f008b1 commit 7944bf5
Show file tree
Hide file tree
Showing 116 changed files with 264 additions and 293 deletions.
2 changes: 1 addition & 1 deletion src/server/game/AI/CoreAI/GuardAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool GuardAI::CanSeeAlways(WorldObject const* obj)
if (!obj->isType(TYPEMASK_UNIT))
return false;

ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
if ((*itr)->getUnitGuid() == obj->GetGUID())
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/CoreAI/UnitAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void UnitAI::DoAddAuraToAllHostilePlayers(uint32 spellid)
{
if (me->IsInCombat())
{
ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
if (Unit* unit = Unit::GetUnit(*me, (*itr)->getUnitGuid()))
Expand All @@ -120,7 +120,7 @@ void UnitAI::DoCastToAllHostilePlayers(uint32 spellid, bool triggered)
{
if (me->IsInCombat())
{
ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
if (Unit* unit = Unit::GetUnit(*me, (*itr)->getUnitGuid()))
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/CoreAI/UnitAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class TC_GAME_API UnitAI
// order, if <targetType> is SelectTargetMethod::Random) are skipped.
template <class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE const& predicate)
{
ThreatContainer::StorageType const& threatlist = me->getThreatManager().getThreatList();
ThreatContainer::StorageType const& threatlist = me->GetThreatManager().getThreatList();
if (position >= threatlist.size())
return NULL;

Expand Down Expand Up @@ -287,7 +287,7 @@ class TC_GAME_API UnitAI
// order, if <targetType> is SelectTargetMethod::Random) are skipped.
template <class PREDICATE> void SelectTargetList(std::list<Unit*>& targetList, PREDICATE const& predicate, uint32 maxTargets, SelectAggroTarget targetType)
{
ThreatContainer::StorageType const& threatlist = me->getThreatManager().getThreatList();
ThreatContainer::StorageType const& threatlist = me->GetThreatManager().getThreatList();
if (threatlist.empty())
return;

Expand Down
8 changes: 4 additions & 4 deletions src/server/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= NULL*/, float maxRangeToN
if (Unit* summoner = creature->ToTempSummon()->GetSummoner())
{
Unit* target = summoner->getAttackerForHelper();
if (!target && summoner->CanHaveThreatList() && !summoner->getThreatManager().isThreatListEmpty())
target = summoner->getThreatManager().getHostilTarget();
if (!target && summoner->CanHaveThreatList() && !summoner->GetThreatManager().isThreatListEmpty())
target = summoner->GetThreatManager().getHostilTarget();
if (target && (creature->IsFriendlyTo(summoner) || creature->IsHostileTo(target)))
creature->AI()->AttackStart(target);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ void CreatureAI::DoAttackerAreaInCombat(Unit* attacker, float range, Unit* pUnit
if (!map->IsDungeon())
return;

if (!pUnit->CanHaveThreatList() || pUnit->getThreatManager().isThreatListEmpty())
if (!pUnit->CanHaveThreatList() || pUnit->GetThreatManager().isThreatListEmpty())
return;

Map::PlayerList const& PlayerList = map->GetPlayers();
Expand Down Expand Up @@ -317,7 +317,7 @@ bool CreatureAI::UpdateVictim()
AttackStart(victim);
return me->GetVictim();
}
else if (me->getThreatManager().isThreatListEmpty())
else if (me->GetThreatManager().isThreatListEmpty())
{
EnterEvadeMode();
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec

void ScriptedAI::DoResetThreat()
{
if (!me->CanHaveThreatList() || me->getThreatManager().isThreatListEmpty())
if (!me->CanHaveThreatList() || me->GetThreatManager().isThreatListEmpty())
{
TC_LOG_ERROR("scripts", "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = %d)", me->GetEntry());
return;
}

ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList();

for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
Expand All @@ -294,14 +294,14 @@ float ScriptedAI::DoGetThreat(Unit* unit)
{
if (!unit)
return 0.0f;
return me->getThreatManager().getThreat(unit);
return me->GetThreatManager().getThreat(unit);
}

void ScriptedAI::DoModifyThreatPercent(Unit* unit, int32 pct)
{
if (!unit)
return;
me->getThreatManager().modifyThreatPercent(unit, pct);
me->GetThreatManager().modifyThreatPercent(unit, pct);
}

void ScriptedAI::DoTeleportTo(float x, float y, float z, uint32 time)
Expand Down Expand Up @@ -641,7 +641,7 @@ void BossAI::TeleportCheaters()
float x, y, z;
me->GetPosition(x, y, z);

ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
if (Unit* target = (*itr)->getTarget())
if (target->GetTypeId() == TYPEID_PLAYER && !CheckBoundary(target))
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!me)
break;

ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
{
if (Unit* target = Unit::GetUnit(*me, (*i)->getUnitGuid()))
{
me->getThreatManager().modifyThreatPercent(target, e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
me->GetThreatManager().modifyThreatPercent(target, e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_ALL_PCT: Creature guidLow %u modify threat for unit %u, value %i",
me->GetGUID().GetCounter(), target->GetGUID().GetCounter(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
}
Expand All @@ -427,7 +427,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsUnit(*itr))
{
me->getThreatManager().modifyThreatPercent((*itr)->ToUnit(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
me->GetThreatManager().modifyThreatPercent((*itr)->ToUnit(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_SINGLE_PCT: Creature guidLow %u modify threat for unit %u, value %i",
me->GetGUID().GetCounter(), (*itr)->GetGUID().GetCounter(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
}
Expand Down Expand Up @@ -2911,7 +2911,7 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
{
if (me)
{
ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList();
ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
if (Unit* temp = Unit::GetUnit(*me, (*i)->getUnitGuid()))
l->push_back(temp);
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Combat/ThreatManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Combat/UnitEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ThreatRefStatusChangeEvent : public UnitBaseEvent

void setThreatManager(ThreatManager* pThreatManager) { iThreatManager = pThreatManager; }

ThreatManager* getThreatManager() const { return iThreatManager; }
ThreatManager* GetThreatManager() const { return iThreatManager; }
};

//==============================================================
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2484,8 +2484,8 @@ void Creature::FixateOnTarget(ObjectGuid targetGUID, uint32 timer)
{
if (Unit* target = ObjectAccessor::GetUnit(*this, targetGUID))
{
getThreatManager().clearReferences();
getThreatManager().addThreat(target, std::numeric_limits<float>::max());
GetThreatManager().clearReferences();
GetThreatManager().addThreat(target, std::numeric_limits<float>::max());

if (AI())
AI()->AttackStart(target);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,8 @@ bool WorldObject::CanDetectStealthOf(WorldObject const* obj) const
// Hack for Subterfuge. When rogue opens and Subterfuge triggered - player is still invisible and mob just goes to evade.
if (Player const* player = obj->ToPlayer())
if (GetTypeId() == TYPEID_UNIT && player->IsInCombat() && player->HasAura(115192))
if (const_cast<Unit*>(unit)->getThreatManager().getThreatList().size() == 1)
if (const_cast<Unit*>(unit)->getThreatManager().getThreat(const_cast<Player*>(player)) > 0.0f)
if (const_cast<Unit*>(unit)->GetThreatManager().getThreatList().size() == 1)
if (const_cast<Unit*>(unit)->GetThreatManager().getThreat(const_cast<Player*>(player)) > 0.0f)
return true;

if (!HasInArc(M_PI, obj))
Expand Down
24 changes: 12 additions & 12 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void Unit::Update(uint32 p_time)
// Having this would prevent spells from being proced, so let's crash
ASSERT(!m_procDeep);

if (CanHaveThreatList() && getThreatManager().isNeedUpdateToClient(p_time))
if (CanHaveThreatList() && GetThreatManager().isNeedUpdateToClient(p_time))
SendThreatListUpdate();

// update combat timer only for players and pets (only pets with PetAI)
Expand Down Expand Up @@ -17326,8 +17326,8 @@ void Unit::SetPhaseMask(uint32 newPhaseMask, bool update)
// modify threat lists for new phasemask
if (GetTypeId() != TYPEID_PLAYER)
{
std::list<HostileReference*> threatList = getThreatManager().getThreatList();
std::list<HostileReference*> offlineThreatList = getThreatManager().getOfflineThreatList();
std::list<HostileReference*> threatList = GetThreatManager().getThreatList();
std::list<HostileReference*> offlineThreatList = GetThreatManager().getOfflineThreatList();

// merge expects sorted lists
threatList.sort();
Expand Down Expand Up @@ -17390,8 +17390,8 @@ bool Unit::SetPhased(uint32 id, bool update, bool apply)
// modify threat lists for new phasemask
if (GetTypeId() != TYPEID_PLAYER)
{
std::list<HostileReference*> threatList = getThreatManager().getThreatList();
std::list<HostileReference*> offlineThreatList = getThreatManager().getOfflineThreatList();
std::list<HostileReference*> threatList = GetThreatManager().getThreatList();
std::list<HostileReference*> offlineThreatList = GetThreatManager().getOfflineThreatList();

// merge expects sorted lists
threatList.sort();
Expand Down Expand Up @@ -18794,9 +18794,9 @@ void Unit::UpdateHeight(float newZ)

void Unit::SendThreatListUpdate()
{
if (!getThreatManager().isThreatListEmpty())
if (!GetThreatManager().isThreatListEmpty())
{
uint32 count = getThreatManager().getThreatList().size();
uint32 count = GetThreatManager().getThreatList().size();

TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_THREAT_UPDATE Message");

Expand All @@ -18812,7 +18812,7 @@ void Unit::SendThreatListUpdate()
data.WriteBit(Guid[4]);
data.WriteBits(count, 21);

ThreatContainer::StorageType const &tlist = getThreatManager().getThreatList();
ThreatContainer::StorageType const &tlist = GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
{
ObjectGuid unitGuid = (*itr)->getUnitGuid();
Expand Down Expand Up @@ -18859,9 +18859,9 @@ void Unit::SendThreatListUpdate()

void Unit::SendChangeCurrentVictimOpcode(HostileReference* pHostileReference)
{
if (!getThreatManager().isThreatListEmpty())
if (!GetThreatManager().isThreatListEmpty())
{
uint32 count = getThreatManager().getThreatList().size();
uint32 count = GetThreatManager().getThreatList().size();

TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message");
ObjectGuid unitGuid = pHostileReference->getUnitGuid();
Expand All @@ -18883,7 +18883,7 @@ void Unit::SendChangeCurrentVictimOpcode(HostileReference* pHostileReference)
data.WriteBit(guid[4]);
data.WriteBits(count, 21);

ThreatContainer::StorageType const &tlist = getThreatManager().getThreatList();
ThreatContainer::StorageType const &tlist = GetThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
{
ObjectGuid UnitGuid = (*itr)->getUnitGuid();
Expand Down Expand Up @@ -20162,7 +20162,7 @@ float Unit::GetScallingDamageMod() const
// calculate celestials scalling mod
if (GetEntry() == 71955 || GetEntry() == 71953 || GetEntry() == 71952 || GetEntry() == 71954)
{
auto threatList = const_cast<Unit*>(this)->getThreatManager().getThreatList();
auto threatList = const_cast<Unit*>(this)->GetThreatManager().getThreatList();
for (auto&& itr : threatList)
if (Unit* unit = ObjectAccessor::GetUnit(*this, itr->getUnitGuid()))
if (unit->GetTypeId() == TYPEID_PLAYER && unit->IsWithinDist(this, 100.0f))
Expand Down
6 changes: 2 additions & 4 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2114,10 +2114,8 @@ class TC_GAME_API Unit : public WorldObject
void DeleteThreatList();
void TauntApply(Unit* victim);
void TauntFadeOut(Unit* taunter);
ThreatManager& getThreatManager()
{
return m_ThreatManager;
}
ThreatManager& GetThreatManager() { return m_ThreatManager; }
ThreatManager const& GetThreatManager() const { return m_ThreatManager; }
void addHatedBy(HostileReference* pHostileReference)
{
m_HostileRefManager.insertFirst(pHostileReference);
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/LuaEngine/CreatureMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ namespace LuaCreature
//int32 aura = luaL_optint(L, 5, 0);

//;
//std::list<HostileReference*>& threatlist = creature->getThreatManager().getThreatList();
////std::list<HostileReference*>& threatlist = creature->getThreatManager().getThreatList();
//std::list<HostileReference*>& threatlist = creature->GetThreatManager().getThreatList();
////std::list<HostileReference*>& threatlist = creature->GetThreatManager().getThreatList();
//if (position >= threatlist.size())
//{
// sEluna->Push(L);
Expand Down Expand Up @@ -596,7 +596,7 @@ namespace LuaCreature
//int tbl = lua_gettop(L);
//uint32 i = 0;

//std::list<HostileReference*>& threatList = creature->getThreatManager().getThreatList();
//std::list<HostileReference*>& threatList = creature->GetThreatManager().getThreatList();
////ThreatContainer::StorageType::const_iterator itr;
////for (itr = threatList.begin(); itr != threatList.end(); ++itr)
//for (auto itr : threatList)
Expand All @@ -616,7 +616,7 @@ namespace LuaCreature

int GetAITargetsCount(lua_State* L, Creature* creature)
{
sEluna->Push(L, creature->getThreatManager().getThreatList().size());
sEluna->Push(L, creature->GetThreatManager().getThreatList().size());
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/LuaEngine/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace LuaUnit

int ClearThreatList(lua_State* L, Unit* unit)
{
unit->getThreatManager().clearReferences();
unit->GetThreatManager().clearReferences();
return 0;
}

Expand Down
41 changes: 7 additions & 34 deletions src/server/game/Spells/Auras/SpellAuraEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pAuraEffectHandler AuraEffectHandler[TOTAL_AURAS]=
&AuraEffect::HandleNoImmediateEffect, //125 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
&AuraEffect::HandleNoImmediateEffect, //126 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
&AuraEffect::HandleNoImmediateEffect, //127 SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
&AuraEffect::HandleModFixateTarget, //128 SPELL_AURA_FIXATE_TARGET
&AuraEffect::HandleModFixateTarget, //128 SPELL_AURA_FIXATE_TARGET
&AuraEffect::HandleAuraModIncreaseSpeed, //129 SPELL_AURA_MOD_SPEED_ALWAYS
&AuraEffect::HandleAuraModIncreaseMountedSpeed, //130 SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
&AuraEffect::HandleNoImmediateEffect, //131 SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
Expand Down Expand Up @@ -3167,44 +3167,17 @@ void AuraEffect::HandleModFixateTarget(AuraApplication const* aurApp, uint8 mode
if (!(mode & AURA_EFFECT_HANDLE_REAL))
return;

Unit* caster = GetCaster();
Unit* target = aurApp->GetTarget();
if (!target->IsAlive())
return;

Unit* caster = GetCaster();
if (!caster || caster->GetTypeId() != TYPEID_UNIT || !caster->IsAlive())
if (!caster || !caster->IsAlive() || !target->IsAlive() || caster->GetTypeId() != TYPEID_UNIT )
return;

// Todo ThreatManager needs upgrade
// if (apply)
// caster->BindAura(aurApp->GetBase());

Pet* pet = target->ToPet();
if (apply)
{
if (caster->ToPlayer()->GetPet() != pet)
return;

pet->SetCharmedBy(caster, CHARM_TYPE_POSSESS, aurApp);
}
else
{
pet->RemoveCharmedBy(caster);

if (!pet->IsWithinDistInMap(caster, pet->GetMap()->GetVisibilityRange()))
pet->Remove(PET_REMOVE_DISMISS, PET_REMOVE_FLAG_RETURN_REAGENT | PET_REMOVE_FLAG_RESET_CURRENT);
//pet->Remove(PET_REMOVE_DISMISS, true); // PET_SAVE_NOT_IN_SLOT
else
{
// Reinitialize the pet bar or it will appear greyed out
caster->ToPlayer()->PetSpellInitialize();

// TODO: remove this
if (!pet->GetVictim() && !pet->GetCharmInfo()->HasCommandState(COMMAND_STAY))
pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, pet->GetFollowAngle());
}
}

// No need to unbind it will happen automatically
// caster->GetThreatManager().FixateTarget(target);
// else
// caster->GetThreatManager().ClearFixate();
}

void AuraEffect::HandleModCharm(AuraApplication const* aurApp, uint8 mode, bool apply) const
Expand Down
Loading

0 comments on commit 7944bf5

Please sign in to comment.