Bot spell actions use actual DBC range instead of global spellDistance#268
Conversation
Looks up each spell's true max range from SpellRangeEntry at construction. getPrerequisites() early-exits if already in range, avoiding movement when unnecessary. spellDistance config remains a backstop for engagement distance.
There was a problem hiding this comment.
Pull request overview
This PR modifies bot spell actions to use the actual spell range from DBC (game data) files instead of a global spellDistance configuration value. It also adds distance-aware logic to getPrerequisites() so bots avoid unnecessary movement when already in range.
Changes:
- In the
CastSpellActionconstructor, the spell's DBC max range is looked up and used to set therangefield instead of always using the config-basedspellDistance. - In
getPrerequisites(), a new early-return block checks if the bot is already within range and returns appropriate prerequisites (no movement for ranged, "reach melee" for melee spells).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| float currentDistance = AI_VALUE2(float, "distance", GetTargetName()); | ||
|
|
||
| if (currentDistance <= range) | ||
| { | ||
| if (range > ATTACK_DISTANCE) | ||
| { | ||
| return Action::getPrerequisites(); | ||
| } | ||
| else | ||
| { | ||
| return NextAction::merge(NextAction::array(0, new NextAction("reach melee"), NULL), Action::getPrerequisites()); | ||
| } | ||
| } |
There was a problem hiding this comment.
The "reach spell" action used in the existing fallback path (below this block, around line 100) always targets sPlayerbotAIConfig.spellDistance as its stopping distance (see ReachSpellAction in ReachTargetActions.h:55). With this PR, range is now set from DBC data and can be less than spellDistance (e.g., a 20-yard range spell when spellDistance defaults to 30). For spells where ATTACK_DISTANCE < range < spellDistance, the bot will use "reach spell" to move within spellDistance of the target, but the spell actually requires the bot to be within the smaller DBC range. The bot will stop too far away and isPossible() will fail, creating a situation where the bot never gets close enough to cast.
To fix this, either the "reach spell" action needs to be parameterized with the actual spell range, or the distance check and movement logic needs to account for the DBC range being smaller than spellDistance.
There was a problem hiding this comment.
I hate to say it, but this is actually a good point. That said, the behavior prior to the PR was even worse. This PR fixes the narrow problem of unnecessary movement, and I hope that improvement is good enough for now. I'll look into other ways of having each spell impact the reach distance individually.
This fixes an problem where the spell range stored in the DBC file was being ignored by bots in favor of a universal spellDistance value in the bot config. The spellDistance config would remain and be used only as a limit. Also ensures that bots run into melee when the range requires it.
This change is