diff --git a/src/strategy/actions/CheckMountStateAction.cpp b/src/strategy/actions/CheckMountStateAction.cpp index 17660836..12909414 100644 --- a/src/strategy/actions/CheckMountStateAction.cpp +++ b/src/strategy/actions/CheckMountStateAction.cpp @@ -18,31 +18,28 @@ bool CheckMountStateAction::Execute(Event event) AI_VALUE2(bool, "combat", "self target") ? (AI_VALUE(uint8, "attacker count") > 0 ? false : true) : true; bool enemy = AI_VALUE(Unit*, "enemy player target"); // ignore grind target in BG or bots will dismount near any creature (eg: the rams in AV) - bool dps = (AI_VALUE(Unit*, "dps target") || (!bot->InBattleground() && AI_VALUE(Unit*, "grind target"))); + bool dps = AI_VALUE(Unit*, "dps target"); bool fartarget = (enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 40.0f)) || (dps && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), 50.0f)); bool attackdistance = false; - bool chasedistance = false; + // bool chasedistance = false; float attack_distance = 35.0f; if (PlayerbotAI::IsMelee(bot)) { - attack_distance = 10.0f; + attack_distance = 5.0f; } else { - attack_distance = 40.0f; + attack_distance = 30.0f; } - if (enemy) - attack_distance /= 2; if (dps || enemy) { - attackdistance = (enemy || dps) && sServerFacade->IsDistanceLessThan( - AI_VALUE2(float, "distance", "current target"), attack_distance); - chasedistance = - enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 45.0f) && - AI_VALUE2(bool, "moving", "enemy player target"); + Unit* currentTarget = AI_VALUE(Unit*, "current target"); + attackdistance = + (enemy || dps) && currentTarget && + sServerFacade->IsDistanceLessThan(AI_VALUE2(float, "distance", "current target"), attack_distance); } if (bot->IsMounted() && attackdistance) diff --git a/src/strategy/values/Arrow.cpp b/src/strategy/values/Arrow.cpp index adcfcde4..a981eade 100644 --- a/src/strategy/values/Arrow.cpp +++ b/src/strategy/values/Arrow.cpp @@ -48,8 +48,8 @@ WorldLocation ArrowFormation::GetLocationInternal() float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); float z = master->GetPositionZ(); - float ground = master->GetMapHeight(x, y, z + 30.0f); - if (ground <= INVALID_HEIGHT) + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) return Formation::NullLocation; // master->UpdateGroundPositionZ(x, y, z); return WorldLocation(master->GetMapId(), x, y, z); diff --git a/src/strategy/values/Formations.cpp b/src/strategy/values/Formations.cpp index 7036609f..9418b441 100644 --- a/src/strategy/values/Formations.cpp +++ b/src/strategy/values/Formations.cpp @@ -89,12 +89,9 @@ public: float y = master->GetPositionY() + sin(angle) * range; float z = master->GetPositionZ(); - float ground = master->GetMapHeight(x, y, z + 30.0f); - if (ground <= INVALID_HEIGHT) + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) return Formation::NullLocation; - - // z += CONTACT_DISTANCE; - // bot->UpdateAllowedPositionZ(x, y, z); return WorldLocation(master->GetMapId(), x, y, z); } @@ -118,21 +115,39 @@ public: time_t now = time(nullptr); if (!lastChangeTime || now - lastChangeTime >= 3) { - lastChangeTime = now; - dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; - dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; - dr = sqrt(dx * dx + dy * dy); + Player* master = botAI->GetGroupMaster(); + if (!master) + return WorldLocation(); + + float range = sPlayerbotAIConfig->followDistance; + float angle = GetFollowAngle(); + + time_t now = time(nullptr); + if (!lastChangeTime || now - lastChangeTime >= 3) + { + lastChangeTime = now; + dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; + dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance; + dr = sqrt(dx * dx + dy * dy); + } + + float x = master->GetPositionX() + cos(angle) * range + dx; + float y = master->GetPositionY() + sin(angle) * range + dy; + float z = master->GetPositionZ(); + if (!master->GetMap()->CheckCollisionAndGetValidCoords( + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) + return Formation::NullLocation; + // bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), + // bot->GetPositionZ(), x, y, z); + return WorldLocation(master->GetMapId(), x, y, z); } float x = master->GetPositionX() + cos(angle) * range + dx; float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); - float ground = master->GetMapHeight(x, y, z + 30.0f); - if (ground <= INVALID_HEIGHT) + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) return Formation::NullLocation; - - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(x, y, z); return WorldLocation(master->GetMapId(), x, y, z); } @@ -184,13 +199,10 @@ public: float x = target->GetPositionX() + cos(angle) * range; float y = target->GetPositionY() + sin(angle) * range; float z = target->GetPositionZ(); - float ground = target->GetMapHeight(x, y, z + 30.0f); - if (ground <= INVALID_HEIGHT) + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) return Formation::NullLocation; - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(x, y, z); - return WorldLocation(bot->GetMapId(), x, y, z); } }; @@ -350,16 +362,18 @@ public: if (minDist) { - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(minX, minY, z); + if (!master->GetMap()->CheckCollisionAndGetValidCoords( + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) + return Formation::NullLocation; return WorldLocation(bot->GetMapId(), minX, minY, z); } return Formation::NullLocation; } - z += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(x, y, z); + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) + return Formation::NullLocation; return WorldLocation(bot->GetMapId(), x, y, z); } }; @@ -618,12 +632,12 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector line, float dif float lx = x + cos(angle) * radius; float ly = y + sin(angle) * radius; float lz = cz; - float ground = bot->GetMapHeight(lx, ly, lz + 30.0f); - if (ground <= INVALID_HEIGHT) + + Player* master = botAI->GetMaster(); + if (!master->GetMap()->CheckCollisionAndGetValidCoords( + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz)) return Formation::NullLocation; - lz += CONTACT_DISTANCE; - bot->UpdateAllowedPositionZ(lx, ly, lz); return WorldLocation(bot->GetMapId(), lx, ly, lz); }