1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-30 16:17:46 +00:00

add deminishing aggro range based on level difference

This commit is contained in:
NotAdam 2019-01-31 17:53:20 +11:00
parent 8e945a5698
commit 085a184ad3
2 changed files with 22 additions and 8 deletions

View file

@ -402,7 +402,6 @@ void Sapphire::Entity::BNpc::onTick()
void Sapphire::Entity::BNpc::update( int64_t currTime )
{
const uint8_t minActorDistance = 4;
const uint8_t aggroRange = 8;
const uint8_t maxDistanceToOrigin = 40;
const uint32_t roamTick = 20;
@ -441,7 +440,7 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
m_state = BNpcState::Idle;
}
checkAggro( aggroRange );
checkAggro();
}
break;
@ -462,7 +461,7 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
m_state = BNpcState::Roaming;
}
checkAggro( aggroRange );
checkAggro();
}
case BNpcState::Combat:
@ -574,7 +573,7 @@ void Sapphire::Entity::BNpc::setTimeOfDeath( uint32_t timeOfDeath )
m_timeOfDeath = timeOfDeath;
}
void Sapphire::Entity::BNpc::checkAggro( uint32_t range )
void Sapphire::Entity::BNpc::checkAggro()
{
// passive mobs should ignore players unless aggro'd
if( m_aggressionMode == 1 )
@ -582,14 +581,29 @@ void Sapphire::Entity::BNpc::checkAggro( uint32_t range )
CharaPtr pClosestChara = getClosestChara();
if( pClosestChara && pClosestChara->isAlive() )
if( pClosestChara && pClosestChara->isAlive() && pClosestChara->isPlayer() )
{
// will use this range if chara level is lower than bnpc, otherwise deminishing equation applies
float range = 13.f;
if( pClosestChara->getLevel() > m_level )
{
auto levelDiff = std::abs( pClosestChara->getLevel() - this->getLevel() );
range = std::max< float >( 0.f, range - std::pow( 1.53f, levelDiff * 0.6f ) );
}
// level difference too great, ignore player
if( range == 0.f )
return;
auto distance = Util::distance( getPos().x, getPos().y, getPos().z,
pClosestChara->getPos().x,
pClosestChara->getPos().y,
pClosestChara->getPos().z );
if( distance < range && pClosestChara->isPlayer() )
if( distance < range )
{
aggro( pClosestChara );
}
}
}
}

View file

@ -93,7 +93,7 @@ namespace Sapphire::Entity
void regainHp();
void checkAggro( uint32_t range );
void checkAggro();
private:
uint32_t m_bNpcBaseId;