mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 23:27:45 +00:00
136 lines
3.8 KiB
C++
136 lines
3.8 KiB
C++
#include "Director.h"
|
|
|
|
#include <Network/PacketDef/ServerIpcs.h>
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
|
#include <Network/CommonActorControl.h>
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket.h"
|
|
#include "Network/PacketWrappers/ActorControlSelfPacket.h"
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Service.h>
|
|
#include "WorldServer.h"
|
|
#include "Session.h"
|
|
#include "Network/GameConnection.h"
|
|
|
|
using namespace Sapphire::Common;
|
|
using namespace Sapphire::Network::Packets;
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
|
using namespace Sapphire::Network::ActorControl;
|
|
|
|
Sapphire::Event::Director::Director( Sapphire::Event::Director::DirectorType type, uint16_t contentId ) :
|
|
m_contextId( contentId ),
|
|
m_type( type ),
|
|
m_directorId( ( static_cast< uint32_t >( type ) << 16 ) | contentId ),
|
|
m_sequence( 1 ),
|
|
m_flags( 0 )
|
|
{
|
|
memset( m_vars, 0, sizeof( m_vars ) );
|
|
}
|
|
|
|
uint32_t Sapphire::Event::Director::getDirectorId() const
|
|
{
|
|
return m_directorId;
|
|
}
|
|
|
|
uint16_t Sapphire::Event::Director::getContextId() const
|
|
{
|
|
return m_contextId;
|
|
}
|
|
|
|
uint8_t Sapphire::Event::Director::getSequence() const
|
|
{
|
|
return m_sequence;
|
|
}
|
|
|
|
void Sapphire::Event::Director::sendDirectorClear( Sapphire::Entity::Player& player ) const
|
|
{
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
|
server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), DirectorClear, m_directorId ) );
|
|
}
|
|
|
|
void Sapphire::Event::Director::sendDirectorVars( Sapphire::Entity::Player& player ) const
|
|
{
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
|
|
|
auto varPacket = makeZonePacket< FFXIVIpcDirectorVars >( player.getId() );
|
|
varPacket->data().directorId = getDirectorId();
|
|
varPacket->data().sequence = getSequence();
|
|
varPacket->data().flags = getFlags();
|
|
memcpy( varPacket->data().vars, m_vars, sizeof( m_vars ) );
|
|
server.queueForPlayer( player.getCharacterId(), varPacket );
|
|
}
|
|
|
|
void Sapphire::Event::Director::sendDirectorInit( Sapphire::Entity::Player& player ) const
|
|
{
|
|
Logger::debug( "[{}] directorInit: directorId#{}, contextId#{}", player.getId(), m_directorId, m_contextId );
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
|
server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), DirectorInit, m_directorId, m_contextId ) );
|
|
}
|
|
|
|
Sapphire::Event::Director::DirectorType Sapphire::Event::Director::getType() const
|
|
{
|
|
return m_type;
|
|
}
|
|
|
|
uint8_t Sapphire::Event::Director::getFlags() const
|
|
{
|
|
return m_flags;
|
|
}
|
|
|
|
void Sapphire::Event::Director::setDirectorFlags( uint8_t value )
|
|
{
|
|
m_flags = value;
|
|
}
|
|
|
|
void Sapphire::Event::Director::setDirectorSequence( uint8_t value )
|
|
{
|
|
m_sequence = value;
|
|
}
|
|
|
|
void Sapphire::Event::Director::setDirectorVar( uint8_t index, uint8_t value )
|
|
{
|
|
if( index < sizeof( m_vars ) )
|
|
{
|
|
m_vars[ index ] = value;
|
|
}
|
|
else
|
|
Logger::warn( "[{0}] Director::setDirectorVar - out of range index {1} value {2}", m_directorId, index, value );
|
|
}
|
|
|
|
uint8_t Sapphire::Event::Director::getDirectorVar( uint8_t index )
|
|
{
|
|
if( index < sizeof( m_vars ) )
|
|
{
|
|
return m_vars[ index ];
|
|
}
|
|
else
|
|
Logger::warn( "[{0}] Director::getDirectorVar - out of range index {1}", m_directorId, index );
|
|
|
|
return 0;
|
|
}
|
|
|
|
void Sapphire::Event::Director::setDirectorVar( uint8_t index, uint8_t valueLeft, uint8_t valueRight )
|
|
{
|
|
setDirectorVar( index, ( valueRight & 0x0F ) + ( valueLeft << 4 ) );
|
|
}
|
|
|
|
uint8_t Sapphire::Event::Director::getDirectorVar( uint8_t index, bool shiftLeft )
|
|
{
|
|
return getDirectorVar( index ) & ( shiftLeft ? 0xF0 : 0x0F );
|
|
}
|
|
|
|
void Sapphire::Event::Director::setCustomVar( uint32_t index, uint64_t value )
|
|
{
|
|
m_customVarMap[ index ] = value;
|
|
}
|
|
|
|
uint64_t Sapphire::Event::Director::getCustomVar( uint32_t index )
|
|
{
|
|
auto it = m_customVarMap.find( index );
|
|
if( it != m_customVarMap.end() )
|
|
return it->second;
|
|
return 0;
|
|
}
|