1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00

Further clean up in range stuff

This commit is contained in:
Mordred 2018-02-11 23:52:44 +01:00
parent cee84cd9ff
commit 649bd7d8e6
5 changed files with 47 additions and 66 deletions

View file

@ -309,9 +309,7 @@ Change the current target and propagate to in range players
void Core::Entity::Actor::changeTarget( uint64_t targetId ) void Core::Entity::Actor::changeTarget( uint64_t targetId )
{ {
setTargetId( targetId ); setTargetId( targetId );
sendToInRangeSet( ActorControlPacket144( m_id, SetTarget, 0, 0, 0, 0, targetId ) );
sendToInRangeSet( ActorControlPacket144( m_id, SetTarget,
0, 0, 0, 0, targetId ) );
} }
/*! /*!
@ -495,12 +493,10 @@ void Core::Entity::Actor::addInRangeActor( ActorPtr pActor )
// if actor is a player, add it to the in range player set // if actor is a player, add it to the in range player set
m_inRangePlayers.insert( pPlayer ); m_inRangePlayers.insert( pPlayer );
} }
m_inRangeActorMap[pActor->getId()] = pActor;
} }
/*! /*!
Remove a given actor from the fitting in range set according to type Remove a given actor from the matching in range set according to type
but also to the global actor map but also to the global actor map
\param ActorPtr to remove \param ActorPtr to remove
@ -519,13 +515,9 @@ void Core::Entity::Actor::removeInRangeActor( Actor& actor )
actor.despawn( getAsPlayer() ); actor.despawn( getAsPlayer() );
if( actor.isPlayer() ) if( actor.isPlayer() )
{
m_inRangePlayers.erase( actor.getAsPlayer() ); m_inRangePlayers.erase( actor.getAsPlayer() );
} }
m_inRangeActorMap.erase( actor.getId() );
}
/*! \return true if there is at least one actor in the in range set */ /*! \return true if there is at least one actor in the in range set */
bool Core::Entity::Actor::hasInRangeActor() const bool Core::Entity::Actor::hasInRangeActor() const
{ {
@ -583,7 +575,6 @@ void Core::Entity::Actor::clearInRangeSet()
{ {
m_inRangeActors.clear(); m_inRangeActors.clear();
m_inRangePlayers.clear(); m_inRangePlayers.clear();
m_inRangeActorMap.clear();
} }
/*! \return ZonePtr to the current zone, nullptr if not set */ /*! \return ZonePtr to the current zone, nullptr if not set */

View file

@ -141,7 +141,6 @@ protected:
std::set< ActorPtr > m_inRangeActors; std::set< ActorPtr > m_inRangeActors;
std::set< PlayerPtr > m_inRangePlayers; std::set< PlayerPtr > m_inRangePlayers;
std::map< uint32_t, ActorPtr > m_inRangeActorMap;
public: public:
Actor( ObjKind type ); Actor( ObjKind type );
@ -194,11 +193,8 @@ public:
ActorStats getStats() const; ActorStats getStats() const;
uint32_t getHp() const; uint32_t getHp() const;
uint32_t getMp() const; uint32_t getMp() const;
uint16_t getTp() const; uint16_t getTp() const;
uint16_t getGp() const; uint16_t getGp() const;
Common::InvincibilityType getInvincibilityType() const; Common::InvincibilityType getInvincibilityType() const;
@ -216,17 +212,13 @@ public:
bool isAlive() const; bool isAlive() const;
virtual uint32_t getMaxHp() const; virtual uint32_t getMaxHp() const;
virtual uint32_t getMaxMp() const; virtual uint32_t getMaxMp() const;
void resetHp(); void resetHp();
void resetMp(); void resetMp();
void setHp( uint32_t hp ); void setHp( uint32_t hp );
void setMp( uint32_t mp ); void setMp( uint32_t mp );
void setGp( uint32_t gp ); void setGp( uint32_t gp );
void setInvincibilityType( Common::InvincibilityType type ); void setInvincibilityType( Common::InvincibilityType type );
@ -241,10 +233,8 @@ public:
virtual void autoAttack( ActorPtr pTarget ); virtual void autoAttack( ActorPtr pTarget );
virtual void spawn( PlayerPtr pTarget ) {}
virtual void despawn( PlayerPtr pTarget ) {}
virtual void onRemoveInRangeActor( Actor& pActor ) {} virtual void onRemoveInRangeActor( Actor& pActor ) {}
virtual void onDeath() {}; virtual void onDeath() {};
virtual void onDamageTaken( Actor& pSource ) {}; virtual void onDamageTaken( Actor& pSource ) {};
virtual void onActionHostile( Actor& source ) {}; virtual void onActionHostile( Actor& source ) {};
@ -273,7 +263,7 @@ public:
void sendToInRangeSet( Network::Packets::GamePacketPtr pPacket, bool bToSelf = false ); void sendToInRangeSet( Network::Packets::GamePacketPtr pPacket, bool bToSelf = false );
// add an actor to in range set // add an actor to in range set
virtual void addInRangeActor( ActorPtr pActor ); void addInRangeActor( ActorPtr pActor );
// remove an actor from the in range set // remove an actor from the in range set
void removeInRangeActor( Actor& pActor ); void removeInRangeActor( Actor& pActor );

View file

@ -53,6 +53,9 @@ namespace Entity {
explicit GameObject( ObjKind type ); explicit GameObject( ObjKind type );
virtual ~GameObject() {}; virtual ~GameObject() {};
virtual void spawn( PlayerPtr pTarget ) {}
virtual void despawn( PlayerPtr pTarget ) {}
uint32_t getId() const; uint32_t getId() const;
ObjKind getObjKind() const; ObjKind getObjKind() const;

View file

@ -9,8 +9,8 @@ Core::Entity::InstanceObject::InstanceObject( uint32_t objectId, uint32_t mapLin
m_id = objectId; m_id = objectId;
} }
Core::Entity::InstanceObject::InstanceObject( uint32_t objectId, uint32_t mapLinkId, Common::FFXIVARR_POSITION3 pos ) Core::Entity::InstanceObject::InstanceObject( uint32_t objectId, uint32_t mapLinkId, Common::FFXIVARR_POSITION3 pos ) :
: InstanceObject( objectId, mapLinkId ) InstanceObject( objectId, mapLinkId )
{ {
} }

View file

@ -37,12 +37,11 @@ extern Core::Data::ExdDataGenerated g_exdDataGen;
extern Core::Scripting::ScriptManager g_scriptMgr; extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::TerritoryMgr g_territoryMgr; extern Core::TerritoryMgr g_territoryMgr;
namespace Core {
/** /**
* \brief * \brief
*/ */
Zone::Zone() : Core::Zone::Zone() :
m_territoryId( 0 ), m_territoryId( 0 ),
m_guId( 0 ), m_guId( 0 ),
m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ), m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ),
@ -52,7 +51,7 @@ Zone::Zone() :
{ {
} }
Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName ) : Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName ) :
m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) )
{ {
m_guId = guId; m_guId = guId;
@ -85,11 +84,11 @@ Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName
m_currentWeather = getNextWeather(); m_currentWeather = getNextWeather();
} }
Zone::~Zone() Core::Zone::~Zone()
{ {
} }
bool Zone::init() bool Core::Zone::init()
{ {
memset( m_pCellCache, 0, sizeof( CellCache* ) * _sizeX ); memset( m_pCellCache, 0, sizeof( CellCache* ) * _sizeX );
@ -103,27 +102,27 @@ bool Zone::init()
return true; return true;
} }
void Zone::setWeatherOverride( uint8_t weather ) void Core::Zone::setWeatherOverride( uint8_t weather )
{ {
m_weatherOverride = weather; m_weatherOverride = weather;
} }
uint8_t Zone::getCurrentWeather() const uint8_t Core::Zone::getCurrentWeather() const
{ {
return m_currentWeather; return m_currentWeather;
} }
uint16_t Zone::getCurrentFestival() const uint16_t Core::Zone::getCurrentFestival() const
{ {
return m_currentFestivalId; return m_currentFestivalId;
} }
void Zone::setCurrentFestival( uint16_t festivalId ) void Core::Zone::setCurrentFestival( uint16_t festivalId )
{ {
m_currentFestivalId = festivalId; m_currentFestivalId = festivalId;
} }
CellCache* Zone::getCellCacheList( uint32_t cellx, uint32_t celly ) Core::CellCache* Core::Zone::getCellCacheList( uint32_t cellx, uint32_t celly )
{ {
assert( cellx < _sizeX ); assert( cellx < _sizeX );
assert( celly < _sizeY ); assert( celly < _sizeY );
@ -133,7 +132,7 @@ CellCache* Zone::getCellCacheList( uint32_t cellx, uint32_t celly )
return m_pCellCache[cellx][celly]; return m_pCellCache[cellx][celly];
} }
CellCache* Zone::getCellCacheAndCreate( uint32_t cellx, uint32_t celly ) Core::CellCache* Core::Zone::getCellCacheAndCreate( uint32_t cellx, uint32_t celly )
{ {
assert( cellx < _sizeX ); assert( cellx < _sizeX );
assert( celly < _sizeY ); assert( celly < _sizeY );
@ -151,7 +150,7 @@ CellCache* Zone::getCellCacheAndCreate( uint32_t cellx, uint32_t celly )
return m_pCellCache[cellx][celly]; return m_pCellCache[cellx][celly];
} }
void Zone::loadCellCache() void Core::Zone::loadCellCache()
{ {
auto pQR = g_charaDb.query( "SELECT Id," auto pQR = g_charaDb.query( "SELECT Id,"
"Zoneid," "Zoneid,"
@ -228,7 +227,7 @@ void Zone::loadCellCache()
} }
uint8_t Zone::getNextWeather() uint8_t Core::Zone::getNextWeather()
{ {
uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() ); uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() );
// Get Eorzea hour for weather start // Get Eorzea hour for weather start
@ -258,7 +257,7 @@ uint8_t Zone::getNextWeather()
return 1; return 1;
} }
void Zone::pushActor( Entity::ActorPtr pActor ) void Core::Zone::pushActor( Entity::ActorPtr pActor )
{ {
float mx = pActor->getPos().x; float mx = pActor->getPos().x;
float my = pActor->getPos().z; float my = pActor->getPos().z;
@ -323,7 +322,7 @@ void Zone::pushActor( Entity::ActorPtr pActor )
} }
void Zone::removeActor( Entity::ActorPtr pActor ) void Core::Zone::removeActor( Entity::ActorPtr pActor )
{ {
if( pActor->m_pCell ) if( pActor->m_pCell )
@ -357,7 +356,7 @@ void Zone::removeActor( Entity::ActorPtr pActor )
} }
void Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry ) void Core::Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry )
{ {
if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) ) if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) )
return; return;
@ -381,32 +380,32 @@ void Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range,
} }
} }
uint32_t Zone::getTerritoryId() const uint32_t Core::Zone::getTerritoryId() const
{ {
return m_territoryId; return m_territoryId;
} }
uint32_t Zone::getGuId() const uint32_t Core::Zone::getGuId() const
{ {
return m_guId; return m_guId;
} }
const std::string& Zone::getName() const const std::string& Core::Zone::getName() const
{ {
return m_placeName; return m_placeName;
} }
const std::string& Zone::getInternalName() const const std::string& Core::Zone::getInternalName() const
{ {
return m_internalName; return m_internalName;
} }
std::size_t Zone::getPopCount() const std::size_t Core::Zone::getPopCount() const
{ {
return m_playerMap.size(); return m_playerMap.size();
} }
bool Zone::checkWeather() bool Core::Zone::checkWeather()
{ {
if ( m_weatherOverride != 0 ) if ( m_weatherOverride != 0 )
{ {
@ -430,7 +429,7 @@ bool Zone::checkWeather()
return false; return false;
} }
void Zone::updateBnpcs( int64_t tickCount ) void Core::Zone::updateBnpcs( int64_t tickCount )
{ {
if( ( tickCount - m_lastMobUpdate ) > 250 ) if( ( tickCount - m_lastMobUpdate ) > 250 )
{ {
@ -478,7 +477,7 @@ void Zone::updateBnpcs( int64_t tickCount )
} }
} }
bool Zone::update( uint32_t currTime ) bool Core::Zone::update( uint32_t currTime )
{ {
int64_t tickCount = Util::getTimeMs(); int64_t tickCount = Util::getTimeMs();
@ -530,7 +529,7 @@ bool Zone::update( uint32_t currTime )
return true; return true;
} }
bool Zone::isCellActive( uint32_t x, uint32_t y ) bool Core::Zone::isCellActive( uint32_t x, uint32_t y )
{ {
uint32_t endX = ( ( x + 1 ) <= _sizeX ) ? x + 1 : ( _sizeX - 1 ); uint32_t endX = ( ( x + 1 ) <= _sizeX ) ? x + 1 : ( _sizeX - 1 );
uint32_t endY = ( ( y + 1 ) <= _sizeY ) ? y + 1 : ( _sizeY - 1 ); uint32_t endY = ( ( y + 1 ) <= _sizeY ) ? y + 1 : ( _sizeY - 1 );
@ -555,7 +554,7 @@ bool Zone::isCellActive( uint32_t x, uint32_t y )
return false; return false;
} }
void Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius ) void Core::Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius )
{ {
uint32_t endX = ( x + radius ) <= _sizeX ? x + radius : ( _sizeX - 1 ); uint32_t endX = ( x + radius ) <= _sizeX ? x + radius : ( _sizeX - 1 );
@ -609,7 +608,7 @@ void Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius )
} }
} }
void Zone::updateActorPosition( Entity::Actor &actor ) void Core::Zone::updateActorPosition( Entity::Actor &actor )
{ {
if( actor.getCurrentZone() != shared_from_this() ) if( actor.getCurrentZone() != shared_from_this() )
@ -676,7 +675,7 @@ void Zone::updateActorPosition( Entity::Actor &actor )
} }
void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
{ {
if( pCell == nullptr ) if( pCell == nullptr )
return; return;
@ -756,36 +755,34 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
} }
} }
void Zone::onEnterTerritory( Entity::Player& player ) void Core::Zone::onEnterTerritory( Entity::Player& player )
{ {
g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) + g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( player.getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
} }
void Zone::onLeaveTerritory( Entity::Player& player ) void Core::Zone::onLeaveTerritory( Entity::Player& player )
{ {
g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) + g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( player.getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
} }
void Zone::onUpdate( uint32_t currTime ) void Core::Zone::onUpdate( uint32_t currTime )
{ {
} }
void Zone::onFinishLoading( Entity::Player& player ) void Core::Zone::onFinishLoading( Entity::Player& player )
{ {
} }
void Zone::onInitDirector( Entity::Player& player ) void Core::Zone::onInitDirector( Entity::Player& player )
{ {
} }
} void Core::Zone::registerInstanceObj( Entity::InstanceObjectPtr object )
void Core::Zone::registerInstanceObj( Core::Entity::InstanceObjectPtr object )
{ {
if( !object ) if( !object )
return; return;