mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.
DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.
Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.
Before submitting, make sure your changes aligns with these principles.
-->
## Pull Request Description
<!-- Describe what this change does and why it is needed -->
The current strategy for Onyxia causes bots to get hit by her breath
attack relatively consistently during phase 2.
The problem was that the safe zone coordinates always use the bot's
z-coordinate. If the bots are standing at the lower altitude part of the
arena, `SearchForBestPath` inside `MoveTo` causes `INVALID_HEIGHT`,
resulting in the bot not moving at all and getting hit by the breath
attack.
This PR fixes this behavior by using the actual terrain z-coordinates
for the predefined safe zones instead of always using the bot's
z-coordinate. These values are chosen to ensure valid pathfinding
regardless of the bot's current elevation.
Additionally, bots now interrupt their spells if they are not inside a
safe zone during the breath. This causes the bots to immediately start
running instead of finishing their casts first.
## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->
<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
Replaced the use of `bot->GetPositionZ()` in `GetSafeZonesForBreath`
with predefined safe zone z-coordinates to ensure valid pathfinding.
Added `AttackStop` and `InterruptNonMeleeSpells` to guarantee immediate
movement when outside safe zones.
No additional condition checks or branching logic were introduced.
- Describe the **processing cost** when this logic executes across many
bots.
Minimal. The logic only runs within the Onyxia encounter script and
calling `AttackStop` and `InterruptNonMeleeSpells` should be negligible.
## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->
Enter Onyxia's Lair (10, 25 or 40 (mod-individual-progression)) and
engage Onyxia with the appropriate number of bots.
During phase 2 (Onyxia takes off), check if the bots move to the safe
zones during the breath attack.
Tip: Mark Onyxia as moon (RTI), so that phase 2 doesn't end too quickly.
## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
- - [ ] No, not at all
- - [x] Minimal impact (**explain below**)
- - [ ] Moderate impact (**explain below**)
The calls of `AttackStop` and `InterruptNonMeleeSpells` cause minimal
overhead compared to the original strategy. This should be negligible.
- Does this change modify default bot behavior?
- - [ ] No
- - [x] Yes (**explain why**)
Yes (encounter-specific). Bots will now interrupt casts earlier during
Onyxia phase 2 to prioritize movement to safe zones.
- Does this change add new decision branches or increase maintenance
complexity?
- - [x] No
- - [ ] Yes (**explain below**)
## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [x] No
- - [ ] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->
<!--
TRANSLATIONS:
Anything new that the bots say in chat must be in a translatable format.
This is done using GetBotTextOrDefault,
which you can search for in the codebase to find examples. Your code
needs to have English as the default fallback,
while the full translations need to be in an SQL update file. The
languages in the file are the nine language
options supported by AzerothCore: English, Korean, French, German,
Chinese, Taiwanese, Spanish, Spanish Mexico, and
Russian. See
data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as
an example of a translation SQL
update, whose content are called within the codebase at
src/strategy/actions/FishingAction.cpp
-->
## Final Checklist
- - [x] Stability is not compromised.
- - [x] Performance impact is understood, tested, and acceptable.
- - [x] Added logic complexity is justified and explained.
- - [x] Any new bot dialogue lines are translated.
- - [x] Documentation updated if needed (Conf comments, WiKi commands).
## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
The strategy for Onyxia might need additional work:
For example, the Onyxian Lair Guards are completely ignored while whelps
are alive and their Blast Nova doesn't get handled at all.
This PR focuses on fixing the Deep Breath behavior. Handling of Onyxian
Lair Guards is not included and should be implemented in a separate PR.
162 lines
4.9 KiB
C++
162 lines
4.9 KiB
C++
#include "RaidOnyxiaActions.h"
|
|
|
|
#include "GenericSpellActions.h"
|
|
#include "LastMovementValue.h"
|
|
#include "MovementActions.h"
|
|
#include "Playerbots.h"
|
|
#include "PositionAction.h"
|
|
|
|
bool RaidOnyxiaMoveToSideAction::Execute(Event /*event*/)
|
|
{
|
|
Unit* boss = AI_VALUE2(Unit*, "find target", "onyxia");
|
|
if (!boss)
|
|
return false;
|
|
|
|
float angleToBot = boss->GetAngle(bot);
|
|
float bossFacing = boss->GetOrientation();
|
|
float diff = fabs(angleToBot - bossFacing);
|
|
if (diff > M_PI)
|
|
diff = 2 * M_PI - diff;
|
|
|
|
float distance = bot->GetDistance(boss);
|
|
|
|
// Too close (30 yards) and either in front or behind
|
|
if (distance <= 30.0f && (diff < M_PI / 4 || diff > 3 * M_PI / 4))
|
|
{
|
|
float offsetAngle = bossFacing + M_PI_2; // 90° to the right
|
|
float offsetDist = 15.0f;
|
|
|
|
float sideX = boss->GetPositionX() + offsetDist * cos(offsetAngle);
|
|
float sideY = boss->GetPositionY() + offsetDist * sin(offsetAngle);
|
|
|
|
// bot->Yell("Too close to front or tail — moving to side of Onyxia!", LANG_UNIVERSAL);
|
|
return MoveTo(boss->GetMapId(), sideX, sideY, boss->GetPositionZ(), false, false, false, false,
|
|
MovementPriority::MOVEMENT_COMBAT);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool RaidOnyxiaSpreadOutAction::Execute(Event /*event*/)
|
|
{
|
|
Unit* boss = AI_VALUE2(Unit*, "find target", "onyxia");
|
|
|
|
if (!boss)
|
|
return false;
|
|
|
|
// Trigger may fire on one tick, but the action can execute on a later tick.
|
|
// By that time the cast may have finished, so current spell can be null.
|
|
Spell* currentSpell = boss->GetCurrentSpell(CURRENT_GENERIC_SPELL);
|
|
if (!currentSpell || !currentSpell->m_spellInfo)
|
|
return false;
|
|
|
|
// Fireball
|
|
if (currentSpell->m_spellInfo->Id != 18392)
|
|
return false;
|
|
|
|
Unit* unitTarget = currentSpell->m_targets.GetUnitTarget();
|
|
Player* target = unitTarget ? unitTarget->ToPlayer() : nullptr;
|
|
if (!target || target != bot)
|
|
return false;
|
|
|
|
// bot->Yell("Spreading out — I'm the Fireball target!", LANG_UNIVERSAL);
|
|
return MoveFromGroup(9.0f); // move 9 yards
|
|
}
|
|
|
|
bool RaidOnyxiaMoveToSafeZoneAction::Execute(Event /*event*/)
|
|
{
|
|
Unit* boss = AI_VALUE2(Unit*, "find target", "onyxia");
|
|
if (!boss)
|
|
return false;
|
|
|
|
Spell* currentSpell = boss->GetCurrentSpell(CURRENT_GENERIC_SPELL);
|
|
if (!currentSpell || !currentSpell->m_spellInfo)
|
|
return false;
|
|
|
|
uint32 spellId = currentSpell->m_spellInfo->Id;
|
|
|
|
std::vector<SafeZone> safeZones = GetSafeZonesForBreath(spellId);
|
|
if (safeZones.empty())
|
|
return false;
|
|
|
|
// Find closest safe zone
|
|
SafeZone* bestZone = nullptr;
|
|
float bestDist = std::numeric_limits<float>::max();
|
|
|
|
for (auto& zone : safeZones)
|
|
{
|
|
float dist = bot->GetExactDist2d(zone.pos.GetPositionX(), zone.pos.GetPositionY());
|
|
if (dist < bestDist)
|
|
{
|
|
bestDist = dist;
|
|
bestZone = &zone;
|
|
}
|
|
}
|
|
|
|
if (!bestZone)
|
|
return false;
|
|
|
|
if (bot->IsWithinDist2d(bestZone->pos.GetPositionX(), bestZone->pos.GetPositionY(), bestZone->radius))
|
|
return false; // Already safe
|
|
|
|
// Stop current spell first
|
|
bot->AttackStop();
|
|
bot->InterruptNonMeleeSpells(false);
|
|
|
|
// bot->Yell("Moving to Safe Zone!", LANG_UNIVERSAL);
|
|
return MoveTo(bot->GetMapId(), bestZone->pos.GetPositionX(), bestZone->pos.GetPositionY(), bestZone->pos.GetPositionZ(),
|
|
false, false, false, false, MovementPriority::MOVEMENT_COMBAT);
|
|
}
|
|
|
|
bool RaidOnyxiaKillWhelpsAction::Execute(Event /*event*/)
|
|
{
|
|
Unit* currentTarget = AI_VALUE(Unit*, "current target");
|
|
// If already attacking a whelp, don't swap targets
|
|
if (currentTarget && currentTarget->GetEntry() == 11262)
|
|
{
|
|
return false;
|
|
}
|
|
GuidVector targets = AI_VALUE(GuidVector, "possible targets");
|
|
for (ObjectGuid guid : targets)
|
|
{
|
|
Creature* unit = botAI->GetCreature(guid);
|
|
if (!unit || !unit->IsAlive() || !unit->IsInWorld())
|
|
continue;
|
|
|
|
if (unit->GetEntry() == 11262) // Onyxia Whelp
|
|
{
|
|
// bot->Yell("Attacking Whelps!", LANG_UNIVERSAL);
|
|
return Attack(unit);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool OnyxiaAvoidEggsAction::Execute(Event /*event*/)
|
|
{
|
|
Position botPos = Position(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ());
|
|
|
|
float x, y;
|
|
|
|
// get safe zone slightly away from eggs (Can this be dynamic?)
|
|
if (botPos.GetExactDist2d(-36.0f, -164.0f) <= 5.0f)
|
|
{
|
|
x = -10.0f;
|
|
y = -180.0f;
|
|
}
|
|
else if (botPos.GetExactDist2d(-34.0f, -262.0f) <= 5.0f)
|
|
{
|
|
x = -16.0f;
|
|
y = -250.0f;
|
|
}
|
|
else
|
|
{
|
|
return false; // Not in danger zone
|
|
}
|
|
|
|
// bot->Yell("Too close to eggs — backing off!", LANG_UNIVERSAL);
|
|
|
|
return MoveTo(bot->GetMapId(), x, y, bot->GetPositionZ(), false, false, false, false,
|
|
MovementPriority::MOVEMENT_COMBAT);
|
|
}
|