1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 15:17:46 +00:00
sapphire/src/world/Network/PacketWrappers/ConditionPacket.h

51 lines
1.2 KiB
C
Raw Normal View History

#pragma once
2019-03-08 15:34:38 +01:00
#include <Network/GamePacket.h>
#include "Actor/Player.h"
2023-01-17 12:54:42 +01:00
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include "Forwards.h"
2017-08-08 13:53:47 +02:00
namespace Sapphire::Network::Packets::WorldPackets::Server
2017-08-08 13:53:47 +02:00
{
2018-10-28 21:53:21 +01:00
/**
* @brief Packet sent to set a players state, this impacts which actions he can perform.
*/
2023-02-20 15:25:57 +01:00
class ConditionPacket : public ZoneChannelPacket< FFXIVIpcCondition >
{
2018-10-28 21:53:21 +01:00
public:
2023-02-20 15:25:57 +01:00
ConditionPacket( Entity::Player& player ) :
ZoneChannelPacket< FFXIVIpcCondition >( player.getId(), player.getId() )
2018-10-28 21:53:21 +01:00
{
initialize( player.getConditions().data() );
2018-10-28 21:53:21 +01:00
}
2017-08-08 13:53:47 +02:00
2023-02-20 15:25:57 +01:00
ConditionPacket( Entity::Player& player, std::vector< Common::PlayerCondition > flags ) :
ZoneChannelPacket< FFXIVIpcCondition >( player.getId(), player.getId() )
{
2023-02-20 15:25:57 +01:00
uint8_t newFlags[ 12 ];
2018-10-28 21:53:21 +01:00
memset( newFlags, 0, 12 );
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
for( auto& flag : flags )
{
int32_t iFlag = static_cast< uint32_t >( flag );
uint8_t index = iFlag / 8;
uint8_t bitIndex = iFlag % 8;
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
uint8_t value = 1 << bitIndex;
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
newFlags[ index ] |= value;
}
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
initialize( newFlags );
}
private:
void initialize( const uint8_t* flags )
{
memcpy( m_data.flags, flags, 12 );
};
};
2017-08-08 13:53:47 +02:00
}