mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 17:09:08 +00:00
This PR fixes #1833 where bots could keep chasing a raid target icon (usually skull) across very large distances or even different maps after the mark was set. It replaces the previous attempt with a simpler design that keeps values generic and moves context logic into triggers/actions. Changes - RtiTargetValue now ignores RTI targets that are farther than sPlayerbotAIConfig->sightDistance from the bot or the master (same map only), while still using AttackersValue::IsValidTarget and LOS checks. - AttackersValue is reverted to its original behavior (no special RTI + IsInCombat logic). - RTI triggers only react to "rti target" in combat, as suggested in review (“that condition should be check in trigger…”). - AttackRtiTargetAction keeps a small local fallback: if "rti target" is null, it resolves the raid icon directly from the group so chat commands like “attack rti target” still work, including out of combat. Behavior - Bots no longer run across the world to chase a stale skull far away from the group. - When the group comes back near the marked mob (within sight distance), the skull is again used as a normal focus hint. - Automatic RTI behavior is limited to combat via triggers, while explicit chat commands still work out of combat. Testing - Marked a mob with skull, killed it, moved far away / changed zone, then let it respawn: bots did not chase it from afar. - In a normal dungeon/raid pack, bots still focus skull in combat. - Passing near a previously marked mob: bots only react once it is back within sight distance. --------- Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
184 lines
5.6 KiB
C++
184 lines
5.6 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
|
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#include "ChooseTargetActions.h"
|
|
|
|
#include "ChooseRpgTargetAction.h"
|
|
#include "Event.h"
|
|
#include "LootObjectStack.h"
|
|
#include "NewRpgStrategy.h"
|
|
#include "Playerbots.h"
|
|
#include "RtiTargetValue.h"
|
|
#include "PossibleRpgTargetsValue.h"
|
|
#include "PvpTriggers.h"
|
|
#include "ServerFacade.h"
|
|
|
|
bool AttackEnemyPlayerAction::isUseful()
|
|
{
|
|
if (PlayerHasFlag::IsCapturingFlag(bot))
|
|
return false;
|
|
|
|
return !sPlayerbotAIConfig->IsPvpProhibited(bot->GetZoneId(), bot->GetAreaId());
|
|
}
|
|
|
|
bool AttackEnemyFlagCarrierAction::isUseful()
|
|
{
|
|
Unit* target = context->GetValue<Unit*>("enemy flag carrier")->Get();
|
|
return target && sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target), 100.0f) &&
|
|
PlayerHasFlag::IsCapturingFlag(bot);
|
|
}
|
|
|
|
bool AttackAnythingAction::isUseful()
|
|
{
|
|
if (!bot || !botAI) // Prevents invalid accesses
|
|
return false;
|
|
|
|
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot cannot be active
|
|
return false;
|
|
|
|
if (botAI->HasStrategy("stay", BOT_STATE_NON_COMBAT))
|
|
return false;
|
|
|
|
if (bot->IsInCombat())
|
|
return false;
|
|
|
|
Unit* target = GetTarget();
|
|
if (!target || !target->IsInWorld()) // Checks if the target is valid and in the world
|
|
return false;
|
|
|
|
std::string const name = std::string(target->GetName());
|
|
if (!name.empty() &&
|
|
(name.find("Dummy") != std::string::npos ||
|
|
name.find("Charge Target") != std::string::npos ||
|
|
name.find("Melee Target") != std::string::npos ||
|
|
name.find("Ranged Target") != std::string::npos))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool DropTargetAction::Execute(Event event)
|
|
{
|
|
Unit* target = context->GetValue<Unit*>("current target")->Get();
|
|
if (target && target->isDead())
|
|
{
|
|
ObjectGuid guid = target->GetGUID();
|
|
if (guid)
|
|
context->GetValue<LootObjectStack*>("available loot")->Get()->Add(guid);
|
|
}
|
|
|
|
// ObjectGuid pullTarget = context->GetValue<ObjectGuid>("pull target")->Get();
|
|
// GuidVector possible = botAI->GetAiObjectContext()->GetValue<GuidVector>("possible targets no los")->Get();
|
|
|
|
// if (pullTarget && find(possible.begin(), possible.end(), pullTarget) == possible.end())
|
|
// {
|
|
// context->GetValue<ObjectGuid>("pull target")->Set(ObjectGuid::Empty);
|
|
// }
|
|
|
|
context->GetValue<Unit*>("current target")->Set(nullptr);
|
|
|
|
bot->SetTarget(ObjectGuid::Empty);
|
|
bot->SetSelection(ObjectGuid());
|
|
botAI->ChangeEngine(BOT_STATE_NON_COMBAT);
|
|
if (bot->getClass() == CLASS_HUNTER) // Check for Hunter Class
|
|
{
|
|
Spell const* spell = bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL); // Get the current spell being cast by the bot
|
|
if (spell && spell->m_spellInfo->Id == 75) //Check spell is not nullptr before accessing m_spellInfo
|
|
bot->InterruptSpell(CURRENT_AUTOREPEAT_SPELL); // Interrupt Auto Shot
|
|
}
|
|
bot->AttackStop();
|
|
|
|
// if (Pet* pet = bot->GetPet())
|
|
// {
|
|
// if (CreatureAI* creatureAI = ((Creature*)pet)->AI())
|
|
// {
|
|
// pet->SetReactState(REACT_PASSIVE);
|
|
// pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
|
|
// pet->GetCharmInfo()->SetIsCommandFollow(true);
|
|
// pet->AttackStop();
|
|
// pet->GetCharmInfo()->IsReturning();
|
|
// pet->GetMotionMaster()->MoveFollow(bot, PET_FOLLOW_DIST, pet->GetFollowAngle());
|
|
// }
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
|
|
bool AttackAnythingAction::Execute(Event event)
|
|
{
|
|
bool result = AttackAction::Execute(event);
|
|
if (result)
|
|
{
|
|
if (Unit* grindTarget = GetTarget())
|
|
{
|
|
if (char const* grindName = grindTarget->GetName().c_str())
|
|
{
|
|
context->GetValue<ObjectGuid>("pull target")->Set(grindTarget->GetGUID());
|
|
bot->GetMotionMaster()->Clear();
|
|
// bot->StopMoving();
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
bool AttackAnythingAction::isPossible() { return AttackAction::isPossible() && GetTarget(); }
|
|
|
|
bool DpsAssistAction::isUseful()
|
|
{
|
|
if (PlayerHasFlag::IsCapturingFlag(bot))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool AttackRtiTargetAction::Execute(Event event)
|
|
{
|
|
Unit* rtiTarget = AI_VALUE(Unit*, "rti target");
|
|
|
|
// Fallback: if the "rti target" value did not resolve a valid unit yet,
|
|
// try to resolve the raid icon directly from the group.
|
|
if (!rtiTarget)
|
|
{
|
|
if (Group* group = bot->GetGroup())
|
|
{
|
|
std::string const rti = AI_VALUE(std::string, "rti");
|
|
int32 const index = RtiTargetValue::GetRtiIndex(rti);
|
|
if (index >= 0)
|
|
{
|
|
ObjectGuid const guid = group->GetTargetIcon(index);
|
|
if (!guid.IsEmpty())
|
|
rtiTarget = botAI->GetUnit(guid);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (rtiTarget && rtiTarget->IsInWorld() && rtiTarget->GetMapId() == bot->GetMapId())
|
|
{
|
|
botAI->GetAiObjectContext()->GetValue<GuidVector>("prioritized targets")->Set({rtiTarget->GetGUID()});
|
|
bool result = Attack(botAI->GetUnit(rtiTarget->GetGUID()));
|
|
if (result)
|
|
{
|
|
context->GetValue<ObjectGuid>("pull target")->Set(rtiTarget->GetGUID());
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
botAI->TellError("I dont see my rti attack target");
|
|
|
|
return false;
|
|
}
|
|
|
|
bool AttackRtiTargetAction::isUseful()
|
|
{
|
|
if (botAI->ContainsStrategy(STRATEGY_TYPE_HEAL))
|
|
return false;
|
|
|
|
return true;
|
|
}
|