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.
This commit is contained in:
David Markowitz 2024-01-26 02:20:00 -08:00
parent 5225c86d65
commit a67ef6336f
2 changed files with 15 additions and 21 deletions

View File

@ -1357,17 +1357,11 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
} }
if (!other->GetIsDead()) { if (!other->GetIsDead()) {
auto* combat = GetComponent<BaseCombatAIComponent>(); if (GetComponent<BaseCombatAIComponent>() != nullptr) {
if (combat != nullptr) {
const auto index = std::find(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), otherEntity); const auto index = std::find(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), otherEntity);
if (index != m_TargetsInPhantom.end()) return; if (index != m_TargetsInPhantom.end()) return;
const auto valid = combat->IsEnemy(otherEntity);
if (!valid) return;
m_TargetsInPhantom.push_back(otherEntity); m_TargetsInPhantom.push_back(otherEntity);
} }
} }
@ -1992,25 +1986,25 @@ void Entity::SetNetworkId(const uint16_t id) {
m_NetworkID = id; m_NetworkID = id;
} }
std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() { std::vector<LWOOBJID> Entity::GetTargetsInPhantom() {
std::vector<LWOOBJID> valid;
// Clean up invalid targets, like disconnected players // Clean up invalid targets, like disconnected players
for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) { for (auto i = 0u; i < m_TargetsInPhantom.size(); ) {
const auto id = m_TargetsInPhantom.at(i); if (Game::entityManager->GetEntity(m_TargetsInPhantom.at(i))) {
i++;
auto* entity = Game::entityManager->GetEntity(id);
if (entity == nullptr) {
continue; continue;
} }
m_TargetsInPhantom.erase(m_TargetsInPhantom.begin() + i);
valid.push_back(id);
} }
m_TargetsInPhantom = valid; std::vector<LWOOBJID> enemies;
for (const auto id : m_TargetsInPhantom) {
auto* combat = GetComponent<BaseCombatAIComponent>();
if (!combat || !combat->IsEnemy(id)) continue;
return m_TargetsInPhantom; enemies.push_back(id);
}
return enemies;
} }
void Entity::SendNetworkVar(const std::string& data, const SystemAddress& sysAddr) { void Entity::SendNetworkVar(const std::string& data, const SystemAddress& sysAddr) {

View File

@ -293,7 +293,7 @@ public:
/* /*
* Collision * Collision
*/ */
std::vector<LWOOBJID>& GetTargetsInPhantom(); std::vector<LWOOBJID> GetTargetsInPhantom();
Entity* GetScheduledKiller() { return m_ScheduleKiller; } Entity* GetScheduledKiller() { return m_ScheduleKiller; }