mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-26 21:35:54 +00:00
Make playerbots compatible with latest refactoring done on azerothcore (#2158)
# Pull Request When integrating latest changes from https://github.com/azerothcore/azerothcore-wotlk into https://github.com/mod-playerbots/azerothcore-wotlk/tree/Playerbot you will face some compiling issues due to refactoring. That PR does not change any of the logic, but implements needed changes to be compatible again --- ## 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: - Describe the **minimum logic** required to achieve the intended behavior? - Describe the **cheapest implementation** that produces an acceptable result? - Describe the **runtime cost** when this logic executes across many bots? --- ## How to Test the Changes - Step-by-step instructions to test the change - Any required setup (e.g. multiple players, bots, specific configuration) - Expected behavior and how to verify it ## 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 Please doublecheck if none of the timing-logic (migration from uint32 to microseconds) has been changed --------- Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com> Co-authored-by: bash <hermensb@gmail.com>
This commit is contained in:
@@ -7,10 +7,13 @@
|
||||
|
||||
#include "PlayerbotAI.h"
|
||||
|
||||
#include "InstancePackets.h"
|
||||
|
||||
bool ResetInstancesAction::Execute(Event /*event*/)
|
||||
{
|
||||
WorldPacket packet(CMSG_RESET_INSTANCES, 0);
|
||||
bot->GetSession()->HandleResetInstancesOpcode(packet);
|
||||
WorldPackets::Instance::ResetInstances resetInstance(std::move(packet));
|
||||
bot->GetSession()->HandleResetInstancesOpcode(resetInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,18 +45,18 @@ void StatsCollector::CollectItemStats(ItemTemplate const* proto)
|
||||
switch (proto->Spells[j].SpellTrigger)
|
||||
{
|
||||
case ITEM_SPELLTRIGGER_ON_USE:
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, proto->Spells[j].SpellCooldown);
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, Milliseconds(proto->Spells[j].SpellCooldown));
|
||||
break;
|
||||
case ITEM_SPELLTRIGGER_ON_EQUIP:
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 0);
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, Milliseconds(0));
|
||||
break;
|
||||
case ITEM_SPELLTRIGGER_CHANCE_ON_HIT:
|
||||
if (type_ & CollectorType::MELEE)
|
||||
{
|
||||
if (proto->Spells[j].SpellPPMRate > 0.01f)
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 60000 / proto->Spells[j].SpellPPMRate);
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, Milliseconds(static_cast<int>(60000 / proto->Spells[j].SpellPPMRate)));
|
||||
else
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 60000 / 1.8f); // Default PPM = 1.8
|
||||
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, Milliseconds(static_cast<int>(60000 / 1.8f))); // Default PPM = 1.8
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -71,7 +71,7 @@ void StatsCollector::CollectItemStats(ItemTemplate const* proto)
|
||||
}
|
||||
}
|
||||
|
||||
void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 spellCooldown)
|
||||
void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, Milliseconds spellCooldown)
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
|
||||
@@ -81,21 +81,21 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
|
||||
if (SpecialSpellFilter(spellId))
|
||||
return;
|
||||
|
||||
const SpellProcEventEntry* eventEntry = sSpellMgr->GetSpellProcEvent(spellInfo->Id);
|
||||
const SpellProcEntry* eventEntry = sSpellMgr->GetSpellProcEntry(spellInfo->Id);
|
||||
|
||||
uint32 triggerCooldown = eventEntry ? eventEntry->cooldown : 0;
|
||||
Milliseconds triggerCooldown = eventEntry ? eventEntry->Cooldown : 0ms;
|
||||
|
||||
bool canNextTrigger = true;
|
||||
|
||||
uint32 procFlags;
|
||||
uint32 procChance;
|
||||
if (eventEntry && eventEntry->procFlags)
|
||||
procFlags = eventEntry->procFlags;
|
||||
if (eventEntry && eventEntry->ProcFlags)
|
||||
procFlags = eventEntry->ProcFlags;
|
||||
else
|
||||
procFlags = spellInfo->ProcFlags;
|
||||
|
||||
if (eventEntry && eventEntry->customChance)
|
||||
procChance = eventEntry->customChance;
|
||||
if (eventEntry && eventEntry->Chance)
|
||||
procChance = eventEntry->Chance;
|
||||
else
|
||||
procChance = spellInfo->ProcChance;
|
||||
bool lowChance = procChance <= 5;
|
||||
@@ -142,11 +142,11 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
|
||||
break;
|
||||
|
||||
float coverage;
|
||||
if (spellCooldown <= 2000 || spellInfo->GetDuration() == -1)
|
||||
if (spellCooldown.count() <= 2000 || spellInfo->GetDuration() == -1)
|
||||
coverage = 1.0f;
|
||||
else
|
||||
coverage =
|
||||
std::min(1.0f, (float)spellInfo->GetDuration() / (spellInfo->GetDuration() + spellCooldown));
|
||||
std::min(1.0f, (float)spellInfo->GetDuration() / (spellInfo->GetDuration() + spellCooldown.count()));
|
||||
|
||||
multiplier *= coverage;
|
||||
HandleApplyAura(effectInfo, multiplier, canNextTrigger, triggerCooldown);
|
||||
@@ -155,9 +155,9 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
|
||||
case SPELL_EFFECT_HEAL:
|
||||
{
|
||||
/// @todo Handle spell without cooldown
|
||||
if (!spellCooldown)
|
||||
if (!spellCooldown.count())
|
||||
break;
|
||||
float normalizedCd = std::max((float)spellCooldown / 1000, 5.0f);
|
||||
float normalizedCd = std::max((float)spellCooldown.count() / 1000, 5.0f);
|
||||
int32 val = AverageValue(effectInfo);
|
||||
float transfer_multiplier = 1;
|
||||
stats[STATS_TYPE_HEAL_POWER] += (float)val / normalizedCd * multiplier * transfer_multiplier;
|
||||
@@ -166,11 +166,11 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
|
||||
case SPELL_EFFECT_ENERGIZE:
|
||||
{
|
||||
/// @todo Handle spell without cooldown
|
||||
if (!spellCooldown)
|
||||
if (!spellCooldown.count())
|
||||
break;
|
||||
if (effectInfo.MiscValue != POWER_MANA)
|
||||
break;
|
||||
float normalizedCd = std::max((float)spellCooldown / 1000, 5.0f);
|
||||
float normalizedCd = std::max((float)spellCooldown.count() / 1000, 5.0f);
|
||||
int32 val = AverageValue(effectInfo);
|
||||
float transfer_multiplier = 0.2;
|
||||
stats[STATS_TYPE_MANA_REGENERATION] += (float)val / normalizedCd * multiplier * transfer_multiplier;
|
||||
@@ -179,9 +179,9 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
|
||||
case SPELL_EFFECT_SCHOOL_DAMAGE:
|
||||
{
|
||||
/// @todo Handle spell without cooldown
|
||||
if (!spellCooldown)
|
||||
if (!spellCooldown.count())
|
||||
break;
|
||||
float normalizedCd = std::max((float)spellCooldown / 1000, 5.0f);
|
||||
float normalizedCd = std::max((float)spellCooldown.count() / 1000, 5.0f);
|
||||
int32 val = AverageValue(effectInfo);
|
||||
if (type_ & (CollectorType::MELEE | CollectorType::RANGED))
|
||||
{
|
||||
@@ -352,12 +352,12 @@ bool StatsCollector::SpecialEnchantFilter(uint32 enchantSpellId)
|
||||
|
||||
bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 procFlags, bool strict)
|
||||
{
|
||||
const SpellProcEventEntry* eventEntry = sSpellMgr->GetSpellProcEvent(spellInfo->Id);
|
||||
const SpellProcEntry* eventEntry = sSpellMgr->GetSpellProcEntry(spellInfo->Id);
|
||||
uint32 spellFamilyName = 0;
|
||||
if (eventEntry)
|
||||
{
|
||||
spellFamilyName = eventEntry->spellFamilyName;
|
||||
flag96 spellFamilyMask = eventEntry->spellFamilyMask;
|
||||
spellFamilyName = eventEntry->SpellFamilyName;
|
||||
flag96 spellFamilyMask = eventEntry->SpellFamilyMask;
|
||||
if (spellFamilyName != 0)
|
||||
{
|
||||
if (!CheckSpellValidation(spellFamilyName, spellFamilyMask, strict))
|
||||
@@ -548,7 +548,7 @@ void StatsCollector::CollectByItemStatType(uint32 itemStatType, int32 val)
|
||||
}
|
||||
|
||||
void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float multiplier, bool canNextTrigger,
|
||||
uint32 triggerCooldown)
|
||||
Milliseconds triggerCooldown)
|
||||
{
|
||||
if (effectInfo.Effect != SPELL_EFFECT_APPLY_AURA)
|
||||
return;
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
StatsCollector(StatsCollector& stats) = default;
|
||||
void Reset();
|
||||
void CollectItemStats(ItemTemplate const* proto);
|
||||
void CollectSpellStats(uint32 spellId, float multiplier = 1.0f, int32 spellCooldown = -1);
|
||||
void CollectSpellStats(uint32 spellId, float multiplier = 1.0f, Milliseconds spellCooldown = -1ms);
|
||||
void CollectEnchantStats(SpellItemEnchantmentEntry const* enchant, uint32 default_enchant_amount = 0);
|
||||
bool CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 procFlags, bool strict = true);
|
||||
bool CheckSpellValidation(uint32 spellFamilyName, flag96 spelFalimyFlags, bool strict = true);
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
bool SpecialEnchantFilter(uint32 enchantSpellId);
|
||||
|
||||
void HandleApplyAura(const SpellEffectInfo& effectInfo, float multiplier, bool canNextTrigger,
|
||||
uint32 triggerCooldown);
|
||||
Milliseconds triggerCooldown);
|
||||
float AverageValue(const SpellEffectInfo& effectInfo);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user