From c1b70480ff0800e55493330d56ce127d957fc23d Mon Sep 17 00:00:00 2001 From: collett Date: Mon, 16 Nov 2020 23:30:28 +0900 Subject: [PATCH] make CharaVisualEffect a field in player so we can track and send to other players --- src/world/Actor/Player.cpp | 49 ++++++++++++++----- src/world/Actor/Player.h | 6 +++ src/world/Manager/DebugCommandMgr.cpp | 4 +- src/world/Network/Handlers/PacketHandlers.cpp | 1 + 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 923b32b4..c3fbb828 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -83,7 +83,8 @@ Sapphire::Entity::Player::Player() : m_directorInitialized( false ), m_onEnterEventDone( false ), m_falling( false ), - m_pQueuedAction( nullptr ) + m_pQueuedAction( nullptr ), + m_effect( 0 ) { m_id = 0; m_currentStance = Stance::Passive; @@ -962,6 +963,13 @@ void Sapphire::Entity::Player::spawn( Entity::PlayerPtr pTarget ) Logger::debug( "[{0}] Spawning {1} for {2}", pTarget->getId(), getName(), pTarget->getName() ); pTarget->queuePacket( std::make_shared< PlayerSpawnPacket >( *getAsPlayer(), *pTarget ) ); + if( m_effect > 0 ) + { + auto effect = makeZonePacket< FFXIVIpcCharaVisualEffect >( pTarget->getId() ); + effect->setSourceActor( getId() ); + effect->data().id = m_effect; + pTarget->queuePacket( effect ); + } } // despawn @@ -2538,6 +2546,25 @@ void Sapphire::Entity::Player::gaugeSetRaw( uint8_t* pData ) sendActorGauge(); } +uint32_t Sapphire::Entity::Player::getVisualEffect() +{ + return m_effect; +} + +void Sapphire::Entity::Player::setVisualEffect( uint32_t effect, bool sendPacket ) +{ + m_effect = effect; + if( sendPacket ); + sendVisualEffect(); +} + +void Sapphire::Entity::Player::sendVisualEffect() +{ + auto pPacket = makeZonePacket< FFXIVIpcCharaVisualEffect >( getId() ); + pPacket->data().id = m_effect; + sendToInRangeSet( pPacket, true ); +} + void Sapphire::Entity::Player::gaugeWarSetIb( uint8_t value ) { assert( value >= 0 && value <= 100 ); @@ -2545,12 +2572,10 @@ void Sapphire::Entity::Player::gaugeWarSetIb( uint8_t value ) if( ( oldValue == 0 && value != 0 ) || ( oldValue != 0 && value == 0 ) ) { - auto pPacket = makeZonePacket< FFXIVIpcCharaVisualEffect >( getId() ); - if( value != 0 ) - { - pPacket->data().id = 7; - } - sendToInRangeSet( pPacket, true ); + if( m_effect == 0 && value != 0 ) + setVisualEffect( 7, true ); + else if ( m_effect == 7 && value == 0 ) + setVisualEffect( 0, true ); } m_gauge.war.beastGauge = value; if( oldValue != value ) @@ -2643,12 +2668,10 @@ void Sapphire::Entity::Player::gaugeDrkSetDarkSideTimer( uint16_t value, bool se if( ( oldValue == 0 && value != 0 ) || ( oldValue != 0 && value == 0 ) ) { - auto pPacket = makeZonePacket< FFXIVIpcCharaVisualEffect >( getId() ); - if( value != 0 ) - { - pPacket->data().id = 22; - } - sendToInRangeSet( pPacket, true ); + if( m_effect == 0 && value != 0 ) + setVisualEffect( 22, true ); + else if ( m_effect == 22 && value == 0 ) + setVisualEffect( 0, true ); } if( sendPacket ) sendActorGauge(); diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 089413e3..10bc2521 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -990,6 +990,10 @@ namespace Sapphire::Entity void sendActorGauge(); void gaugeSetRaw( uint8_t* pData ); + uint32_t getVisualEffect(); + void setVisualEffect( uint32_t effect, bool sendPacket = true ); + void sendVisualEffect(); + void gaugeWarSetIb( uint8_t value ); uint8_t gaugeWarGetIb(); @@ -1217,6 +1221,8 @@ namespace Sapphire::Entity std::array< Common::HuntingLogEntry, 12 > m_huntingLogEntries; std::unordered_map< uint32_t, std::vector< ShopBuyBackEntry > > m_shopBuyBackMap; + + uint32_t m_effect; }; } diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index 04d0d69a..3f6b85ff 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -375,9 +375,7 @@ void Sapphire::World::Manager::DebugCommandMgr::set( char* data, Entity::Player& { int32_t id; sscanf( params.c_str(), "%d", &id ); - auto pPacket = makeZonePacket< FFXIVIpcCharaVisualEffect >( player.getId() ); - pPacket->data().id = id; - player.sendToInRangeSet( pPacket, true ); + player.setVisualEffect( id ); } else { diff --git a/src/world/Network/Handlers/PacketHandlers.cpp b/src/world/Network/Handlers/PacketHandlers.cpp index cc5afaeb..f12ef34d 100644 --- a/src/world/Network/Handlers/PacketHandlers.cpp +++ b/src/world/Network/Handlers/PacketHandlers.cpp @@ -402,6 +402,7 @@ void Sapphire::Network::GameConnection::finishLoadingHandler( const Packets::FFX player.setIsLogin( false ); } + player.setVisualEffect( 0, false ); // spawn the player for himself player.spawn( player.getAsPlayer() );