1
0

Added m_IsFlying and m_CanFly. Both have a Get and Set function. Added cClientHandle::SendPlayerAbilities() function

This commit is contained in:
STRWarrior 2013-12-15 14:48:17 +01:00
parent 4f92f18a8d
commit b10d0b95cb
5 changed files with 90 additions and 3 deletions

View File

@ -490,6 +490,30 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel
void cClientHandle::HandlePlayerAbilities(int Flags, float FlyingSpeed, float WalkingSpeed)
{
if ((Flags & 2) != 0)
{
m_Player->SetFlying(true);
}
else
{
m_Player->SetFlying(false);
}
if ((Flags & 4) != 0)
{
m_Player->SetCanFly(true);
}
else
{
m_Player->SetCanFly(false);
}
}
void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround) void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround)
{ {
if ((m_Player == NULL) || (m_State != csPlaying)) if ((m_Player == NULL) || (m_State != csPlaying))
@ -1831,6 +1855,15 @@ void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animati
void cClientHandle::SendPlayerAbilities()
{
m_Protocol->SendPlayerAbilities();
}
void cClientHandle::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) void cClientHandle::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline)
{ {
m_Protocol->SendPlayerListItem(a_Player, a_IsOnline); m_Protocol->SendPlayerListItem(a_Player, a_IsOnline);

View File

@ -116,6 +116,7 @@ public:
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
void SendPickupSpawn (const cPickup & a_Pickup); void SendPickupSpawn (const cPickup & a_Pickup);
void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); void SendEntityAnimation (const cEntity & a_Entity, char a_Animation);
void SendPlayerAbilities (void);
void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline); void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline);
void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+) void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+)
void SendPlayerMoveLook (void); void SendPlayerMoveLook (void);
@ -175,6 +176,7 @@ public:
void HandleKeepAlive (int a_KeepAliveID); void HandleKeepAlive (int a_KeepAliveID);
void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
void HandlePing (void); void HandlePing (void);
void HandlePlayerAbilities (int Flags, float FlyingSpeed, float WalkingSpeed);
void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround); void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround);
void HandlePlayerMoveLook (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround); // While m_bPositionConfirmed (normal gameplay) void HandlePlayerMoveLook (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround); // While m_bPositionConfirmed (normal gameplay)
void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround); void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround);

View File

@ -63,6 +63,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_IsSprinting(false) , m_IsSprinting(false)
, m_IsSwimming(false) , m_IsSwimming(false)
, m_IsSubmerged(false) , m_IsSubmerged(false)
, m_IsFlying(false)
, m_CanFly(false)
, m_EatingFinishTick(-1) , m_EatingFinishTick(-1)
, m_IsChargingBow(false) , m_IsChargingBow(false)
, m_BowCharge(0) , m_BowCharge(0)
@ -751,6 +753,36 @@ void cPlayer::SetSprint(bool a_IsSprinting)
void cPlayer::SetCanFly(bool a_CanFly)
{
if (a_CanFly == m_CanFly)
{
return;
}
m_CanFly = a_CanFly;
m_ClientHandle->SendPlayerAbilities();
}
void cPlayer::SetFlying(bool a_IsFlying)
{
if (a_IsFlying == m_IsFlying)
{
return;
}
m_IsFlying = a_IsFlying;
m_ClientHandle->SendPlayerAbilities();
}
void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{ {
if (a_TDI.DamageType != dtInVoid) if (a_TDI.DamageType != dtInVoid)

View File

@ -250,6 +250,8 @@ public:
/// Returns true if the player is currently in the process of eating the currently equipped item /// Returns true if the player is currently in the process of eating the currently equipped item
bool IsEating(void) const { return (m_EatingFinishTick >= 0); } bool IsEating(void) const { return (m_EatingFinishTick >= 0); }
/// Returns true if the player is currently flying.
bool IsFlying(void) const { return m_IsFlying; }
// tolua_end // tolua_end
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
@ -319,12 +321,20 @@ public:
/// Starts or stops sprinting, sends the max speed update to the client, if needed /// Starts or stops sprinting, sends the max speed update to the client, if needed
void SetSprint(bool a_IsSprinting); void SetSprint(bool a_IsSprinting);
/// Flags the player as flying
void SetFlying(bool a_IsFlying);
/// If true the player can fly even when he's not in creative.
void SetCanFly(bool a_CanFly);
/// Returns whether the player is swimming or not /// Returns whether the player is swimming or not
virtual bool IsSwimming(void) const{ return m_IsSwimming; } virtual bool IsSwimming(void) const{ return m_IsSwimming; }
/// Return whether the player is under water or not /// Return whether the player is under water or not
virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } virtual bool IsSubmerged(void) const{ return m_IsSubmerged; }
/// Returns wheter the player can fly or not.
virtual bool CanFly(void) const { return m_CanFly; }
// tolua_end // tolua_end
// cEntity overrides: // cEntity overrides:
@ -415,10 +425,12 @@ protected:
bool m_IsCrouched; bool m_IsCrouched;
bool m_IsSprinting; bool m_IsSprinting;
bool m_IsFlying;
bool m_IsSwimming; bool m_IsSwimming;
bool m_IsSubmerged; bool m_IsSubmerged;
bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
/// The world tick in which eating will be finished. -1 if not eating /// The world tick in which eating will be finished. -1 if not eating
Int64 m_EatingFinishTick; Int64 m_EatingFinishTick;

View File

@ -491,7 +491,15 @@ void cProtocol172::SendPlayerAbilities(void)
{ {
Flags |= 0x01; Flags |= 0x01;
} }
// TODO: Other flags (god mode, flying, can fly if (m_Client->GetPlayer()->IsFlying())
{
Flags |= 0x02;
}
if (m_Client->GetPlayer()->CanFly())
{
Flags |= 0x04;
}
// TODO: Other flags (god mode)
Pkt.WriteByte(Flags); Pkt.WriteByte(Flags);
// TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed()); // TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed());
Pkt.WriteFloat(0.05f); Pkt.WriteFloat(0.05f);
@ -1278,7 +1286,7 @@ void cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
// TODO: m_Client->HandlePlayerAbilities(); m_Client->HandlePlayerAbilities(Flags, FlyingSpeed, WalkingSpeed);
} }