Health regen, run bugfix
This was SVN commit r3382.
This commit is contained in:
parent
230b7a896c
commit
5d4ec7f4bb
@ -31,6 +31,9 @@ CBaseEntity::CBaseEntity()
|
||||
AddProperty( L"traits.health.max", &m_healthMax );
|
||||
AddProperty( L"traits.health.bar_height", &m_healthBarHeight );
|
||||
AddProperty( L"traits.health.bar_size", &m_healthBarSize );
|
||||
AddProperty( L"traits.health.regen_rate", &m_healthRegenRate );
|
||||
AddProperty( L"traits.health.regen_start", &m_healthRegenStart );
|
||||
AddProperty( L"traits.health.decay_rate", &m_healthDecayRate );
|
||||
AddProperty( L"traits.stamina.curr", &m_staminaCurr );
|
||||
AddProperty( L"traits.stamina.max", &m_staminaMax );
|
||||
AddProperty( L"traits.stamina.bar_height", &m_staminaBarHeight );
|
||||
|
@ -68,6 +68,10 @@ public:
|
||||
float m_healthBarHeight;
|
||||
int m_healthBarSize;
|
||||
|
||||
float m_healthRegenRate;
|
||||
float m_healthRegenStart;
|
||||
float m_healthDecayRate;
|
||||
|
||||
// Minimap properties
|
||||
CStrW m_minimapType;
|
||||
int m_minimapR;
|
||||
|
@ -55,6 +55,9 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
AddProperty( L"traits.health.max", &m_healthMax );
|
||||
AddProperty( L"traits.health.bar_height", &m_healthBarHeight );
|
||||
AddProperty( L"traits.health.bar_size", &m_healthBarSize );
|
||||
AddProperty( L"traits.health.regen_rate", &m_healthRegenRate );
|
||||
AddProperty( L"traits.health.regen_start", &m_healthRegenStart );
|
||||
AddProperty( L"traits.health.decay_rate", &m_healthDecayRate );
|
||||
AddProperty( L"traits.stamina.curr", &m_staminaCurr );
|
||||
AddProperty( L"traits.stamina.max", &m_staminaMax );
|
||||
AddProperty( L"traits.stamina.bar_height", &m_staminaBarHeight );
|
||||
@ -104,7 +107,10 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
m_shouldRun = false;
|
||||
m_triggerRun = false;
|
||||
|
||||
m_healthDecay = false;
|
||||
|
||||
m_frameCheck = 0;
|
||||
m_lastAttackTime = 0;
|
||||
|
||||
m_grouped = -1;
|
||||
|
||||
@ -309,12 +315,15 @@ void CEntity::update( size_t timestep )
|
||||
m_position_previous = m_position;
|
||||
m_orientation_previous = m_orientation;
|
||||
|
||||
if ( IsAttacking() )
|
||||
m_lastAttackTime = get_time();
|
||||
|
||||
CalculateRun( timestep );
|
||||
CalculateHealth( timestep );
|
||||
|
||||
if ( m_triggerRun )
|
||||
m_frameCheck++;
|
||||
|
||||
CalculateRun( timestep );
|
||||
|
||||
if ( m_frameCheck != 0 )
|
||||
{
|
||||
m_shouldRun = true;
|
||||
@ -1015,6 +1024,31 @@ void CEntity::CalculateRun(float timestep)
|
||||
m_staminaCurr = min( m_staminaMax, m_staminaCurr + timestep / 1000.0f / m_runRegenRate * m_staminaMax );
|
||||
}
|
||||
|
||||
void CEntity::CalculateHealth(float timestep)
|
||||
{
|
||||
if ( m_healthDecay && m_healthDecayRate > 0 )
|
||||
{
|
||||
m_healthCurr = max( 0.0f, m_healthCurr - timestep / 1000.0f / m_healthDecayRate * m_healthMax );
|
||||
}
|
||||
else if ( m_healthRegenRate > 0 && get_time() - m_lastAttackTime > m_healthRegenStart && !IsAttacking() )
|
||||
{
|
||||
m_healthCurr = min( m_healthMax, m_healthCurr + timestep / 1000.0f / m_healthRegenRate * m_healthMax );
|
||||
}
|
||||
}
|
||||
bool CEntity::IsAttacking()
|
||||
{
|
||||
if ( !m_orderQueue.empty() )
|
||||
{
|
||||
if ( ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GENERIC ||
|
||||
m_orderQueue.front().m_type == CEntityOrder::ORDER_GENERIC_NOPATHING ) &&
|
||||
m_orderQueue.front().m_data[1].data == 1 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Scripting interface
|
||||
@ -1039,6 +1073,7 @@ void CEntity::ScriptingInit()
|
||||
AddMethod<jsval, &CEntity::RequestNotification>( "requestNotification", 3 );
|
||||
AddMethod<jsval, &CEntity::TriggerRun>( "triggerRun", 1 );
|
||||
AddMethod<jsval, &CEntity::SetRun>( "setRun", 1 );
|
||||
AddMethod<jsval, &CEntity::GetRunState>( "getRunState", 0 );
|
||||
|
||||
|
||||
AddClassProperty( L"template", (CBaseEntity* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::loadBase );
|
||||
@ -1527,7 +1562,11 @@ jsval CEntity::SetRun( JSContext* cx, uintN argc, jsval* argv )
|
||||
JS_ReportError( cx, "Too few parameters" );
|
||||
return( false );
|
||||
}
|
||||
m_isRunning = ToPrimitive<bool> ( argv[0] );
|
||||
m_shouldRun = ToPrimitive<bool> ( argv[0] );
|
||||
m_isRunning = m_shouldRun;
|
||||
return JSVAL_VOID;
|
||||
}
|
||||
|
||||
jsval CEntity::GetRunState( JSContext* cx, uintN argc, jsval* argv )
|
||||
{
|
||||
return m_isRunning;
|
||||
}
|
@ -94,6 +94,7 @@ public:
|
||||
bool m_triggerRun; //used in SetRun, corrects 1 frame stamina imbalance
|
||||
int m_frameCheck; //counts the frame
|
||||
|
||||
float m_lastAttackTime;
|
||||
|
||||
//SP properties
|
||||
float m_staminaCurr;
|
||||
@ -107,6 +108,11 @@ public:
|
||||
float m_healthBarHeight;
|
||||
int m_healthBarSize;
|
||||
|
||||
float m_healthRegenRate;
|
||||
float m_healthRegenStart;
|
||||
float m_healthDecayRate;
|
||||
bool m_healthDecay;
|
||||
|
||||
// Minimap properties
|
||||
CStrW m_minimapType;
|
||||
int m_minimapR;
|
||||
@ -241,6 +247,8 @@ public:
|
||||
|
||||
//Calculate stamina points
|
||||
void CalculateRun(float timestep);
|
||||
void CalculateHealth(float timestep);
|
||||
bool IsAttacking();
|
||||
|
||||
// Reset properties after the entity-template we use changes.
|
||||
void loadBase();
|
||||
@ -278,6 +286,7 @@ public:
|
||||
jsval TriggerRun( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval SetRun( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval IsRunning( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval GetRunState( JSContext* cx, uintN argc, jsval* argv );
|
||||
|
||||
jsval RequestNotification( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval CheckListeners( JSContext* cx, uintN argc, jsval* argv );
|
||||
|
@ -552,6 +552,7 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times
|
||||
// Close enough, but turn to face them.
|
||||
m_orientation = atan2( delta.x, delta.y );
|
||||
m_ahead = delta.normalize();
|
||||
m_isRunning = false;
|
||||
}
|
||||
|
||||
// Pick our animation, calculate the time to play it, and start the timer.
|
||||
|
Loading…
Reference in New Issue
Block a user