mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-29 07:37:45 +00:00
Improve path finding and stop position of mobs, also auto attack distance fixed
This commit is contained in:
parent
a5ba5bb2fb
commit
ab1fbd833e
5 changed files with 29 additions and 32 deletions
|
@ -67,12 +67,12 @@ float Util::calcAngFrom( float x, float y, float x1, float y1 )
|
||||||
|
|
||||||
uint16_t Util::floatToUInt16( float val )
|
uint16_t Util::floatToUInt16( float val )
|
||||||
{
|
{
|
||||||
return static_cast< uint16_t >( ( ( val + 1000.0f ) * 100.0f) * 0.32767501f );
|
return static_cast< uint16_t >( ( ( val + 1000.0f ) * 100.0f ) * 0.32767501f );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Util::floatToUInt16Rot( float val )
|
uint16_t Util::floatToUInt16Rot( float val )
|
||||||
{
|
{
|
||||||
return static_cast< uint16_t >( ( ( ( val + 3.1415927f ) * 100.f) * 103.30219106f ) );
|
return static_cast< uint16_t >( ( ( ( val + 3.1415927f ) * 100.f ) * 103.30219106f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Util::floatToUInt8Rot( float val )
|
uint8_t Util::floatToUInt8Rot( float val )
|
||||||
|
|
|
@ -150,14 +150,15 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance
|
||||||
auto modelChara = exdData.getRow< Component::Excel::ModelChara >( bNpcBaseData->data().Model );
|
auto modelChara = exdData.getRow< Component::Excel::ModelChara >( bNpcBaseData->data().Model );
|
||||||
if( modelChara )
|
if( modelChara )
|
||||||
{
|
{
|
||||||
auto modelSkeleton = exdData.getRow< Component::Excel::ModelSkeleton >( modelChara->data().ModelType );
|
auto modelSkeleton = exdData.getRow< Component::Excel::ModelSkeleton >( modelChara->data().SkeletonId );
|
||||||
if( modelSkeleton )
|
if( modelSkeleton )
|
||||||
|
{
|
||||||
m_radius *= modelSkeleton->data().Radius;
|
m_radius *= modelSkeleton->data().Radius;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo: is this actually good?
|
// todo: is this actually good?
|
||||||
//m_naviTargetReachedDistance = m_scale * 2.f;
|
m_naviTargetReachedDistance = m_radius * 2;
|
||||||
m_naviTargetReachedDistance = 4.f;
|
|
||||||
|
|
||||||
calculateStats();
|
calculateStats();
|
||||||
|
|
||||||
|
@ -267,8 +268,7 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: is this actually good?
|
// todo: is this actually good?
|
||||||
//m_naviTargetReachedDistance = m_scale * 2.f;
|
m_naviTargetReachedDistance = m_radius;
|
||||||
m_naviTargetReachedDistance = 4.f;
|
|
||||||
|
|
||||||
calculateStats();
|
calculateStats();
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,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 ) < getRadius() + 3.f )
|
if( Util::distance( pos1, pos ) < getNaviTargetReachedDistance() )
|
||||||
{
|
{
|
||||||
// Reached destination
|
// Reached destination
|
||||||
face( pos );
|
face( pos );
|
||||||
|
@ -386,26 +386,25 @@ bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
|
||||||
|
|
||||||
if( !pNaviProvider )
|
if( !pNaviProvider )
|
||||||
{
|
{
|
||||||
Logger::error( "No NaviProvider for zone#{0} - {1}",
|
Logger::error( "No NaviProvider for zone#{0} - {1}", m_pCurrentTerritory->getGuId(), m_pCurrentTerritory->getInternalName() );
|
||||||
m_pCurrentTerritory->getGuId(),
|
|
||||||
m_pCurrentTerritory->getInternalName() );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pos1 = pNaviProvider->getMovePos( *this );
|
auto pos1 = pNaviProvider->getMovePos( *this );
|
||||||
|
|
||||||
if( Util::distance( pos1, targetChara.getPos() ) <= ( getRadius() + targetChara.getRadius() ) + 3.f )
|
if( Util::distance( pos1, targetChara.getPos() ) <= ( getNaviTargetReachedDistance() + targetChara.getRadius() ) )
|
||||||
{
|
{
|
||||||
// Reached destination
|
// Reached destination
|
||||||
face( targetChara.getPos() );
|
face( targetChara.getPos() );
|
||||||
setPos( pos1 );
|
setPos( pos1 );
|
||||||
sendPositionUpdate();
|
sendPositionUpdate();
|
||||||
|
pNaviProvider->resetMoveTarget( *this );
|
||||||
pNaviProvider->updateAgentPosition( *this );
|
pNaviProvider->updateAgentPosition( *this );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCurrentTerritory->updateActorPosition( *this );
|
m_pCurrentTerritory->updateActorPosition( *this );
|
||||||
face( targetChara.getPos() );
|
face( { ( pos1.x - getPos().x ) + pos1.x, 1, (pos1.z - getPos().z ) + pos1.z } );
|
||||||
setPos( pos1 );
|
setPos( pos1 );
|
||||||
sendPositionUpdate();
|
sendPositionUpdate();
|
||||||
return false;
|
return false;
|
||||||
|
@ -654,8 +653,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
|
|
||||||
pNaviProvider->updateAgentParameters( *this );
|
pNaviProvider->updateAgentParameters( *this );
|
||||||
|
|
||||||
auto distanceOrig = Util::distance( getPos().x, getPos().y, getPos().z,
|
auto distanceOrig = Util::distance( getPos().x, getPos().y, getPos().z, m_spawnPos.x, m_spawnPos.y, m_spawnPos.z );
|
||||||
m_spawnPos.x, m_spawnPos.y, m_spawnPos.z );
|
|
||||||
|
|
||||||
if( pHatedActor && !pHatedActor->isAlive() )
|
if( pHatedActor && !pHatedActor->isAlive() )
|
||||||
{
|
{
|
||||||
|
@ -663,9 +661,6 @@ 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,
|
||||||
|
@ -681,7 +676,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( distance > ( getRadius() + pHatedActor->getRadius() ) )
|
if( distance > ( getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
|
||||||
{
|
{
|
||||||
if( hasFlag( Immobile ) )
|
if( hasFlag( Immobile ) )
|
||||||
break;
|
break;
|
||||||
|
@ -692,7 +687,10 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
||||||
moveTo( *pHatedActor );
|
moveTo( *pHatedActor );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( distance < ( getRadius() + pHatedActor->getRadius() + 3.f ) )
|
if( pNaviProvider->syncPosToChara( *this ) )
|
||||||
|
sendPositionUpdate();
|
||||||
|
|
||||||
|
if( distance < ( getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
|
||||||
{
|
{
|
||||||
if( !hasFlag( TurningDisabled ) && face( pHatedActor->getPos() ) )
|
if( !hasFlag( TurningDisabled ) && face( pHatedActor->getPos() ) )
|
||||||
sendPositionUpdate();
|
sendPositionUpdate();
|
||||||
|
|
|
@ -1151,11 +1151,11 @@ void Sapphire::Entity::Player::update( uint64_t tickCount )
|
||||||
auto chara = actor->getAsChara();
|
auto chara = actor->getAsChara();
|
||||||
|
|
||||||
// default autoattack range
|
// default autoattack range
|
||||||
float range = 3.f + chara->getRadius();
|
float range = 3.f + chara->getRadius() + getRadius() * 0.5f;
|
||||||
|
|
||||||
// default autoattack range for ranged classes
|
// default autoattack range for ranged classes
|
||||||
if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer )
|
if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer )
|
||||||
range = 25.f;
|
range = 25.f + chara->getRadius() + getRadius() * 0.5f;
|
||||||
|
|
||||||
if( Util::distance( getPos(), actor->getPos() ) <= range )
|
if( Util::distance( getPos(), actor->getPos() ) <= range )
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,9 +24,9 @@ Sapphire::World::Navi::NaviProvider::NaviProvider( const std::string& internalNa
|
||||||
m_internalName( internalName )
|
m_internalName( internalName )
|
||||||
{
|
{
|
||||||
// Set defaults
|
// Set defaults
|
||||||
m_polyFindRange[ 0 ] = 10;
|
m_polyFindRange[ 0 ] = 20;
|
||||||
m_polyFindRange[ 1 ] = 20;
|
m_polyFindRange[ 1 ] = 20;
|
||||||
m_polyFindRange[ 2 ] = 10;
|
m_polyFindRange[ 2 ] = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::World::Navi::NaviProvider::init()
|
bool Sapphire::World::Navi::NaviProvider::init()
|
||||||
|
@ -355,7 +355,7 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 >
|
||||||
// iterPos[ 0 ], iterPos[ 1 ], iterPos[ 2 ],
|
// iterPos[ 0 ], iterPos[ 1 ], iterPos[ 2 ],
|
||||||
// targetPos[ 0 ], targetPos[ 1 ], targetPos[ 2 ] );
|
// targetPos[ 0 ], targetPos[ 1 ], targetPos[ 2 ] );
|
||||||
|
|
||||||
const float STEP_SIZE = 1.2f;
|
const float STEP_SIZE = 0.5f;
|
||||||
const float SLOP = 0.15f;
|
const float SLOP = 0.15f;
|
||||||
|
|
||||||
int32_t numSmoothPath = 0;
|
int32_t numSmoothPath = 0;
|
||||||
|
@ -620,6 +620,11 @@ void Sapphire::World::Navi::NaviProvider::calcVel( float* vel, const float* pos,
|
||||||
dtVscale( vel, vel, speed );
|
dtVscale( vel, vel, speed );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sapphire::World::Navi::NaviProvider::resetMoveTarget( Entity::Chara& chara )
|
||||||
|
{
|
||||||
|
m_pCrowd->resetMoveTarget( chara.getAgentId() );
|
||||||
|
}
|
||||||
|
|
||||||
void Sapphire::World::Navi::NaviProvider::setMoveTarget( Entity::Chara& chara,
|
void Sapphire::World::Navi::NaviProvider::setMoveTarget( Entity::Chara& chara,
|
||||||
const Sapphire::Common::FFXIVARR_POSITION3& endPos )
|
const Sapphire::Common::FFXIVARR_POSITION3& endPos )
|
||||||
{
|
{
|
||||||
|
@ -671,11 +676,6 @@ bool Sapphire::World::Navi::NaviProvider::hasTargetState( Entity::Chara& chara )
|
||||||
return ag->targetState != DT_CROWDAGENT_TARGET_NONE;
|
return ag->targetState != DT_CROWDAGENT_TARGET_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::World::Navi::NaviProvider::resetMoveTarget( Entity::Chara& chara )
|
|
||||||
{
|
|
||||||
m_pCrowd->resetMoveTarget( chara.getAgentId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sapphire::World::Navi::NaviProvider::updateAgentPosition( Entity::Chara& chara )
|
void Sapphire::World::Navi::NaviProvider::updateAgentPosition( Entity::Chara& chara )
|
||||||
{
|
{
|
||||||
removeAgent( chara );
|
removeAgent( chara );
|
||||||
|
|
|
@ -56,14 +56,13 @@ namespace Sapphire::World::Navi
|
||||||
static void calcVel( float* vel, const float* pos, const float* tgt, const float speed );
|
static void calcVel( float* vel, const float* pos, const float* tgt, const float speed );
|
||||||
|
|
||||||
void setMoveTarget( Entity::Chara& chara, const Common::FFXIVARR_POSITION3& endPos );
|
void setMoveTarget( Entity::Chara& chara, const Common::FFXIVARR_POSITION3& endPos );
|
||||||
|
void resetMoveTarget( Entity::Chara& chara );
|
||||||
|
|
||||||
Common::FFXIVARR_POSITION3 getMovePos( Entity::Chara& chara );
|
Common::FFXIVARR_POSITION3 getMovePos( Entity::Chara& chara );
|
||||||
|
|
||||||
bool isAgentActive( Entity::Chara& chara ) const;
|
bool isAgentActive( Entity::Chara& chara ) const;
|
||||||
bool hasTargetState( Entity::Chara& chara ) const;
|
bool hasTargetState( Entity::Chara& chara ) const;
|
||||||
|
|
||||||
void resetMoveTarget( Entity::Chara& chara );
|
|
||||||
|
|
||||||
void updateAgentPosition( Entity::Chara& chara );
|
void updateAgentPosition( Entity::Chara& chara );
|
||||||
|
|
||||||
bool syncPosToChara( Entity::Chara& chara );
|
bool syncPosToChara( Entity::Chara& chara );
|
||||||
|
|
Loading…
Add table
Reference in a new issue