Fix Imp Fire Shield owner targeting while grouped.#3329
Fix Imp Fire Shield owner targeting while grouped.#3329mserajnik wants to merge 4 commits intovmangos:developmentfrom
Conversation
| m_AllySet.clear(); | ||
| m_AllySet.insert(m_creature->GetObjectGuid()); | ||
| m_AllySet.insert(owner->GetObjectGuid()); // Owner must always be a valid friendly target | ||
| m_AllySet.insert(owner->GetObjectGuid()); // The pet owner must always be a valid friendly target. |
There was a problem hiding this comment.
If the owner is charmed it will not be a friendly target.
There was a problem hiding this comment.
Good point, I forgot about that.
This makes the set size checks questionable because a lot can change within 10 seconds in regards to party composition and party members getting charmed.
I will have a look at this later and try to come up with a good solution.
There was a problem hiding this comment.
Had a few minutes and checked how CMaNGOS does it and it looks like they also add the owner unconditionally: https://github.com/cmangos/mangos-classic/blob/db3c5cba390b8f02c709675780bc086dc88fec37/src/game/AI/BaseAI/PetAI.cpp#L429
But maybe they check if the potential ally is charmed later; will investigate once I am home, if they have a good solution it may be worth it aligning our handling here.
There was a problem hiding this comment.
I looked into this:
Unless I misunderstood something when reading the code, with this PR we are essentially matching current CMaNGOS behavior: the owner is added unconditionally to m_AllySet and a charmed owner or party members are not filtered there. Instead, the charm state is validated later at cast time. I added a comment in UpdateAllies() to make that explicit.
In VMaNGOS, friendly-target pet casts go through Spell::CheckPetCast(), which rejects hostile targets via IsHostileTo(), so a charmed target is filtered there rather than when adding them to m_AllySet. CMaNGOS handles this in the same way conceptually as well, but through CanAssistSpell() / CanAssist() instead.
If we wanted to, we could additionally rebuild m_AllySet earlier when a charmed party member is detected and explicitly exclude charmed targets from the set, but I am not sure if that is worth adding here; since m_AllySet is only rebuilt every 10 seconds, that would mostly just invert the stale cache problem: a temporarily charmed target would stay excluded until the next set rebuild even after the charm ends. And since in that time frame also other charms can happen, we can not blindly rely on the set being correct anyway.
Unrelated, but I also noticed that CMaNGOS likely has a bug in the GetMembersCount() + 2 check, because GetMembersCount() already includes the owner there as well, just like in VMaNGOS (so it should probably be + 1 instead there as well).
🍰 Pullrequest
Currently,
PetAI::UpdateAllies()skips the owner (= the summoning Warlock in this case) in the grouped-member loop here:core/src/game/AI/PetAI.cpp
Lines 382 to 383 in 09a9a84
That would be fine if the owner were added unconditionally elsewhere. However, in the current code the owner is only inserted in the non-grouped branch here:
core/src/game/AI/PetAI.cpp
Lines 388 to 389 in 09a9a84
That makes the Imp stop considering its summoning Warlock as a valid friendly autocast target while grouped.
In addition, the cached
m_AllySetcan also stay stale after leaving a 2-player party, because a 2-entry set can still be{pet, former party member}(since the owner was never added in the grouped branch) versus{pet, owner}after leaving the party, and the size-basedm_AllySet.size() == 2 && !groupcheck will incorrectly still pass.This change always inserts the owner before processing grouped allies. This fixes both the grouped case and the stale cache after leaving a 2-player party, because even with a 2-player party the size of
m_AllySetwill be 3 ({pet, owner, party member}) and thus not hit the early return anymore.Note that I could not reproduce the GM visibility issue around Fire Shield that I first reported in #2916 anymore, so I probably initially misinterpreted it while simultaneously hitting this party bug.
Proof
Issues
How2Test
.levelup 13(need to be level 14 to learn Fire Shield).learn all_myclass.additem 16326 1Summon ImpGrimoire of Fire Shield (Rank 1)in the inventory.partybot add priestTodo / Checklist
Spell::CanAutoCast()usesGetAttackerForHelper(). I am not entirely sure, but I think this is not fully blizz-like. I didn't touch this in this PR though.