1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 23:27:45 +00:00

Improve path finding and stop position of mobs, also auto attack distance fixed

This commit is contained in:
Mordred 2022-01-04 22:51:29 +01:00
parent a5ba5bb2fb
commit ab1fbd833e
5 changed files with 29 additions and 32 deletions

View file

@ -67,12 +67,12 @@ float Util::calcAngFrom( float x, float y, float x1, float y1 )
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 )
{
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 )

View file

@ -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 );
if( modelChara )
{
auto modelSkeleton = exdData.getRow< Component::Excel::ModelSkeleton >( modelChara->data().ModelType );
auto modelSkeleton = exdData.getRow< Component::Excel::ModelSkeleton >( modelChara->data().SkeletonId );
if( modelSkeleton )
{
m_radius *= modelSkeleton->data().Radius;
}
}
// todo: is this actually good?
//m_naviTargetReachedDistance = m_scale * 2.f;
m_naviTargetReachedDistance = 4.f;
m_naviTargetReachedDistance = m_radius * 2;
calculateStats();
@ -267,8 +268,7 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance
}
// todo: is this actually good?
//m_naviTargetReachedDistance = m_scale * 2.f;
m_naviTargetReachedDistance = 4.f;
m_naviTargetReachedDistance = m_radius;
calculateStats();
}
@ -362,7 +362,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
auto pos1 = pNaviProvider->getMovePos( *this );
if( Util::distance( pos1, pos ) < getRadius() + 3.f )
if( Util::distance( pos1, pos ) < getNaviTargetReachedDistance() )
{
// Reached destination
face( pos );
@ -386,26 +386,25 @@ bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
if( !pNaviProvider )
{
Logger::error( "No NaviProvider for zone#{0} - {1}",
m_pCurrentTerritory->getGuId(),
m_pCurrentTerritory->getInternalName() );
Logger::error( "No NaviProvider for zone#{0} - {1}", m_pCurrentTerritory->getGuId(), m_pCurrentTerritory->getInternalName() );
return false;
}
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
face( targetChara.getPos() );
setPos( pos1 );
sendPositionUpdate();
pNaviProvider->resetMoveTarget( *this );
pNaviProvider->updateAgentPosition( *this );
return true;
}
m_pCurrentTerritory->updateActorPosition( *this );
face( targetChara.getPos() );
face( { ( pos1.x - getPos().x ) + pos1.x, 1, (pos1.z - getPos().z ) + pos1.z } );
setPos( pos1 );
sendPositionUpdate();
return false;
@ -654,8 +653,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
pNaviProvider->updateAgentParameters( *this );
auto distanceOrig = Util::distance( getPos().x, getPos().y, getPos().z,
m_spawnPos.x, m_spawnPos.y, m_spawnPos.z );
auto distanceOrig = Util::distance( getPos().x, getPos().y, getPos().z, m_spawnPos.x, m_spawnPos.y, m_spawnPos.z );
if( pHatedActor && !pHatedActor->isAlive() )
{
@ -663,9 +661,6 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
pHatedActor = hateListGetHighest();
}
if( pNaviProvider->syncPosToChara( *this ) )
sendPositionUpdate();
if( pHatedActor )
{
auto distance = Util::distance( getPos().x, getPos().y, getPos().z,
@ -681,7 +676,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
break;
}
if( distance > ( getRadius() + pHatedActor->getRadius() ) )
if( distance > ( getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
{
if( hasFlag( Immobile ) )
break;
@ -692,7 +687,10 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
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() ) )
sendPositionUpdate();

View file

@ -1151,11 +1151,11 @@ void Sapphire::Entity::Player::update( uint64_t tickCount )
auto chara = actor->getAsChara();
// default autoattack range
float range = 3.f + chara->getRadius();
float range = 3.f + chara->getRadius() + getRadius() * 0.5f;
// default autoattack range for ranged classes
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 )
{

View file

@ -24,9 +24,9 @@ Sapphire::World::Navi::NaviProvider::NaviProvider( const std::string& internalNa
m_internalName( internalName )
{
// Set defaults
m_polyFindRange[ 0 ] = 10;
m_polyFindRange[ 0 ] = 20;
m_polyFindRange[ 1 ] = 20;
m_polyFindRange[ 2 ] = 10;
m_polyFindRange[ 2 ] = 20;
}
bool Sapphire::World::Navi::NaviProvider::init()
@ -355,7 +355,7 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 >
// iterPos[ 0 ], iterPos[ 1 ], iterPos[ 2 ],
// targetPos[ 0 ], targetPos[ 1 ], targetPos[ 2 ] );
const float STEP_SIZE = 1.2f;
const float STEP_SIZE = 0.5f;
const float SLOP = 0.15f;
int32_t numSmoothPath = 0;
@ -620,6 +620,11 @@ void Sapphire::World::Navi::NaviProvider::calcVel( float* vel, const float* pos,
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,
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;
}
void Sapphire::World::Navi::NaviProvider::resetMoveTarget( Entity::Chara& chara )
{
m_pCrowd->resetMoveTarget( chara.getAgentId() );
}
void Sapphire::World::Navi::NaviProvider::updateAgentPosition( Entity::Chara& chara )
{
removeAgent( chara );

View file

@ -56,14 +56,13 @@ namespace Sapphire::World::Navi
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 resetMoveTarget( Entity::Chara& chara );
Common::FFXIVARR_POSITION3 getMovePos( Entity::Chara& chara );
bool isAgentActive( Entity::Chara& chara ) const;
bool hasTargetState( Entity::Chara& chara ) const;
void resetMoveTarget( Entity::Chara& chara );
void updateAgentPosition( Entity::Chara& chara );
bool syncPosToChara( Entity::Chara& chara );