Question about CreatureAI::JustDied()

I’m working on a bug with the PetAI such that in certain cases it isn’t properly receiving notification when a Unit is killed.

Currently there is code in Unit::DealDamage() that calls PetAI::KilledUnit() if the target is killed. The problem is it only notifies the player and / or pet that did the killing. If you have a pet class fighting a creature and someone else kills it, they don’t receive the notification.

I was thinking of implementing JustDied() but that will essentially result in the same problem. How do I broadcast the fact that the creature died to all attackers? Do I need to loop over the mob’s threat list? I think this could cause lag in 40 man instances because there are lots of mobs and lots of deaths. To cycle over 40 players + pets at every death might be noticeable.

I’ll try to illustrate the current problem:

[ul][li]HunterA + PetA start fighting a mob. Mob dies and Unit::DealDamage() calls[/li]PetAI::KilledUnit() for PetA which triggers next target selection.

[li][*]HunterA + PetA start fighting a mob. PaladinB kills the mob. Unit::DealDamage()[/li]never calls PetAI::KilledUnit() because PaladinB doesn’t have a pet. PetA bugs out.

[li][*]HunterA + PetA start fighting a mob. WarlockB + PetB kills the mob. Unit::DealDamage()[/li]calls PetAI::KilledUnit() for PetB. PetA bugs out.


When the npc dies, make it warn he’s dead to all references in its threat list. Not sure if it’s blizzlike but it should work.

Edit:didn’t read you completely. But that’s the only way I can think of right now.

I think it should be on the PetAI update function, if the target the pet was attacking is dead / something else, make it reset itself

LOL, I was just coming here to post that I decided to go this route. I originally had put the KilledUnit() function in to give the AI early notification but it seems that it’s more trouble than it’s worth.

Just an update:

I decided to go with what Subv suggested as well as modifying HandleReturnMovement() based on a suggestion from Oiler2112 who has been testing some things. If all works out then I’ll post the pull request. This should fix the problem with pets standing around after a mob dies.