mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 14:37:44 +00:00
Further improvement of crowd logic
This commit is contained in:
parent
373a638703
commit
8fa3fa325d
3 changed files with 53 additions and 22 deletions
|
@ -241,7 +241,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
||||||
|
|
||||||
auto pos1 = pNaviProvider->getMovePos( *this );
|
auto pos1 = pNaviProvider->getMovePos( *this );
|
||||||
|
|
||||||
if( Util::distance( pos1, pos ) < 1.1f )
|
if( Util::distance( pos1, pos ) < ( getScale() / 2 ) )
|
||||||
{
|
{
|
||||||
// Reached destination
|
// Reached destination
|
||||||
face( pos1 );
|
face( pos1 );
|
||||||
|
@ -259,6 +259,41 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
|
||||||
|
{
|
||||||
|
|
||||||
|
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
||||||
|
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
||||||
|
|
||||||
|
if( !pNaviProvider )
|
||||||
|
{
|
||||||
|
Logger::error( "No NaviProvider for zone#{0} - {1}",
|
||||||
|
m_pCurrentZone->getGuId(),
|
||||||
|
m_pCurrentZone->getInternalName() );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pos1 = pNaviProvider->getMovePos( *this );
|
||||||
|
|
||||||
|
if( Util::distance( pos1, targetChara.getPos() ) <= ( ( getScale() / 2 + targetChara.getScale() / 2 ) ) )
|
||||||
|
{
|
||||||
|
// Reached destination
|
||||||
|
face( pos1 );
|
||||||
|
setPos( pos1 );
|
||||||
|
sendPositionUpdate();
|
||||||
|
//pNaviProvider->resetMoveTarget( *this );
|
||||||
|
pNaviProvider->updateAgentPosition( *this );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pCurrentZone->updateActorPosition( *this );
|
||||||
|
face( pos1 );
|
||||||
|
setPos( pos1 );
|
||||||
|
sendPositionUpdate();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Sapphire::Entity::BNpc::sendPositionUpdate()
|
void Sapphire::Entity::BNpc::sendPositionUpdate()
|
||||||
{
|
{
|
||||||
uint8_t unk1 = 0x3a;
|
uint8_t unk1 = 0x3a;
|
||||||
|
@ -411,6 +446,8 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
const uint8_t maxDistanceToOrigin = 40;
|
const uint8_t maxDistanceToOrigin = 40;
|
||||||
const uint32_t roamTick = 20;
|
const uint32_t roamTick = 20;
|
||||||
|
|
||||||
|
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
||||||
|
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
||||||
|
|
||||||
switch( m_state )
|
switch( m_state )
|
||||||
{
|
{
|
||||||
|
@ -422,11 +459,8 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
{
|
{
|
||||||
setInvincibilityType( InvincibilityType::InvincibilityIgnoreDamage );
|
setInvincibilityType( InvincibilityType::InvincibilityIgnoreDamage );
|
||||||
|
|
||||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
|
||||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
|
||||||
if( pNaviProvider )
|
if( pNaviProvider )
|
||||||
{
|
{
|
||||||
//if( !pNaviProvider->hasTargetState( *this ) )
|
|
||||||
pNaviProvider->setMoveTarget( *this, m_spawnPos );
|
pNaviProvider->setMoveTarget( *this, m_spawnPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,13 +483,10 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
|
|
||||||
case BNpcState::Roaming:
|
case BNpcState::Roaming:
|
||||||
{
|
{
|
||||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
|
||||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
|
||||||
|
|
||||||
if( pNaviProvider )
|
if( pNaviProvider )
|
||||||
{
|
{
|
||||||
//if( !pNaviProvider->hasTargetState( *this ) )
|
pNaviProvider->setMoveTarget( *this, m_roamPos );
|
||||||
pNaviProvider->setMoveTarget( *this, m_roamPos );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( moveTo( m_roamPos ) )
|
if( moveTo( m_roamPos ) )
|
||||||
|
@ -474,9 +505,6 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
if( pHatedActor )
|
if( pHatedActor )
|
||||||
aggro( pHatedActor );
|
aggro( pHatedActor );
|
||||||
|
|
||||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
|
||||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
|
||||||
|
|
||||||
if( pNaviProvider->syncPosToChara( *this ) )
|
if( pNaviProvider->syncPosToChara( *this ) )
|
||||||
sendPositionUpdate();
|
sendPositionUpdate();
|
||||||
|
|
||||||
|
@ -513,6 +541,9 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
pHatedActor = hateListGetHighest();
|
pHatedActor = hateListGetHighest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( pNaviProvider->syncPosToChara( *this ) )
|
||||||
|
sendPositionUpdate();
|
||||||
|
|
||||||
if( pHatedActor )
|
if( pHatedActor )
|
||||||
{
|
{
|
||||||
auto distance = Util::distance( getPos().x, getPos().y, getPos().z,
|
auto distance = Util::distance( getPos().x, getPos().y, getPos().z,
|
||||||
|
@ -530,18 +561,16 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !hasFlag( Immobile ) && ( distance > minActorDistance ) )
|
if( distance > ( getScale() / 2 + pHatedActor->getScale() / 2 ) )
|
||||||
{
|
{
|
||||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
if( hasFlag( Immobile ) )
|
||||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
break;
|
||||||
|
|
||||||
if( pNaviProvider )
|
if( pNaviProvider )
|
||||||
{
|
{
|
||||||
//if( !pNaviProvider->hasTargetState( *this ) )
|
|
||||||
pNaviProvider->setMoveTarget( *this, pHatedActor->getPos() );
|
pNaviProvider->setMoveTarget( *this, pHatedActor->getPos() );
|
||||||
}
|
}
|
||||||
//auto pTeriMgr = m_pFw->get< World::Manager::TerritoryMgr >();
|
moveTo( *pHatedActor );
|
||||||
//if ( ( currTime - m_lastAttack ) > 600 && pTeriMgr->isDefaultTerritory( getCurrentZone()->getTerritoryTypeId() ) )
|
|
||||||
moveTo( pHatedActor->getPos() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -666,7 +695,7 @@ void Sapphire::Entity::BNpc::setOwner( Sapphire::Entity::CharaPtr m_pChara )
|
||||||
{
|
{
|
||||||
auto setOwnerPacket = makeZonePacket< FFXIVIpcActorOwner >( getId() );
|
auto setOwnerPacket = makeZonePacket< FFXIVIpcActorOwner >( getId() );
|
||||||
setOwnerPacket->data().type = 0x01;
|
setOwnerPacket->data().type = 0x01;
|
||||||
setOwnerPacket->data().actorId = 0;
|
setOwnerPacket->data().actorId = INVALID_GAME_OBJECT_ID;
|
||||||
sendToInRangeSet( setOwnerPacket );
|
sendToInRangeSet( setOwnerPacket );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@ namespace Sapphire::Entity
|
||||||
// return true if it reached the position
|
// return true if it reached the position
|
||||||
bool moveTo( const Common::FFXIVARR_POSITION3& pos );
|
bool moveTo( const Common::FFXIVARR_POSITION3& pos );
|
||||||
|
|
||||||
|
bool moveTo( const Entity::Chara& targetChara );
|
||||||
|
|
||||||
// processes movement
|
// processes movement
|
||||||
void step();
|
void step();
|
||||||
|
|
||||||
|
|
|
@ -571,11 +571,11 @@ int32_t Sapphire::World::Navi::NaviProvider::addAgent( Entity::Chara& chara )
|
||||||
dtCrowdAgentParams params;
|
dtCrowdAgentParams params;
|
||||||
std::memset( ¶ms, 0, sizeof( params ) );
|
std::memset( ¶ms, 0, sizeof( params ) );
|
||||||
params.height = 7.f;
|
params.height = 7.f;
|
||||||
params.maxAcceleration = 26.f;
|
params.maxAcceleration = 126.f;
|
||||||
params.maxSpeed = 13.5f;
|
params.maxSpeed = 13.5f;
|
||||||
params.radius = chara.getScale() / 2;
|
params.radius = chara.getScale() / 2;
|
||||||
params.collisionQueryRange = params.radius * 12.0f;
|
params.collisionQueryRange = params.radius * 20.0f;
|
||||||
params.pathOptimizationRange = params.radius * 30.0f;
|
params.pathOptimizationRange = params.radius * 10.0f;
|
||||||
params.updateFlags = 0;
|
params.updateFlags = 0;
|
||||||
//params.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE;
|
//params.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE;
|
||||||
float position[] = { chara.getPos().x, chara.getPos().y, chara.getPos().z };
|
float position[] = { chara.getPos().x, chara.getPos().y, chara.getPos().z };
|
||||||
|
|
Loading…
Add table
Reference in a new issue