fix(Core/Units): Stop melee attacking victim if being charmed by non-friendly target. (#11353)

Fixes #11316
This commit is contained in:
UltraNix
2022-04-16 14:45:16 +02:00
committed by GitHub
parent b88f442861
commit 13993a0b5b
2 changed files with 36 additions and 0 deletions

View File

@@ -17896,6 +17896,8 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
// Set charmed
charmer->SetCharm(this, true);
StopAttackingInvalidTarget();
if (GetTypeId() == TYPEID_UNIT)
{
if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MOTION_SLOT_IDLE))
@@ -18060,6 +18062,8 @@ void Unit::RemoveCharmedBy(Unit* charmer)
charmer->SetCharm(this, false);
StopAttackingInvalidTarget();
Player* playerCharmer = charmer->ToPlayer();
if (playerCharmer)
{
@@ -19591,6 +19595,37 @@ void Unit::StopAttackFaction(uint32 faction_id)
(*itr)->StopAttackFaction(faction_id);
}
void Unit::StopAttackingInvalidTarget()
{
AttackerSet const& attackers = getAttackers();
for (AttackerSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
{
Unit* attacker = (*itr);
if (!attacker->IsValidAttackTarget(this))
{
attacker->AttackStop();
if (attacker->GetTypeId() == TYPEID_PLAYER)
{
attacker->ToPlayer()->SendAttackSwingCancelAttack();
}
for (Unit* controled : attacker->m_Controlled)
{
if (controled->GetVictim() == this && !controled->IsValidAttackTarget(this))
{
controled->AttackStop();
}
}
itr = attackers.begin();
}
else
{
++itr;
}
}
}
void Unit::OutDebugInfo() const
{
LOG_ERROR("entities.unit", "Unit::OutDebugInfo");