-
Notifications
You must be signed in to change notification settings - Fork 0
Fix trainer related stuff #92
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
base: master
Are you sure you want to change the base?
Conversation
…eless checks and variables
…al action's logic
…fix-trainer-related-stuff
There was a problem hiding this 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 PR refactors “trainer” behavior/configuration for playerbots by simplifying the train trigger logic, adding a reusable “can train” value, and reworking the trainer action to support explicit target selection (master vs bot) and trainer validation.
Changes:
- Replaced
AiPlayerbot.AutoTrainSpells(string) withAiPlayerbot.AllowLearnTrainerSpells(bool) and updated config initialization + conf template. - Added
CanTrainValueand wired it intoValueContext, then simplifiedRpgTrainTriggerto rely on that value. - Refactored
TrainerActionandRpgTrainActionto centralize validation/affordability checks and streamline spell iteration/learning.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PlayerbotAIConfig.h | Replaces autoTrainSpells string with allowLearnTrainerSpells bool. |
| src/PlayerbotAIConfig.cpp | Loads the new AiPlayerbot.AllowLearnTrainerSpells config option. |
| src/Ai/World/Rpg/Action/NewRpgBaseAction.cpp | Simplifies questgiver interaction checks (removes trainer-related logic from this path). |
| src/Ai/Base/ValueContext.h | Registers new "can train" value creator. |
| src/Ai/Base/Value/MaintenanceValues.h | Adds CanTrainValue declaration. |
| src/Ai/Base/Value/MaintenanceValues.cpp | Implements CanTrainValue based on free money for spells. |
| src/Ai/Base/Value/LogLevelValue.h | Adds missing include for logging common definitions. |
| src/Ai/Base/Value/BudgetValues.cpp | Refactors train/repair cost calculations; changes trainer scan logic. |
| src/Ai/Base/Trigger/RpgTriggers.h | Removes RpgTrainTrigger::IsTrainerOf declaration. |
| src/Ai/Base/Trigger/RpgTriggers.cpp | Simplifies train trigger to use "can train" and basic trainer flag check. |
| src/Ai/Base/Actions/TrainerAction.h | Refactors trainer action interface and private helpers. |
| src/Ai/Base/Actions/TrainerAction.cpp | Refactors execution/validation/learning flow and target selection logic. |
| src/Ai/Base/Actions/RpgSubActions.h | Adds isPossible/isUseful overrides for RpgTrainAction. |
| src/Ai/Base/Actions/RpgSubActions.cpp | Implements trainer affordability/teachability checks for RPG train action. |
| conf/playerbots.conf.dist | Updates documentation and default for AiPlayerbot.AllowLearnTrainerSpells. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Creature* target = GetTarget()->ToCreature(); | ||
| if (!target) | ||
| return false; |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTarget() can return nullptr (no selection by bot/master), but GetTarget()->ToCreature() dereferences it unconditionally. This can crash in Execute() (and the same pattern is used in isUseful() / isPossible()). Store the Unit* returned by GetTarget() and null-check it before calling ToCreature()/accessing it.
| if (trainer->GetSpells().empty()) | ||
| { | ||
| if (spellInfo->Effects[j].Effect == SPELL_EFFECT_LEARN_SPELL) | ||
| { | ||
| uint32 learnedSpell = spellInfo->Effects[j].TriggerSpell; | ||
| if (!bot->HasSpell(learnedSpell)) | ||
| { | ||
| bot->learnSpell(learnedSpell); | ||
| learned = true; | ||
| } | ||
| } | ||
| // Not sure why we need to say anything, especially w/o master | ||
| botAI->TellError("No spells can be learned from this trainer"); | ||
| return false; |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isPossible() should ideally be side-effect free, but it calls botAI->TellError(...). Since isPossible() is used during regular action selection (not just on explicit command execution), this can generate repeated error notifications. Consider moving this message to Execute() (only when the trainer action is actually run), or gate it behind an explicit player command / debug mode.
| if (!(itr->second.npcflag & UNIT_NPC_FLAG_TRAINER)) | ||
| continue; | ||
|
|
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrainCostValue::Calculate() now skips creature templates unless npcflag contains UNIT_NPC_FLAG_TRAINER. Other parts of the codebase iterate all templates and rely on sObjectMgr->GetTrainer(entry) (e.g., PlayerbotFactory::InitAvailableSpells()), so this filter can cause train cost to be undercounted for trainers that exist but don't have this specific flag set (or use other trainer-related flags). Consider removing the npcflag filter, or expanding it to include all trainer-related flags you expect (class/profession/etc).
| if (!(itr->second.npcflag & UNIT_NPC_FLAG_TRAINER)) | |
| continue; |
Pull Request
Describe what this change does and why it is needed...
Design Philosophy
We prioritize stability, performance, and predictability over behavioral realism.
Complex player-mimicking logic is intentionally limited due to its negative impact on scalability, maintainability, and
long-term robustness.
Excessive processing overhead can lead to server hiccups, increased CPU usage, and degraded performance for all
participants. Because every action and
decision tree is executed per bot and per trigger, even small increases in logic complexity can scale poorly and
negatively affect both players and
world (random) bots. Bots are not expected to behave perfectly, and perfect simulation of human decision-making is not a
project goal. Increased behavioral
realism often introduces disproportionate cost, reduced predictability, and significantly higher maintenance overhead.
Every additional branch of logic increases long-term responsibility. All decision paths must be tested, validated, and
maintained continuously as the system evolves.
If advanced or AI-intensive behavior is introduced, the default configuration must remain the lightweight decision
model. More complex behavior should only be
available as an explicit opt-in option, clearly documented as having a measurable performance cost.
Principles:
Stability before intelligence
A stable system is always preferred over a smarter one.
Performance is a shared resource
Any increase in bot cost affects all players and all bots.
Simple logic scales better than smart logic
Predictable behavior under load is more valuable than perfect decisions.
Complexity must justify itself
If a feature cannot clearly explain its cost, it should not exist.
Defaults must be cheap
Expensive behavior must always be optional and clearly communicated.
Bots should look reasonable, not perfect
The goal is believable behavior, not human simulation.
Before submitting, confirm that this change aligns with those principles.
Feature Evaluation
Please answer the following:
How to Test the Changes
Complexity & Impact
Does this change add new decision branches?
Does this change increase per-bot or per-tick processing?
Could this logic scale poorly under load?
Defaults & Configuration
Does this change modify default bot behavior?
If this introduces more advanced or AI-heavy logic:
AI Assistance
Was AI assistance (e.g. ChatGPT or similar tools) used while working on this change?
If yes, please specify:
AI assistance is allowed, but all submitted code must be fully understood, reviewed, and owned by the contributor.
Any AI-influenced changes must be verified against existing CORE and PB logic. We expect contributors to be honest
about what they do and do not understand.
Final Checklist
Notes for Reviewers
Anything that significantly improves realism at the cost of stability or performance should be carefully discussed
before merging.