Skip to content

Commit

Permalink
Fixed pathing being reset properly
Browse files Browse the repository at this point in the history
  • Loading branch information
SapphireMordred committed Jan 12, 2025
1 parent c0aed54 commit d08906e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 14 deletions.
39 changes: 36 additions & 3 deletions src/world/Actor/BNpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,29 +831,62 @@ bool BNpc::hasFlag( uint32_t flag ) const
{
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 )
{
uint32_t oldFlags = m_flags;
m_flags = 0;
m_flags |= flag;

auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
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 )
{
Logger::debug( "{} {} Pathing deactivated", m_id, getAgentId() );
auto pNaviProvider = pZone->getNaviProvider();
pNaviProvider->removeAgent( *this );
setAgentId( 0 );
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();
pNaviProvider->removeAgent( *this );
if( getAgentId() != -1 )
pNaviProvider->removeAgent( *this );
auto agentId = pNaviProvider->addAgent( *this );
setAgentId( agentId );
setPathingActive( true );
Expand Down
3 changes: 3 additions & 0 deletions src/world/Actor/BNpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ namespace Sapphire::Entity

bool hasFlag( uint32_t flag ) const;
void setFlag( uint32_t flags );

// resets all flags to the given flags
void resetFlags( uint32_t flags );
void removeFlag( uint32_t flag );
void clearFlags();

Expand Down
4 changes: 2 additions & 2 deletions src/world/Actor/Chara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,12 @@ void Chara::setDirectorId( uint32_t directorId )
m_directorId = directorId;
}

uint32_t Chara::getAgentId() const
int32_t Chara::getAgentId() const
{
return m_agentId;
}

void Chara::setAgentId( uint32_t agentId )
void Chara::setAgentId( int32_t agentId )
{
m_agentId = agentId;
}
Expand Down
6 changes: 3 additions & 3 deletions src/world/Actor/Chara.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Sapphire::Entity
std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap;

/*! Detour Crowd AgentId */
uint32_t m_agentId{0};
int32_t m_agentId{-1};

/*! Detour Crowd actor scale */
float m_radius;
Expand Down Expand Up @@ -279,8 +279,8 @@ namespace Sapphire::Entity
uint32_t getDirectorId() const;
void setDirectorId( uint32_t directorId );

uint32_t getAgentId() const;
void setAgentId( uint32_t agentId );
int32_t getAgentId() const;
void setAgentId( int32_t agentId );

float getRadius() const;

Expand Down
2 changes: 1 addition & 1 deletion src/world/Actor/Npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Sapphire::Entity
void setPathingActive( bool pathing );

private:
bool m_bPathingActive{true};
bool m_bPathingActive{false};


};
Expand Down
6 changes: 2 additions & 4 deletions src/world/Encounter/Timepoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,7 @@ namespace Sapphire::Encounter

if( pBNpc )
{
pBNpc->clearFlags();
pBNpc->setFlag( pSpawnData->m_flags );
pBNpc->resetFlags( pSpawnData->m_flags );
pBNpc->init();

pTeri->pushActor( pBNpc );
Expand All @@ -677,8 +676,7 @@ namespace Sapphire::Encounter

if( pBNpc )
{
pBNpc->clearFlags();
pBNpc->setFlag( pBNpcFlagData->m_flags );
pBNpc->resetFlags( pBNpcFlagData->m_flags );
// todo: resend some bnpc packet/actrl?
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/world/Navi/NaviProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ int32_t Sapphire::World::Navi::NaviProvider::addAgent( Entity::Chara& chara )

void Sapphire::World::Navi::NaviProvider::updateAgentParameters( Entity::BNpc& bnpc )
{
if( bnpc.getAgentId() == -1 )
return;
dtCrowdAgentParams params{};
std::memset( &params, 0, sizeof( params ) );
params.height = 3.f;
Expand Down
3 changes: 2 additions & 1 deletion src/world/Territory/Territory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ void Territory::pushActor( const Entity::GameObjectPtr& pActor )
{
auto pBNpc = pActor->getAsBNpc();

if( m_pNaviProvider && pBNpc->pathingActive() )
if( m_pNaviProvider && !pBNpc->hasFlag( Entity::Immobile ) )
{
agentId = m_pNaviProvider->addAgent( *pBNpc );
pBNpc->setAgentId( agentId );
pBNpc->setPathingActive( true );
}

m_bNpcMap[ pBNpc->getId() ] = pBNpc;
Expand Down

0 comments on commit d08906e

Please sign in to comment.