diff --git a/src/servers/sapphire_zone/Actor/Actor.cpp b/src/servers/sapphire_zone/Actor/Actor.cpp index a874b71c..45b076a6 100644 --- a/src/servers/sapphire_zone/Actor/Actor.cpp +++ b/src/servers/sapphire_zone/Actor/Actor.cpp @@ -538,38 +538,6 @@ void Core::Entity::Actor::removeFromInRange() } -void Core::Entity::Actor::checkInRangeActors() -{ - if( hasInRangeActor() ) - { - Entity::ActorPtr pCurAct; - - float fRange = 70.0f; - for( auto iter = m_inRangeActors.begin(); iter != m_inRangeActors.end();) - { - pCurAct = *iter; - auto iter2 = iter++; - - float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z, - getPos().x, getPos().y, getPos().z ); - - if( fRange > 0.0f && distance > fRange ) - { - pCurAct->removeInRangeActor( *this ); - - if( getCurrentZone() != pCurAct->getCurrentZone() ) - return; - - removeInRangeActor( **iter2 ); - - // @TODO FIXME! - // this break is more or less a hack, iteration will break otherwise after removing - break; - } - } - } -} - /*! Clear the whole in range set, this does no cleanup */ void Core::Entity::Actor::clearInRangeSet() { diff --git a/src/servers/sapphire_zone/Actor/Actor.h b/src/servers/sapphire_zone/Actor/Actor.h index e65d1b0a..cb2142af 100644 --- a/src/servers/sapphire_zone/Actor/Actor.h +++ b/src/servers/sapphire_zone/Actor/Actor.h @@ -271,8 +271,6 @@ public: // return true if there is at least one actor in the in range set bool hasInRangeActor() const; - void checkInRangeActors(); - void removeFromInRange(); // clear the whole in range set, this does no cleanup diff --git a/src/servers/sapphire_zone/Zone/Zone.cpp b/src/servers/sapphire_zone/Zone/Zone.cpp index 30d7e399..c930f3da 100644 --- a/src/servers/sapphire_zone/Zone/Zone.cpp +++ b/src/servers/sapphire_zone/Zone/Zone.cpp @@ -631,7 +631,7 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor ) if( actor.getCurrentZone() != shared_from_this() ) return; - actor.checkInRangeActors(); + //actor.checkInRangeActors(); uint32_t cellX = getPosX( actor.getPos().x ); uint32_t cellY = getPosY( actor.getPos().z ); @@ -712,19 +712,18 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) pCurAct = *iter; ++iter; - if( !pCurAct ) + if( !pCurAct || pCurAct == pActor ) continue; float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z, pActor->getPos().x, pActor->getPos().y, pActor->getPos().z ); - // Add if we are not ourself and range == 0 or distance is withing range. - if( pCurAct != pActor && ( fRange == 0.0f || distance <= fRange ) ) - { + bool isInRange = ( fRange == 0.0f || distance <= fRange ); + bool isInRangeSet = pActor->isInRangeSet( pCurAct ); - if( pActor->isInRangeSet( pCurAct ) ) - // Actor already in range set, skip - continue; + // Add if we are not ourself and range == 0 or distance is withing range. + if( isInRange && !isInRangeSet ) + { if( pActor->isPlayer() ) { @@ -769,6 +768,15 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) pCurAct->addInRangeActor( pActor ); } } + else if( !isInRange && isInRangeSet ) + { + pCurAct->removeInRangeActor( *pActor ); + + if( pActor->getCurrentZone() != pCurAct->getCurrentZone() ) + continue; + + pActor->removeInRangeActor( *pCurAct ); + } } }