Skip to content

Pet/Guardian AI hook re-organizing#19824

Merged
Treeston merged 4 commits into
TrinityCore:3.3.5from
Treeston:3.3.5-guardianaihooks
Jun 7, 2017
Merged

Pet/Guardian AI hook re-organizing#19824
Treeston merged 4 commits into
TrinityCore:3.3.5from
Treeston:3.3.5-guardianaihooks

Conversation

@Treeston

Copy link
Copy Markdown
Contributor

Pet/Guardian AI hook re-organizing:

  • Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
  • Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
    • Adjust PetAI to use DamageTaken instead of AttackedBy.
    • Adjust behavior of AttackStart on PetAI to compensate.

- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.
@Shauren

Shauren commented May 29, 2017

Copy link
Copy Markdown
Member

Shouldn't AttackedBy fire on events that cause aggro but not deal damage like taunt/debuff/dot without instant damage component?

@Treeston

Treeston commented May 29, 2017

Copy link
Copy Markdown
Contributor Author

In current core, EnterCombat is used if it's initial aggro, plus various spell related hooks.
If we want AttackedBy to actually be a functional hook, that'd be a different PR - in its current state, it does nothing.

@Shauren

Shauren commented May 29, 2017

Copy link
Copy Markdown
Member

Well, all of the scenarios I described are valid even as non-initial-aggro

@Treeston

Treeston commented May 29, 2017

Copy link
Copy Markdown
Contributor Author

Yes, but currently AttackedBy won't fire in these scenarios. It only fires in two places:

  • From DealDamage
  • In a hack-y branch in CombatStart

Comment thread src/server/game/AI/CreatureAI.cpp Outdated
if (!attacker || !me->IsAlive())
return;

if (!me->HasReactState(REACT_PASSIVE) && me->CanStartAttack(attacker, false))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me->CanStartAttack(attacker, false)

prevents combat with neutral units that the owner is attacking

me->CanStartAttack(attacker, true)

testing with force = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually makes sense for it to be true, faction check can be sort of ignored and distance check is useless

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sort of ignored"

You were supposed to tell me whether it worked without force, not lead me into darkness.
Comment thread src/server/game/AI/CreatureAI.h Outdated

// Called when owner attacks something
virtual void OwnerAttacked(Unit* /*target*/) { }
virtual void OwnerAttacked(Unit* target) { CreatureAI::OwnerAttackedBy(target); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You talked about traps for scripters but here you add another one - it would be better to introduce a separate (nonvirtual) method that is called by both OwnerAttacked and OwnerAttackedBy. Someone less experienced might think that if he overrides OwnerAttackedBy in his own script but not OwnerAttacked that it will call his overriden OwnerAttackedBy (but it will be the base CreatureAI one)

@Treeston Treeston merged commit 1660bb7 into TrinityCore:3.3.5 Jun 7, 2017
@Treeston Treeston deleted the 3.3.5-guardianaihooks branch June 7, 2017 00:33
Aokromes added a commit to Aokromes/TrinityCore that referenced this pull request Jun 7, 2017
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.
Carbenium pushed a commit to Carbenium/TrinityCore that referenced this pull request Jun 24, 2020
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.

(cherry picked from commit 1660bb7)
Carbenium pushed a commit to Carbenium/TrinityCore that referenced this pull request Jun 25, 2020
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.

(cherry picked from commit 1660bb7)
Shauren pushed a commit to Carbenium/TrinityCore that referenced this pull request Jul 16, 2020
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.

(cherry picked from commit 1660bb7)
Shauren pushed a commit to Carbenium/TrinityCore that referenced this pull request Jul 16, 2020
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
  - Adjust PetAI to use DamageTaken instead of AttackedBy.
  - Adjust behavior of AttackStart on PetAI to compensate.

(cherry picked from commit 1660bb7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants