Skip to content

Commit

Permalink
Merge pull request liyunfan1223#234 from yuan227301/opt_quest
Browse files Browse the repository at this point in the history
[Optimization] Optimize quests initialization code.
  • Loading branch information
liyunfan1223 authored May 26, 2024
2 parents 6ebd054 + 9ee873f commit 9510b6b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
48 changes: 13 additions & 35 deletions src/PlayerbotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/PlayerbotFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 9510b6b

Please sign in to comment.