Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PetAI #520

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Refactor PetAI #520

wants to merge 14 commits into from

Conversation

deiteris
Copy link
Contributor

@deiteris deiteris commented Oct 29, 2023

🍰 Pullrequest

Refactors PetAI logic to be more concise and possibly a bit more optimized by reducing number of checks:

  • Remove PetAI::UpdateAllies() and timer and iterate over the owner's group directly (incl. owner and self check).
  • Remove unnecessary duplicate check for disabled actions in PetAI::UpdateAI()
  • Convert and store Creature pointer as a pet in PetAI to simplify checks.
  • Create Pet::HasActionsDisabled() and refactor checks for disabled pet mode
  • Refactor spell pick and cast into separate PetAI::Cast() and PetAI::PickSpellWithTarget() functions.
  • Refactor autocast spell picking logic and order.
  • Use a single spell-target pair instead of a vector storage and random choice.
  • Reworks logic in a way some automated spell casts are meaningful (i.e., harmful AoE spells are cast in melee range, AoE buffs are cast only in combat).
  • Adjusts logic in a way any other actions won't interfere with scripted actions.

Additionally, introduces conditional spell casts based on the info I managed to gather:

  • Spell lock is automatically casted only when the target is casting a non-melee spell.
  • Dive and Dash are only casted when enemy is not within the melee range. (post)
  • Shell Shield is only casted when the pet's HP falls below 50%. (post)

Proof

  • None

Issues

  • None

How2Test

  • None

Regression test checklist

I've tried to cover all scenarios that are affected by this refactor, but I can check more if something is missing.

  • Pet autocasts combat spells and buffs in combat.
  • Pet autocasts only non-combat spells outside combat.
  • Pet buffs party members.
  • Pet automatically attacks an enemy in line of sight in aggressive mode.
  • Pet does not automatically attack a CCed target in aggressive mode.
  • Pet does not interrupt for attack when retreating in aggressive mode.
  • Pet returns to follow state after combat.
  • Pet returns to its stay position after combat.
  • Pet stops attacking CCed target and returns back to owner.
  • Attack order overrides restriction to attack CCed target.

* Remove PetAI::UpdateAllies() and timer and iterate over the owner's group directly.
* Remove unnecessary duplicate check for disabled actions in PetAI::UpdateAI()
* Convert and store Creature pointer as a pet in PetAI to simplify checks.
* Create Pet::HasActionsDisabled() and refactor checks for disabled pet mode
* Refactor spell pick and cast into separate PetAI::Cast() and PetAI::PickSpellWithTarget() functions.
* Refactor autocast spell picking logic and order.
* Use a single spell-target pair instead of a vector storage and random choice.
@killerwife
Copy link
Contributor

killerwife commented Oct 29, 2023

Did you make sure a pet breaks attack off when a target was cced after attack order was issues? Because that currently works.

@deiteris
Copy link
Contributor Author

Aha! So that additional check for victim was actually to support this behavior. I noticed that pet stops attacking polymorphed creature, but then ignores attack order.

Though I see that pet still attacks feared target, even though this a CC that we might not want to break. Is this expected? 🤔

@insunaa
Copy link
Contributor

insunaa commented Oct 29, 2023

It's common for warlocks to fear-juggle enemies. If their pets would stop attacking with every fear that'd be a significant DPS loss, so I'm pretty sure the only CCs that should stop pet attacks are those that break with any damage, such as sap, sheep or gouge
There are probably still a few other issues that need solving with pets. For example they don't always cast sprint on attack order, even if it's off cd, but then occasionally in melee combat they cast sprint.

@killerwife
Copy link
Contributor

The pet needs to ignore damage breakable cc that occurs after attack order. You can always tell pet to attack after the fact and it needs to comply.

@killerwife
Copy link
Contributor

Lookup the commits adding it to see the rationale using git blame.

@deiteris
Copy link
Contributor Author

deiteris commented Oct 30, 2023

The pet needs to ignore damage breakable cc that occurs after attack order. You can always tell pet to attack after the fact and it needs to comply.

Yes, I understand and I will fix this. I'm trying to identify the culprit of this issue since I see it occasionally happens even with the current code (and the AI logic does not seem to handle this in any way, it seems to me as a timing issue or improper state handling). The attack order may still be ignored sometimes after the target was polymorphed and only target switching helps to bypass the restriction to attack CCed target.

It's common for warlocks to fear-juggle enemies. If their pets would stop attacking with every fear that'd be a significant DPS loss, so I'm pretty sure the only CCs that should stop pet attacks are those that break with any damage, such as sap, sheep or gouge

I don't object this kind of logic, but I'd like to understand whether this is a blizzlike behavior. Another example, pets also don't stop attacking enemies affected by frost nova, but this is a CC that breaks immediately.

For example they don't always cast sprint on attack order, even if it's off cd, but then occasionally in melee combat they cast sprint.

I think this might be an issue with updated logic too (it most likely will always autocast it), but I'm not sure how to check. Can I somehow make pet learn spells with a command?

There is a similar issue (in both the current and updated logic) with Thunderstomp that's an AoE spell that has no min/max distance, and pets need to get into the victim to actually cast it.

@deiteris
Copy link
Contributor Author

deiteris commented Oct 31, 2023

I think I've sorted the issues out. Pets stop attacking CCed targets correctly in this PR now, and there were also a few fixes added to different behaviors:

  • Pets kept switching targets when commanded to retreat, causing them to stop attacking and not retreating until they're in the owner's following distance.
  • Pets could target CCed targets in aggressive mode after you command attack and cancel attack with follow.

@killerwife
Copy link
Contributor

Ok and now one last thing to bother you with

PetAI is notoriously known to be ass to script.

Something like this:

https://github.com/cmangos/mangos-tbc/blob/master/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp#L2231

When you start a script, nothing that a player can do, short of abandon or unsummon should be able to interrupt such a sequence. I understand its a tbc script but I am sure you could write a similar thing in vanilla where a pet moves a bit, does some emote and wont have its script broken.

@deiteris
Copy link
Contributor Author

deiteris commented Nov 1, 2023

When you start a script, nothing that a player can do, short of abandon or unsummon should be able to interrupt such a sequence.

Done. I've tested on TBC and scripted pet shouldn't get stuck anymore. The issue you mentioned was mostly due to the fact that pet was interrupted on combat or on retreating and this messed up the combat and movement states.

EDIT: Though I noticed that it still may stuck when commanded to stay or retreat during/after scripted scene (pet gets stuck in following state and does not actually follow after stay, but continues to follow after attack). And I think it may also stuck when commanded to attack during script. I'll look into it.

@deiteris
Copy link
Contributor Author

deiteris commented Nov 2, 2023

I think simply removing this line would suffice once the changes are ported to other cores.
https://github.com/cmangos/mangos-tbc/blob/master/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp#L2294

IMO, there's no point in sending pet back to owner after scripted sequence, since once you remove combat script status, the movement will be delegated back to AI (unless it's really necessary to send pet back even if it's supposed to stay, then setting asMain = false in MoveFollow probably should fix it. Otherwise, it affects the movement state and cannot be recovered later).

Works almost flawlessly:
https://github-production-user-asset-6210df.s3.amazonaws.com/6103913/280117133-2727f10c-e4ed-4fc4-9ab1-3cbd1bc09b2a.mp4

@deiteris deiteris force-pushed the refactor-petai branch 3 times, most recently from 4e476af to 0561c88 Compare November 3, 2023 12:44
@deiteris deiteris force-pushed the refactor-petai branch 4 times, most recently from f0e0768 to 334446b Compare November 3, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants