Files
mod-playerbots/src/strategy/actions/ChooseTargetActions.cpp
2025-01-01 21:10:05 +08:00

173 lines
5.3 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 "ChooseTargetActions.h"
#include "ChooseRpgTargetAction.h"
#include "Event.h"
#include "LootObjectStack.h"
#include "NewRpgStrategy.h"
#include "Playerbots.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), 75.0f) &&
PlayerHasFlag::IsCapturingFlag(bot);
}
bool AttackAnythingAction::isUseful()
{
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot not allowed to be active
return false;
if (!AI_VALUE(bool, "can move around"))
return false;
// if (context->GetValue<TravelTarget*>("travel target")->Get()->isTraveling() &&
// ChooseRpgTargetAction::isFollowValid(
// bot, *context->GetValue<TravelTarget*>("travel target")->Get()->getPosition())) // Bot is traveling
// return false;
Unit* target = GetTarget();
if (!target)
return false;
bool inactiveGrindStatus = botAI->rpgInfo.status == NewRpgStatus::GO_GRIND ||
botAI->rpgInfo.status == NewRpgStatus::NEAR_NPC ||
botAI->rpgInfo.status == NewRpgStatus::REST ||
botAI->rpgInfo.status == NewRpgStatus::GO_INNKEEPER;
if (inactiveGrindStatus && bot->GetDistance(target) > 25.0f)
return false;
std::string const name = std::string(target->GetName());
// Check for invalid targets: Dummy, Charge Target, Melee Target, Ranged Target
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; // Target is one of the disallowed types
}
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);
// botAI->InterruptSpell();
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");
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;
}