From 692ca9d56e1693b80e71546e5596f75cef00552e Mon Sep 17 00:00:00 2001 From: Mordred Date: Thu, 22 Feb 2018 18:12:36 +0100 Subject: [PATCH] More stuff moved over to actor baseclass --- .../sapphire_zone/Action/ActionMount.cpp | 2 +- .../sapphire_zone/Action/ActionTeleport.cpp | 2 +- .../sapphire_zone/Action/EventItemAction.cpp | 2 +- src/servers/sapphire_zone/Actor/Actor.cpp | 41 ++++++++++- src/servers/sapphire_zone/Actor/Actor.h | 16 +++++ src/servers/sapphire_zone/Actor/Chara.cpp | 69 ++----------------- src/servers/sapphire_zone/Actor/Chara.h | 23 ------- .../sapphire_zone/Actor/EventObject.cpp | 6 +- src/servers/sapphire_zone/Actor/EventObject.h | 4 +- src/servers/sapphire_zone/Actor/Player.cpp | 16 ++--- src/servers/sapphire_zone/Actor/PlayerSql.cpp | 8 +-- .../DebugCommand/DebugCommandHandler.cpp | 18 ++--- .../Network/Handlers/GMCommandHandlers.cpp | 10 ++- .../Network/Handlers/PacketHandlers.cpp | 10 +-- .../Network/PacketWrappers/MoveActorPacket.h | 2 +- .../PacketWrappers/PlayerSpawnPacket.h | 2 +- src/servers/sapphire_zone/Zone/CellHandler.h | 6 +- src/servers/sapphire_zone/Zone/Zone.cpp | 32 +++++---- src/servers/sapphire_zone/Zone/Zone.h | 2 +- 19 files changed, 120 insertions(+), 151 deletions(-) diff --git a/src/servers/sapphire_zone/Action/ActionMount.cpp b/src/servers/sapphire_zone/Action/ActionMount.cpp index 53d72eca..3fd67f0d 100644 --- a/src/servers/sapphire_zone/Action/ActionMount.cpp +++ b/src/servers/sapphire_zone/Action/ActionMount.cpp @@ -78,7 +78,7 @@ void Core::Action::ActionMount::onFinish() effectPacket.data().unknown_62 = 13; effectPacket.data().actionTextId = 4; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot( pPlayer->getRotation() ); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( pPlayer->getRot() ); effectPacket.data().effectTarget = INVALID_GAME_OBJECT_ID; effectPacket.data().effects[0].effectType = ActionEffectType::Mount; effectPacket.data().effects[0].hitSeverity = ActionHitSeverityType::CritDamage; diff --git a/src/servers/sapphire_zone/Action/ActionTeleport.cpp b/src/servers/sapphire_zone/Action/ActionTeleport.cpp index 18c41dee..55a6fc5a 100644 --- a/src/servers/sapphire_zone/Action/ActionTeleport.cpp +++ b/src/servers/sapphire_zone/Action/ActionTeleport.cpp @@ -88,7 +88,7 @@ void Core::Action::ActionTeleport::onFinish() effectPacket.data().actionTextId = 5; effectPacket.data().unknown_5 = 1; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRotation() + 3.1415926 ) ) / 3.1415926 ); + effectPacket.data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRot() + 3.1415926 ) ) / 3.1415926 ); effectPacket.data().effectTarget = pPlayer->getId(); pPlayer->sendToInRangeSet( effectPacket, true ); diff --git a/src/servers/sapphire_zone/Action/EventItemAction.cpp b/src/servers/sapphire_zone/Action/EventItemAction.cpp index 742a40ae..cf1d242b 100644 --- a/src/servers/sapphire_zone/Action/EventItemAction.cpp +++ b/src/servers/sapphire_zone/Action/EventItemAction.cpp @@ -73,7 +73,7 @@ void Core::Action::EventItemAction::onFinish() effectPacket.data().actionTextId = m_id; effectPacket.data().unknown_5 = 2; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot( m_pSource->getRotation() ); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( m_pSource->getRot() ); effectPacket.data().effectTarget = static_cast< uint32_t >( m_additional ); m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting ); diff --git a/src/servers/sapphire_zone/Actor/Actor.cpp b/src/servers/sapphire_zone/Actor/Actor.cpp index 1fc923b0..acefabbc 100644 --- a/src/servers/sapphire_zone/Actor/Actor.cpp +++ b/src/servers/sapphire_zone/Actor/Actor.cpp @@ -5,11 +5,16 @@ #include #include -#include "Chara.h" + #include "Network/GameConnection.h" + +#include "Chara.h" +#include "EventObject.h" #include "Player.h" + #include "ServerZone.h" #include "Session.h" +#include "Zone/Zone.h" extern Core::ServerZone g_serverZone; @@ -39,11 +44,13 @@ void Core::Entity::Actor::setPos( float x, float y, float z ) m_pos.x = x; m_pos.y = y; m_pos.z = z; + m_pCurrentZone->updateActorPosition( *this ); } void Core::Entity::Actor::setPos( const Core::Common::FFXIVARR_POSITION3& pos ) { m_pos = pos; + m_pCurrentZone->updateActorPosition( *this ); } float Core::Entity::Actor::getRot() const @@ -288,3 +295,35 @@ std::set< Core::Entity::ActorPtr > Core::Entity::Actor::getInRangeActors( bool i return tempInRange; } + +/*! \return ZonePtr to the current zone, nullptr if not set */ +Core::ZonePtr Core::Entity::Actor::getCurrentZone() const +{ + return m_pCurrentZone; +} + +/*! \param ZonePtr to the zone to be set as current */ +void Core::Entity::Actor::setCurrentZone( ZonePtr currZone ) +{ + m_pCurrentZone = currZone; +} + +/*! +Get the current cell of a region the actor is in + +\return Cell* +*/ +Core::Cell * Core::Entity::Actor::getCellPtr() +{ + return m_pCell; +} + +/*! +Set the current cell the actor is in + +\param Cell* for the cell to be set +*/ +void Core::Entity::Actor::setCell( Cell * pCell ) +{ + m_pCell = pCell; +} \ No newline at end of file diff --git a/src/servers/sapphire_zone/Actor/Actor.h b/src/servers/sapphire_zone/Actor/Actor.h index 1b4c1ee3..647af43e 100644 --- a/src/servers/sapphire_zone/Actor/Actor.h +++ b/src/servers/sapphire_zone/Actor/Actor.h @@ -48,11 +48,18 @@ namespace Entity { uint32_t m_id; /*! Type of the actor */ ObjKind m_objKind; + /*! Id of the zone the actor currently is in */ + uint32_t m_zoneId; + /*! Ptr to the ZoneObj the actor belongs to */ + ZonePtr m_pCurrentZone; /*! list of various actors in range */ std::set< ActorPtr > m_inRangeActor; std::set< PlayerPtr > m_inRangePlayers; + /*! Parent cell in the zone */ + Core::Cell* m_pCell; + public: explicit Actor( ObjKind type ); virtual ~Actor() {}; @@ -112,6 +119,15 @@ namespace Entity { CharaPtr getAsChara(); PlayerPtr getAsPlayer(); EventObjectPtr getAsEventObj(); + + ZonePtr getCurrentZone() const; + void setCurrentZone( ZonePtr currZone ); + + // get the current cell of a region the actor is in + Cell* getCellPtr(); + // set the current cell + void setCell( Cell* pCell ); + }; } diff --git a/src/servers/sapphire_zone/Actor/Chara.cpp b/src/servers/sapphire_zone/Actor/Chara.cpp index 588ef935..eb6e0896 100644 --- a/src/servers/sapphire_zone/Actor/Chara.cpp +++ b/src/servers/sapphire_zone/Actor/Chara.cpp @@ -229,36 +229,17 @@ position */ bool Core::Entity::Chara::face( const Common::FFXIVARR_POSITION3& p ) { - float oldRot = getRotation(); + float oldRot = getRot(); float rot = Math::Util::calcAngFrom( getPos().x, getPos().z, p.x, p.z ); float newRot = PI - rot + ( PI / 2 ); m_pCell = nullptr; - setRotation( newRot ); + setRot( newRot ); return oldRot != newRot ? true : false; } -/*! -Sets the actors position and notifies the zone to propagate the change - -\param Position to set -*/ -void Core::Entity::Chara::setPosition( const Common::FFXIVARR_POSITION3& pos ) -{ - m_pos = pos; - m_pCurrentZone->updateActorPosition( *this ); -} - -void Core::Entity::Chara::setPosition( float x, float y, float z ) -{ - m_pos.x = x; - m_pos.y = y; - m_pos.z = z; - m_pCurrentZone->updateActorPosition( *this ); -} - /*! Set and propagate the actor stance to in range players ( not the actor himself ) @@ -386,38 +367,6 @@ void Core::Entity::Chara::setCurrentAction( Core::Action::ActionPtr pAction ) m_pCurrentAction = pAction; } -/*! \return ZonePtr to the current zone, nullptr if not set */ -Core::ZonePtr Core::Entity::Chara::getCurrentZone() const -{ - return m_pCurrentZone; -} - -/*! \param ZonePtr to the zone to be set as current */ -void Core::Entity::Chara::setCurrentZone( ZonePtr currZone ) -{ - m_pCurrentZone = currZone; -} - -/*! -Get the current cell of a region the actor is in - -\return Cell* -*/ -Core::Cell * Core::Entity::Chara::getCell() const -{ - return m_pCell; -} - -/*! -Set the current cell the actor is in - -\param Cell* for the cell to be set -*/ -void Core::Entity::Chara::setCell( Cell * pCell ) -{ - m_pCell = pCell; -} - /*! Autoattack prototype implementation TODO: move the check if the autoAttack can be performed to the callee @@ -448,7 +397,7 @@ void Core::Entity::Chara::autoAttack( CharaPtr pTarget ) // effectPacket.data().unknown_3 = 1; effectPacket.data().actionTextId = 0x366; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); effectPacket.data().effectTarget = pTarget->getId(); effectPacket.data().effects[0].value = damage; effectPacket.data().effects[0].effectType = ActionEffectType::Damage; @@ -492,7 +441,7 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u effectPacket.data().unknown_2 = 1; // This seems to have an effect on the "double-cast finish" animation effectPacket.data().actionTextId = actionId; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); effectPacket.data().effectTarget = target.getId(); // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step @@ -655,16 +604,6 @@ void Core::Entity::Chara::addStatusEffectByIdIfNotExist( uint32_t id, int32_t du } -float Core::Entity::Chara::getRotation() const -{ - return m_rot; -} - -void Core::Entity::Chara::setRotation( float rot ) -{ - m_rot = rot; -} - int8_t Core::Entity::Chara::getStatusEffectFreeSlot() { int8_t freeEffectSlot = -1; diff --git a/src/servers/sapphire_zone/Actor/Chara.h b/src/servers/sapphire_zone/Actor/Chara.h index d24c96e2..dd5bb340 100644 --- a/src/servers/sapphire_zone/Actor/Chara.h +++ b/src/servers/sapphire_zone/Actor/Chara.h @@ -106,10 +106,6 @@ public: protected: char m_name[34]; - /*! Id of the zone the actor currently is in */ - uint32_t m_zoneId; - /*! Ptr to the ZoneObj the actor belongs to */ - ZonePtr m_pCurrentZone; /*! Last tick time for the actor ( in ms ) */ uint64_t m_lastTickTime; /*! Last time the actor performed an autoAttack ( in ms ) */ @@ -182,13 +178,6 @@ public: void removeSingleStatusEffectFromId( uint32_t id ); /// End Status Effect Functions - void setPosition( const Common::FFXIVARR_POSITION3& pos ); - void setPosition( float x, float y, float z ); - - void setRotation( float rot ); - - float getRotation() const; - std::string getName() const; bool face( const Common::FFXIVARR_POSITION3& p ); @@ -260,18 +249,6 @@ public: void setCurrentAction( Action::ActionPtr pAction ); - ZonePtr getCurrentZone() const; - - void setCurrentZone( ZonePtr currZone ); - - // get the current cell of a region the actor is in - Cell* getCell() const; - - // set the current cell - void setCell( Cell* pCell ); - - Core::Cell* m_pCell; - }; } diff --git a/src/servers/sapphire_zone/Actor/EventObject.cpp b/src/servers/sapphire_zone/Actor/EventObject.cpp index 9dc54b5b..6f361889 100644 --- a/src/servers/sapphire_zone/Actor/EventObject.cpp +++ b/src/servers/sapphire_zone/Actor/EventObject.cpp @@ -15,14 +15,14 @@ Core::Entity::EventObject::EventObject( uint32_t objectId, uint32_t mapLinkId, C } -uint32_t Core::Entity::EventObject::getHierachyId() const +uint32_t Core::Entity::EventObject::getMapLinkId() const { return m_mapLinkId; } -void Core::Entity::EventObject::setHierachyId( uint32_t hierachyId ) +void Core::Entity::EventObject::setMapLinkId( uint32_t mapLinkId ) { - m_mapLinkId = hierachyId; + m_mapLinkId = mapLinkId; } uint8_t Core::Entity::EventObject::getState() const diff --git a/src/servers/sapphire_zone/Actor/EventObject.h b/src/servers/sapphire_zone/Actor/EventObject.h index 4a0c8180..49df8e18 100644 --- a/src/servers/sapphire_zone/Actor/EventObject.h +++ b/src/servers/sapphire_zone/Actor/EventObject.h @@ -13,8 +13,8 @@ namespace Entity EventObject( uint32_t objectId, uint32_t mapLinkId ); EventObject( uint32_t objectId, uint32_t mapLinkId, Common::FFXIVARR_POSITION3 pos ); - uint32_t getHierachyId() const; - void setHierachyId( uint32_t hierachyId ); + uint32_t getMapLinkId() const; + void setMapLinkId( uint32_t mapLinkId ); uint8_t getState() const; void setState( uint8_t state ); diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp index 46cb3280..44d990e7 100644 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ b/src/servers/sapphire_zone/Actor/Player.cpp @@ -973,7 +973,7 @@ void Core::Entity::Player::update( int64_t currTime ) setActorPosPacket.data().y = targetPos.y; setActorPosPacket.data().z = targetPos.z; sendToInRangeSet( setActorPosPacket, true ); - setPosition( targetPos ); + setPos( targetPos ); } m_queuedZoneing.reset(); return; @@ -1190,7 +1190,7 @@ void Core::Entity::Player::performZoning( uint16_t zoneId, const Common::FFXIVAR m_pos = pos; m_zoneId = zoneId; m_bMarkedForZoning = true; - setRotation( rotation ); + setRot( rotation ); setZone( zoneId ); } @@ -1375,11 +1375,9 @@ void Core::Entity::Player::autoAttack( CharaPtr pTarget ) uint32_t damage = static_cast< uint32_t >( mainWeap->getAutoAttackDmg() ); uint32_t variation = 0 + rand() % 3; - if( getClass() == ClassJob::Machinist || - getClass() == ClassJob::Bard || - getClass() == ClassJob::Archer ) + if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) { - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); + ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); effectPacket.data().targetId = pTarget->getId(); effectPacket.data().actionAnimationId = 8; // effectPacket.data().unknown_2 = variation; @@ -1387,7 +1385,7 @@ void Core::Entity::Player::autoAttack( CharaPtr pTarget ) effectPacket.data().unknown_61 = 1; effectPacket.data().unknown_62 = 1; effectPacket.data().actionTextId = 8; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); effectPacket.data().effectTargetId = pTarget->getId(); effectPacket.data().effectTarget = pTarget->getId(); effectPacket.data().effects[0].value = damage; @@ -1400,7 +1398,7 @@ void Core::Entity::Player::autoAttack( CharaPtr pTarget ) else { - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); + ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); effectPacket.data().targetId = pTarget->getId(); effectPacket.data().actionAnimationId = 7; // effectPacket.data().unknown_2 = variation; @@ -1408,7 +1406,7 @@ void Core::Entity::Player::autoAttack( CharaPtr pTarget ) effectPacket.data().unknown_61 = 1; effectPacket.data().unknown_62 = 1; effectPacket.data().actionTextId = 7; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() ); effectPacket.data().effectTarget = pTarget->getId(); effectPacket.data().effects[0].value = damage; effectPacket.data().effects[0].effectType = Common::ActionEffectType::Damage; diff --git a/src/servers/sapphire_zone/Actor/PlayerSql.cpp b/src/servers/sapphire_zone/Actor/PlayerSql.cpp index b1522720..ab127e0f 100644 --- a/src/servers/sapphire_zone/Actor/PlayerSql.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerSql.cpp @@ -64,7 +64,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) m_pos.x = res->getFloat( "PosX" ); m_pos.y = res->getFloat( "PosY" ); m_pos.z = res->getFloat( "PosZ" ); - setRotation( res->getFloat( "PosR" ) ); + setRot( res->getFloat( "PosR" ) ); m_prevPos.x = res->getFloat( "OPosX" ); m_prevPos.y = res->getFloat( "OPosY" ); @@ -85,7 +85,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) m_pos.x = m_prevPos.x; m_pos.y = m_prevPos.y; m_pos.z = m_prevPos.z; - setRotation( m_prevRot ); + setRot( m_prevRot ); pCurrZone = g_territoryMgr.getZoneByTerriId( zoneId ); } } @@ -110,7 +110,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) m_pos.x = 0.0f; m_pos.y = 0.0f; m_pos.z = 0.0f; - setRotation( 0.0f ); + setRot( 0.0f ); } // Stats @@ -369,7 +369,7 @@ void Core::Entity::Player::updateSql() stmt->setDouble( 20, m_pos.x ); stmt->setDouble( 21, m_pos.y ); stmt->setDouble( 22, m_pos.z ); - stmt->setDouble( 23, getRotation() ); + stmt->setDouble( 23, getRot() ); stmt->setInt( 24, m_prevZoneType ); // OTerritoryType stmt->setInt( 25, m_prevZoneId ); // OTerritoryId diff --git a/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp index 736e87c5..14a938c7 100644 --- a/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp @@ -174,13 +174,13 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: } if( subCommand == "pos" ) - player.setPosition( static_cast< float >( posX ), - static_cast< float >( posY ), - static_cast< float >( posZ ) ); + player.setPos( static_cast< float >( posX ), + static_cast< float >( posY ), + static_cast< float >( posZ ) ); else - player.setPosition( player.getPos().x + static_cast< float >( posX ), - player.getPos().y + static_cast< float >( posY ), - player.getPos().z + static_cast< float >( posZ ) ); + player.setPos( player.getPos().x + static_cast< float >( posX ), + player.getPos().y + static_cast< float >( posY ), + player.getPos().z + static_cast< float >( posZ ) ); Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorSetPos > setActorPosPacket( player.getId() ); @@ -444,7 +444,7 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost: std::to_string( player.getPos().x ) + "\n" + std::to_string( player.getPos().y ) + "\n" + std::to_string( player.getPos().z ) + "\n" + - std::to_string( player.getRotation() ) + "\nMapId: " + + std::to_string( player.getRot() ) + "\nMapId: " + std::to_string( map_id ) + "\nZoneID: " + std::to_string(player.getCurrentZone()->getTerritoryId() ) + "\n" ); } @@ -549,7 +549,7 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boos } else { - float angle = player.getRotation() + ( PI / 2 ); + float angle = player.getRot() + ( PI / 2 ); pos.x -= offset * cos( angle ); pos.z += offset * sin( angle ); player.sendNotice( "nudge: Placing forward " + std::to_string( offset ) + " yalms" ); @@ -561,7 +561,7 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boos setActorPosPacket.data().x = player.getPos().x; setActorPosPacket.data().y = player.getPos().y; setActorPosPacket.data().z = player.getPos().z; - setActorPosPacket.data().r16 = Math::Util::floatToUInt16Rot( player.getRotation() ); + setActorPosPacket.data().r16 = Math::Util::floatToUInt16Rot( player.getRot() ); player.queuePacket( setActorPosPacket ); } } diff --git a/src/servers/sapphire_zone/Network/Handlers/GMCommandHandlers.cpp b/src/servers/sapphire_zone/Network/Handlers/GMCommandHandlers.cpp index 578b2ad6..9fa34628 100644 --- a/src/servers/sapphire_zone/Network/Handlers/GMCommandHandlers.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/GMCommandHandlers.cpp @@ -190,8 +190,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac if( targetPlayer->getZoneId() != player.getZoneId() ) targetPlayer->setZone( player.getZoneId() ); - targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, - player.getRotation() ); + targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, player.getRot() ); player.sendNotice( "Calling " + targetPlayer->getName() ); break; } @@ -419,7 +418,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac player.sendUrgent( "No zone instance found for " + std::to_string( param1 ) ); break; } - targetPlayer->setPosition( targetPlayer->getPos() ); + targetPlayer->setPos( targetPlayer->getPos() ); targetPlayer->performZoning( param1, targetPlayer->getPos(), 0 ); player.sendNotice( targetPlayer->getName() + " was warped to zone " + std::to_string( param1 ) + " (" + pZone->getName() + ")" ); } @@ -511,7 +510,7 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac player.setZone( targetPlayer->getZoneId() ); } player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z, - targetActor->getRotation() ); + targetActor->getRot() ); player.sendNotice( "Jumping to " + targetPlayer->getName() ); break; } @@ -520,8 +519,7 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac if( targetPlayer->getZoneId() != player.getZoneId() ) targetPlayer->setZone( player.getZoneId() ); - targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, - player.getRotation() ); + targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, player.getRot() ); player.sendNotice( "Calling " + targetPlayer->getName() ); break; } diff --git a/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp b/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp index c6232a22..50f38dd4 100644 --- a/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp @@ -178,13 +178,13 @@ void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePa ( player.getPos().y != inPacket.getValAt< float >( 0x30 ) ) || ( player.getPos().z != inPacket.getValAt< float >( 0x34 ) ) ) bPosChanged = true; - if( !bPosChanged && player.getRotation() == inPacket.getValAt< float >( 0x20 ) ) + if( !bPosChanged && player.getRot() == inPacket.getValAt< float >( 0x20 ) ) return; - player.setRotation( inPacket.getValAt< float >( 0x20 ) ); - player.setPosition( inPacket.getValAt< float >( 0x2c ), - inPacket.getValAt< float >( 0x30 ), - inPacket.getValAt< float >( 0x34 ) ); + player.setRot( inPacket.getValAt< float >( 0x20 ) ); + player.setPos( inPacket.getValAt< float >( 0x2c ), + inPacket.getValAt< float >( 0x30 ), + inPacket.getValAt< float >( 0x34 ) ); if( ( player.getCurrentAction() != nullptr ) && bPosChanged ) player.getCurrentAction()->setInterrupted(); diff --git a/src/servers/sapphire_zone/Network/PacketWrappers/MoveActorPacket.h b/src/servers/sapphire_zone/Network/PacketWrappers/MoveActorPacket.h index ee671e85..2ffa31d2 100644 --- a/src/servers/sapphire_zone/Network/PacketWrappers/MoveActorPacket.h +++ b/src/servers/sapphire_zone/Network/PacketWrappers/MoveActorPacket.h @@ -31,7 +31,7 @@ private: void initialize( Entity::Chara& actor, uint8_t unk1, uint8_t unk2, uint8_t unk3, uint16_t unk4 ) { - m_data.rotation = Math::Util::floatToUInt8Rot( actor.getRotation() ); + m_data.rotation = Math::Util::floatToUInt8Rot( actor.getRot() ); m_data.unknown_1 = unk1; m_data.unknown_2 = unk2; m_data.unknown_3 = unk3; diff --git a/src/servers/sapphire_zone/Network/PacketWrappers/PlayerSpawnPacket.h b/src/servers/sapphire_zone/Network/PacketWrappers/PlayerSpawnPacket.h index 7aa01d61..c56f9ccf 100644 --- a/src/servers/sapphire_zone/Network/PacketWrappers/PlayerSpawnPacket.h +++ b/src/servers/sapphire_zone/Network/PacketWrappers/PlayerSpawnPacket.h @@ -64,7 +64,7 @@ namespace Server { m_data.pos.x = player.getPos().x; m_data.pos.y = player.getPos().y; m_data.pos.z = player.getPos().z; - m_data.rotation = Math::Util::floatToUInt16Rot( player.getRotation() ); + m_data.rotation = Math::Util::floatToUInt16Rot( player.getRot() ); m_data.title = player.getTitle(); diff --git a/src/servers/sapphire_zone/Zone/CellHandler.h b/src/servers/sapphire_zone/Zone/CellHandler.h index 253f4823..8c2ff8ff 100644 --- a/src/servers/sapphire_zone/Zone/CellHandler.h +++ b/src/servers/sapphire_zone/Zone/CellHandler.h @@ -26,7 +26,7 @@ public: CellHandler(); ~CellHandler(); - T* getCell( uint32_t x, uint32_t y ); + T* getCellPtr( uint32_t x, uint32_t y ); T* getCellByCoords( float x, float y ); T* create( uint32_t x, uint32_t y ); T* createByCoords( float x, float y ); @@ -144,7 +144,7 @@ void CellHandler::remove( uint32_t x, uint32_t y ) } template -T* CellHandler::getCell( uint32_t x, uint32_t y ) +T* CellHandler::getCellPtr( uint32_t x, uint32_t y ) { if( !m_pCells[x] ) { @@ -157,7 +157,7 @@ T* CellHandler::getCell( uint32_t x, uint32_t y ) template T* CellHandler::getCellByCoords( float x, float y ) { - return getCell( getPosX( x ), getPosY( y ) ); + return getCellPtr(getPosX(x), getPosY(y)); } template diff --git a/src/servers/sapphire_zone/Zone/Zone.cpp b/src/servers/sapphire_zone/Zone/Zone.cpp index f8c7c58f..a1442fee 100644 --- a/src/servers/sapphire_zone/Zone/Zone.cpp +++ b/src/servers/sapphire_zone/Zone/Zone.cpp @@ -175,7 +175,7 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara ) uint32_t cx = getPosX( mx ); uint32_t cy = getPosY( my ); - Cell* pCell = getCell( cx, cy ); + Cell* pCell = getCellPtr(cx, cy); if( !pCell ) { pCell = create( cx, cy ); @@ -199,7 +199,7 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara ) { for( posY = startY; posY <= endY; ++posY ) { - pCell = getCell( posX, posY ); + pCell = getCellPtr(posX, posY); if( pCell ) updateInRangeSet( pChara, pCell ); } @@ -220,10 +220,11 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara ) void Core::Zone::removeActor( Entity::CharaPtr pChara ) { - if( pChara->m_pCell ) + auto pCell = pChara->getCellPtr(); + if( pCell ) { - pChara->m_pCell->removeChara(pChara); - pChara->m_pCell = nullptr; + pCell->removeChara(pChara); + pCell = nullptr; } if( pChara->isPlayer() ) @@ -410,7 +411,7 @@ void Core::Zone::updateSessions( bool changedWeather ) // this session is not linked to this area anymore, remove it from zone session list if( ( !pPlayer->getCurrentZone() ) || ( pPlayer->getCurrentZone() != shared_from_this() ) ) { - if( pPlayer->getCell() ) + if( pPlayer->getCellPtr() ) removeActor( pSession->getPlayer() ); it = m_sessionSet.erase(it ); @@ -446,7 +447,7 @@ bool Core::Zone::isCellActive( uint32_t x, uint32_t y ) { for( posY = startY; posY <= endY; posY++ ) { - pCell = getCell( posX, posY ); + pCell = getCellPtr(posX, posY); if( pCell && ( pCell->hasPlayers() || pCell->isForcedActive() ) ) return true; @@ -471,7 +472,7 @@ void Core::Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius ) { for( posY = startY; posY <= endY; posY++ ) { - pCell = getCell( posX, posY ); + pCell = getCellPtr(posX, posY); if( !pCell ) { @@ -505,7 +506,7 @@ void Core::Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius ) } } -void Core::Zone::updateActorPosition( Entity::Chara &actor ) +void Core::Zone::updateActorPosition( Entity::Actor &actor ) { if( actor.getCurrentZone() != shared_from_this() ) @@ -519,8 +520,9 @@ void Core::Zone::updateActorPosition( Entity::Chara &actor ) if( cellX >= _sizeX || cellY >= _sizeY ) return; - Cell* pCell = getCell( cellX, cellY ); - Cell* pOldCell = actor.m_pCell; + auto pCell = getCellPtr(cellX, cellY); + + auto pOldCell = actor.getCellPtr(); if( !pCell ) { pCell = create( cellX, cellY ); @@ -534,8 +536,8 @@ void Core::Zone::updateActorPosition( Entity::Chara &actor ) if( pOldCell ) pOldCell->removeChara(actor.getAsChara()); - pCell->addChara(actor.getAsChara()); - actor.m_pCell = pCell; + pCell->addChara( actor.getAsChara() ); + pOldCell = pCell; // if player we need to update cell activity // radius = 2 is used in order to update both @@ -564,7 +566,7 @@ void Core::Zone::updateActorPosition( Entity::Chara &actor ) { for( posY = startY; posY <= endY; ++posY ) { - pCell = getCell( posX, posY ); + pCell = getCellPtr(posX, posY); if( pCell ) updateInRangeSet( actor.getAsChara(), pCell ); } @@ -685,7 +687,7 @@ void Core::Zone::updateEObj( Entity::EventObjectPtr object ) eobjStatePacket.data().objKind = object->getObjKind(); eobjStatePacket.data().state = object->getState(); eobjStatePacket.data().objId = object->getId(); - eobjStatePacket.data().hierachyId = object->getHierachyId(); + eobjStatePacket.data().hierachyId = object->getMapLinkId(); eobjStatePacket.data().position = object->getPos(); // ???? diff --git a/src/servers/sapphire_zone/Zone/Zone.h b/src/servers/sapphire_zone/Zone/Zone.h index 11a188da..72a5fa9c 100644 --- a/src/servers/sapphire_zone/Zone/Zone.h +++ b/src/servers/sapphire_zone/Zone/Zone.h @@ -78,7 +78,7 @@ public: void removeActor( Entity::CharaPtr pActor ); - void updateActorPosition( Entity::Chara &pActor ); + void updateActorPosition( Entity::Actor &pActor ); bool isCellActive( uint32_t x, uint32_t y );