Skip to content

Feature/configurable combat delay#72

Closed
kadeshar wants to merge 7 commits intokadeshar:masterfrom
jads147:feature/configurable-combat-delay
Closed

Feature/configurable combat delay#72
kadeshar wants to merge 7 commits intokadeshar:masterfrom
jads147:feature/configurable-combat-delay

Conversation

@kadeshar
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 15, 2026 20:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces a configurable combat delay feature for bots to prevent immediate engagement in combat. The delay applies only to PvE targets when the "combat delay" strategy is active, allowing for more natural bot behavior.

Changes:

  • Added a new CombatDelayStrategy that can be enabled/disabled per bot
  • Implemented combat delay logic in AttackAction::Attack() with a static map to track when targets were first seen
  • Added configuration option AiPlayerbot.CombatDelay with default value of 3000ms

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/strategy/generic/CombatDelayStrategy.h New strategy class definition for combat delay feature
src/strategy/generic/CombatDelayStrategy.cpp Minimal implementation file for the strategy
src/strategy/actions/AttackAction.h Added skipCombatDelay parameter to Attack method
src/strategy/actions/AttackAction.cpp Implemented combat delay logic with target tracking and cleanup mechanism
src/strategy/StrategyContext.h Registered combat delay strategy in the strategy context
src/PlayerbotAIConfig.h Added combatDelay configuration variable
src/PlayerbotAIConfig.cpp Read combat delay value from config file
conf/playerbots.conf.dist Added configuration documentation and default value
Comments suppressed due to low confidence (1)

src/strategy/actions/AttackAction.cpp:1

  • The AttackRtiTargetAction::Execute method calls Attack() with only one argument, which will use the default values for with_pet=true and skipCombatDelay=false. This means RTI (raid target icon) attacks will be subject to combat delay, which is likely unintended for explicit player-directed attacks. Update this call to pass true for skipCombatDelay to match the behavior of AttackMyTargetAction and AttackDuelOpponentAction.
/*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

bool isPvPTarget = target->IsPlayer() || (target->IsPet() && target->GetOwner() && target->GetOwner()->IsPlayer());
if (!skipCombatDelay && botAI->HasStrategy("combat delay", BOT_STATE_NON_COMBAT) && sPlayerbotAIConfig->combatDelay > 0 && !sameTarget && !inCombat && !isPvPTarget)
{
static std::unordered_map<ObjectGuid, uint32> targetFirstSeenTime;
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The static map targetFirstSeenTime is shared across all bots and accessed without thread synchronization, which could lead to race conditions if multiple threads execute attacks concurrently. Similar patterns in this codebase (e.g., WarlockActions.cpp) use mutex protection with std::lock_guard. Add a static mutex and protect all accesses to targetFirstSeenTime.

Copilot uses AI. Check for mistakes.
# ReturnDelay has a minimum value of 2000 - lower values will cause a crash!
AiPlayerbot.ReturnDelay = 2000
AiPlayerbot.LootDelay = 1000
# Default delay in milliseconds before bots engage in combat (0 = no delay)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The default value of 3000ms differs from the documented default in the code (0 = no delay). The config comment states 'Default delay in milliseconds before bots engage in combat (0 = no delay)' but sets it to 3000. This inconsistency is confusing. Either change the default to 0 to match the documentation, or update the comment to clarify that 3000ms is the recommended default.

Suggested change
# Default delay in milliseconds before bots engage in combat (0 = no delay)
# Delay in milliseconds before bots engage in combat (default: 3000 ms; set to 0 for no delay)

Copilot uses AI. Check for mistakes.
Comment on lines 81 to 87
for (auto it = targetFirstSeenTime.begin(); it != targetFirstSeenTime.end();)
{
if (currentTime - it->second > sPlayerbotAIConfig->combatDelay + 10000)
it = targetFirstSeenTime.erase(it);
else
++it;
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The cleanup loop iterates through the entire map on every attack when combat delay is active, which could become a performance issue with many tracked targets. Consider implementing periodic cleanup (e.g., only when map size exceeds a threshold or using a time-based check) rather than on every attack.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +8

#include "Playerbots.h"
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The include of Playerbots.h appears unused in this file. The CombatDelayStrategy class doesn't require anything from Playerbots.h as it's a minimal strategy with no implementation beyond the header. Consider removing this include to reduce unnecessary dependencies.

Suggested change
#include "Playerbots.h"

Copilot uses AI. Check for mistakes.
hermensbas and others added 6 commits January 16, 2026 17:39
As requested

Poll
```
1. Yes
2. Yes
3. Maybe, but yes
```

---------

Co-authored-by: Celandriel <22352763+Celandriel@users.noreply.github.com>
- Combat delay now only applies to PvE targets (NPCs, mobs)
- Players and player-owned pets attack immediately without delay
- NPC pets still subject to combat delay
- Created CombatDelayStrategy that can be toggled per-bot
- Players can now enable/disable with `.bot strategy add/remove combat delay`
- Config option remains as default delay value in milliseconds
- Strategy must be active for delay to apply
- Allows per-bot control instead of global-only setting

Benefits:
- Individual bot control (some bots can have delay, others don't)
- Runtime toggling without config changes
- More flexible than global config option
- Follows existing playerbot patterns
- Add skipCombatDelay parameter to Attack method

- Bypass combat delay when player explicitly commands attack

- Apply to attack my target and duel opponent commands

- cleanup logic now time-based instead of size-based
@jads147 jads147 force-pushed the feature/configurable-combat-delay branch from 4f834ac to bb4e5d6 Compare January 17, 2026 18:53
Copilot AI review requested due to automatic review settings January 17, 2026 18:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kadeshar kadeshar closed this Feb 8, 2026
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