mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49:25 +02:00
Flying mount fixes and self-bot (#2351)
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.
DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.
Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.
Before submitting, make sure your changes aligns with these principles.
-->
## Pull Request Description
<!-- Describe what this change does and why it is needed -->
This PR does a few things.
1. Enable Selfbots to mount up. Because they have masters, but are their
own masters, they would never mount up because their master never
mounted.
2. Fix flag state handling after processing the aura change.
3. Add in the Dismount packet handler. This is intended to implement
fall animations and have bots touch the ground when dismounting instead
of floating off the ground. (It was cleared anyway after the first move,
but this should make it more seamless.)
## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->
<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
- Describe the **processing cost** when this logic executes across many
bots.
## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->
self bot should mount up, and select area appropriate mounts.
Bots in your team should mount up, and on your dismount properly snap to
the ground.
should test at low Z (<1.0 off the ground) and higher z (> 1.0 off the
ground)
## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
- - [ ] No, not at all
- - [x] Minimal impact (**explain below**)
- - [ ] Moderate impact (**explain below**)
The processing of a fall path has some impact, but I dont think itll be
too much.
- Does this change modify default bot behavior?
- - [ ] No
- - [x] Yes (**explain why**)
Add natural falling when dismounting. May incurr fall damange....
- Does this change add new decision branches or increase maintenance
complexity?
- - [x] No
- - [ ] Yes (**explain below**)
## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [ ] No
- - [x] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->
Comparison of code bases, searching for flags, adding diagnostic
logging, and processing of said logging.
iterating and brainstorming.
Code was also written, but fully reviewed by me, and fixed where
appropriate.
<!--
TRANSLATIONS:
Anything new that the bots say in chat must be in a translatable format.
This is done using GetBotTextOrDefault,
which you can search for in the codebase to find examples. Your code
needs to have English as the default fallback,
while the full translations need to be in an SQL update file. The
languages in the file are the nine language
options supported by AzerothCore: English, Korean, French, German,
Chinese, Taiwanese, Spanish, Spanish Mexico, and
Russian. See
data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as
an example of a translation SQL
update, whose content are called within the codebase at
src/strategy/actions/FishingAction.cpp
-->
## Final Checklist
- - [x] Stability is not compromised.
- - [x] Performance impact is understood, tested, and acceptable.
- - [x] Added logic complexity is justified and explained.
- - [x] Any new bot dialogue lines are translated.
- - [x] Documentation updated if needed (Conf comments, WiKi commands).
## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
826887133d
commit
b8ff5996f8
@ -4,9 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CheckMountStateAction.h"
|
#include "CheckMountStateAction.h"
|
||||||
|
#include "AreaDefines.h"
|
||||||
#include "BattleGroundTactics.h"
|
#include "BattleGroundTactics.h"
|
||||||
#include "BattlegroundEY.h"
|
#include "BattlegroundEY.h"
|
||||||
#include "BattlegroundWS.h"
|
#include "BattlegroundWS.h"
|
||||||
|
#include "DBCStores.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "PlayerbotAI.h"
|
#include "PlayerbotAI.h"
|
||||||
#include "PlayerbotAIConfig.h"
|
#include "PlayerbotAIConfig.h"
|
||||||
@ -14,6 +16,8 @@
|
|||||||
#include "ServerFacade.h"
|
#include "ServerFacade.h"
|
||||||
#include "SpellAuraEffects.h"
|
#include "SpellAuraEffects.h"
|
||||||
|
|
||||||
|
static constexpr uint32 SPELL_COLD_WEATHER_FLYING = 54197;
|
||||||
|
|
||||||
// Define the static map / init bool for caching bot preferred mount data globally
|
// Define the static map / init bool for caching bot preferred mount data globally
|
||||||
std::unordered_map<uint32, PreferredMountCache> CheckMountStateAction::mountCache;
|
std::unordered_map<uint32, PreferredMountCache> CheckMountStateAction::mountCache;
|
||||||
bool CheckMountStateAction::preferredMountTableChecked = false;
|
bool CheckMountStateAction::preferredMountTableChecked = false;
|
||||||
@ -94,9 +98,10 @@ bool CheckMountStateAction::Execute(Event /*event*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool inBattleground = bot->InBattleground();
|
bool inBattleground = bot->InBattleground();
|
||||||
|
bool const noRealMaster = (!master || master == bot);
|
||||||
|
|
||||||
// If there is a master and bot not in BG, follow master's mount state regardless of group leader
|
// If there is a master and bot not in BG, follow master's mount state regardless of group leader
|
||||||
if (master && !inBattleground)
|
if (!noRealMaster && !inBattleground)
|
||||||
{
|
{
|
||||||
if (ShouldFollowMasterMountState(master, noAttackers, shouldMount))
|
if (ShouldFollowMasterMountState(master, noAttackers, shouldMount))
|
||||||
return Mount();
|
return Mount();
|
||||||
@ -110,8 +115,8 @@ bool CheckMountStateAction::Execute(Event /*event*/)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no master or bot in BG
|
// No real master (random bot or self-bot) OR bot in BG
|
||||||
if ((!master || inBattleground) && !bot->IsMounted() &&
|
if ((noRealMaster || inBattleground) && !bot->IsMounted() &&
|
||||||
noAttackers && shouldMount && !bot->IsInCombat())
|
noAttackers && shouldMount && !bot->IsInCombat())
|
||||||
return Mount();
|
return Mount();
|
||||||
|
|
||||||
@ -228,6 +233,39 @@ void CheckMountStateAction::Dismount()
|
|||||||
|
|
||||||
WorldPacket emptyPacket;
|
WorldPacket emptyPacket;
|
||||||
bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket);
|
bot->GetSession()->HandleCancelMountAuraOpcode(emptyPacket);
|
||||||
|
|
||||||
|
bool const wantsFly = bot->HasIncreaseMountedFlightSpeedAura() || bot->HasFlyAura();
|
||||||
|
bool const isWaterWalking = bot->HasUnitMovementFlag(MOVEMENTFLAG_WATERWALKING);
|
||||||
|
bool const isFlying = bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING);
|
||||||
|
bool const hasGravityDisabled = bot->HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY);
|
||||||
|
if (!wantsFly && !isWaterWalking && (isFlying || hasGravityDisabled))
|
||||||
|
{
|
||||||
|
bot->RemoveUnitMovementFlag(
|
||||||
|
MOVEMENTFLAG_FLYING | MOVEMENTFLAG_CAN_FLY | MOVEMENTFLAG_DISABLE_GRAVITY);
|
||||||
|
if (!bot->IsRooted())
|
||||||
|
bot->SendMovementFlagUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckMountStateAction::CompleteDismount(Player* bot)
|
||||||
|
{
|
||||||
|
if (!bot || !bot->IsInWorld())
|
||||||
|
return;
|
||||||
|
|
||||||
|
float const x = bot->GetPositionX();
|
||||||
|
float const y = bot->GetPositionY();
|
||||||
|
float const startZ = bot->GetPositionZ();
|
||||||
|
|
||||||
|
float groundZ = startZ;
|
||||||
|
bot->UpdateAllowedPositionZ(x, y, groundZ);
|
||||||
|
|
||||||
|
bot->GetMotionMaster()->MoveFall();
|
||||||
|
MovementInfo fallInfo = bot->m_movementInfo;
|
||||||
|
// Need to set the start of the fall, otherwise the fall may start from too high of a Z and kill the bot.
|
||||||
|
bot->SetFallInformation(0, startZ);
|
||||||
|
fallInfo.pos.Relocate(x, y, groundZ);
|
||||||
|
bot->HandleFall(fallInfo);
|
||||||
|
bot->RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_FAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckMountStateAction::TryForms(Player* master, int32 masterMountType, int32 masterSpeed) const
|
bool CheckMountStateAction::TryForms(Player* master, int32 masterMountType, int32 masterSpeed) const
|
||||||
@ -434,6 +472,24 @@ bool CheckMountStateAction::ShouldDismountForMaster(Player* master) const
|
|||||||
return !isMasterMounted && bot->IsMounted();
|
return !isMasterMounted && bot->IsMounted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool BotCanUseFlyingMount(Player const* bot)
|
||||||
|
{
|
||||||
|
if (bot->GetPureSkillValue(SKILL_RIDING) < 225)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AreaTableEntry const* area = sAreaTableStore.LookupEntry(bot->GetAreaId());
|
||||||
|
if (!area || !area->IsFlyable())
|
||||||
|
return false;
|
||||||
|
if (area->flags & AREA_FLAG_NO_FLY_ZONE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
uint32 const vmap = GetVirtualMapForMapAndZone(bot->GetMapId(), bot->GetZoneId());
|
||||||
|
if (vmap == MAP_NORTHREND && !bot->HasSpell(SPELL_COLD_WEATHER_FLYING))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int32 CheckMountStateAction::CalculateMasterMountSpeed(Player* master, const MountData& mountData) const
|
int32 CheckMountStateAction::CalculateMasterMountSpeed(Player* master, const MountData& mountData) const
|
||||||
{
|
{
|
||||||
// Check riding skill and level requirements
|
// Check riding skill and level requirements
|
||||||
@ -443,8 +499,10 @@ int32 CheckMountStateAction::CalculateMasterMountSpeed(Player* master, const Mou
|
|||||||
if (ridingSkill <= 75 && botLevel < static_cast<int32>(sPlayerbotAIConfig.useFastGroundMountAtMinLevel))
|
if (ridingSkill <= 75 && botLevel < static_cast<int32>(sPlayerbotAIConfig.useFastGroundMountAtMinLevel))
|
||||||
return 59;
|
return 59;
|
||||||
|
|
||||||
// If there is a master and bot not in BG, use master's aura effects.
|
// check if bot has master and if master is self
|
||||||
if (master && !bot->InBattleground())
|
bool const noRealMaster = (!master || master == bot);
|
||||||
|
|
||||||
|
if (!noRealMaster && !bot->InBattleground())
|
||||||
{
|
{
|
||||||
auto auraEffects = master->GetAuraEffectsByType(SPELL_AURA_MOUNTED);
|
auto auraEffects = master->GetAuraEffectsByType(SPELL_AURA_MOUNTED);
|
||||||
if (!auraEffects.empty())
|
if (!auraEffects.empty())
|
||||||
@ -458,27 +516,27 @@ int32 CheckMountStateAction::CalculateMasterMountSpeed(Player* master, const Mou
|
|||||||
return 279;
|
return 279;
|
||||||
else if (masterInShapeshiftForm == FORM_FLIGHT)
|
else if (masterInShapeshiftForm == FORM_FLIGHT)
|
||||||
return 149;
|
return 149;
|
||||||
}
|
return 59; // walk pace
|
||||||
else
|
|
||||||
{
|
|
||||||
// Bots on their own.
|
|
||||||
int32 speed = mountData.maxSpeed;
|
|
||||||
if (bot->InBattleground() && speed > 99)
|
|
||||||
return 99;
|
|
||||||
|
|
||||||
return speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 59;
|
// No real master OR battleground: pick speed by skill tier.
|
||||||
|
if (!bot->InBattleground() && BotCanUseFlyingMount(bot))
|
||||||
|
return (ridingSkill >= 300) ? 279 : 149;
|
||||||
|
|
||||||
|
int32 maxGround = (ridingSkill >= 150) ? 99 : 59;
|
||||||
|
if (bot->InBattleground() && maxGround > 99)
|
||||||
|
maxGround = 99;
|
||||||
|
return maxGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CheckMountStateAction::GetMountType(Player* master) const
|
uint32 CheckMountStateAction::GetMountType(Player* master) const
|
||||||
{
|
{
|
||||||
if (!master)
|
bool const noRealMaster = (!master || master == bot);
|
||||||
return 0;
|
|
||||||
|
if (noRealMaster)
|
||||||
|
return (!bot->InBattleground() && BotCanUseFlyingMount(bot)) ? 1 : 0;
|
||||||
|
|
||||||
auto auraEffects = master->GetAuraEffectsByType(SPELL_AURA_MOUNTED);
|
auto auraEffects = master->GetAuraEffectsByType(SPELL_AURA_MOUNTED);
|
||||||
|
|
||||||
if (!auraEffects.empty())
|
if (!auraEffects.empty())
|
||||||
{
|
{
|
||||||
SpellInfo const* masterSpell = auraEffects.front()->GetSpellInfo();
|
SpellInfo const* masterSpell = auraEffects.front()->GetSpellInfo();
|
||||||
|
|||||||
@ -42,6 +42,8 @@ public:
|
|||||||
bool isPossible() override { return true; }
|
bool isPossible() override { return true; }
|
||||||
bool Mount();
|
bool Mount();
|
||||||
|
|
||||||
|
static void CompleteDismount(Player* bot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Player* master;
|
Player* master;
|
||||||
ShapeshiftForm masterInShapeshiftForm;
|
ShapeshiftForm masterInShapeshiftForm;
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include "ChannelMgr.h"
|
#include "ChannelMgr.h"
|
||||||
#include "CharacterPackets.h"
|
#include "CharacterPackets.h"
|
||||||
#include "ChatHelper.h"
|
#include "ChatHelper.h"
|
||||||
|
#include "CheckMountStateAction.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "CreatureData.h"
|
#include "CreatureData.h"
|
||||||
#include "EmoteAction.h"
|
#include "EmoteAction.h"
|
||||||
@ -1365,6 +1366,17 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
|
|||||||
// */
|
// */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case SMSG_DISMOUNT:
|
||||||
|
{
|
||||||
|
WorldPacket p(packet);
|
||||||
|
p.rpos(0);
|
||||||
|
ObjectGuid guid;
|
||||||
|
p >> guid.ReadAsPacked();
|
||||||
|
if (guid != bot->GetGUID())
|
||||||
|
return;
|
||||||
|
CheckMountStateAction::CompleteDismount(bot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
botOutgoingPacketHandlers.AddPacket(packet);
|
botOutgoingPacketHandlers.AddPacket(packet);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user