mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-23 13:17:45 +00:00
manage timer vars and call onTick from Chara update instead of derived classes
This commit is contained in:
parent
1380db037a
commit
1bbc01f04f
6 changed files with 34 additions and 19 deletions
|
@ -88,7 +88,7 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, BNpcTemplatePtr pTemplate, float posX
|
|||
memcpy( m_customize, pTemplate->getCustomize(), sizeof( m_customize ) );
|
||||
memcpy( m_modelEquip, pTemplate->getModelEquip(), sizeof( m_modelEquip ) );
|
||||
|
||||
m_lastTickTime = Util::getTimeMs();
|
||||
m_lastTickTime = 0;
|
||||
}
|
||||
|
||||
Sapphire::Entity::BNpc::~BNpc()
|
||||
|
@ -177,7 +177,7 @@ void Sapphire::Entity::BNpc::step()
|
|||
// This is probably not a good way to do it but works fine for now
|
||||
float angle = Util::calcAngFrom( getPos().x, getPos().z, stepPos.x, stepPos.z ) + PI;
|
||||
|
||||
auto delta = static_cast< float >( Util::getTimeMs() - m_lastTickTime ) / 1000.f;
|
||||
auto delta = static_cast< float >( Util::getTimeMs() - m_lastUpdate ) / 1000.f;
|
||||
|
||||
float speed = 7.5f * delta;
|
||||
|
||||
|
@ -388,6 +388,14 @@ void Sapphire::Entity::BNpc::deaggro( Sapphire::Entity::CharaPtr pChara )
|
|||
}
|
||||
}
|
||||
|
||||
void Sapphire::Entity::BNpc::onTick()
|
||||
{
|
||||
if( m_state == BNpcState::Retreat )
|
||||
{
|
||||
regainHp();
|
||||
}
|
||||
}
|
||||
|
||||
void Sapphire::Entity::BNpc::update( int64_t currTime )
|
||||
{
|
||||
const uint8_t minActorDistance = 4;
|
||||
|
@ -406,9 +414,6 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
|||
{
|
||||
setInvincibilityType( InvincibilityType::InvincibilityIgnoreDamage );
|
||||
|
||||
if( std::difftime( currTime, m_lastTickTime ) > 3000 )
|
||||
regainHp( currTime );
|
||||
|
||||
if( moveTo( m_spawnPos ) )
|
||||
{
|
||||
setInvincibilityType( InvincibilityType::InvincibilityNone );
|
||||
|
@ -511,10 +516,11 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
|||
}
|
||||
}
|
||||
|
||||
m_lastTickTime = currTime;
|
||||
|
||||
Chara::update( currTime );
|
||||
}
|
||||
|
||||
void Sapphire::Entity::BNpc::regainHp( int64_t currTime )
|
||||
void Sapphire::Entity::BNpc::regainHp()
|
||||
{
|
||||
if( this->m_hp < this->getMaxHp() )
|
||||
{
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace Sapphire::Entity
|
|||
void deaggro( CharaPtr pChara );
|
||||
|
||||
void update( int64_t currTime ) override;
|
||||
void onTick() override;
|
||||
|
||||
void onActionHostile( CharaPtr pSource ) override;
|
||||
|
||||
|
@ -90,7 +91,7 @@ namespace Sapphire::Entity
|
|||
uint32_t getTimeOfDeath() const;
|
||||
void setTimeOfDeath( uint32_t timeOfDeath );
|
||||
|
||||
void regainHp( int64_t currTime );
|
||||
void regainHp();
|
||||
|
||||
void checkAggro( uint32_t range );
|
||||
|
||||
|
|
|
@ -280,6 +280,18 @@ bool Sapphire::Entity::Chara::checkAction()
|
|||
|
||||
}
|
||||
|
||||
void Sapphire::Entity::Chara::update( int64_t currTime )
|
||||
{
|
||||
if( std::difftime( currTime, m_lastTickTime ) > 3000 )
|
||||
{
|
||||
onTick();
|
||||
|
||||
m_lastTickTime = currTime;
|
||||
}
|
||||
|
||||
m_lastUpdate = currTime;
|
||||
}
|
||||
|
||||
/*!
|
||||
Change the current target and propagate to in range players
|
||||
|
||||
|
|
|
@ -68,11 +68,11 @@ namespace Sapphire::Entity
|
|||
protected:
|
||||
char m_name[34];
|
||||
/*! Last tick time for the actor ( in ms ) */
|
||||
uint64_t m_lastTickTime;
|
||||
int64_t m_lastTickTime;
|
||||
/*! Last time the actor performed an autoAttack ( in ms ) */
|
||||
uint64_t m_lastAttack;
|
||||
/*! Last time the actor was updated ( in ms ) */
|
||||
uint64_t m_lastUpdate;
|
||||
int64_t m_lastUpdate;
|
||||
/*! Current stance of the actor */
|
||||
Common::Stance m_currentStance;
|
||||
/*! Current staus of the actor */
|
||||
|
@ -237,7 +237,7 @@ namespace Sapphire::Entity
|
|||
|
||||
virtual bool checkAction();
|
||||
|
||||
virtual void update( int64_t currTime ) {};
|
||||
virtual void update( int64_t currTime );
|
||||
|
||||
Action::ActionPtr getCurrentAction() const;
|
||||
|
||||
|
|
|
@ -1043,7 +1043,6 @@ void Sapphire::Entity::Player::unsetStateFlag( Common::PlayerStateFlag flag )
|
|||
|
||||
void Sapphire::Entity::Player::update( int64_t currTime )
|
||||
{
|
||||
|
||||
// a zoning is pending, lets do it
|
||||
if( m_queuedZoneing && ( currTime - m_queuedZoneing->m_queueTime ) > 800 )
|
||||
{
|
||||
|
@ -1115,13 +1114,7 @@ void Sapphire::Entity::Player::update( int64_t currTime )
|
|||
}
|
||||
}
|
||||
|
||||
if( ( currTime - m_lastTickTime ) > 3000 )
|
||||
{
|
||||
// add 3 seconds to total play time
|
||||
m_playTime += 3;
|
||||
m_lastTickTime = currTime;
|
||||
onTick();
|
||||
}
|
||||
Chara::update( currTime );
|
||||
}
|
||||
|
||||
void Sapphire::Entity::Player::onMobKill( uint16_t nameId )
|
||||
|
|
|
@ -355,6 +355,9 @@ void Sapphire::Entity::Player::onDeath()
|
|||
void Sapphire::Entity::Player::onTick()
|
||||
{
|
||||
|
||||
// add 3 seconds to total play time
|
||||
m_playTime += 3;
|
||||
|
||||
bool sendUpdate = false;
|
||||
|
||||
if( !isAlive() || !isLoadingComplete() )
|
||||
|
|
Loading…
Add table
Reference in a new issue