From 54462b79c56d8086e94e35e2eb77ed980a543bf0 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 25 Aug 2023 02:28:56 +0800 Subject: [PATCH] swimming --- src/strategy/actions/MovementActions.cpp | 126 ++++++++++++----------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index b1743802..ebb10b45 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -132,14 +132,20 @@ bool MovementAction::MoveToLOS(WorldObject* target, bool ranged) bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, bool react) { + UpdateMovementState(); if (!IsMovingAllowed(mapId, x, y, z)) { return false; } - UpdateMovementState(); - // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_SLOW | MOVEMENTFLAG_FALLING_FAR)) { + // if (bot->Unit::IsFalling()) { // bot->Say("I'm falling!, flag:" + std::to_string(bot->m_movementInfo.GetMovementFlags()), LANG_UNIVERSAL); // return false; // } + // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_SWIMMING)) { + // bot->Say("I'm swimming", LANG_UNIVERSAL); + // } + // if (bot->Unit::IsFalling()) { + // bot->Say("I'm falling", LANG_UNIVERSAL); + // } z += 2.0f; bot->UpdateAllowedPositionZ(x, y, z); // z += 0.5f; @@ -750,7 +756,7 @@ bool MovementAction::Follow(Unit* target, float distance) void MovementAction::UpdateMovementState() { - if (bot->IsInWater() || bot->IsUnderWater()) + if (bot->Unit::IsInWater() || bot->Unit::IsUnderWater()) { bot->m_movementInfo.AddMovementFlag(MOVEMENTFLAG_SWIMMING); bot->UpdateSpeed(MOVE_SWIM, true); @@ -769,69 +775,69 @@ void MovementAction::UpdateMovementState() //bot->SetSpeedRate(MOVE_RUN, 1.1f); // check if target is not reachable (from Vmangos) - if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() && !bot->InBattleground()) - { - if (Unit* pTarget = sServerFacade->GetChaseTarget(bot)) - { - if (!bot->IsWithinMeleeRange(pTarget) && pTarget->GetTypeId() == TYPEID_UNIT) - { - float angle = bot->GetAngle(pTarget); - float distance = 5.0f; - float x = bot->GetPositionX() + cos(angle) * distance; - float y = bot->GetPositionY() + sin(angle) * distance; - float z = bot->GetPositionZ(); + // if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() && !bot->InBattleground()) + // { + // if (Unit* pTarget = sServerFacade->GetChaseTarget(bot)) + // { + // if (!bot->IsWithinMeleeRange(pTarget) && pTarget->GetTypeId() == TYPEID_UNIT) + // { + // float angle = bot->GetAngle(pTarget); + // float distance = 5.0f; + // float x = bot->GetPositionX() + cos(angle) * distance; + // float y = bot->GetPositionY() + sin(angle) * distance; + // float z = bot->GetPositionZ(); - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(x, y, z); + // z += CONTACT_DISTANCE; + // bot->UpdateAllowedPositionZ(x, y, z); - bot->StopMoving(); - bot->GetMotionMaster()->Clear(); - bot->NearTeleportTo(x, y, z, bot->GetOrientation()); - //bot->GetMotionMaster()->MovePoint(bot->GetMapId(), x, y, z, FORCED_MOVEMENT_RUN, false); - return; - /*if (pTarget->IsCreature() && !bot->isMoving() && bot->IsWithinDist(pTarget, 10.0f)) - { - // Cheating to prevent getting stuck because of bad mmaps. - bot->StopMoving(); - bot->GetMotionMaster()->Clear(); - bot->GetMotionMaster()->MovePoint(bot->GetMapId(), pTarget->GetPosition(), FORCED_MOVEMENT_RUN, false); - return; - }*/ - } - } - } + // bot->StopMoving(); + // bot->GetMotionMaster()->Clear(); + // bot->NearTeleportTo(x, y, z, bot->GetOrientation()); + // //bot->GetMotionMaster()->MovePoint(bot->GetMapId(), x, y, z, FORCED_MOVEMENT_RUN, false); + // return; + // /*if (pTarget->IsCreature() && !bot->isMoving() && bot->IsWithinDist(pTarget, 10.0f)) + // { + // // Cheating to prevent getting stuck because of bad mmaps. + // bot->StopMoving(); + // bot->GetMotionMaster()->Clear(); + // bot->GetMotionMaster()->MovePoint(bot->GetMapId(), pTarget->GetPosition(), FORCED_MOVEMENT_RUN, false); + // return; + // }*/ + // } + // } + // } - if ((bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE || - bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == POINT_MOTION_TYPE) && bot->CanNotReachTarget() && !bot->InBattleground()) - { - if (Unit* pTarget = sServerFacade->GetChaseTarget(bot)) - { - if (pTarget != botAI->GetGroupMaster()) - return; + // if ((bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE || + // bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == POINT_MOTION_TYPE) && bot->CanNotReachTarget() && !bot->InBattleground()) + // { + // if (Unit* pTarget = sServerFacade->GetChaseTarget(bot)) + // { + // if (pTarget != botAI->GetGroupMaster()) + // return; - if (!bot->IsWithinMeleeRange(pTarget)) - { - if (!bot->isMoving() && bot->IsWithinDist(pTarget, 10.0f)) - { - // Cheating to prevent getting stuck because of bad mmaps. - float angle = bot->GetAngle(pTarget); - float distance = 5.0f; - float x = bot->GetPositionX() + cos(angle) * distance; - float y = bot->GetPositionY() + sin(angle) * distance; - float z = bot->GetPositionZ(); + // if (!bot->IsWithinMeleeRange(pTarget)) + // { + // if (!bot->isMoving() && bot->IsWithinDist(pTarget, 10.0f)) + // { + // // Cheating to prevent getting stuck because of bad mmaps. + // float angle = bot->GetAngle(pTarget); + // float distance = 5.0f; + // float x = bot->GetPositionX() + cos(angle) * distance; + // float y = bot->GetPositionY() + sin(angle) * distance; + // float z = bot->GetPositionZ(); - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(x, y, z); + // z += CONTACT_DISTANCE; + // bot->UpdateAllowedPositionZ(x, y, z); - bot->StopMoving(); - bot->GetMotionMaster()->Clear(); - bot->NearTeleportTo(x, y, z, bot->GetOrientation()); - //bot->GetMotionMaster()->MovePoint(bot->GetMapId(), x, y, z, FORCED_MOVEMENT_RUN, false); - return; - } - } - } - } + // bot->StopMoving(); + // bot->GetMotionMaster()->Clear(); + // bot->NearTeleportTo(x, y, z, bot->GetOrientation()); + // //bot->GetMotionMaster()->MovePoint(bot->GetMapId(), x, y, z, FORCED_MOVEMENT_RUN, false); + // return; + // } + // } + // } + // } } bool MovementAction::Follow(Unit* target, float distance, float angle)