Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)

# Pull Request

- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )

Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---

## 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**)

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)
---

## 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: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
This commit is contained in:
bashermens
2026-01-30 21:49:37 +01:00
committed by GitHub
parent a92886032c
commit 13fff46fa0
233 changed files with 2460 additions and 2354 deletions

View File

@@ -75,4 +75,4 @@ bool DeathAndDecayCooldownTrigger::IsActive()
return true;
return bot->GetSpellCooldownDelay(spellId) >= 2000;
}
}

View File

@@ -43,8 +43,8 @@ bool CastStarfallAction::isUseful()
Unit* ccTarget = context->GetValue<Unit*>("current cc target")->Get();
if (ccTarget && ccTarget->IsAlive())
{
float dist2d = sServerFacade->GetDistance2d(ccTarget, aoePos.GetPositionX(), aoePos.GetPositionY());
if (sServerFacade->IsDistanceLessOrEqualThan(dist2d, sPlayerbotAIConfig->aoeRadius))
float dist2d = ServerFacade::instance().GetDistance2d(ccTarget, aoePos.GetPositionX(), aoePos.GetPositionY());
if (ServerFacade::instance().IsDistanceLessOrEqualThan(dist2d, sPlayerbotAIConfig.aoeRadius))
return false;
}
@@ -75,7 +75,7 @@ std::vector<NextAction> CastRebirthAction::getPrerequisites()
bool CastRebirthAction::isUseful()
{
return CastSpellAction::isUseful() &&
AI_VALUE2(float, "distance", GetTargetName()) <= sPlayerbotAIConfig->spellDistance;
AI_VALUE2(float, "distance", GetTargetName()) <= sPlayerbotAIConfig.spellDistance;
}
Unit* CastRejuvenationOnNotFullAction::GetTarget()
@@ -91,7 +91,7 @@ Unit* CastRejuvenationOnNotFullAction::GetTarget()
{
continue;
}
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->spellDistance)
if (player->GetDistance2d(bot) > sPlayerbotAIConfig.spellDistance)
{
continue;
}
@@ -107,4 +107,4 @@ Unit* CastRejuvenationOnNotFullAction::GetTarget()
bool CastRejuvenationOnNotFullAction::isUseful()
{
return GetTarget();
}
}

View File

@@ -36,7 +36,7 @@ bool CastCasterFormAction::isUseful()
{
return botAI->HasAnyAuraOf(GetTarget(), "dire bear form", "bear form", "cat form", "travel form", "aquatic form",
"flight form", "swift flight form", "moonkin form", nullptr) &&
AI_VALUE2(uint8, "mana", "self target") > sPlayerbotAIConfig->mediumHealth;
AI_VALUE2(uint8, "mana", "self target") > sPlayerbotAIConfig.mediumHealth;
}
bool CastCasterFormAction::Execute(Event event)
@@ -59,4 +59,4 @@ bool CastCancelTreeFormAction::Execute(Event event)
bool CastTreeFormAction::isUseful()
{
return GetTarget() && CastSpellAction::isUseful() && !botAI->HasAura(33891, bot);
}
}

View File

@@ -24,4 +24,4 @@
}
};
#endif
#endif

View File

@@ -62,7 +62,7 @@ bool HuntersPetLowHealthTrigger::IsActive()
bool HuntersPetMediumHealthTrigger::IsActive()
{
Unit* pet = AI_VALUE(Unit*, "pet target");
return pet && AI_VALUE2(uint8, "health", "pet target") < sPlayerbotAIConfig->mediumHealth &&
return pet && AI_VALUE2(uint8, "health", "pet target") < sPlayerbotAIConfig.mediumHealth &&
!AI_VALUE2(bool, "dead", "pet target") && !AI_VALUE2(bool, "mounted", "self target");
}
@@ -74,7 +74,7 @@ bool HunterPetNotHappy::IsActive()
bool HunterAspectOfTheViperTrigger::IsActive()
{
return SpellTrigger::IsActive() && !botAI->HasAura(spell, GetTarget()) &&
AI_VALUE2(uint8, "mana", "self target") < (sPlayerbotAIConfig->lowMana / 2);
AI_VALUE2(uint8, "mana", "self target") < (sPlayerbotAIConfig.lowMana / 2);
;
}
@@ -96,7 +96,7 @@ bool SwitchToRangedTrigger::IsActive()
Unit* target = AI_VALUE(Unit*, "current target");
return botAI->HasStrategy("close", BOT_STATE_COMBAT) && target &&
(target->GetVictim() != bot &&
sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
ServerFacade::instance().IsDistanceGreaterThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
}
bool SwitchToMeleeTrigger::IsActive()
@@ -104,7 +104,7 @@ bool SwitchToMeleeTrigger::IsActive()
Unit* target = AI_VALUE(Unit*, "current target");
return botAI->HasStrategy("ranged", BOT_STATE_COMBAT) && target &&
(target->GetVictim() == bot &&
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
ServerFacade::instance().IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
}
bool NoTrackTrigger::IsActive()

View File

@@ -61,13 +61,13 @@ bool CastFrostNovaAction::isUseful()
if (target->isFrozen())
return false;
return sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", GetTargetName()), 10.f);
return ServerFacade::instance().IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", GetTargetName()), 10.f);
}
bool CastConeOfColdAction::isUseful()
{
bool facingTarget = AI_VALUE2(bool, "facing", "current target");
bool targetClose = sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", GetTargetName()), 10.f);
bool targetClose = ServerFacade::instance().IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", GetTargetName()), 10.f);
return facingTarget && targetClose;
}
@@ -105,7 +105,7 @@ Unit* CastFocusMagicOnPartyAction::GetTarget()
if (!member || member == bot || !member->IsAlive())
continue;
if (member->GetMap() != bot->GetMap() || bot->GetDistance(member) > sPlayerbotAIConfig->spellDistance)
if (member->GetMap() != bot->GetMap() || bot->GetDistance(member) > sPlayerbotAIConfig.spellDistance)
continue;
if (member->HasAura(54646))

View File

@@ -454,4 +454,4 @@ void PaladinAiObjectContext::BuildSharedTriggerContexts(SharedNamedObjectContext
void PaladinAiObjectContext::BuildSharedValueContexts(SharedNamedObjectContextList<UntypedValue>& valueContexts)
{
AiObjectContext::BuildSharedValueContexts(valueContexts);
}
}

View File

@@ -24,4 +24,4 @@ public:
}
};
#endif
#endif

View File

@@ -30,11 +30,11 @@ Unit* CastPowerWordShieldOnAlmostFullHealthBelowAction::GetTarget()
{
continue;
}
if (player->GetHealthPct() > sPlayerbotAIConfig->almostFullHealth)
if (player->GetHealthPct() > sPlayerbotAIConfig.almostFullHealth)
{
continue;
}
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->spellDistance)
if (player->GetDistance2d(bot) > sPlayerbotAIConfig.spellDistance)
{
continue;
}
@@ -59,11 +59,11 @@ bool CastPowerWordShieldOnAlmostFullHealthBelowAction::isUseful()
{
continue;
}
if (player->GetHealthPct() > sPlayerbotAIConfig->almostFullHealth)
if (player->GetHealthPct() > sPlayerbotAIConfig.almostFullHealth)
{
continue;
}
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->spellDistance)
if (player->GetDistance2d(bot) > sPlayerbotAIConfig.spellDistance)
{
continue;
}
@@ -89,7 +89,7 @@ Unit* CastPowerWordShieldOnNotFullAction::GetTarget()
{
continue;
}
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->spellDistance)
if (player->GetDistance2d(bot) > sPlayerbotAIConfig.spellDistance)
{
continue;
}
@@ -105,4 +105,4 @@ Unit* CastPowerWordShieldOnNotFullAction::GetTarget()
bool CastPowerWordShieldOnNotFullAction::isUseful()
{
return GetTarget();
}
}

View File

@@ -68,14 +68,14 @@ bool ShadowformTrigger::IsActive() { return !botAI->HasAura("shadowform", bot);
bool ShadowfiendTrigger::IsActive() { return BoostTrigger::IsActive() && !bot->HasSpellCooldown(34433); }
BindingHealTrigger::BindingHealTrigger(PlayerbotAI* botAI)
: PartyMemberLowHealthTrigger(botAI, "binding heal", sPlayerbotAIConfig->lowHealth, 0)
: PartyMemberLowHealthTrigger(botAI, "binding heal", sPlayerbotAIConfig.lowHealth, 0)
{
}
bool BindingHealTrigger::IsActive()
{
return PartyMemberLowHealthTrigger::IsActive() &&
AI_VALUE2(uint8, "health", "self target") < sPlayerbotAIConfig->mediumHealth;
AI_VALUE2(uint8, "health", "self target") < sPlayerbotAIConfig.mediumHealth;
}
const std::set<uint32> MindSearChannelCheckTrigger::MIND_SEAR_SPELL_IDS = {

View File

@@ -14,7 +14,7 @@
bool CastStealthAction::isUseful()
{
Unit* target = AI_VALUE(Unit*, "current target");
if (target && bot->GetDistance(target) >= sPlayerbotAIConfig->spellDistance)
if (target && bot->GetDistance(target) >= sPlayerbotAIConfig.spellDistance)
return false;
return true;
}

View File

@@ -227,4 +227,4 @@ void RogueAiObjectContext::BuildSharedTriggerContexts(SharedNamedObjectContextLi
void RogueAiObjectContext::BuildSharedValueContexts(SharedNamedObjectContextList<UntypedValue>& valueContexts)
{
AiObjectContext::BuildSharedValueContexts(valueContexts);
}
}

View File

@@ -16,4 +16,4 @@ public:
uint32 GetType() const override { return MeleeCombatStrategy::GetType() | STRATEGY_TYPE_DPS; }
};
#endif
#endif

View File

@@ -22,7 +22,7 @@ bool UnstealthTrigger::IsActive()
return botAI->HasAura("stealth", bot) && !AI_VALUE(uint8, "attacker count") &&
(AI_VALUE2(bool, "moving", "self target") &&
((botAI->GetMaster() &&
sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "group leader"), 10.0f) &&
ServerFacade::instance().IsDistanceGreaterThan(AI_VALUE2(float, "distance", "group leader"), 10.0f) &&
AI_VALUE2(bool, "moving", "group leader")) ||
!AI_VALUE(uint8, "attacker count")));
}
@@ -60,7 +60,7 @@ bool StealthTrigger::IsActive()
if (bot->InArena())
distance += 15;
return target && sServerFacade->GetDistance2d(bot, target) < distance;
return target && ServerFacade::instance().GetDistance2d(bot, target) < distance;
}
bool SapTrigger::IsPossible() { return bot->GetLevel() > 10 && bot->HasSpell(6770) && !bot->IsInCombat(); }
@@ -99,8 +99,8 @@ bool SprintTrigger::IsActive()
return AI_VALUE2(bool, "moving", "self target") &&
(AI_VALUE2(bool, "moving", "dps target") || AI_VALUE2(bool, "moving", "enemy player target")) && targeted &&
(sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), distance) ||
sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), distance));
(ServerFacade::instance().IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), distance) ||
ServerFacade::instance().IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), distance));
}
bool ExposeArmorTrigger::IsActive()

View File

@@ -25,7 +25,7 @@ const int ITEM_SOUL_SHARD = 6265;
bool CastDrainSoulAction::isUseful() { return AI_VALUE2(uint32, "item count", "soul shard") < 26; }
// Checks if the bot's health is above a certain threshold, and if so, allows casting Life Tap
bool CastLifeTapAction::isUseful() { return AI_VALUE2(uint8, "health", "self target") > sPlayerbotAIConfig->lowHealth; }
bool CastLifeTapAction::isUseful() { return AI_VALUE2(uint8, "health", "self target") > sPlayerbotAIConfig.lowHealth; }
// Checks if the target marked with the moon icon can be banished
bool CastBanishOnCcAction::isPossible()
@@ -288,7 +288,7 @@ bool UseSoulstoneMasterAction::Execute(Event event)
soulstoneReservations[master->GetGUID()] = now + 2500; // Reserve for 2.5 seconds
}
float distance = sServerFacade->GetDistance2d(bot, master);
float distance = ServerFacade::instance().GetDistance2d(bot, master);
if (distance >= 30.0f)
return false;
@@ -325,7 +325,7 @@ bool UseSoulstoneTankAction::Execute(Event event)
if (soulstoneReservations.count(member->GetGUID()) && soulstoneReservations[member->GetGUID()] > now)
continue; // Already being soulstoned
float distance = sServerFacade->GetDistance2d(bot, member);
float distance = ServerFacade::instance().GetDistance2d(bot, member);
if (distance < 30.0f && bot->IsWithinLOSInMap(member))
{
chosenTank = member;
@@ -348,7 +348,7 @@ bool UseSoulstoneTankAction::Execute(Event event)
soulstoneReservations[member->GetGUID()] > now)
continue; // Already being soulstoned
float distance = sServerFacade->GetDistance2d(bot, member);
float distance = ServerFacade::instance().GetDistance2d(bot, member);
if (distance < 30.0f && bot->IsWithinLOSInMap(member))
{
chosenTank = member;
@@ -392,7 +392,7 @@ bool UseSoulstoneHealerAction::Execute(Event event)
soulstoneReservations[member->GetGUID()] > now)
continue; // Already being soulstoned
float distance = sServerFacade->GetDistance2d(bot, member);
float distance = ServerFacade::instance().GetDistance2d(bot, member);
if (distance < 30.0f && bot->IsWithinLOSInMap(member))
{
healer = member;

View File

@@ -96,7 +96,7 @@ bool DecimationTrigger::IsActive()
// Checks if the bot's mana is below 85% and health is above a low health threshold
bool LifeTapTrigger::IsActive()
{
if (AI_VALUE2(uint8, "health", "self target") <= sPlayerbotAIConfig->lowHealth)
if (AI_VALUE2(uint8, "health", "self target") <= sPlayerbotAIConfig.lowHealth)
return false;
if (!AI_VALUE2(bool, "has mana", "self target"))

View File

@@ -9,7 +9,7 @@
bool BloodrageBuffTrigger::IsActive()
{
return AI_VALUE2(uint8, "health", "self target") >= sPlayerbotAIConfig->mediumHealth &&
return AI_VALUE2(uint8, "health", "self target") >= sPlayerbotAIConfig.mediumHealth &&
AI_VALUE2(uint8, "rage", "self target") < 20;
}

View File

@@ -358,4 +358,4 @@ void WarriorAiObjectContext::BuildSharedTriggerContexts(SharedNamedObjectContext
void WarriorAiObjectContext::BuildSharedValueContexts(SharedNamedObjectContextList<UntypedValue>& valueContexts)
{
AiObjectContext::BuildSharedValueContexts(valueContexts);
}
}