Merge pull request #234 from yuan227301/opt_quest

[Optimization] Optimize quests initialization code.
This commit is contained in:
Yunfan Li
2024-05-26 15:01:46 +08:00
committed by GitHub
3 changed files with 19 additions and 36 deletions

View File

@@ -212,29 +212,11 @@ void PlayerbotFactory::Randomize(bool incremental)
if (pmo)
pmo->finish();
*/
InitInstanceQuests();
// clear quest reward inventory
ClearInventory();
bot->GiveLevel(level);
if (sPlayerbotAIConfig->randomBotPreQuests)
{
uint32 currentXP = bot->GetUInt32Value(PLAYER_XP);
LOG_INFO("playerbots", "Initializing quests...");
if (sPlayerbotAIConfig->randomBotPreQuests){
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Quests");
InitQuests(classQuestIds);
InitQuests(specialQuestIds);
// quest rewards boost bot level, so reduce back
bot->GiveLevel(level);
ClearInventory();
bot->SetUInt32Value(PLAYER_XP, currentXP);
CancelAuras();
bot->SaveToDB(false, false);
if (pmo)
InitInstanceQuests();
if (pmo)
pmo->finish();
}
@@ -2454,21 +2436,17 @@ void PlayerbotFactory::InitQuests(std::list<uint32>& questMap)
void PlayerbotFactory::InitInstanceQuests()
{
// Yunfan: use configuration instead of hard code
uint32 currentXP = bot->GetUInt32Value(PLAYER_XP);
LOG_INFO("playerbots", "Initializing quests...");
InitQuests(classQuestIds);
InitQuests(specialQuestIds);
// The Caverns of Time
if (bot->GetLevel() >= 64) {
uint32 questId = 10277;
Quest const *quest = sObjectMgr->GetQuestTemplate(questId);
bot->SetQuestStatus(questId, QUEST_STATUS_COMPLETE);
bot->RewardQuest(quest, 5, bot, false);
}
// Return to Andormu
if (bot->GetLevel() >= 66) {
uint32 questId = 10285;
Quest const *quest = sObjectMgr->GetQuestTemplate(questId);
bot->SetQuestStatus(questId, QUEST_STATUS_COMPLETE);
bot->RewardQuest(quest, 5, bot, false);
}
// quest rewards boost bot level, so reduce back
bot->GiveLevel(level);
ClearInventory();
bot->SetUInt32Value(PLAYER_XP, currentXP);
bot->SaveToDB(false, false);
}
void PlayerbotFactory::ClearInventory()

View File

@@ -135,6 +135,7 @@ class PlayerbotFactory
void InitMounts();
void InitBags(bool destroyOld = true);
void ApplyEnchantAndGemsNew(bool destoryOld = true);
void InitInstanceQuests();
private:
void Prepare();
// void InitSecondEquipmentSet();
@@ -151,7 +152,6 @@ class PlayerbotFactory
void InitTalents(uint32 specNo);
void InitTalentsByTemplate(uint32 specNo);
void InitQuests(std::list<uint32>& questMap);
void InitInstanceQuests();
void ClearInventory();
void ClearAllItems();
void ResetQuests();

View File

@@ -628,6 +628,11 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
sRandomPlayerbotMgr->Randomize(bot);
return "ok";
}
else if (cmd == "quests"){
PlayerbotFactory factory(bot, bot->getLevel());
factory.InitInstanceQuests();
return "Initialization quests";
}
// }
return "unknown command";