From c5882e0ed9cfbed46c53e461e6d9ea64cc276dfe Mon Sep 17 00:00:00 2001 From: Mordred Date: Wed, 30 Jan 2019 22:37:58 +0100 Subject: [PATCH] #48 - Fixed bnpcs not despawning properly, aswell as not updating cell as they go --- src/world/Actor/BNpc.cpp | 1 + src/world/Actor/Chara.cpp | 2 -- src/world/Territory/Zone.cpp | 10 +++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index b04fbf2f..77b97740 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -260,6 +260,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos ) step(); + m_pCurrentZone->updateActorPosition( *this ); return false; } diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 3c888b35..8ba8311b 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -240,8 +240,6 @@ bool Sapphire::Entity::Chara::face( const Common::FFXIVARR_POSITION3& p ) float rot = Util::calcAngFrom( getPos().x, getPos().z, p.x, p.z ); float newRot = PI - rot + ( PI / 2 ); - m_pCell = nullptr; - setRot( newRot ); return oldRot != newRot; diff --git a/src/world/Territory/Zone.cpp b/src/world/Territory/Zone.cpp index ffd55a60..4e62c898 100644 --- a/src/world/Territory/Zone.cpp +++ b/src/world/Territory/Zone.cpp @@ -408,6 +408,9 @@ void Sapphire::Zone::updateBNpcs( int64_t tickCount ) } } + // Update loop may move actors from cell to cell, breaking iterator validity + std::vector< Entity::BNpcPtr > m_activeBNpc; + for( uint32_t y = 0; y < _sizeY; ++y ) { for( uint32_t x = 0; x < _sizeX; ++x ) @@ -426,10 +429,15 @@ void Sapphire::Zone::updateBNpcs( int64_t tickCount ) for( const auto& actor : cell->m_actors ) { if( actor->isBattleNpc() ) - actor->getAsBNpc()->update( tickCount ); + m_activeBNpc.push_back( actor->getAsBNpc() ); } } } + + // iterate the cached active bnpcs + for( const auto& actor : m_activeBNpc ) + actor->update( tickCount ); + }