1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-13 14:07:46 +00:00

Fixed pathing being reset properly

This commit is contained in:
Mordred 2025-01-12 21:16:55 +01:00
parent c0aed54dfe
commit d08906e736
8 changed files with 51 additions and 14 deletions

View file

@ -831,28 +831,61 @@ bool BNpc::hasFlag( uint32_t flag ) const
{ {
return m_flags & flag; return m_flags & flag;
} }
void BNpc::resetFlags( uint32_t flags )
{
uint32_t oldFlags = m_flags;
m_flags = 0;
m_flags |= flags;
auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() );
if( pZone && getAgentId() != -1 && ( oldFlags & Entity::Immobile ) != Entity::Immobile &&
( m_flags & Entity::Immobile ) == Entity::Immobile )
{
Logger::debug( "{} {} Pathing deactivated", m_id, getAgentId() );
auto pNaviProvider = pZone->getNaviProvider();
pNaviProvider->removeAgent( *this );
setPathingActive( false );
}
else if( pZone && ( oldFlags & Entity::Immobile ) == Entity::Immobile &&
( m_flags & Entity::Immobile ) != Entity::Immobile )
{
Logger::debug( "{} Pathing activated", m_id );
auto pNaviProvider = pZone->getNaviProvider();
if( getAgentId() != -1 )
pNaviProvider->removeAgent( *this );
auto agentId = pNaviProvider->addAgent( *this );
setAgentId( agentId );
setPathingActive( true );
}
}
void BNpc::setFlag( uint32_t flag ) void BNpc::setFlag( uint32_t flag )
{ {
uint32_t oldFlags = m_flags; uint32_t oldFlags = m_flags;
m_flags = 0;
m_flags |= flag; m_flags |= flag;
auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() );
if( pZone && ( oldFlags & Entity::Immobile ) != Entity::Immobile && if( pZone && getAgentId() != -1 && ( oldFlags & Entity::Immobile ) != Entity::Immobile &&
( m_flags & Entity::Immobile ) == Entity::Immobile ) ( m_flags & Entity::Immobile ) == Entity::Immobile )
{ {
Logger::debug( "{} {} Pathing deactivated", m_id, getAgentId() );
auto pNaviProvider = pZone->getNaviProvider(); auto pNaviProvider = pZone->getNaviProvider();
pNaviProvider->removeAgent( *this ); pNaviProvider->removeAgent( *this );
setAgentId( 0 );
setPathingActive( false ); setPathingActive( false );
} }
else if( pZone && ( oldFlags & Entity::Immobile ) == Entity::Immobile && else if( pZone && ( oldFlags & Entity::Immobile ) == Entity::Immobile &&
( m_flags & Entity::Immobile ) != Entity::Immobile ) ( m_flags & Entity::Immobile ) != Entity::Immobile )
{ {
Logger::debug( "{} Pathing activated", m_id );
auto pNaviProvider = pZone->getNaviProvider(); auto pNaviProvider = pZone->getNaviProvider();
if( getAgentId() != -1 )
pNaviProvider->removeAgent( *this ); pNaviProvider->removeAgent( *this );
auto agentId = pNaviProvider->addAgent( *this ); auto agentId = pNaviProvider->addAgent( *this );
setAgentId( agentId ); setAgentId( agentId );

View file

@ -146,6 +146,9 @@ namespace Sapphire::Entity
bool hasFlag( uint32_t flag ) const; bool hasFlag( uint32_t flag ) const;
void setFlag( uint32_t flags ); void setFlag( uint32_t flags );
// resets all flags to the given flags
void resetFlags( uint32_t flags );
void removeFlag( uint32_t flag ); void removeFlag( uint32_t flag );
void clearFlags(); void clearFlags();

View file

@ -756,12 +756,12 @@ void Chara::setDirectorId( uint32_t directorId )
m_directorId = directorId; m_directorId = directorId;
} }
uint32_t Chara::getAgentId() const int32_t Chara::getAgentId() const
{ {
return m_agentId; return m_agentId;
} }
void Chara::setAgentId( uint32_t agentId ) void Chara::setAgentId( int32_t agentId )
{ {
m_agentId = agentId; m_agentId = agentId;
} }

View file

@ -99,7 +99,7 @@ namespace Sapphire::Entity
std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap; std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap;
/*! Detour Crowd AgentId */ /*! Detour Crowd AgentId */
uint32_t m_agentId{0}; int32_t m_agentId{-1};
/*! Detour Crowd actor scale */ /*! Detour Crowd actor scale */
float m_radius; float m_radius;
@ -279,8 +279,8 @@ namespace Sapphire::Entity
uint32_t getDirectorId() const; uint32_t getDirectorId() const;
void setDirectorId( uint32_t directorId ); void setDirectorId( uint32_t directorId );
uint32_t getAgentId() const; int32_t getAgentId() const;
void setAgentId( uint32_t agentId ); void setAgentId( int32_t agentId );
float getRadius() const; float getRadius() const;

View file

@ -27,7 +27,7 @@ namespace Sapphire::Entity
void setPathingActive( bool pathing ); void setPathingActive( bool pathing );
private: private:
bool m_bPathingActive{true}; bool m_bPathingActive{false};
}; };

View file

@ -662,8 +662,7 @@ namespace Sapphire::Encounter
if( pBNpc ) if( pBNpc )
{ {
pBNpc->clearFlags(); pBNpc->resetFlags( pSpawnData->m_flags );
pBNpc->setFlag( pSpawnData->m_flags );
pBNpc->init(); pBNpc->init();
pTeri->pushActor( pBNpc ); pTeri->pushActor( pBNpc );
@ -677,8 +676,7 @@ namespace Sapphire::Encounter
if( pBNpc ) if( pBNpc )
{ {
pBNpc->clearFlags(); pBNpc->resetFlags( pBNpcFlagData->m_flags );
pBNpc->setFlag( pBNpcFlagData->m_flags );
// todo: resend some bnpc packet/actrl? // todo: resend some bnpc packet/actrl?
} }
} }

View file

@ -586,6 +586,8 @@ int32_t Sapphire::World::Navi::NaviProvider::addAgent( Entity::Chara& chara )
void Sapphire::World::Navi::NaviProvider::updateAgentParameters( Entity::BNpc& bnpc ) void Sapphire::World::Navi::NaviProvider::updateAgentParameters( Entity::BNpc& bnpc )
{ {
if( bnpc.getAgentId() == -1 )
return;
dtCrowdAgentParams params{}; dtCrowdAgentParams params{};
std::memset( &params, 0, sizeof( params ) ); std::memset( &params, 0, sizeof( params ) );
params.height = 3.f; params.height = 3.f;

View file

@ -259,10 +259,11 @@ void Territory::pushActor( const Entity::GameObjectPtr& pActor )
{ {
auto pBNpc = pActor->getAsBNpc(); auto pBNpc = pActor->getAsBNpc();
if( m_pNaviProvider && pBNpc->pathingActive() ) if( m_pNaviProvider && !pBNpc->hasFlag( Entity::Immobile ) )
{ {
agentId = m_pNaviProvider->addAgent( *pBNpc ); agentId = m_pNaviProvider->addAgent( *pBNpc );
pBNpc->setAgentId( agentId ); pBNpc->setAgentId( agentId );
pBNpc->setPathingActive( true );
} }
m_bNpcMap[ pBNpc->getId() ] = pBNpc; m_bNpcMap[ pBNpc->getId() ] = pBNpc;