Added some basic functionality to 'bot guard'

This commit is contained in:
Uleat 2018-02-08 16:46:43 -05:00
parent fb8873e77b
commit 0b97db9fd2
3 changed files with 54 additions and 10 deletions

View File

@ -2041,6 +2041,20 @@ void Bot::SetTarget(Mob* mob) {
} }
} }
void Bot::SetGuardMode() {
WipeHateList();
SetTarget(nullptr);
SetFollowID(GetID());
StopMoving();
m_GuardPoint = GetPosition();
if (HasPet()) {
GetPet()->WipeHateList();
GetPet()->SetTarget(nullptr);
GetPet()->StopMoving();
}
}
// AI Processing for the Bot object // AI Processing for the Bot object
void Bot::AI_Process() { void Bot::AI_Process() {
@ -2091,6 +2105,8 @@ void Bot::AI_Process() {
return; return;
} }
bool guard_mode = (follow_mob == this);
auto fm_dist = DistanceSquared(m_Position, follow_mob->GetPosition()); auto fm_dist = DistanceSquared(m_Position, follow_mob->GetPosition());
auto lo_distance = DistanceSquared(m_Position, leash_owner->GetPosition()); auto lo_distance = DistanceSquared(m_Position, leash_owner->GetPosition());
@ -2113,6 +2129,17 @@ void Bot::AI_Process() {
return; return;
if (fm_dist > GetFollowDistance()) // Cancel out-of-combat casting if movement is required if (fm_dist > GetFollowDistance()) // Cancel out-of-combat casting if movement is required
InterruptSpell(); InterruptSpell();
if (guard_mode) {
auto& my_pos = GetPosition();
auto& my_guard = GetGuardPoint();
if (my_pos.x != my_guard.x ||
my_pos.y != my_guard.y ||
my_pos.z != my_guard.z)
{
InterruptSpell();
}
}
return; return;
} }
@ -2147,7 +2174,7 @@ void Bot::AI_Process() {
} }
// Empty hate list - let's find a target // Empty hate list - let's find a target
if (!IsEngaged()) { if (!guard_mode && !IsEngaged()) {
Mob* lo_target = leash_owner->GetTarget(); Mob* lo_target = leash_owner->GetTarget();
if (lo_target && lo_target->IsNPC() && if (lo_target && lo_target->IsNPC() &&
@ -2234,7 +2261,8 @@ void Bot::AI_Process() {
// Let's check if we have a los with our target. // Let's check if we have a los with our target.
// If we don't, our hate_list is wiped. // If we don't, our hate_list is wiped.
// Else, it was causing the bot to aggro behind wall etc... causing massive trains. // Else, it was causing the bot to aggro behind wall etc... causing massive trains.
if (!tar->IsNPC() || if (guard_mode ||
!tar->IsNPC() ||
tar->IsMezzed() || tar->IsMezzed() ||
(!tar->GetHateAmount(this) && !tar->GetHateAmount(leash_owner) && !leash_owner->AutoAttackEnabled()) || (!tar->GetHateAmount(this) && !tar->GetHateAmount(leash_owner) && !leash_owner->AutoAttackEnabled()) ||
lo_distance > BOT_LEASH_DISTANCE || lo_distance > BOT_LEASH_DISTANCE ||
@ -2698,8 +2726,28 @@ void Bot::AI_Process() {
if (m_PlayerState & static_cast<uint32>(PlayerState::Aggressive)) if (m_PlayerState & static_cast<uint32>(PlayerState::Aggressive))
SendRemovePlayerState(PlayerState::Aggressive); SendRemovePlayerState(PlayerState::Aggressive);
// Check guard point
if (guard_mode) {
auto& my_pos = GetPosition();
auto& my_guard = GetGuardPoint();
if (my_pos.x != my_guard.x ||
my_pos.y != my_guard.y ||
my_pos.z != my_guard.z)
{
if (IsMoving())
StopMoving();
Warp(glm::vec3(my_guard));
if (HasPet())
GetPet()->Warp(glm::vec3(my_guard));
return;
}
}
// Leash the bot // Leash the bot
if (lo_distance > BOT_LEASH_DISTANCE) { else if (lo_distance > BOT_LEASH_DISTANCE) {
if (IsMoving()) if (IsMoving())
StopMoving(); StopMoving();

View File

@ -339,6 +339,7 @@ public:
bool IsStanding(); bool IsStanding();
int GetBotWalkspeed() const { return (int)((float)_GetWalkSpeed() * 1.786f); } // 1.25 / 0.7 = 1.7857142857142857142857142857143 int GetBotWalkspeed() const { return (int)((float)_GetWalkSpeed() * 1.786f); } // 1.25 / 0.7 = 1.7857142857142857142857142857143
int GetBotRunspeed() const { return (int)((float)_GetRunSpeed() * 1.786f); } int GetBotRunspeed() const { return (int)((float)_GetRunSpeed() * 1.786f); }
int GetBotFearSpeed() const { return (int)((float)_GetFearSpeed() * 1.786f); }
bool UseDiscipline(uint32 spell_id, uint32 target); bool UseDiscipline(uint32 spell_id, uint32 target);
uint8 GetNumberNeedingHealedInGroup(uint8 hpr, bool includePets); uint8 GetNumberNeedingHealedInGroup(uint8 hpr, bool includePets);
bool GetNeedsCured(Mob *tar); bool GetNeedsCured(Mob *tar);
@ -405,6 +406,7 @@ public:
bool AIHealRotation(Mob* tar, bool useFastHeals); bool AIHealRotation(Mob* tar, bool useFastHeals);
bool GetPauseAI() { return _pauseAI; } bool GetPauseAI() { return _pauseAI; }
void SetPauseAI(bool pause_flag) { _pauseAI = pause_flag; } void SetPauseAI(bool pause_flag) { _pauseAI = pause_flag; }
void SetGuardMode();
// Mob AI Virtual Override Methods // Mob AI Virtual Override Methods
virtual void AI_Process(); virtual void AI_Process();

View File

@ -3047,13 +3047,7 @@ void bot_command_guard(Client *c, const Seperator *sep)
sbl.remove(nullptr); sbl.remove(nullptr);
for (auto bot_iter : sbl) { for (auto bot_iter : sbl) {
bot_iter->WipeHateList(); bot_iter->SetGuardMode();
bot_iter->SetFollowID(0);
if (!bot_iter->GetPet())
continue;
bot_iter->GetPet()->WipeHateList();
bot_iter->GetPet()->SetFollowID(0);
} }
if (sbl.size() == 1) if (sbl.size() == 1)
Bot::BotGroupSay(sbl.front(), "Guarding this position"); Bot::BotGroupSay(sbl.front(), "Guarding this position");