mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-12 21:47:45 +00:00
Fixed pathing being reset properly
This commit is contained in:
parent
c0aed54dfe
commit
d08906e736
8 changed files with 51 additions and 14 deletions
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Sapphire::Entity
|
|||
void setPathingActive( bool pathing );
|
||||
|
||||
private:
|
||||
bool m_bPathingActive{true};
|
||||
bool m_bPathingActive{false};
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -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 );
|
||||
|
@ -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?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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( ¶ms, 0, sizeof( params ) );
|
||||
params.height = 3.f;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue