mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.
DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.
Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.
Before submitting, make sure your changes aligns with these principles.
-->
## Pull Request Description
<!-- Describe what this change does and why it is needed -->
Modification to threat system required for current core update PR.
## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->
<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
- Describe the **processing cost** when this logic executes across many
bots.
## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->
## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
- - [x] No, not at all
- - [ ] Minimal impact (**explain below**)
- - [ ] Moderate impact (**explain below**)
- Does this change modify default bot behavior?
- - [x] No
- - [ ] Yes (**explain why**)
- Does this change add new decision branches or increase maintenance
complexity?
- - [x] No
- - [ ] Yes (**explain below**)
## Messages to Translate
<!--
Bot messages have to be translatable, but you don't need to do the
translations here. You only need to make sure
the message is in a translatable format, and list in the table the
message_key and the default English message.
Search for GetBotTextOrDefault in the codebase for examples.
-->
Does this change add bot messages to translate?
- - [x] No
- - [ ] Yes (**list messages in the table**)
| Message key | Default message |
| --------------- | ------------------ |
| | |
| | |
## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [ ] No
- - [x] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->
Claude. Module search for changes made. It also identified a section of
dead code in EnemyPlayerValue due to incorrect ref that was fixed.
## Final Checklist
- - [X] Stability is not compromised.
- - [X] Performance impact is understood, tested, and acceptable.
- - [X] Added logic complexity is justified and explained.
- - [X] Documentation updated if needed (Conf comments, WiKi commands).
## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
168 lines
5.5 KiB
C++
168 lines
5.5 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 "EnemyPlayerValue.h"
|
|
|
|
#include "CombatManager.h"
|
|
#include "Playerbots.h"
|
|
#include "ServerFacade.h"
|
|
#include "Vehicle.h"
|
|
|
|
bool NearestEnemyPlayersValue::AcceptUnit(Unit* unit)
|
|
{
|
|
// Apply parent's filtering first (includes level difference checks)
|
|
if (!PossibleTargetsValue::AcceptUnit(unit))
|
|
return false;
|
|
|
|
bool inCannon = botAI->IsInVehicle(false, true);
|
|
Player* enemy = dynamic_cast<Player*>(unit);
|
|
if (enemy && botAI->IsOpposing(enemy) && enemy->IsPvP() &&
|
|
!sPlayerbotAIConfig.IsPvpProhibited(enemy->GetZoneId(), enemy->GetAreaId()) &&
|
|
!enemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NON_ATTACKABLE_2) &&
|
|
((inCannon || !enemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE))) &&
|
|
/*!enemy->HasStealthAura() && !enemy->HasInvisibilityAura()*/ enemy->CanSeeOrDetect(bot) &&
|
|
!(enemy->HasSpiritOfRedemptionAura()))
|
|
{
|
|
// If with master, only attack if master is PvP flagged
|
|
Player* master = botAI->GetMaster();
|
|
if (master && !master->IsPvP() && !master->IsFFAPvP())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Unit* EnemyPlayerValue::Calculate()
|
|
{
|
|
bool controllingCannon = false;
|
|
bool controllingVehicle = false;
|
|
if (Vehicle* vehicle = bot->GetVehicle())
|
|
{
|
|
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
|
|
if (!seat || !seat->CanControl()) // not in control of vehicle so cant attack anyone
|
|
return nullptr;
|
|
VehicleEntry const* vi = vehicle->GetVehicleInfo();
|
|
if (vi && vi->m_flags & VEHICLE_FLAG_FIXED_POSITION)
|
|
controllingCannon = true;
|
|
else
|
|
controllingVehicle = true;
|
|
}
|
|
|
|
// 1. Check units we are currently in PvP combat with.
|
|
std::vector<Unit*> targets;
|
|
Unit* pVictim = bot->GetVictim();
|
|
for (auto const& [guid, combatRef] : bot->GetCombatManager().GetPvPCombatRefs())
|
|
{
|
|
Unit* pTarget = combatRef->GetOther(bot);
|
|
if (!pTarget || pTarget == pVictim || !pTarget->IsPlayer() || !pTarget->CanSeeOrDetect(bot) ||
|
|
!bot->IsWithinDist(pTarget, VISIBILITY_DISTANCE_NORMAL))
|
|
continue;
|
|
|
|
if ((bot->GetTeamId() == TEAM_HORDE && Target->HasAura(23333)) ||
|
|
(bot->GetTeamId() == TEAM_ALLIANCE && pTarget->HasAura(23335)))
|
|
return pTarget;
|
|
|
|
targets.push_back(pTarget);
|
|
}
|
|
|
|
if (!targets.empty())
|
|
{
|
|
std::sort(targets.begin(), targets.end(),
|
|
[&](Unit const* pUnit1, Unit const* pUnit2)
|
|
{ return bot->GetDistance(pUnit1) < bot->GetDistance(pUnit2); });
|
|
|
|
return *targets.begin();
|
|
}
|
|
|
|
// 2. Find enemy player in range.
|
|
|
|
GuidVector players = AI_VALUE(GuidVector, "nearest enemy players");
|
|
float const maxAggroDistance = GetMaxAttackDistance();
|
|
for (auto const& gTarget : players)
|
|
{
|
|
Unit* pUnit = botAI->GetUnit(gTarget);
|
|
if (!pUnit)
|
|
continue;
|
|
|
|
Player* pTarget = dynamic_cast<Player*>(pUnit);
|
|
if (!pTarget)
|
|
continue;
|
|
|
|
if (pTarget == pVictim)
|
|
continue;
|
|
|
|
if (bot->GetTeamId() == TEAM_HORDE)
|
|
{
|
|
if (pTarget->HasAura(23333))
|
|
return pTarget;
|
|
}
|
|
else
|
|
{
|
|
if (pTarget->HasAura(23335))
|
|
return pTarget;
|
|
}
|
|
|
|
// Aggro weak enemies from further away.
|
|
// If controlling mobile vehicle only agro close enemies (otherwise will never reach objective)
|
|
uint32 const aggroDistance = controllingVehicle ? 5.0f
|
|
: (controllingCannon || bot->GetHealth() > pTarget->GetHealth()) ? maxAggroDistance
|
|
: 20.0f;
|
|
if (!bot->IsWithinDist(pTarget, aggroDistance))
|
|
continue;
|
|
|
|
if (bot->IsWithinLOSInMap(pTarget) &&
|
|
(controllingCannon || (fabs(bot->GetPositionZ() - pTarget->GetPositionZ()) < 30.0f)))
|
|
return pTarget;
|
|
}
|
|
|
|
// 3. Check party attackers.
|
|
|
|
if (Group* pGroup = bot->GetGroup())
|
|
{
|
|
for (GroupReference* itr = pGroup->GetFirstMember(); itr != nullptr; itr = itr->next())
|
|
{
|
|
if (Unit* pMember = itr->GetSource())
|
|
{
|
|
if (pMember == bot)
|
|
continue;
|
|
|
|
if (ServerFacade::instance().GetDistance2d(bot, pMember) > 30.0f)
|
|
continue;
|
|
|
|
if (Unit* pAttacker = pMember->getAttackerForHelper())
|
|
if (pAttacker->IsPlayer() && bot->IsWithinDist(pAttacker, maxAggroDistance * 2.0f) &&
|
|
bot->IsWithinLOSInMap(pAttacker) && pAttacker != pVictim && pAttacker->CanSeeOrDetect(bot))
|
|
return pAttacker;
|
|
}
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
float EnemyPlayerValue::GetMaxAttackDistance()
|
|
{
|
|
if (!bot->GetBattleground())
|
|
return 60.0f;
|
|
|
|
Battleground* bg = bot->GetBattleground();
|
|
if (!bg)
|
|
return 40.0f;
|
|
|
|
BattlegroundTypeId bgType = bg->GetBgTypeID();
|
|
if (bgType == BATTLEGROUND_RB)
|
|
bgType = bg->GetBgTypeID(true);
|
|
|
|
if (bgType == BATTLEGROUND_IC)
|
|
{
|
|
if (botAI->IsInVehicle(false, true))
|
|
return 120.0f;
|
|
}
|
|
|
|
return 40.0f;
|
|
}
|