mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 07:07:45 +00:00
minor bnpc cleanup, correctly set lastticktime on bnpc entities
This commit is contained in:
parent
6070247dc9
commit
fcd934034d
4 changed files with 13 additions and 9 deletions
|
@ -15,6 +15,11 @@ float Sapphire::Util::distance( float x, float y, float z, float x1, float y1, f
|
||||||
return sqrtf( distanceSq( x, y, z, x1, y1, z1 ) );
|
return sqrtf( distanceSq( x, y, z, x1, y1, z1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Sapphire::Util::distance( const Common::FFXIVARR_POSITION3& pos1, const Common::FFXIVARR_POSITION3& pos2 )
|
||||||
|
{
|
||||||
|
return sqrtf( distanceSq( pos1.x, pos1.y, pos1.z, pos2.x, pos2.y, pos2.z ) );
|
||||||
|
}
|
||||||
|
|
||||||
float Sapphire::Util::distance2DSq( float x, float y, float x1, float y1 )
|
float Sapphire::Util::distance2DSq( float x, float y, float x1, float y1 )
|
||||||
{
|
{
|
||||||
float deltaX = x - x1;
|
float deltaX = x - x1;
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Sapphire::Util
|
||||||
float distanceSq( float x, float y, float z, float x1, float y1, float z1 );
|
float distanceSq( float x, float y, float z, float x1, float y1, float z1 );
|
||||||
|
|
||||||
float distance( float x, float y, float z, float x1, float y1, float z1 );
|
float distance( float x, float y, float z, float x1, float y1, float z1 );
|
||||||
|
float distance( const Common::FFXIVARR_POSITION3& pos1, const Common::FFXIVARR_POSITION3& pos2 );
|
||||||
|
|
||||||
float distance2DSq( float x, float y, float x1, float y1 );
|
float distance2DSq( float x, float y, float x1, float y1 );
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, BNpcTemplatePtr pTemplate, float posX
|
||||||
memcpy( m_customize, pTemplate->getCustomize(), sizeof( m_customize ) );
|
memcpy( m_customize, pTemplate->getCustomize(), sizeof( m_customize ) );
|
||||||
memcpy( m_modelEquip, pTemplate->getModelEquip(), sizeof( m_modelEquip ) );
|
memcpy( m_modelEquip, pTemplate->getModelEquip(), sizeof( m_modelEquip ) );
|
||||||
|
|
||||||
|
m_lastTickTime = Util::getTimeMs();
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::Entity::BNpc::~BNpc()
|
Sapphire::Entity::BNpc::~BNpc()
|
||||||
|
@ -162,11 +163,9 @@ void Sapphire::Entity::BNpc::step()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto stepPos = m_naviLastPath[ m_naviPathStep ];
|
auto stepPos = m_naviLastPath[ m_naviPathStep ];
|
||||||
auto distanceToStep = Util::distance( getPos().x, getPos().y, getPos().z,
|
|
||||||
stepPos.x, stepPos.y, stepPos.z );
|
|
||||||
|
|
||||||
auto distanceToDest = Util::distance( getPos().x, getPos().y, getPos().z,
|
auto distanceToStep = Util::distance( getPos(), stepPos );
|
||||||
m_naviTarget.x, m_naviTarget.y, m_naviTarget.z );
|
auto distanceToDest = Util::distance( getPos(), m_naviTarget );
|
||||||
|
|
||||||
if( distanceToStep <= 4 && m_naviPathStep < m_naviLastPath.size() - 1 )
|
if( distanceToStep <= 4 && m_naviPathStep < m_naviLastPath.size() - 1 )
|
||||||
{
|
{
|
||||||
|
@ -201,7 +200,7 @@ void Sapphire::Entity::BNpc::step()
|
||||||
|
|
||||||
bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
||||||
{
|
{
|
||||||
if( Util::distance( getPos().x, getPos().y, getPos().z, pos.x, pos.y, pos.z ) <= 4 )
|
if( Util::distance( getPos(), pos ) <= 4 )
|
||||||
{
|
{
|
||||||
// Reached destination
|
// Reached destination
|
||||||
m_naviLastPath.clear();
|
m_naviLastPath.clear();
|
||||||
|
@ -389,7 +388,6 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
||||||
if( std::difftime( currTime, m_lastTickTime ) > 3000 )
|
if( std::difftime( currTime, m_lastTickTime ) > 3000 )
|
||||||
regainHp( currTime );
|
regainHp( currTime );
|
||||||
|
|
||||||
// slowly restore hp every tick
|
|
||||||
if( moveTo( m_spawnPos ) )
|
if( moveTo( m_spawnPos ) )
|
||||||
{
|
{
|
||||||
setInvincibilityType( InvincibilityType::InvincibilityNone );
|
setInvincibilityType( InvincibilityType::InvincibilityNone );
|
||||||
|
@ -491,12 +489,12 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_lastTickTime = currTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::Entity::BNpc::regainHp( int64_t currTime )
|
void Sapphire::Entity::BNpc::regainHp( int64_t currTime )
|
||||||
{
|
{
|
||||||
this->m_lastTickTime = currTime;
|
|
||||||
|
|
||||||
if( this->m_hp < this->getMaxHp() )
|
if( this->m_hp < this->getMaxHp() )
|
||||||
{
|
{
|
||||||
auto addHp = static_cast< uint32_t >( this->getMaxHp() * 0.1f + 1 );
|
auto addHp = static_cast< uint32_t >( this->getMaxHp() * 0.1f + 1 );
|
||||||
|
|
|
@ -393,7 +393,7 @@ void Sapphire::Zone::updateBNpcs( int64_t tickCount )
|
||||||
m_lastMobUpdate = tickCount;
|
m_lastMobUpdate = tickCount;
|
||||||
uint32_t currTime = Sapphire::Util::getTimeSeconds();
|
uint32_t currTime = Sapphire::Util::getTimeSeconds();
|
||||||
|
|
||||||
for( auto entry : m_bNpcMap )
|
for( const auto& entry : m_bNpcMap )
|
||||||
{
|
{
|
||||||
Entity::BNpcPtr pBNpc = entry.second;
|
Entity::BNpcPtr pBNpc = entry.second;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue