mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49:25 +02:00
# Pull Request
- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )
Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
---
## 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
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
79 lines
2.5 KiB
C++
79 lines
2.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 "RtiTargetValue.h"
|
|
|
|
#include "AttackersValue.h"
|
|
#include "Playerbots.h"
|
|
#include "ServerFacade.h"
|
|
|
|
int32 RtiTargetValue::GetRtiIndex(std::string const rti)
|
|
{
|
|
int32 index = -1;
|
|
if (rti == "star")
|
|
index = 0;
|
|
else if (rti == "circle")
|
|
index = 1;
|
|
else if (rti == "diamond")
|
|
index = 2;
|
|
else if (rti == "triangle")
|
|
index = 3;
|
|
else if (rti == "moon")
|
|
index = 4;
|
|
else if (rti == "square")
|
|
index = 5;
|
|
else if (rti == "cross")
|
|
index = 6;
|
|
else if (rti == "skull")
|
|
index = 7;
|
|
|
|
return index;
|
|
}
|
|
|
|
Unit* RtiTargetValue::Calculate()
|
|
{
|
|
Group* group = bot->GetGroup();
|
|
if (!group)
|
|
return nullptr;
|
|
|
|
std::string const rti = AI_VALUE(std::string, type);
|
|
int32 index = GetRtiIndex(rti);
|
|
|
|
if (index == -1)
|
|
return nullptr;
|
|
|
|
ObjectGuid guid = group->GetTargetIcon(index);
|
|
if (!guid)
|
|
return nullptr;
|
|
|
|
//////////////////////////////////////////////////////begin: delete below check
|
|
// Some units that need to be killed in battle are not on the list of attackers,
|
|
// such as the Kor'kron Battle-Mage in Icecrown Citadel.
|
|
|
|
// GuidVector attackers = context->GetValue<GuidVector >("attackers")->Get();
|
|
// if (find(attackers.begin(), attackers.end(), guid) == attackers.end())
|
|
// return nullptr;
|
|
//
|
|
//////////////////////////////////////////////////////end: delete below check
|
|
|
|
Unit* unit = botAI->GetUnit(guid);
|
|
if (!unit || unit->isDead() || !bot->IsWithinLOSInMap(unit) || !AttackersValue::IsValidTarget(unit, bot) ||
|
|
ServerFacade::instance().IsDistanceGreaterThan(ServerFacade::instance().GetDistance2d(bot, unit),
|
|
sPlayerbotAIConfig.sightDistance))
|
|
return nullptr;
|
|
|
|
// Also prevent chasing raid icon targets that are too far away from the master,
|
|
// even if they are technically visible to the bot.
|
|
if (Player* master = botAI->GetMaster())
|
|
{
|
|
if (master->IsInWorld() && master->GetMapId() == unit->GetMapId() &&
|
|
ServerFacade::instance().IsDistanceGreaterThan(ServerFacade::instance().GetDistance2d(master, unit),
|
|
sPlayerbotAIConfig.sightDistance))
|
|
return nullptr;
|
|
}
|
|
|
|
return unit;
|
|
}
|