From eb3d0f7da86b5981e536190c6b017d893fa650ef Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 30 Jul 2024 16:44:58 +0800 Subject: [PATCH 01/14] [Movement] Improve knockback --- src/PlayerbotAI.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index fa59ff11..f3cd2996 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -834,9 +834,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) float vcos, vsin, horizontalSpeed, verticalSpeed = 0.f; p >> guid.ReadAsPacked() >> counter >> vcos >> vsin >> horizontalSpeed >> verticalSpeed; - if (horizontalSpeed <= 0.1f) { - horizontalSpeed = 0.11f; - } + // if (horizontalSpeed <= 0.1f) { + // horizontalSpeed = 0.11f; + // } verticalSpeed = -verticalSpeed; // stop casting @@ -846,23 +846,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) bot->StopMoving(); bot->GetMotionMaster()->Clear(); - - float moveTimeHalf = verticalSpeed / Movement::gravity; - float dist = 2 * moveTimeHalf * horizontalSpeed; - Position dest = bot->GetPosition(); - - bot->MovePositionToFirstCollision(dest, dist, bot->GetRelativeAngle(bot->GetPositionX() + vcos, bot->GetPositionY() + vsin)); - float x, y, z; - x = dest.GetPositionX(); - y = dest.GetPositionY(); - z = dest.GetPositionZ(); - // char speak[1024]; - // sprintf(speak, "SMSG_MOVE_KNOCK_BACK: %.2f %.2f, horizontalSpeed: %.2f, verticalSpeed: %.2f, tX: %.2f, tY: %.2f, tZ: %.2f, relativeAngle: %.2f, orientation: %.2f", - // vcos, vsin, horizontalSpeed, verticalSpeed, x, y, z, bot->GetRelativeAngle(vcos, vsin), bot->GetOrientation()); - // bot->Say(speak, LANG_UNIVERSAL); - // bot->GetClosePoint(x, y, z, bot->GetObjectSize(), dist, bot->GetAngle(vcos, vsin)); Unit* currentTarget = GetAiObjectContext()->GetValue("current target")->Get(); - bot->GetMotionMaster()->MoveJump(x, y, z, horizontalSpeed, verticalSpeed, 0, currentTarget); + bot->GetMotionMaster()->MoveKnockbackFromForPlayer(bot->GetPositionX() + vcos, bot->GetPositionY() + vsin, horizontalSpeed, verticalSpeed); + // bot->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); // bot->AddUnitMovementFlag(MOVEMENTFLAG_FORWARD); // bot->m_movementInfo.AddMovementFlag(MOVEMENTFLAG_PENDING_STOP); From 8ef7bcd8b57efcf89b673aeea78f1a184b140067 Mon Sep 17 00:00:00 2001 From: mtm84 Date: Tue, 30 Jul 2024 09:22:06 -0700 Subject: [PATCH 02/14] Update RandomPlayerbotFactory.h code cleanup --- src/RandomPlayerbotFactory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/RandomPlayerbotFactory.h b/src/RandomPlayerbotFactory.h index f022f013..e7dbf795 100644 --- a/src/RandomPlayerbotFactory.h +++ b/src/RandomPlayerbotFactory.h @@ -23,7 +23,8 @@ class RandomPlayerbotFactory RandomPlayerbotFactory(uint32 accountId); virtual ~RandomPlayerbotFactory() { } - Player* CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names); + //Player* CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names); + Player* CreateRandomBot(WorldSession* session, uint8 cls); static void CreateRandomBots(); static void CreateRandomGuilds(); static void CreateRandomArenaTeams(ArenaType slot, uint32 count); From 8ebed9557e8ceb312848d3f7d8e73b2648e2c5ed Mon Sep 17 00:00:00 2001 From: mtm84 Date: Tue, 30 Jul 2024 09:24:44 -0700 Subject: [PATCH 03/14] Update RandomPlayerbotFactory.cpp code cleanup --- src/RandomPlayerbotFactory.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 2ee1a1a0..93ec5a40 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -117,7 +117,8 @@ RandomPlayerbotFactory::RandomPlayerbotFactory(uint32 accountId) : accountId(acc } } -Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names) +//Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names) +Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls) { LOG_DEBUG("playerbots", "Creating new random bot for class {}", cls); @@ -416,7 +417,7 @@ void RandomPlayerbotFactory::CreateRandomBots() uint32 totalRandomBotChars = 0; uint32 totalCharCount = sPlayerbotAIConfig->randomBotAccountCount * 10; - std::unordered_map> names; + //std::unordered_map> names; std::vector> playerBots; std::vector sessionBots; int bot_creation = 0; @@ -463,7 +464,8 @@ void RandomPlayerbotFactory::CreateRandomBots() } if (cls != 10) { - if (Player* playerBot = factory.CreateRandomBot(session, cls, names)) { + //if (Player* playerBot = factory.CreateRandomBot(session, cls, names)) { + if (Player* playerBot = factory.CreateRandomBot(session, cls)) { playerBot->SaveToDB(true, false); sCharacterCache->AddCharacterCacheEntry(playerBot->GetGUID(), accountId, playerBot->GetName(), playerBot->getGender(), playerBot->getRace(), playerBot->getClass(), playerBot->GetLevel()); From 5a77ea54605aabbd9eddbc52830616df6f1311fb Mon Sep 17 00:00:00 2001 From: mtm84 Date: Tue, 30 Jul 2024 09:35:45 -0700 Subject: [PATCH 04/14] Update RandomPlayerbotFactory.h code cleanup --- src/RandomPlayerbotFactory.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RandomPlayerbotFactory.h b/src/RandomPlayerbotFactory.h index e7dbf795..0d338d88 100644 --- a/src/RandomPlayerbotFactory.h +++ b/src/RandomPlayerbotFactory.h @@ -23,7 +23,6 @@ class RandomPlayerbotFactory RandomPlayerbotFactory(uint32 accountId); virtual ~RandomPlayerbotFactory() { } - //Player* CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names); Player* CreateRandomBot(WorldSession* session, uint8 cls); static void CreateRandomBots(); static void CreateRandomGuilds(); From 3cd0947762138b85f4682fb04138818b3f819b05 Mon Sep 17 00:00:00 2001 From: mtm84 Date: Tue, 30 Jul 2024 11:53:28 -0700 Subject: [PATCH 05/14] Update RandomPlayerbotFactory.cpp code cleanup --- src/RandomPlayerbotFactory.cpp | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 93ec5a40..5e44f14b 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -117,7 +117,6 @@ RandomPlayerbotFactory::RandomPlayerbotFactory(uint32 accountId) : accountId(acc } } -//Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map> names) Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls) { LOG_DEBUG("playerbots", "Creating new random bot for class {}", cls); @@ -131,28 +130,7 @@ Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls break; } } - std::string name; - // int tries = 10; - // while (tries--) { - // std::string cur_name; - // if (names.empty()) - name = CreateRandomBotName(gender); - // else - // { - // if (names[gender].empty()) - // return nullptr; - - // uint32 i = urand(0, names[gender].size() - 1); - // cur_name = names[gender][i]; - // std::swap(names[gender][i], names[gender].back()); - // names[gender].pop_back(); - // } - // if (ObjectMgr::CheckPlayerName(name) != CHAR_NAME_SUCCESS) - // { - // name.clear(); - // continue; - // } - // } + std::string name = CreateRandomBotName(gender); if (name.empty()) { LOG_ERROR("playerbots", "Unable to get random bot name!"); @@ -417,7 +395,6 @@ void RandomPlayerbotFactory::CreateRandomBots() uint32 totalRandomBotChars = 0; uint32 totalCharCount = sPlayerbotAIConfig->randomBotAccountCount * 10; - //std::unordered_map> names; std::vector> playerBots; std::vector sessionBots; int bot_creation = 0; @@ -464,7 +441,6 @@ void RandomPlayerbotFactory::CreateRandomBots() } if (cls != 10) { - //if (Player* playerBot = factory.CreateRandomBot(session, cls, names)) { if (Player* playerBot = factory.CreateRandomBot(session, cls)) { playerBot->SaveToDB(true, false); sCharacterCache->AddCharacterCacheEntry(playerBot->GetGUID(), accountId, playerBot->GetName(), From e1e51f52d1b7b23726a0e52d3032e43b45c6873b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Wed, 31 Jul 2024 23:20:54 +0800 Subject: [PATCH 06/14] Fix triggers bug --- src/strategy/Engine.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index c4ca7394..cf939ea9 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -470,7 +470,7 @@ bool Engine::HasStrategy(std::string const name) void Engine::ProcessTriggers(bool minimal) { - // std::unordered_map fires; + std::unordered_map fires; for (std::vector::iterator i = triggers.begin(); i != triggers.end(); i++) { TriggerNode* node = *i; @@ -486,7 +486,10 @@ void Engine::ProcessTriggers(bool minimal) if (!trigger) continue; - + + if (fires.find(trigger) != fires.end()) + continue; + if (testMode || trigger->needCheck()) { if (minimal && node->getFirstRelevance() < 100) @@ -500,22 +503,21 @@ void Engine::ProcessTriggers(bool minimal) if (!event) continue; - // fires[trigger] = event; + fires[trigger] = event; LogAction("T:%s", trigger->getName().c_str()); - MultiplyAndPush(node->getHandlers(), 0.0f, false, event, "trigger"); } } - // for (std::vector::iterator i = triggers.begin(); i != triggers.end(); i++) - // { - // TriggerNode* node = *i; - // Trigger* trigger = node->getTrigger(); - // if (fires.find(trigger) == fires.end()) - // continue; + for (std::vector::iterator i = triggers.begin(); i != triggers.end(); i++) + { + TriggerNode* node = *i; + Trigger* trigger = node->getTrigger(); + if (fires.find(trigger) == fires.end()) + continue; - // Event event = fires[trigger]; - - // } + Event event = fires[trigger]; + MultiplyAndPush(node->getHandlers(), 0.0f, false, event, "trigger"); + } for (std::vector::iterator i = triggers.begin(); i != triggers.end(); i++) { From 024efede0e4f144295f778ef8889cbb64f0e6312 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Wed, 31 Jul 2024 23:32:34 +0800 Subject: [PATCH 07/14] Fix knockback vertical speed --- src/PlayerbotAI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index f3cd2996..8b5aa806 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -834,9 +834,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) float vcos, vsin, horizontalSpeed, verticalSpeed = 0.f; p >> guid.ReadAsPacked() >> counter >> vcos >> vsin >> horizontalSpeed >> verticalSpeed; - // if (horizontalSpeed <= 0.1f) { - // horizontalSpeed = 0.11f; - // } + if (horizontalSpeed <= 0.1f) { + horizontalSpeed = 0.11f; + } verticalSpeed = -verticalSpeed; // stop casting From 01a6af7aa3d971e2a9f7934e0e2c4825d75b72ff Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 30 Jul 2024 16:44:58 +0800 Subject: [PATCH 08/14] [Movement] Improve knockback --- src/PlayerbotAI.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index fa59ff11..f3cd2996 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -834,9 +834,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) float vcos, vsin, horizontalSpeed, verticalSpeed = 0.f; p >> guid.ReadAsPacked() >> counter >> vcos >> vsin >> horizontalSpeed >> verticalSpeed; - if (horizontalSpeed <= 0.1f) { - horizontalSpeed = 0.11f; - } + // if (horizontalSpeed <= 0.1f) { + // horizontalSpeed = 0.11f; + // } verticalSpeed = -verticalSpeed; // stop casting @@ -846,23 +846,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) bot->StopMoving(); bot->GetMotionMaster()->Clear(); - - float moveTimeHalf = verticalSpeed / Movement::gravity; - float dist = 2 * moveTimeHalf * horizontalSpeed; - Position dest = bot->GetPosition(); - - bot->MovePositionToFirstCollision(dest, dist, bot->GetRelativeAngle(bot->GetPositionX() + vcos, bot->GetPositionY() + vsin)); - float x, y, z; - x = dest.GetPositionX(); - y = dest.GetPositionY(); - z = dest.GetPositionZ(); - // char speak[1024]; - // sprintf(speak, "SMSG_MOVE_KNOCK_BACK: %.2f %.2f, horizontalSpeed: %.2f, verticalSpeed: %.2f, tX: %.2f, tY: %.2f, tZ: %.2f, relativeAngle: %.2f, orientation: %.2f", - // vcos, vsin, horizontalSpeed, verticalSpeed, x, y, z, bot->GetRelativeAngle(vcos, vsin), bot->GetOrientation()); - // bot->Say(speak, LANG_UNIVERSAL); - // bot->GetClosePoint(x, y, z, bot->GetObjectSize(), dist, bot->GetAngle(vcos, vsin)); Unit* currentTarget = GetAiObjectContext()->GetValue("current target")->Get(); - bot->GetMotionMaster()->MoveJump(x, y, z, horizontalSpeed, verticalSpeed, 0, currentTarget); + bot->GetMotionMaster()->MoveKnockbackFromForPlayer(bot->GetPositionX() + vcos, bot->GetPositionY() + vsin, horizontalSpeed, verticalSpeed); + // bot->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); // bot->AddUnitMovementFlag(MOVEMENTFLAG_FORWARD); // bot->m_movementInfo.AddMovementFlag(MOVEMENTFLAG_PENDING_STOP); From 5f117eb9d1fe9e1191068e4b6401847ace220af7 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Wed, 31 Jul 2024 23:32:34 +0800 Subject: [PATCH 09/14] Fix knockback vertical speed --- src/PlayerbotAI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index f3cd2996..8b5aa806 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -834,9 +834,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet) float vcos, vsin, horizontalSpeed, verticalSpeed = 0.f; p >> guid.ReadAsPacked() >> counter >> vcos >> vsin >> horizontalSpeed >> verticalSpeed; - // if (horizontalSpeed <= 0.1f) { - // horizontalSpeed = 0.11f; - // } + if (horizontalSpeed <= 0.1f) { + horizontalSpeed = 0.11f; + } verticalSpeed = -verticalSpeed; // stop casting From ff6106bf8dd40f16581cd8284f888c426d304a91 Mon Sep 17 00:00:00 2001 From: Fuzz Date: Fri, 2 Aug 2024 17:05:16 +1000 Subject: [PATCH 10/14] [Battlegrounds] bots will no longer hide within flagpoles when capping points in AV AB or IOC --- src/strategy/actions/BattleGroundTactics.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/strategy/actions/BattleGroundTactics.cpp b/src/strategy/actions/BattleGroundTactics.cpp index 4c9ad122..e3fadd49 100644 --- a/src/strategy/actions/BattleGroundTactics.cpp +++ b/src/strategy/actions/BattleGroundTactics.cpp @@ -4410,11 +4410,11 @@ bool BGTactics::moveToObjective() //std::ostringstream out; out << "Moving to objective " << pos.x << ", " << pos.y << ", Distance: " << sServerFacade->GetDistance2d(bot, pos.x, pos.y); //bot->Say(out.str(), LANG_UNIVERSAL); - // more precise position for wsg and AV (flags in AV towers require precision) - if (bgType == BATTLEGROUND_WS || bgType == BATTLEGROUND_AV) + // more precise position for wsg + if (bgType == BATTLEGROUND_WS) return MoveTo(bot->GetMapId(), pos.x, pos.y, pos.z); else - return MoveNear(bot->GetMapId(), pos.x, pos.y, pos.z, 3.0f); + return MoveNear(bot->GetMapId(), pos.x, pos.y, pos.z, 1.5f);//note - don't make distance too large or horde bots may struggle to get flags in alliance AV towers (because they'll be targetting a spot in midair) } return false; } @@ -4774,9 +4774,9 @@ bool BGTactics::atFlag(std::vector const& vPaths, std::vectorCanUseBattlegroundObject(go) && bgType != BATTLEGROUND_WS) continue; - if (flagRange) - if (!bot->IsWithinDistInMap(go, flagRange)) - continue; + float const dist = sqrt(bot->GetDistance(go)); + if (flagRange && dist > flagRange) + continue; bool atBase = bgType == BATTLEGROUND_WS ? go->GetEntry() == vFlagsWS[bot->GetTeamId()] : bgType == BATTLEGROUND_EY ? go->GetEntry() == vFlagsEY[0] : false; @@ -4789,6 +4789,13 @@ bool BGTactics::atFlag(std::vector const& vPaths, std::vectorGetObjectSize() + go->GetObjectSize() + 0.1f; + return MoveTo(bot->GetMapId(), go->GetPositionX() + (urand(0, 1) ? -moveDist : moveDist), go->GetPositionY() + (urand(0, 1) ? -moveDist : moveDist), go->GetPositionZ()); + } if (bot->IsMounted()) bot->RemoveAurasByType(SPELL_AURA_MOUNTED); From c050c698849aadc862742a68c2f05420ee5dfd46 Mon Sep 17 00:00:00 2001 From: Fuzz Date: Fri, 2 Aug 2024 17:17:22 +1000 Subject: [PATCH 11/14] [Battlegrounds] additional change I meant to include last commit --- src/strategy/actions/BattleGroundTactics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategy/actions/BattleGroundTactics.cpp b/src/strategy/actions/BattleGroundTactics.cpp index e3fadd49..2c693a97 100644 --- a/src/strategy/actions/BattleGroundTactics.cpp +++ b/src/strategy/actions/BattleGroundTactics.cpp @@ -4827,7 +4827,7 @@ bool BGTactics::atFlag(std::vector const& vPaths, std::vectorIsWithinDistInMap(go, INTERACTION_DISTANCE)) + if (dist < INTERACTION_DISTANCE) { if (atBase) { @@ -4875,7 +4875,7 @@ bool BGTactics::atFlag(std::vector const& vPaths, std::vectorIsWithinDistInMap(go, INTERACTION_DISTANCE)) + if (dist < INTERACTION_DISTANCE) { if (bot->IsMounted()) bot->RemoveAurasByType(SPELL_AURA_MOUNTED); From 8df01e8fedd440113a1cd4a7cdcbe4113b321b24 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 3 Aug 2024 00:01:40 +0800 Subject: [PATCH 12/14] Enable flight mount for bots --- src/strategy/actions/MovementActions.cpp | 33 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index e2288195..2ce77bf7 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -857,9 +857,16 @@ void MovementAction::UpdateMovementState() bot->SetSwim(false); } - if (bot->IsFlying()) - bot->UpdateSpeed(MOVE_FLIGHT, true); + bool onGround = bot->GetPositionZ() < bot->GetMapWaterOrGroundLevel(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()) + 1.0f; + if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !onGround) + { + bot->AddUnitMovementFlag(MOVEMENTFLAG_FLYING); + } + if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && (!bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) || onGround)) + { + bot->RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING); + } Transport* newTransport = bot->GetMap()->GetTransportForPos(bot->GetPhaseMask(), bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot); if (newTransport != bot->GetTransport()) { @@ -874,10 +881,13 @@ void MovementAction::UpdateMovementState() bot->StopMovingOnCurrentPos(); } + bot->SendMovementFlagUpdate(); // Temporary speed increase in group - //if (botAI->HasRealPlayerMaster()) - //bot->SetSpeedRate(MOVE_RUN, 1.1f); - + // if (botAI->HasRealPlayerMaster()) { + // bot->SetSpeedRate(MOVE_RUN, 1.1f); + // } else { + // bot->SetSpeedRate(MOVE_RUN, 1.0f); + // } // check if target is not reachable (from Vmangos) // if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() && !bot->InBattleground()) // { @@ -1146,7 +1156,18 @@ bool MovementAction::ChaseTo(WorldObject* obj, float distance, float angle) float MovementAction::MoveDelay(float distance) { - return distance / bot->GetSpeed(MOVE_RUN); + float speed; + if (bot->isSwimming()) { + speed = bot->GetSpeed(MOVE_SWIM); + } else if (bot->IsFlying()) { + speed = bot->GetSpeed(MOVE_FLIGHT); + } else { + speed = bot->GetSpeed(MOVE_RUN); + } + float delay = distance / speed - sPlayerbotAIConfig->reactDistance; + if (delay < 0) + delay = 0; + return delay; } void MovementAction::WaitForReach(float distance) From b0ab63238c87fd78fe4a4e15ee1b562c6c748115 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 3 Aug 2024 00:02:11 +0800 Subject: [PATCH 13/14] Fix mount bug after bot logout --- src/PlayerbotAI.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 8b5aa806..52dcbfbf 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -497,6 +497,7 @@ void PlayerbotAI::Reset(bool full) } currentEngine = engines[BOT_STATE_NON_COMBAT]; + currentState = BOT_STATE_NON_COMBAT; nextAICheckDelay = 0; whispers.clear(); @@ -1165,19 +1166,26 @@ void PlayerbotAI::DoNextAction(bool min) bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_WALKING); else if ((nextAICheckDelay < 1000) && bot->IsSitState()) bot->SetStandState(UNIT_STAND_STATE_STAND); - - if (bot->IsFlying() && !!bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !bot->HasAuraType(SPELL_AURA_FLY)) + + bool hasMountAura = bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED) || bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED); + if (hasMountAura && !bot->IsMounted()) { - if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FLYING)) - bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_FLYING); - - if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY)) - bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_CAN_FLY); - - if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY)) - bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); + bot->RemoveAurasByType(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); + bot->RemoveAurasByType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED); } + // if (bot->IsFlying() && !bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !bot->HasAuraType(SPELL_AURA_FLY)) + // { + // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FLYING)) + // bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_FLYING); + + // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY)) + // bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_CAN_FLY); + + // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY)) + // bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); + // } + /* // land after kncokback/jump if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING)) From 54c06887d5003c7f56f0831d8564f50a3f033bfc Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 3 Aug 2024 00:02:34 +0800 Subject: [PATCH 14/14] Enable mount for random bots --- src/strategy/actions/AttackAction.cpp | 10 +++--- .../actions/CheckMountStateAction.cpp | 35 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 1ba9f4b5..344138d6 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -95,11 +95,11 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) return false; } - if (bot->IsMounted() && bot->IsWithinLOSInMap(target)) - { - WorldPacket emptyPacket; - bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket); - } + // if (bot->IsMounted() && bot->IsWithinLOSInMap(target)) + // { + // WorldPacket emptyPacket; + // bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket); + // } ObjectGuid guid = target->GetGUID(); bot->SetSelection(target->GetGUID()); diff --git a/src/strategy/actions/CheckMountStateAction.cpp b/src/strategy/actions/CheckMountStateAction.cpp index 6e4e84d1..09a4e208 100644 --- a/src/strategy/actions/CheckMountStateAction.cpp +++ b/src/strategy/actions/CheckMountStateAction.cpp @@ -5,6 +5,7 @@ #include "CheckMountStateAction.h" #include "BattlegroundWS.h" #include "Event.h" +#include "PlayerbotAI.h" #include "Playerbots.h" #include "ServerFacade.h" #include "SpellAuraEffects.h" @@ -20,18 +21,11 @@ bool CheckMountStateAction::Execute(Event event) bool attackdistance = false; bool chasedistance = false; float attack_distance = 35.0f; - - switch (bot->getClass()) - { - case CLASS_WARRIOR: - case CLASS_PALADIN: - attack_distance = 10.0f; - break; - case CLASS_ROGUE: - attack_distance = 40.0f; - break; + if (PlayerbotAI::IsMelee(bot)) { + attack_distance = 10.0f; + } else { + attack_distance = 40.0f; } - if (enemy) attack_distance /= 2; @@ -41,6 +35,12 @@ bool CheckMountStateAction::Execute(Event event) chasedistance = enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 45.0f) && AI_VALUE2(bool, "moving", "enemy player target"); } + if (bot->IsMounted() && attackdistance) { + WorldPacket emptyPacket; + bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket); + return true; + } + Player* master = GetMaster(); if (master != nullptr && !bot->InBattleground()) { @@ -48,7 +48,7 @@ bool CheckMountStateAction::Execute(Event event) return false; // bool farFromMaster = sServerFacade->GetDistance2d(bot, master) > sPlayerbotAIConfig->sightDistance; - if (master->IsMounted() && !bot->IsMounted() && noattackers) + if (master->IsMounted() && !bot->IsMounted() && noattackers && !attackdistance && !bot->IsInCombat() && botAI->GetState() != BOT_STATE_COMBAT) { return Mount(); } @@ -72,6 +72,13 @@ bool CheckMountStateAction::Execute(Event event) return false; } + // For random bots + if (!bot->InBattleground() && !master) { + if (!bot->IsMounted() && noattackers && !attackdistance && !bot->IsInCombat()) { + return Mount(); + } + } + if (bot->InBattleground() && !attackdistance && (noattackers || fartarget) && !bot->IsInCombat() && !bot->IsMounted()) { if (bot->GetBattlegroundTypeId() == BATTLEGROUND_WS) @@ -269,8 +276,8 @@ bool CheckMountStateAction::Mount() if (index >= ids.size()) continue; - botAI->CastSpell(ids[index], bot); - return true; + + return botAI->CastSpell(ids[index], bot);; } std::vector items = AI_VALUE2(std::vector, "inventory items", "mount");