mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-26 21:35:54 +00:00
Fix rest of trainers' related stuff + codestyle changes and corrections (#2104)
# 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>
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
|
||||
uint32 MaxGearRepairCostValue::Calculate()
|
||||
{
|
||||
uint32 TotalCost = 0;
|
||||
uint32 totalCost = 0;
|
||||
|
||||
for (int i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; ++i)
|
||||
{
|
||||
uint16 pos = ((INVENTORY_SLOT_BAG_0 << 8) | i);
|
||||
@@ -43,15 +44,16 @@ uint32 MaxGearRepairCostValue::Calculate()
|
||||
|
||||
uint32 costs = uint32(maxDurability * dmultiplier * double(dQualitymodEntry->quality_mod));
|
||||
|
||||
TotalCost += costs;
|
||||
totalCost += costs;
|
||||
}
|
||||
|
||||
return TotalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
uint32 RepairCostValue::Calculate()
|
||||
{
|
||||
uint32 TotalCost = 0;
|
||||
uint32 totalCost = 0;
|
||||
|
||||
for (int i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; ++i)
|
||||
{
|
||||
uint16 pos = ((INVENTORY_SLOT_BAG_0 << 8) | i);
|
||||
@@ -86,45 +88,49 @@ uint32 RepairCostValue::Calculate()
|
||||
dcost->multiplier[ItemSubClassToDurabilityMultiplierId(ditemProto->Class, ditemProto->SubClass)];
|
||||
uint32 costs = uint32(LostDurability * dmultiplier * double(dQualitymodEntry->quality_mod));
|
||||
|
||||
TotalCost += costs;
|
||||
totalCost += costs;
|
||||
}
|
||||
|
||||
return TotalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
uint32 TrainCostValue::Calculate()
|
||||
{
|
||||
uint32 TotalCost = 0;
|
||||
uint32 totalCost = 0;
|
||||
|
||||
std::set<uint32> spells;
|
||||
std::unordered_set<uint32> spells;
|
||||
|
||||
if (CreatureTemplateContainer const* creatures = sObjectMgr->GetCreatureTemplates())
|
||||
CreatureTemplateContainer const* ctc = sObjectMgr->GetCreatureTemplates();
|
||||
for (CreatureTemplateContainer::const_iterator itr = ctc->begin(); itr != ctc->end(); ++itr)
|
||||
{
|
||||
for (CreatureTemplateContainer::const_iterator itr = creatures->begin(); itr != creatures->end(); ++itr)
|
||||
if (!(itr->second.npcflag & UNIT_NPC_FLAG_TRAINER))
|
||||
continue;
|
||||
|
||||
Trainer::Trainer* trainer = sObjectMgr->GetTrainer(itr->first);
|
||||
if (!trainer)
|
||||
continue;
|
||||
|
||||
if (trainer->GetTrainerType() != Trainer::Type::Class || !trainer->IsTrainerValidForPlayer(bot))
|
||||
continue;
|
||||
|
||||
for (auto& spell : trainer->GetSpells())
|
||||
{
|
||||
Trainer::Trainer* trainer = sObjectMgr->GetTrainer(itr->first);
|
||||
|
||||
if (!trainer)
|
||||
Trainer::Spell const* trainerSpell = trainer->GetSpell(spell.SpellId);
|
||||
if (!trainerSpell)
|
||||
continue;
|
||||
|
||||
if (trainer->GetTrainerType() != Trainer::Type::Class || !trainer->IsTrainerValidForPlayer(bot))
|
||||
if (!trainer->CanTeachSpell(bot, trainerSpell))
|
||||
continue;
|
||||
|
||||
for (auto& spell : trainer->GetSpells())
|
||||
{
|
||||
if (!trainer->CanTeachSpell(bot, trainer->GetSpell(spell.SpellId)))
|
||||
continue;
|
||||
if (spells.find(trainerSpell->SpellId) != spells.end())
|
||||
continue;
|
||||
|
||||
if (spells.find(spell.SpellId) != spells.end())
|
||||
continue;
|
||||
|
||||
TotalCost += spell.MoneyCost;
|
||||
spells.insert(spell.SpellId);
|
||||
}
|
||||
totalCost += trainerSpell->MoneyCost;
|
||||
spells.insert(trainerSpell->SpellId);
|
||||
}
|
||||
}
|
||||
|
||||
return TotalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
uint32 MoneyNeededForValue::Calculate()
|
||||
|
||||
@@ -44,6 +44,11 @@ bool CanSellValue::Calculate()
|
||||
AI_VALUE2(uint32, "item count", "usage " + std::to_string(ITEM_USAGE_AH))) > 1;
|
||||
}
|
||||
|
||||
bool CanTrainValue::Calculate()
|
||||
{
|
||||
return AI_VALUE2(uint32, "free money for", (uint32)NeedMoneyFor::spells) > 0;
|
||||
}
|
||||
|
||||
bool CanFightEqualValue::Calculate() { return AI_VALUE(uint8, "durability") > 20; }
|
||||
|
||||
bool CanFightEliteValue::Calculate()
|
||||
|
||||
@@ -58,6 +58,14 @@ public:
|
||||
bool Calculate() override;
|
||||
};
|
||||
|
||||
class CanTrainValue : public BoolCalculatedValue
|
||||
{
|
||||
public:
|
||||
CanTrainValue(PlayerbotAI* botAI) : BoolCalculatedValue(botAI, "can train", 2 * 2000) {}
|
||||
|
||||
bool Calculate() override;
|
||||
};
|
||||
|
||||
class CanFightEqualValue : public BoolCalculatedValue
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user