mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-21 18:40:01 +01:00
# 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>
54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
#include "Log.h"
|
|
#include "DBCStores.h"
|
|
#include "DatabaseEnv.h"
|
|
#include "Field.h"
|
|
// Required due to poor implementation on AC side
|
|
#include "QueryResult.h"
|
|
|
|
#include "PlayerbotSpellRepository.h"
|
|
|
|
// caches the result set
|
|
void PlayerbotSpellRepository::Initialize()
|
|
{
|
|
LOG_INFO("playerbots", "Playerbots: ListSpellsAction caches initialized");
|
|
|
|
for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
|
|
{
|
|
if (SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j))
|
|
skillSpells[skillLine->Spell] = skillLine;
|
|
}
|
|
|
|
// Fill the vendorItems cache once from the world database.
|
|
QueryResult results = WorldDatabase.Query("SELECT item FROM npc_vendor WHERE maxcount = 0");
|
|
if (results)
|
|
{
|
|
do
|
|
{
|
|
Field* fields = results->Fetch();
|
|
int32 entry = fields[0].Get<int32>();
|
|
if (entry <= 0)
|
|
continue;
|
|
|
|
vendorItems.insert(static_cast<uint32>(entry));
|
|
}
|
|
while (results->NextRow());
|
|
}
|
|
|
|
LOG_DEBUG("playerbots",
|
|
"ListSpellsAction: initialized caches (skillSpells={}, vendorItems={}).",
|
|
skillSpells.size(), vendorItems.size());
|
|
}
|
|
|
|
SkillLineAbilityEntry const* PlayerbotSpellRepository::GetSkillLine(uint32 spellId) const
|
|
{
|
|
auto itr = skillSpells.find(spellId);
|
|
if (itr != skillSpells.end())
|
|
return itr->second;
|
|
return nullptr;
|
|
}
|
|
|
|
bool PlayerbotSpellRepository::IsItemBuyable(uint32 itemId) const
|
|
{
|
|
return vendorItems.find(itemId) != vendorItems.end();
|
|
}
|