Skip to content

Commit

Permalink
Merge pull request liyunfan1223#427 from liyunfan1223/mount_0731
Browse files Browse the repository at this point in the history
Mount Improvement
  • Loading branch information
liyunfan1223 authored Aug 3, 2024
2 parents 966cc1b + 54c0688 commit c85b8fd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 34 deletions.
26 changes: 17 additions & 9 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ void PlayerbotAI::Reset(bool full)
}

currentEngine = engines[BOT_STATE_NON_COMBAT];
currentState = BOT_STATE_NON_COMBAT;
nextAICheckDelay = 0;
whispers.clear();

Expand Down Expand Up @@ -1165,18 +1166,25 @@ 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);
bot->RemoveAurasByType(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED);
bot->RemoveAurasByType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED);
}

if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY))
bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_CAN_FLY);
// 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_DISABLE_GRAVITY))
bot->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY);
}
// 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
Expand Down
10 changes: 5 additions & 5 deletions src/strategy/actions/AttackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
35 changes: 21 additions & 14 deletions src/strategy/actions/CheckMountStateAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand All @@ -41,14 +35,20 @@ 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())
{
if (!bot->GetGroup() || bot->GetGroup()->GetLeaderGUID() != master->GetGUID())
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();
}
Expand All @@ -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)
Expand Down Expand Up @@ -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<Item*> items = AI_VALUE2(std::vector<Item*>, "inventory items", "mount");
Expand Down
33 changes: 27 additions & 6 deletions src/strategy/actions/MovementActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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())
// {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c85b8fd

Please sign in to comment.