mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
# Pull Request
* Fix the rest of the trainer-related functionality: list spells and
learn (cast vs. direct learn) spells.
* Rewrite `TrainerAction`: split the logic between appropriate methods
(`GetTarget`, `isUseful`, `isPossible`) instead of pushing everything
inside a single `Execute` method.
* Change method definitions to remove unnecessary declarations and
parameters overhead.
* Move the `Trainer` header into the implementation. Rewrite
`RpgTrainTrigger` to fit the original logic and move all validation to
`RpgTrainAction` (`isUseful` + `isPossible`).
* Implement "can train" context value calculation to use with
`RpgTrainTrigger`.
* Update and optimize "train cost" context value calculation -- it
should be much faster.
* Replace `AiPlayerbot.AutoTrainSpells` with
`AiPlayerbot.AllowLearnTrainerSpells` and remove the "free" value
behavior — please use `AiPlayerbot.BotCheats` if you want bots to learn
trainer's spells for "free".
* Add `nullptr` checks wherever necessary (only inside targeted
methods/functions).
* Make some codestyle changes and corrections based on the AC codestyle
guide.
---
## 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.
---
## How to Test the Changes
Force bots to learn spells from trainers using the chat command `trainer
learn` or `trainer learn <spellId>`. Bots should properly list available
spells (`trainer` command) or learn them (based on configuration and
command).
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
If this introduces more advanced or AI-heavy logic:
- [x] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
If yes, please specify:
- AI tool or model used (e.g. ChatGPT, GPT-4, Claude, etc.)
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation)
- Which parts of the change were influenced or generated
- Whether the result was manually reviewed and adapted
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
- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
269 lines
6.8 KiB
C++
269 lines
6.8 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
|
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#ifndef _PLAYERBOT_RPGSUBACTIONS_H
|
|
#define _PLAYERBOT_RPGSUBACTIONS_H
|
|
|
|
#include "Action.h"
|
|
#include "AiObject.h"
|
|
#include "Item.h"
|
|
|
|
class GuidPosition;
|
|
class ObjectGuid;
|
|
class PlayerbotAI;
|
|
|
|
class RpgHelper : public AiObject
|
|
{
|
|
public:
|
|
RpgHelper(PlayerbotAI* botAI) : AiObject(botAI) {}
|
|
virtual ~RpgHelper() = default;
|
|
void OnExecute(std::string nextAction = "rpg");
|
|
void BeforeExecute();
|
|
void AfterExecute(bool doDelay = true, bool waitForGroup = false);
|
|
|
|
virtual GuidPosition guidP();
|
|
virtual ObjectGuid guid();
|
|
virtual bool InRange();
|
|
|
|
private:
|
|
void setFacingTo(GuidPosition guidPosition);
|
|
void setFacing(GuidPosition guidPosition);
|
|
void setDelay(bool waitForGroup);
|
|
};
|
|
|
|
class RpgEnabled
|
|
{
|
|
public:
|
|
RpgEnabled(PlayerbotAI* botAI) { rpg = std::make_unique<RpgHelper>(botAI); }
|
|
|
|
protected:
|
|
std::unique_ptr<RpgHelper> rpg;
|
|
};
|
|
|
|
class RpgSubAction : public Action, public RpgEnabled
|
|
{
|
|
public:
|
|
RpgSubAction(PlayerbotAI* botAI, std::string const name = "rpg sub") : Action(botAI, name), RpgEnabled(botAI) {}
|
|
|
|
// Long range is possible?
|
|
bool isPossible() override;
|
|
// Short range can we do the action now?
|
|
bool isUseful() override;
|
|
|
|
bool Execute(Event event) override;
|
|
|
|
protected:
|
|
virtual std::string const ActionName();
|
|
virtual Event ActionEvent(Event event);
|
|
};
|
|
|
|
class RpgStayAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgStayAction(PlayerbotAI* botAI, std::string const name = "rpg stay") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgWorkAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgWorkAction(PlayerbotAI* botAI, std::string const name = "rpg work") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgEmoteAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgEmoteAction(PlayerbotAI* botAI, std::string const name = "rpg emote") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgCancelAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgCancelAction(PlayerbotAI* botAI, std::string const name = "rpg cancel") : RpgSubAction(botAI, name) {}
|
|
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgTaxiAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgTaxiAction(PlayerbotAI* botAI, std::string const name = "rpg taxi") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgDiscoverAction : public RpgTaxiAction
|
|
{
|
|
public:
|
|
RpgDiscoverAction(PlayerbotAI* botAI, std::string const name = "rpg discover") : RpgTaxiAction(botAI, name) {}
|
|
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgStartQuestAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgStartQuestAction(PlayerbotAI* botAI, std::string const name = "rpg start quest") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgEndQuestAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgEndQuestAction(PlayerbotAI* botAI, std::string const name = "rpg end quest") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgBuyAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgBuyAction(PlayerbotAI* botAI, std::string const name = "rpg buy") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgSellAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgSellAction(PlayerbotAI* botAI, std::string const name = "rpg sell") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgRepairAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgRepairAction(PlayerbotAI* botAI, std::string const name = "rpg repair") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
};
|
|
|
|
class RpgTrainAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgTrainAction(PlayerbotAI* botAI, std::string const name = "rpg train") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isPossible() override;
|
|
bool isUseful() override;
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
};
|
|
|
|
class RpgHealAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgHealAction(PlayerbotAI* botAI, std::string const name = "rpg heal") : RpgSubAction(botAI, name) {}
|
|
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgHomeBindAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgHomeBindAction(PlayerbotAI* botAI, std::string const name = "rpg home bind") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
};
|
|
|
|
class RpgQueueBgAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgQueueBgAction(PlayerbotAI* botAI, std::string const name = "rpg queue bg") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
};
|
|
|
|
class RpgBuyPetitionAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgBuyPetitionAction(PlayerbotAI* botAI, std::string const name = "rpg buy petition") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
};
|
|
|
|
class RpgUseAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgUseAction(PlayerbotAI* botAI, std::string const name = "rpg use") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgSpellAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgSpellAction(PlayerbotAI* botAI, std::string const name = "rpg spell") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgCraftAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgCraftAction(PlayerbotAI* botAI, std::string const name = "rpg craft") : RpgSubAction(botAI, name) {}
|
|
|
|
private:
|
|
std::string const ActionName() override;
|
|
Event ActionEvent(Event event) override;
|
|
};
|
|
|
|
class RpgTradeUsefulAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgTradeUsefulAction(PlayerbotAI* botAI, std::string const name = "rpg trade useful") : RpgSubAction(botAI, name) {}
|
|
|
|
std::vector<Item*> CanGiveItems(GuidPosition guidPosition);
|
|
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgDuelAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgDuelAction(PlayerbotAI* botAI, std::string const name = "rpg duel") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
class RpgMountAnimAction : public RpgSubAction
|
|
{
|
|
public:
|
|
RpgMountAnimAction(PlayerbotAI* botAI, std::string const name = "rpg mount anim") : RpgSubAction(botAI, name) {}
|
|
|
|
bool isUseful() override;
|
|
bool Execute(Event event) override;
|
|
};
|
|
|
|
#endif
|