Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Redbu11 authored and Redbu11 committed Aug 22, 2024
1 parent 31ee487 commit 8501a60
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
22 changes: 7 additions & 15 deletions playerbot/TravelMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ bool TravelMgr::getObjectiveStatus(Player* bot, Quest const* pQuest, uint32 obje
}

//any quests to take
std::vector<TravelDestination*> TravelMgr::GetAvailableNewQuestTravelDestinations(Player* bot, bool classQuestsOnly, float maxDistance)
std::vector<TravelDestination*> TravelMgr::GetAvailableNewQuestTravelDestinations(Player* bot, bool classQuestsOnly, bool ignoreLowLevelQuests, float maxDistance)
{
WorldPosition botLocation(bot);

Expand All @@ -2716,24 +2716,16 @@ std::vector<TravelDestination*> TravelMgr::GetAvailableNewQuestTravelDestination
{
auto destinationQuest = sObjectMgr.GetQuestTemplate(dest->GetQuestTemplate()->GetQuestId());

if (classQuestsOnly)
if (!classQuestsOnly)
{
// only class quests bot could do
if (destinationQuest->GetRequiredClasses() == 0
|| !bot->SatisfyQuestClass(destinationQuest, false)
|| !bot->SatisfyQuestRace(destinationQuest, false)
|| !bot->SatisfyQuestLevel(destinationQuest, false))
continue;
}
else
{
// only quests bot could do
if (!bot->SatisfyQuestClass(destinationQuest, false)
|| !bot->SatisfyQuestRace(destinationQuest, false)
|| !bot->SatisfyQuestLevel(destinationQuest, false))
//ignore low level quests
if (ignoreLowLevelQuests && !bot->CanSeeStartQuest(destinationQuest))
continue;
}

if (!bot->CanTakeQuest(destinationQuest, false))
continue;

if (currentBotQuestIds.count(destinationQuest->GetQuestId()) > 0)
continue;

Expand Down
2 changes: 1 addition & 1 deletion playerbot/TravelMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ namespace ai
QuestStatusData* getQuestStatus(Player* bot, uint32 questId);
bool getObjectiveStatus(Player* bot, Quest const* pQuest, uint32 objective);
uint32 getDialogStatus(Player* pPlayer, int32 questgiver, Quest const* pQuest);
std::vector<TravelDestination*> GetAvailableNewQuestTravelDestinations(Player* bot, bool classQuestsOnly, float maxDistance);
std::vector<TravelDestination*> GetAvailableNewQuestTravelDestinations(Player* bot, bool classQuestsOnly, bool ignoreLowLevelQuests, float maxDistance);
std::vector<TravelDestination*> GetTurnInCurrentQuestsTravelDestinations(Player* bot, bool classQuestsOnly, float maxDistance);
std::vector<TravelDestination*> GetCurrentQuestsObjectivesTravelDestinations(Player* bot, bool classQuestsOnly, float maxDistance);

Expand Down
41 changes: 27 additions & 14 deletions playerbot/strategy/actions/ChooseTravelTargetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new
}
}

bool shouldGetMoney = AI_VALUE(bool, "should get money");

//Do quests (start, do, end)
//95% chance or 100% chance on last retry if bot is not max level
uint8 doQuestsChance = bot->GetLevel() < botMaxLevel ? 95 : 30; //can finally relax a bit from questing at max level
if (!foundTarget && ((retry == maxRetries && bot->GetLevel() < botMaxLevel) || urand(1, 100) <= doQuestsChance))
{
ai->TellDebug(requester, "Do questing", "debug travel");
PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget", &context->performanceStack);
foundTarget = SetQuestTarget(requester, newTarget);
foundTarget = SetQuestTarget(requester, newTarget, !shouldGetMoney);
if (pmo) pmo->finish();

if (foundTarget)
Expand All @@ -147,7 +149,7 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new
}

//Grind for money (if not in dungeon)
if (!foundTarget && AI_VALUE(bool, "should get money") && botPos.isOverworld())
if (!foundTarget && shouldGetMoney && botPos.isOverworld())
{
//Empty mail for money
if (AI_VALUE(bool, "can get mail"))
Expand Down Expand Up @@ -874,24 +876,29 @@ bool ChooseTravelTargetAction::SetCurrentTarget(Player* requester, TravelTarget*
return target->isActive();
}

bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* target)
bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* target, bool ignoreNewLowLevelQuests)
{
uint32 initialQuestSearchDistance = 400 + bot->GetLevel() * 10;
uint8 maxQuestSearchRetries = 5;

std::vector<TravelDestination*> travelDestinations;

//turn in any completed class quests anywhere
if (SetBestTarget(requester, target, sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, true, 0), 0))
travelDestinations = sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, true, 0);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}

//do current class quests anywhere
if (SetBestTarget(requester, target, sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, true, 0), 0))
travelDestinations = sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, true, 0);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
//find any available class quests anywhere (if quest log is not full)
if (ai->GetAllCurrentQuestIds().size() < MAX_QUEST_LOG_SIZE && SetBestTarget(requester, target, sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, true, 0), 0))
travelDestinations = sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, true, false, 0);
if (ai->GetAllCurrentQuestIds().size() < MAX_QUEST_LOG_SIZE && SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
Expand All @@ -904,12 +911,14 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t
auto distance = retry == maxQuestSearchRetries ? 0 : initialQuestSearchDistance * (retry);

//turn in any completed quests
if (SetBestTarget(requester, target, sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, false, distance), 0))
travelDestinations = sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, false, distance);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
//do current quests
if (SetBestTarget(requester, target, sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, false, distance), 0))
travelDestinations = sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, false, distance);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
Expand All @@ -923,8 +932,9 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t
{
auto distance = retry == maxQuestSearchRetries ? 0 : initialQuestSearchDistance * (retry);

//find any available quests
if (SetBestTarget(requester, target, sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, false, distance), 0))
//find any available quests (appropriate level only)
travelDestinations = sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, false, ignoreNewLowLevelQuests, distance);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
Expand All @@ -933,14 +943,16 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t
//if quest log has some quests but is not full
else
{
//find any available quests nearby
if (SetBestTarget(requester, target, sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, false, 1000.0f), 0))
//find any available quests nearby (appropriate level only)
travelDestinations = sTravelMgr.GetAvailableNewQuestTravelDestinations(bot, false, ignoreNewLowLevelQuests, 1000.0f);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}

//turn in any current quests nearby (with a chance to skip)
if (!urand(0, 2) && SetBestTarget(requester, target, sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, false, 1000.0f), 0))
travelDestinations = sTravelMgr.GetTurnInCurrentQuestsTravelDestinations(bot, false, 1000.0f);
if (!urand(0, 2) && SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
Expand All @@ -951,7 +963,8 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t
auto distance = retry == maxQuestSearchRetries ? 0 : initialQuestSearchDistance * (retry);

//find any available quests
if (SetBestTarget(requester, target, sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, false, distance), 0))
travelDestinations = sTravelMgr.GetCurrentQuestsObjectivesTravelDestinations(bot, false, distance);
if (SetBestTarget(requester, target, travelDestinations, 0))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion playerbot/strategy/actions/ChooseTravelTargetAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ai
bool SetCurrentTarget(Player* requester, TravelTarget* target, TravelTarget* oldTarget);


bool SetQuestTarget(Player* requester, TravelTarget* target);
bool SetQuestTarget(Player* requester, TravelTarget* target, bool ignoreNewLowLevelQuests);
bool SetRpgTarget(Player* requester, TravelTarget* target, bool requireLongDistanceSearch);
bool SetGrindTarget(Player* requester, TravelTarget* target);
bool SetBossTarget(Player* requester, TravelTarget* target);
Expand Down

0 comments on commit 8501a60

Please sign in to comment.