Skip to content

Commit

Permalink
Internal: Travelmgr refactor pt3
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlikely4r committed Dec 23, 2024
1 parent df9ee87 commit edb2bed
Show file tree
Hide file tree
Showing 25 changed files with 256 additions and 242 deletions.
32 changes: 16 additions & 16 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ void PlayerbotAI::Reset(bool full)
aiObjectContext->GetValue<LastMovement& >("last taxi")->Get().Set(NULL);

sTravelMgr.SetNullTravelTarget(aiObjectContext->GetValue<TravelTarget* >("travel target")->Get());
aiObjectContext->GetValue<TravelTarget* >("travel target")->Get()->setStatus(TravelStatus::TRAVEL_STATUS_EXPIRED);
aiObjectContext->GetValue<TravelTarget* >("travel target")->Get()->setExpireIn(1000);
aiObjectContext->GetValue<TravelTarget* >("travel target")->Get()->SetStatus(TravelStatus::TRAVEL_STATUS_EXPIRED);
aiObjectContext->GetValue<TravelTarget* >("travel target")->Get()->SetExpireIn(1000);

InterruptSpell();

Expand Down Expand Up @@ -6001,35 +6001,35 @@ std::string PlayerbotAI::HandleRemoteCommand(std::string command)
std::ostringstream out;

TravelTarget* target = GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get();
if (target->getDestination()) {
if (target->GetDestination()) {
out << "Destination ";

out << ": " << target->getDestination()->GetTitle();
out << ": " << target->GetDestination()->GetTitle();

if (!(*target->getPosition() == WorldPosition()))
if (target->GetPosition())
{
out << "(" << target->getPosition()->getAreaName() << ")";
out << " distance: " << target->getPosition()->distance(bot) << "y";
out << "(" << target->GetPosition()->getAreaName() << ")";
out << " distance: " << target->GetPosition()->distance(bot) << "y";
}
}
out << " Status =";
if (target->getStatus() == TravelStatus::TRAVEL_STATUS_NONE)
if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_NONE)
out << " none";
else if (target->getStatus() == TravelStatus::TRAVEL_STATUS_PREPARE)
else if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_PREPARE)
out << " prepare";
else if (target->getStatus() == TravelStatus::TRAVEL_STATUS_TRAVEL)
else if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_TRAVEL)
out << " travel";
else if (target->getStatus() == TravelStatus::TRAVEL_STATUS_WORK)
else if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_WORK)
out << " work";
else if (target->getStatus() == TravelStatus::TRAVEL_STATUS_COOLDOWN)
else if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_COOLDOWN)
out << " cooldown";
else if (target->getStatus() == TravelStatus::TRAVEL_STATUS_EXPIRED)
else if (target->GetStatus() == TravelStatus::TRAVEL_STATUS_EXPIRED)
out << " expired";

if(target->getStatus() != TravelStatus::TRAVEL_STATUS_EXPIRED)
out << " Expire in " << (target->getTimeLeft()/1000) << "s";
if(target->GetStatus() != TravelStatus::TRAVEL_STATUS_EXPIRED)
out << " Expire in " << (target->GetTimeLeft()/1000) << "s";

out << " Retry " << target->getRetryCount(true) << "/" << target->getRetryCount(false);
out << " Retry " << target->GetRetryCount(true) << "/" << target->GetRetryCount(false);

return out.str();
}
Expand Down
8 changes: 4 additions & 4 deletions playerbot/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ bool RandomPlayerbotMgr::ProcessBot(Player* player)
TravelTarget* target = player->GetPlayerbotAI()->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get();
if (target)
{
if (target->getTravelState() == TravelState::TRAVEL_STATE_IDLE)
if (target->GetTravelState() == TravelState::TRAVEL_STATE_IDLE)
idleBot = true;
}
else
Expand Down Expand Up @@ -3469,7 +3469,7 @@ void RandomPlayerbotMgr::PrintStats(uint32 requesterGuid)
TravelTarget* target = bot->GetPlayerbotAI()->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get();
if (target)
{
TravelState state = target->getTravelState();
TravelState state = target->GetTravelState();
stateCount[(uint8)state]++;
}
});
Expand Down Expand Up @@ -3701,8 +3701,8 @@ void RandomPlayerbotMgr::RandomTeleportForRpg(Player* bot, bool activeOnly)
TravelTarget* travelTarget = AI_VALUE(TravelTarget*, "travel target");

sTravelMgr.SetNullTravelTarget(travelTarget);
travelTarget->setStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
travelTarget->setExpireIn(10 * MINUTE * IN_MILLISECONDS);
travelTarget->SetStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
travelTarget->SetExpireIn(10 * MINUTE * IN_MILLISECONDS);
}
}

Expand Down
99 changes: 55 additions & 44 deletions playerbot/TravelMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool QuestObjectiveTravelDestination::IsActive(Player* bot) const {
TravelTarget* target = context->GetValue<TravelTarget*>("travel target")->Get();

//Only look for the target if it is unique or if we are currently working on it.
if (GetPoints().size() == 1 || (target->getStatus() == TravelStatus::TRAVEL_STATUS_WORK && target->GetEntry() == GetEntry()))
if (GetPoints().size() == 1 || (target->GetStatus() == TravelStatus::TRAVEL_STATUS_WORK && target->GetEntry() == GetEntry()))
{
std::list<ObjectGuid> targets = AI_VALUE(std::list<ObjectGuid>, "possible targets");

Expand Down Expand Up @@ -592,24 +592,24 @@ TravelTarget::TravelTarget(PlayerbotAI* ai) : AiObject(ai)
sTravelMgr.SetNullTravelTarget(this);
}

void TravelTarget::setTarget(TravelDestination* tDestination1, WorldPosition* wPosition1, bool groupCopy1) {
void TravelTarget::SetTarget(TravelDestination* tDestination1, WorldPosition* wPosition1, bool groupCopy1) {
wPosition = wPosition1;
tDestination = tDestination1;
groupCopy = groupCopy1;
forced = false;
radius = 0;

setStatus(TravelStatus::TRAVEL_STATUS_TRAVEL);
SetStatus(TravelStatus::TRAVEL_STATUS_TRAVEL);
}

void TravelTarget::copyTarget(TravelTarget* target) {
setTarget(target->tDestination, target->wPosition);
groupCopy = target->isGroupCopy();
void TravelTarget::CopyTarget(TravelTarget* const target) {
SetTarget(target->tDestination, target->wPosition);
groupCopy = target->IsGroupCopy();
forced = target->forced;
extendRetryCount = target->extendRetryCount;
}

void TravelTarget::setStatus(TravelStatus status) {
void TravelTarget::SetStatus(TravelStatus status) {
m_status = status;
startTime = WorldTimer::getMSTime();

Expand All @@ -620,7 +620,7 @@ void TravelTarget::setStatus(TravelStatus status) {
statusTime = 1;
break;
case TravelStatus::TRAVEL_STATUS_TRAVEL:
statusTime = getMaxTravelTime() * 2 + sPlayerbotAIConfig.maxWaitForMove;
statusTime = GetMaxTravelTime() * 2 + sPlayerbotAIConfig.maxWaitForMove;
break;
case TravelStatus::TRAVEL_STATUS_WORK:
statusTime = tDestination->GetExpireDelay();
Expand All @@ -635,47 +635,47 @@ bool TravelTarget::IsActive() {
if (m_status == TravelStatus::TRAVEL_STATUS_NONE || m_status == TravelStatus::TRAVEL_STATUS_EXPIRED || m_status == TravelStatus::TRAVEL_STATUS_PREPARE)
return false;

if (forced && isTraveling())
if (forced && IsTraveling())
return true;

if ((statusTime > 0 && startTime + statusTime < WorldTimer::getMSTime()))
{
setStatus(TravelStatus::TRAVEL_STATUS_EXPIRED);
SetStatus(TravelStatus::TRAVEL_STATUS_EXPIRED);
return false;
}

if (m_status == TravelStatus::TRAVEL_STATUS_COOLDOWN)
return true;

if (isTraveling())
if (IsTraveling())
return true;

if (isWorking())
if (IsWorking())
return true;

if (!tDestination->IsActive(bot)) //Target has become invalid. Stop.
{
setStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
SetStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
return true;
}

return true;
};

bool TravelTarget::isTraveling() {
bool TravelTarget::IsTraveling() {
if (m_status != TravelStatus::TRAVEL_STATUS_TRAVEL)
return false;

if (bot->GetGroup() && !bot->GetGroup()->IsLeader(bot->GetObjectGuid()))
if (ai->HasStrategy("follow", BotState::BOT_STATE_NON_COMBAT) || ai->HasStrategy("stay", BotState::BOT_STATE_NON_COMBAT))
{
setStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
SetStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
return false;
}

if (!tDestination->IsActive(bot) && !forced) //Target has become invalid. Stop.
{
setStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
SetStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
return false;
}

Expand All @@ -685,7 +685,7 @@ bool TravelTarget::isTraveling() {

if (HasArrived)
{
setStatus(TravelStatus::TRAVEL_STATUS_WORK);
SetStatus(TravelStatus::TRAVEL_STATUS_WORK);
return false;
}

Expand All @@ -698,13 +698,13 @@ bool TravelTarget::isTraveling() {
return true;
}

bool TravelTarget::isWorking() {
bool TravelTarget::IsWorking() {
if (m_status != TravelStatus::TRAVEL_STATUS_WORK)
return false;

if (!tDestination->IsActive(bot)) //Target has become invalid. Stop.
{
setStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
SetStatus(TravelStatus::TRAVEL_STATUS_COOLDOWN);
return false;
}

Expand All @@ -719,46 +719,46 @@ bool TravelTarget::isWorking() {
return true;
}

bool TravelTarget::isPreparing() {
bool TravelTarget::IsPreparing() {
if (m_status != TravelStatus::TRAVEL_STATUS_PREPARE)
return false;

return true;
}

TravelState TravelTarget::getTravelState() {
if (!tDestination || typeid(tDestination) == typeid(NullTravelDestination))
TravelState TravelTarget::GetTravelState() {
if (!tDestination || typeid(*tDestination) == typeid(NullTravelDestination))
return TravelState::TRAVEL_STATE_IDLE;

if (typeid(tDestination) == typeid(QuestRelationTravelDestination))
if (typeid(*tDestination) == typeid(QuestRelationTravelDestination))
{
if (tDestination->GetSubEntry() == 0)
{
if (isTraveling() || isPreparing())
if (IsTraveling() || IsPreparing())
return TravelState::TRAVEL_STATE_TRAVEL_PICK_UP_QUEST;
if (isWorking())
if (IsWorking())
return TravelState::TRAVEL_STATE_WORK_PICK_UP_QUEST;
}
else
{
if (isTraveling() || isPreparing())
if (IsTraveling() || IsPreparing())
return TravelState::TRAVEL_STATE_TRAVEL_HAND_IN_QUEST;
if (isWorking())
if (IsWorking())
return TravelState::TRAVEL_STATE_WORK_HAND_IN_QUEST;
}
}
else if (typeid(tDestination) == typeid(QuestObjectiveTravelDestination))
else if (typeid(*tDestination) == typeid(QuestObjectiveTravelDestination))
{
if (isTraveling() || isPreparing())
if (IsTraveling() || IsPreparing())
return TravelState::TRAVEL_STATE_TRAVEL_DO_QUEST;
if (isWorking())
if (IsWorking())
return TravelState::TRAVEL_STATE_WORK_DO_QUEST;
}
else if (typeid(tDestination) == typeid(RpgTravelDestination))
else if (typeid(*tDestination) == typeid(RpgTravelDestination))
{
return TravelState::TRAVEL_STATE_TRAVEL_RPG;
}
else if (typeid(tDestination) == typeid(ExploreTravelDestination))
else if (typeid(*tDestination) == typeid(ExploreTravelDestination))
{
return TravelState::TRAVEL_STATE_TRAVEL_EXPLORE;
}
Expand Down Expand Up @@ -2108,20 +2108,12 @@ std::vector<TravelDestination*> TravelMgr::GetQuestTravelDestinations(Player* bo
}
else
{
for (auto& dest : destinationMap.at(typeid(QuestRelationTravelDestination)).at(questId))
for (auto& [destQuestId, dests] : destinationMap.at(typeid(QuestRelationTravelDestination)))
{

if (!ignoreInactive && !dest->IsActive(bot))
continue;

if (maxDistance > 0 && dest->DistanceTo(botLocation) > maxDistance)
if (destQuestId != questId)
continue;

retTravelLocations.push_back(dest);
}

if (!ignoreObjectives)
for (auto& dest : destinationMap.at(typeid(QuestObjectiveTravelDestination)).at(questId))
for (auto& dest : dests)
{
if (!ignoreInactive && !dest->IsActive(bot))
continue;
Expand All @@ -2131,6 +2123,25 @@ std::vector<TravelDestination*> TravelMgr::GetQuestTravelDestinations(Player* bo

retTravelLocations.push_back(dest);
}
}

if (!ignoreObjectives)
for (auto& [destQuestId, dests] : destinationMap.at(typeid(QuestObjectiveTravelDestination)))
{
if (destQuestId != questId)
continue;

for (auto& dest : dests)
{
if (!ignoreInactive && !dest->IsActive(bot))
continue;

if (maxDistance > 0 && dest->DistanceTo(botLocation) > maxDistance)
continue;

retTravelLocations.push_back(dest);
}
}
}
return retTravelLocations;
}
Expand Down Expand Up @@ -2240,7 +2251,7 @@ std::vector<TravelDestination*> TravelMgr::GetBossTravelDestinations(Player* bot
void TravelMgr::SetNullTravelTarget(TravelTarget* target) const
{
if (target)
target->setTarget(nullTravelDestination, nullWorldPosition);
target->SetTarget(nullTravelDestination, nullWorldPosition);
}

void TravelMgr::SetNullTravelTarget(Player* player) const
Expand Down
Loading

0 comments on commit edb2bed

Please sign in to comment.