Improve attackaction failure message system (#1498)

This commit is contained in:
brighton-chi
2025-08-03 16:12:33 -05:00
committed by GitHub
parent ee99b66d04
commit a6c07ca16d

View File

@@ -59,10 +59,7 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
bool sameTarget = oldTarget == target && bot->GetVictim() == target;
bool inCombat = botAI->GetState() == BOT_STATE_COMBAT;
bool sameAttackMode = bot->HasUnitState(UNIT_STATE_MELEE_ATTACKING) == shouldMelee;
// there's no reason to do attack again
if (sameTarget && inCombat && sameAttackMode)
return false;
if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE ||
bot->HasUnitState(UNIT_STATE_IN_FLIGHT))
{
@@ -82,52 +79,53 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
if (!target->IsInWorld())
{
if (verbose)
botAI->TellError(std::string(target->GetName()) + " is no longer in the world.");
return false;
}
if ((sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId()) ||
sPlayerbotAIConfig->IsInPvpProhibitedArea(bot->GetAreaId()))
&& (target->IsPlayer() || target->IsPet()))
{
if (verbose)
botAI->TellError("I cannot attack other players in PvP prohibited areas.");
return false;
}
if (bot->IsFriendlyTo(target))
{
if (verbose)
botAI->TellError(std::string(target->GetName()) + " is friendly to me.");
return false;
}
if (target->isDead())
{
if (verbose)
botAI->TellError(std::string(target->GetName()) + " is dead.");
return false;
}
if (!bot->IsWithinLOSInMap(target))
{
if (verbose)
botAI->TellError(std::string(target->GetName()) + " is not in my sight.");
return false;
}
if (sameTarget && inCombat && sameAttackMode)
{
if (verbose)
botAI->TellError("I am already attacking " + std::string(target->GetName()) + ".");
return false;
}
if (!bot->IsValidAttackTarget(target))
{
if (verbose)
botAI->TellError("I cannot attack an invalid target");
return false;
}
std::ostringstream msg;
msg << target->GetName();
if (bot->IsFriendlyTo(target))
{
msg << " is friendly to me";
if (verbose)
botAI->TellError(msg.str());
return false;
}
if (!bot->IsWithinLOSInMap(target))
{
msg << " is not in my sight";
if (verbose)
botAI->TellError(msg.str());
return false;
}
if (target->isDead())
{
msg << " is dead";
if (verbose)
botAI->TellError(msg.str());
return false;
}
if (sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId())
&& (target->IsPlayer() || target->IsPet()))
{
if (verbose)
botAI->TellError("I cannot attack others in PvP prohibited zones");
botAI->TellError("I cannot attack an invalid target.");
return false;
}
@@ -141,9 +139,7 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
ObjectGuid guid = target->GetGUID();
bot->SetSelection(target->GetGUID());
context->GetValue<Unit*>("old target")->Set(oldTarget);
context->GetValue<Unit*>("old target")->Set(oldTarget);
context->GetValue<Unit*>("current target")->Set(target);
context->GetValue<LootObjectStack*>("available loot")->Get()->Add(guid);
@@ -157,7 +153,6 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
bot->StopMoving();
}
if (IsMovingAllowed() && !bot->HasInArc(CAST_ANGLE_IN_FRONT, target))
{
sServerFacade->SetFacingTo(bot, target);