mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49: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>
401 lines
9.0 KiB
C++
401 lines
9.0 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.
|
|
*/
|
|
|
|
#include "RpgTriggers.h"
|
|
|
|
#include "BudgetValues.h"
|
|
#include "GuildCreateActions.h"
|
|
#include "Playerbots.h"
|
|
#include "ServerFacade.h"
|
|
#include "SocialMgr.h"
|
|
|
|
bool NoRpgTargetTrigger::IsActive() { return !AI_VALUE(GuidPosition, "rpg target"); }
|
|
|
|
bool HasRpgTargetTrigger::IsActive() { return !NoRpgTargetTrigger::IsActive(); }
|
|
|
|
bool FarFromRpgTargetTrigger::IsActive()
|
|
{
|
|
return !NoRpgTargetTrigger::IsActive() && AI_VALUE2(float, "distance", "rpg target") > INTERACTION_DISTANCE;
|
|
}
|
|
|
|
bool NearRpgTargetTrigger::IsActive()
|
|
{
|
|
return !NoRpgTargetTrigger::IsActive() && !FarFromRpgTargetTrigger::IsActive();
|
|
}
|
|
|
|
GuidPosition RpgTrigger::getGuidP() { return AI_VALUE(GuidPosition, "rpg target"); }
|
|
|
|
bool RpgTrigger::IsActive() { return true; }
|
|
|
|
Event RpgTrigger::Check()
|
|
{
|
|
if (!NoRpgTargetTrigger::IsActive() && (AI_VALUE(std::string, "next rpg action") == "choose rpg target") ||
|
|
!FarFromRpgTargetTrigger::IsActive())
|
|
return Trigger::Check();
|
|
|
|
return Event();
|
|
}
|
|
|
|
bool RpgTaxiTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_FLIGHTMASTER))
|
|
return false;
|
|
|
|
uint32 node =
|
|
sObjectMgr->GetNearestTaxiNode(guidP.GetPositionX(), guidP.GetPositionY(), guidP.GetPositionZ(),
|
|
guidP.GetMapId(), bot->GetTeamId());
|
|
|
|
if (!node)
|
|
return false;
|
|
|
|
if (!bot->m_taxi.IsTaximaskNodeKnown(node))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgDiscoverTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_FLIGHTMASTER))
|
|
return false;
|
|
|
|
if (bot->isTaxiCheater())
|
|
return false;
|
|
|
|
uint32 node =
|
|
sObjectMgr->GetNearestTaxiNode(guidP.GetPositionX(), guidP.GetPositionY(), guidP.GetPositionZ(),
|
|
guidP.GetMapId(), bot->GetTeamId());
|
|
|
|
if (bot->m_taxi.IsTaximaskNodeKnown(node))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgStartQuestTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsCreature() && !guidP.IsGameObject())
|
|
return false;
|
|
|
|
if (AI_VALUE(bool, "can fight equal"))
|
|
{
|
|
if (AI_VALUE2(bool, "can accept quest npc", guidP.GetEntry()))
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (AI_VALUE2(bool, "can accept quest low level npc", guidP.GetEntry()))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool RpgEndQuestTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsCreature() && !guidP.IsGameObject())
|
|
return false;
|
|
|
|
if (AI_VALUE2(bool, "can turn in quest npc", guidP.GetEntry()))
|
|
return true;
|
|
|
|
if (!AI_VALUE2(bool, "can accept quest low level npc", guidP.GetEntry()))
|
|
return false;
|
|
|
|
if (guidP.GetEntry() == AI_VALUE(TravelTarget*, "travel target")->getEntry())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool RpgBuyTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_VENDOR))
|
|
return false;
|
|
|
|
if (AI_VALUE(uint8, "durability") > 50)
|
|
return false;
|
|
|
|
if (!AI_VALUE(bool, "can sell")) // Need better condition.
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgSellTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_VENDOR))
|
|
return false;
|
|
|
|
if (!AI_VALUE(bool, "can sell"))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgRepairTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_REPAIR))
|
|
return false;
|
|
|
|
if (AI_VALUE2_LAZY(bool, "group or", "should sell,can sell,following party,near leader"))
|
|
return true;
|
|
|
|
if (AI_VALUE2_LAZY(bool, "group or", "should repair,can repair,following party,near leader"))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool RpgTrainTrigger::IsActive()
|
|
{
|
|
GuidPosition gp = getGuidP();
|
|
if (!gp)
|
|
return false;
|
|
|
|
if (!gp.HasNpcFlag(UNIT_NPC_FLAG_TRAINER))
|
|
return false;
|
|
|
|
if (!AI_VALUE(bool, "can train"))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgHealTrigger::IsActive()
|
|
{
|
|
if (!botAI->HasStrategy("heal", BOT_STATE_COMBAT))
|
|
return false;
|
|
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
Unit* unit = guidP.GetUnit();
|
|
|
|
if (!unit)
|
|
return false;
|
|
|
|
if (!unit->IsFriendlyTo(bot))
|
|
return false;
|
|
|
|
if (unit->isDead() || unit->GetHealthPct() >= 100)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgHomeBindTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_INNKEEPER))
|
|
return false;
|
|
|
|
if (AI_VALUE(WorldPosition, "home bind").distance(bot) < 500.0f)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgQueueBGTrigger::IsActive()
|
|
{
|
|
// skip bots not in continents
|
|
if (!WorldPosition(bot).isOverworld()) // bg, raid, dungeon
|
|
return false;
|
|
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsCreature())
|
|
return false;
|
|
|
|
// if bot is not leader disallow tag bg
|
|
if (bot->GetGroup() && !bot->GetGroup()->IsLeader(bot->GetGUID()))
|
|
return false;
|
|
|
|
if (AI_VALUE(BattlegroundTypeId, "rpg bg type") == BATTLEGROUND_TYPE_NONE)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgBuyPetitionTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.HasNpcFlag(UNIT_NPC_FLAG_PETITIONER))
|
|
return false;
|
|
|
|
if (!BuyPetitionAction::canBuyPetition(bot))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgUseTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsGameObject())
|
|
return false;
|
|
|
|
GameObjectTemplate const* goInfo = guidP.GetGameObjectTemplate();
|
|
|
|
switch (goInfo->type)
|
|
{
|
|
case GAMEOBJECT_TYPE_BINDER:
|
|
case GAMEOBJECT_TYPE_GENERIC:
|
|
case GAMEOBJECT_TYPE_TEXT:
|
|
case GAMEOBJECT_TYPE_GOOBER:
|
|
case GAMEOBJECT_TYPE_TRANSPORT:
|
|
case GAMEOBJECT_TYPE_AREADAMAGE:
|
|
case GAMEOBJECT_TYPE_CAMERA:
|
|
case GAMEOBJECT_TYPE_MAP_OBJECT:
|
|
case GAMEOBJECT_TYPE_MO_TRANSPORT:
|
|
case GAMEOBJECT_TYPE_DUEL_ARBITER:
|
|
case GAMEOBJECT_TYPE_FISHINGNODE:
|
|
case GAMEOBJECT_TYPE_GUARDPOST:
|
|
case GAMEOBJECT_TYPE_SPELLCASTER:
|
|
case GAMEOBJECT_TYPE_FISHINGHOLE:
|
|
case GAMEOBJECT_TYPE_AURA_GENERATOR:
|
|
return false;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgSpellTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (guidP.IsPlayer())
|
|
return false;
|
|
|
|
if (!guidP.GetWorldObject())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgCraftTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (guidP.IsPlayer())
|
|
return false;
|
|
|
|
if (!guidP.GetWorldObject())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgTradeUsefulTrigger::IsActive()
|
|
{
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsPlayer())
|
|
return false;
|
|
|
|
Player* player = guidP.GetPlayer();
|
|
if (!player)
|
|
return false;
|
|
|
|
// More code/botAI-value here to see if bot is friendly enough.
|
|
bool isFriend = false;
|
|
if (player->GetGuildId() != bot->GetGuildId())
|
|
isFriend = true;
|
|
|
|
if (bot->GetGroup() == player->GetGroup() && !urand(0, 5))
|
|
isFriend = true;
|
|
|
|
if (!urand(0, 20))
|
|
isFriend = true;
|
|
|
|
if (!isFriend)
|
|
return false;
|
|
|
|
if (!player->IsWithinLOSInMap(bot))
|
|
return false;
|
|
|
|
if (player->GetTrader() && player->GetTrader() != bot)
|
|
return false;
|
|
|
|
if (bot->GetTrader() && bot->GetTrader() != player)
|
|
return false;
|
|
|
|
if (AI_VALUE(std::vector<Item*>, "items useful to give").empty())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgDuelTrigger::IsActive()
|
|
{
|
|
if (!botAI->HasStrategy("start duel", BOT_STATE_NON_COMBAT))
|
|
return false;
|
|
|
|
// Less spammy duels
|
|
if (bot->GetLevel() < 3)
|
|
return false;
|
|
|
|
if (botAI->HasRealPlayerMaster())
|
|
{
|
|
// do not auto duel if master is not afk
|
|
if (botAI->GetMaster() && !botAI->GetMaster()->isAFK())
|
|
return false;
|
|
}
|
|
|
|
// do not auto duel with low hp
|
|
if (AI_VALUE2(uint8, "health", "self target") < 90)
|
|
return false;
|
|
|
|
GuidPosition guidP(getGuidP());
|
|
|
|
if (!guidP.IsPlayer())
|
|
return false;
|
|
|
|
Player* player = guidP.GetPlayer();
|
|
|
|
if (!player)
|
|
return false;
|
|
|
|
if (player->GetLevel() > bot->GetLevel() + 3)
|
|
return false;
|
|
|
|
if (bot->GetLevel() > player->GetLevel() + 10)
|
|
return false;
|
|
|
|
// caster or target already have requested duel
|
|
if (bot->duel || player->duel || !player->GetSocial() || player->GetSocial()->HasIgnore(bot->GetGUID()))
|
|
return false;
|
|
|
|
AreaTableEntry const* targetAreaEntry = sAreaTableStore.LookupEntry(player->GetAreaId());
|
|
if (targetAreaEntry && !(targetAreaEntry->flags & AREA_FLAG_ALLOW_DUELS))
|
|
{
|
|
// Dueling isn't allowed here
|
|
return false;
|
|
}
|
|
|
|
if (!AI_VALUE(GuidVector, "all targets").empty())
|
|
return false;
|
|
|
|
return true;
|
|
}
|