cmangos / issues

This repository is used as a centralized point for all issues regarding CMaNGOS.
179 stars 47 forks source link

🐛 [Bug Report] Relations.cpp function `CanAttack` problem #2052

Closed yukozh closed 4 years ago

yukozh commented 4 years ago

Problem

When a player goes into a netrual city to reset his talent, the NPC will cast "Untalent Visual Effect" to player, so it will trigger melee attack. (mangos-tbc version)

Repro steps:

  1. Create an undead character.
  2. Level up him to 10+.
  3. Go to Orgrimmar class trainner
  4. Request reset talent.
  5. The NPC will attack the character. Due to cast "Untalent Visual Effect" to player causes auto melee attack.

Investigation

https://github.com/cmangos/mangos-tbc/blob/master/src/game/Entities/Relations.cpp#L449

In line 449, it prevents attack only when the player's reputation >= friendly. But in this case, Orgrimmar is netrual to a fresh Undead.

Besides, cast "Untalent Visual Effect" will trigger NPC auto melee attacks.

Suggestions

Not sure how to fix it in a right way. A workaround is limit the netrual NPCs only can attack player when the NPCs are attacked by players.

if (!thisPlayerControlled && unitPlayerControlled)
{
    if (!IsEnemy(unit) && !IsAttackedBy((Unit*)unit))
        return false;
}

But not sure if there may be some case that the natrual NPCs will attack players actively, then it will be broken down by this workaround.

In another hand. Not sure it is a relation problem or a spell problem. Is there any flags could be attached into spell that don't trigger auto melee attack?

Warlockbugs commented 4 years ago

Should be fixed by: https://github.com/cmangos/mangos-classic/commit/be3a77d2f6e413a744be0c28f1b878bf053cd811 https://github.com/cmangos/mangos-tbc/commit/1852b1468c9e9f70878e0293aeffbcf385814bbd https://github.com/cmangos/mangos-wotlk/commit/618bb5327678a166d1adeb00ca4222ec8afbafae

Those are to be improved further a bit later.