From 85eb9bbc323447b88831a97eb137436738bbf858 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 14 Jul 2022 13:09:38 +0200 Subject: [PATCH] add exp sync --- include/game/client/ClientGame.h | 1 + include/protocol/Protocol.h | 2 ++ src/game/client/ClientGame.cpp | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/include/game/client/ClientGame.h b/include/game/client/ClientGame.h index 2a04c3f..a83a24d 100644 --- a/include/game/client/ClientGame.h +++ b/include/game/client/ClientGame.h @@ -47,6 +47,7 @@ public: virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override; virtual void HandlePacket(const protocol::UpdateLobbyTimePacket* packet) override; virtual void HandlePacket(const protocol::UpdateMoneyPacket* packet) override; + virtual void HandlePacket(const protocol::UpdateExpPacket* packet) override; virtual void HandlePacket(const protocol::DisconnectPacket* packet) override; virtual void HandlePacket(const protocol::WorldDataPacket* packet) override; diff --git a/include/protocol/Protocol.h b/include/protocol/Protocol.h index ced2a0b..060a8ed 100644 --- a/include/protocol/Protocol.h +++ b/include/protocol/Protocol.h @@ -199,6 +199,8 @@ public: UpdateExpPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {} virtual ~UpdateExpPacket() {} + std::uint32_t GetExp() const { return m_NewAmount; } + virtual DataBuffer Serialize(bool packetID = true) const; virtual void Deserialize(DataBuffer& data); virtual void Dispatch(PacketHandler* handler) const; diff --git a/src/game/client/ClientGame.cpp b/src/game/client/ClientGame.cpp index f235d90..d8b2a4f 100644 --- a/src/game/client/ClientGame.cpp +++ b/src/game/client/ClientGame.cpp @@ -16,6 +16,7 @@ m_WorldRenderer(&m_WorldClient, this) { GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateLobbyTime, this); GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateGameState, this); GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateMoney, this); + GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateEXP, this); GetDispatcher()->RegisterHandler(protocol::PacketType::Disconnect, this); GetDispatcher()->RegisterHandler(protocol::PacketType::WorldData, this); } @@ -91,6 +92,10 @@ void ClientGame::HandlePacket(const protocol::UpdateMoneyPacket* packet) { m_Player->SetGold(packet->GetGold()); } +void ClientGame::HandlePacket(const protocol::UpdateExpPacket* packet) { + m_Player->SetExp(packet->GetExp()); +} + void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) { m_GameState = game::GameState::Disconnected; m_Renderer->SetBackgroundColor({ 0, 0, 0 });