From b6906ddaf47e77dfd3438e78237e99983b8ae8af Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 15 Mar 2024 00:43:24 +0800 Subject: [PATCH] Enchantments and gems preload --- src/PlayerbotFactory.cpp | 53 +++++++++++++++++++++++++++++++++++++++- src/PlayerbotFactory.h | 3 +++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index d719358a..b8a937e7 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -52,6 +52,8 @@ uint32 PlayerbotFactory::tradeSkills[] = std::list PlayerbotFactory::classQuestIds; std::list PlayerbotFactory::specialQuestIds; +std::vector PlayerbotFactory::enchantSpellIdCache; +std::vector PlayerbotFactory::enchantGemIdCache; PlayerbotFactory::PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality, uint32 gearScoreLimit) : level(level), itemQuality(itemQuality), gearScoreLimit(gearScoreLimit), bot(bot) { @@ -84,6 +86,48 @@ void PlayerbotFactory::Init() specialQuestIds.remove(questId); specialQuestIds.push_back(questId); } + + for (uint32 id = 1; id < sSpellMgr->GetSpellInfoStoreSize(); ++id) + { + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id); + if (!spellInfo) + continue; + + uint32 requiredLevel = spellInfo->BaseLevel; + + for (uint8 j = 0; j < MAX_SPELL_EFFECTS; ++j) + { + if (spellInfo->Effects[j].Effect != SPELL_EFFECT_ENCHANT_ITEM) + continue; + + uint32 enchant_id = spellInfo->Effects[j].MiscValue; + if (!enchant_id) + continue; + + SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id); + if (!enchant || enchant->slot != PERM_ENCHANTMENT_SLOT) + continue; + + SpellInfo const* enchantSpell = sSpellMgr->GetSpellInfo(enchant->spellid[0]); + if (!enchantSpell) + continue; + + enchantSpellIdCache.push_back(id); + } + } + LOG_INFO("playerbots", "Loading {} enchantment spells", enchantSpellIdCache.size()); + for (auto iter = sSpellItemEnchantmentStore.begin(); iter != sSpellItemEnchantmentStore.end(); iter++) { + uint32 gemId = iter->GemID; + if (gemId == 0) { + continue; + } + ItemTemplate const* proto = sObjectMgr->GetItemTemplate(gemId); + if (!proto || !sGemPropertiesStore.LookupEntry(proto->GemProperties)) { + continue; + } + enchantGemIdCache.push_back(gemId); + } + LOG_INFO("playerbots", "Loading {} enchantment gems", enchantGemIdCache.size()); } void PlayerbotFactory::Prepare() @@ -3505,6 +3549,13 @@ float PlayerbotFactory::CalculateItemScore(uint32 item_id, Player* bot) return (0.0001 + score) * itemLevel * (quality + 1); } +float PlayerbotFactory::CalculateEnchantScore(uint32 enchant_id, Player* bot) +{ + SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id); + + return 0.0f; +} + bool PlayerbotFactory::IsShieldTank(Player* bot) { int tab = AiFactory::GetPlayerSpecTab(bot); @@ -3602,4 +3653,4 @@ void PlayerbotFactory::IterateItemsInBank(IterateItemsVisitor* visitor) } } } -} \ No newline at end of file +} diff --git a/src/PlayerbotFactory.h b/src/PlayerbotFactory.h index d3b1bb71..b7da70ea 100644 --- a/src/PlayerbotFactory.h +++ b/src/PlayerbotFactory.h @@ -116,6 +116,7 @@ class PlayerbotFactory static uint32 tradeSkills[]; static float CalculateItemScore(uint32 item_id, Player* bot); + static float CalculateEnchantScore(uint32 enchant_id, Player* bot); void InitTalentsTree(bool incremental = false, bool use_template = true, bool reset = false); static void InitTalentsBySpecNo(Player* bot, int specNo, bool reset); static void InitTalentsByParsedSpecLink(Player* bot, std::vector> parsedSpecLink, bool reset); @@ -188,6 +189,8 @@ class PlayerbotFactory uint32 gearScoreLimit; static std::list specialQuestIds; std::vector trainerIdCache; + static std::vector enchantSpellIdCache; + static std::vector enchantGemIdCache; protected: EnchantContainer m_EnchantContainer; Player* bot;