mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 10:00:28 +00:00
fix(Core/Units): Stop melee attacking victim if being charmed by non-friendly target. (#11353)
Fixes #11316
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user