Files
mod-playerbots/src/strategy/actions/FollowActions.cpp
ThePenguinMan96 aa6f8153a1 Tame Chat Action / Pet Chat Action (stances/commands)
Hello everyone,

I am on a quest to make bot's pets completely functional, focuses on solving issues #1351 , #1230 , and #1137 . This PR achieves the following:

1. Changes the current "pet" chat command to "tame", which is more intuitive that only hunters can use it. The modes are "tame name (name)", "tame id (id)", "tame family (family)", "tame rename (new name)", and "tame abandon". Tame abandon is new - it simply abandons the current pet. Also, now, if you type in "tame family" by itself, it will list the available families. See pictures below for examples.
2. Added new "pet" chat command, with the following modes: "pet passive", "pet aggressive", "pet defensive", "pet stance" (shows current pet stance), "pet attack", "pet follow", and "pet stay". Previously, the pet's stance was not changeable, and there were some less than desired effects from summonable pets - see the issues above.
3. New config option: AiPlayerbot.DefaultPetStance, which changes the stance that all bot's pets are summoned as. This makes sure when feral spirits or treants are summoned by shamans and druids, they are immediately set to this configured stance. Set as 1 as default, which is defensive. (0 = Passive, 1 = Defensive, 2 = Aggressive)
4. New config option: AiPlayerbot.PetChatCommandDebug, which enables debug messages for the "pet" chat command. By default it is set to 0, which is disabled, but if you would like to see when pet's stances are changed, or when you tell the pet to attack/follow/stay, and when pet spells are auto-toggled, this is an option. I made this for myself mainly to test the command - if anyone notices any wierd pet behavior, this will be an option to help them report it as well.
5. Modified FollowActions to not constantly execute the petfollow action, overriding any stay or attack commands issued.
6. Modified GenericActions to have TogglePetSpellAutoCastAction optionally log when spells are toggled based on AiPlayerbot.PetChatCommandDebug.
7. Modified PetAttackAction to not attack if the pet is set to passive, and not override the pet's stance to passive every time it was executed.
8. Modified CombatStrategy.cpp to not constantly issue the petattack command, respecting the "pet stay" and "pet follow" commands. Pets will still automatically attack the enemy if set to aggressive or defensive.
9. Warlocks, Priests, Hunters, Shamans, Mages, Druids, and DKs (all classes that have summons): Added a "new pet" trigger that executes the "set pet stance" action. The "new pet" trigger happens only once, upon summoning a pet. It sets the pet's stance from AiPlayerbot.DefaultPetStance's value.
2025-08-01 01:18:16 -07:00

171 lines
4.7 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
* and/or modify it under version 2 of the License, or (at your option), any later version.
*/
#include "FollowActions.h"
#include <cstddef>
#include "Event.h"
#include "Formations.h"
#include "LastMovementValue.h"
#include "PlayerbotAI.h"
#include "Playerbots.h"
#include "ServerFacade.h"
#include "SharedDefines.h"
bool FollowAction::Execute(Event event)
{
Formation* formation = AI_VALUE(Formation*, "formation");
std::string const target = formation->GetTargetName();
bool moved = false;
if (!target.empty())
{
moved = Follow(AI_VALUE(Unit*, target));
}
else
{
WorldLocation loc = formation->GetLocation();
if (Formation::IsNullLocation(loc) || loc.GetMapId() == -1)
return false;
MovementPriority priority = botAI->GetState() == BOT_STATE_COMBAT ? MovementPriority::MOVEMENT_COMBAT : MovementPriority::MOVEMENT_NORMAL;
moved = MoveTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), false, false, false,
true, priority, true);
}
// This section has been commented out because it was forcing the pet to
// follow the bot on every "follow" action tick, overriding any attack or
// stay commands that might have been issued by the player.
// if (Pet* pet = bot->GetPet())
// {
// botAI->PetFollow();
// }
// if (moved)
// botAI->SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
return moved;
}
bool FollowAction::isUseful()
{
// move from group takes priority over follow as it's added and removed automatically
// (without removing/adding follow)
if (botAI->HasStrategy("move from group", BOT_STATE_COMBAT) ||
botAI->HasStrategy("move from group", BOT_STATE_NON_COMBAT))
return false;
if (bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != nullptr)
return false;
Formation* formation = AI_VALUE(Formation*, "formation");
if (!formation)
return false;
std::string const target = formation->GetTargetName();
Unit* fTarget = nullptr;
if (!target.empty())
fTarget = AI_VALUE(Unit*, target);
else
fTarget = AI_VALUE(Unit*, "master target");
if (fTarget)
{
if (fTarget->HasUnitState(UNIT_STATE_IN_FLIGHT))
return false;
if (!CanDeadFollow(fTarget))
return false;
if (fTarget->GetGUID() == bot->GetGUID())
return false;
}
float distance = 0.f;
if (!target.empty())
{
distance = AI_VALUE2(float, "distance", target);
}
else
{
WorldLocation loc = formation->GetLocation();
if (Formation::IsNullLocation(loc) || bot->GetMapId() != loc.GetMapId())
return false;
distance = bot->GetDistance(loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ());
}
return sServerFacade->IsDistanceGreaterThan(distance, formation->GetMaxDistance());
}
bool FollowAction::CanDeadFollow(Unit* target)
{
// In battleground, wait for spirit healer
if (bot->InBattleground() && !bot->IsAlive())
return false;
// Move to corpse when dead and player is alive or not a ghost.
if (!bot->IsAlive() && (target->IsAlive() || !target->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)))
return false;
return true;
}
bool FleeToMasterAction::Execute(Event event)
{
Unit* fTarget = AI_VALUE(Unit*, "master target");
bool canFollow = Follow(fTarget);
if (!canFollow)
{
// botAI->SetNextCheckDelay(5000);
return false;
}
WorldPosition targetPos(fTarget);
WorldPosition bosPos(bot);
float distance = bosPos.fDist(targetPos);
if (distance < sPlayerbotAIConfig->reactDistance * 3)
{
if (!urand(0, 3))
botAI->TellMaster("I am close, wait for me!");
}
else if (distance < 1000)
{
if (!urand(0, 10))
botAI->TellMaster("I heading to your position.");
}
else if (!urand(0, 20))
botAI->TellMaster("I am traveling to your position.");
botAI->SetNextCheckDelay(3000);
return true;
}
bool FleeToMasterAction::isUseful()
{
if (!botAI->GetGroupMaster())
return false;
if (botAI->GetGroupMaster() == bot)
return false;
Unit* target = AI_VALUE(Unit*, "current target");
if (target && botAI->GetGroupMaster()->GetTarget() == target->GetGUID())
return false;
if (!botAI->HasStrategy("follow", BOT_STATE_NON_COMBAT))
return false;
Unit* fTarget = AI_VALUE(Unit*, "master target");
if (!CanDeadFollow(fTarget))
return false;
return true;
}