mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 22:47:25 +00:00
fix: faction changes not allowing updated targets (#1437)
* fix faction change issue fixes an issue where enemies who would have their faction changed would not change aggro targets. Tested that stromling mechs and ronin/horsemen in forbidden valley still aggro on spawn as expected. * use erase remove if
This commit is contained in:
parent
54ded62757
commit
2f247b1fc9
@ -1357,17 +1357,11 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
|
||||
}
|
||||
|
||||
if (!other->GetIsDead()) {
|
||||
auto* combat = GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
if (combat != nullptr) {
|
||||
if (GetComponent<BaseCombatAIComponent>() != nullptr) {
|
||||
const auto index = std::find(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), otherEntity);
|
||||
|
||||
if (index != m_TargetsInPhantom.end()) return;
|
||||
|
||||
const auto valid = combat->IsEnemy(otherEntity);
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
m_TargetsInPhantom.push_back(otherEntity);
|
||||
}
|
||||
}
|
||||
@ -1992,25 +1986,21 @@ void Entity::SetNetworkId(const uint16_t id) {
|
||||
m_NetworkID = id;
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() {
|
||||
std::vector<LWOOBJID> valid;
|
||||
|
||||
std::vector<LWOOBJID> Entity::GetTargetsInPhantom() {
|
||||
// Clean up invalid targets, like disconnected players
|
||||
for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) {
|
||||
const auto id = m_TargetsInPhantom.at(i);
|
||||
m_TargetsInPhantom.erase(std::remove_if(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), [](const LWOOBJID id) {
|
||||
return !Game::entityManager->GetEntity(id);
|
||||
}), m_TargetsInPhantom.end());
|
||||
|
||||
auto* entity = Game::entityManager->GetEntity(id);
|
||||
std::vector<LWOOBJID> enemies;
|
||||
for (const auto id : m_TargetsInPhantom) {
|
||||
auto* combat = GetComponent<BaseCombatAIComponent>();
|
||||
if (!combat || !combat->IsEnemy(id)) continue;
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
enemies.push_back(id);
|
||||
}
|
||||
|
||||
valid.push_back(id);
|
||||
}
|
||||
|
||||
m_TargetsInPhantom = valid;
|
||||
|
||||
return m_TargetsInPhantom;
|
||||
return enemies;
|
||||
}
|
||||
|
||||
void Entity::SendNetworkVar(const std::string& data, const SystemAddress& sysAddr) {
|
||||
|
@ -293,7 +293,7 @@ public:
|
||||
/*
|
||||
* Collision
|
||||
*/
|
||||
std::vector<LWOOBJID>& GetTargetsInPhantom();
|
||||
std::vector<LWOOBJID> GetTargetsInPhantom();
|
||||
|
||||
Entity* GetScheduledKiller() { return m_ScheduleKiller; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user