Packets Refactor
commit 497a601c424e8e728ef0a8e61f049982f2d4af16 Author: Persson-dev <sim16.prib@gmail.com> Date: Sat Aug 12 10:32:52 2023 +0200 fix warning commit 1bfd019a1ea00dcdb6323d1f285e2cdd3ebb4020 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:05:13 2023 +0200 refactor: update cast commit 5bbc23a7d37e53eb74a885685f18e714f9448fd9 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:04:15 2023 +0200 moved GetImguiTeamColor commit fd0e2d2470ea5cca3553acf280aa371de5c06f4c Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 19:03:37 2023 +0200 packets forward declaration commit 06eb9b99a96731f4b9a2167c00ed0bcd03702e3b Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 18:30:55 2023 +0200 remove Protocol.h includes commit 165f63d2e8b468f3e38992baddc221270010f801 Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 18:30:30 2023 +0200 split packets into separate source files commit f247f146c6c1e804a44b86f65cf3059859c07c6c Author: Persson-dev <sim16.prib@gmail.com> Date: Tue Jul 25 17:45:24 2023 +0200 split packets into separate headers
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "game/Player.h"
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "protocol/packets/SendMobsPacket.h"
|
||||
|
||||
#include "render/Renderer.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "protocol/PacketsForward.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
27
include/protocol/Packets.h
Normal file
27
include/protocol/Packets.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "packets/ConnectionInfoPacket.h"
|
||||
#include "packets/DisconnectPacket.h"
|
||||
#include "packets/KeepAlivePacket.h"
|
||||
#include "packets/PlaceTowerPacket.h"
|
||||
#include "packets/PlayerBuyItemPacket.h"
|
||||
#include "packets/PlayerBuyMobUpgradePacket.h"
|
||||
#include "packets/PlayerJoinPacket.h"
|
||||
#include "packets/PlayerLeavePacket.h"
|
||||
#include "packets/PlayerListPacket.h"
|
||||
#include "packets/PlayerLoginPacket.h"
|
||||
#include "packets/RemoveTowerPacket.h"
|
||||
#include "packets/SelectTeamPacket.h"
|
||||
#include "packets/SendMobsPacket.h"
|
||||
#include "packets/ServerTpsPacket.h"
|
||||
#include "packets/SpawnMobPacket.h"
|
||||
#include "packets/UpdateCastleLifePacket.h"
|
||||
#include "packets/UpdateExpPacket.h"
|
||||
#include "packets/UpdateGameStatePacket.h"
|
||||
#include "packets/UpdateLobbyTimePacket.h"
|
||||
#include "packets/UpdateMobStatesPacket.h"
|
||||
#include "packets/UpdateMoneyPacket.h"
|
||||
#include "packets/UpdatePlayerTeamPacket.h"
|
||||
#include "packets/UpgradeTowerPacket.h"
|
||||
#include "packets/WorldAddTowerPacket.h"
|
||||
#include "packets/WorldAddTowerPacket.h"
|
||||
#include "packets/WorldBeginDataPacket.h"
|
||||
#include "packets/WorldDataPacket.h"
|
||||
34
include/protocol/PacketsForward.h
Normal file
34
include/protocol/PacketsForward.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class PlayerLoginPacket;
|
||||
class WorldBeginDataPacket;
|
||||
class WorldDataPacket;
|
||||
class KeepAlivePacket;
|
||||
class UpdateExpPacket;
|
||||
class UpdateMoneyPacket;
|
||||
class UpdateLobbyTimePacket;
|
||||
class UpdateGameStatePacket;
|
||||
class PlayerListPacket;
|
||||
class PlayerJoinPacket;
|
||||
class PlayerLeavePacket;
|
||||
class ConnexionInfoPacket;
|
||||
class SelectTeamPacket;
|
||||
class UpdatePlayerTeamPacket;
|
||||
class DisconnectPacket;
|
||||
class ServerTpsPacket;
|
||||
class SpawnMobPacket;
|
||||
class PlaceTowerPacket;
|
||||
class WorldAddTowerPacket;
|
||||
class RemoveTowerPacket;
|
||||
class SendMobsPacket;
|
||||
class UpgradeTowerPacket;
|
||||
class UpdateCastleLifePacket;
|
||||
class UpdateMobStatesPacket;
|
||||
class PlayerBuyItemPacket;
|
||||
class PlayerBuyMobUpgradePacket;
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "misc/DataBuffer.h"
|
||||
#include "game/World.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -47,26 +45,6 @@ enum class PacketType : std::uint8_t {
|
||||
PACKET_COUNT
|
||||
};
|
||||
|
||||
struct WorldHeader {
|
||||
game::TowerTileColorPalette m_TowerPlacePalette;
|
||||
Color m_WalkablePalette;
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
game::SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
game::TilePalette m_TilePalette;
|
||||
|
||||
game::Spawn m_RedSpawn, m_BlueSpawn;
|
||||
game::TeamCastle m_RedCastle, m_BlueCastle;
|
||||
|
||||
const game::World* m_World;
|
||||
};
|
||||
|
||||
struct WorldData {
|
||||
std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
|
||||
};
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
Packet() {}
|
||||
@@ -84,556 +62,5 @@ public:
|
||||
|
||||
typedef std::unique_ptr<Packet> PacketPtr;
|
||||
|
||||
class KeepAlivePacket : public Packet {
|
||||
private:
|
||||
std::uint64_t m_AliveID;
|
||||
public:
|
||||
KeepAlivePacket() {}
|
||||
KeepAlivePacket(std::uint64_t aliveID) : m_AliveID(aliveID) {}
|
||||
virtual ~KeepAlivePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint64_t GetAliveID() const { return m_AliveID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::KeepAlive; }
|
||||
};
|
||||
|
||||
class PlayerLoginPacket : public Packet {
|
||||
private:
|
||||
std::string m_PlayerName;
|
||||
public:
|
||||
PlayerLoginPacket() {}
|
||||
PlayerLoginPacket(std::string playerName) : m_PlayerName(playerName) {}
|
||||
virtual ~PlayerLoginPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerLogin; }
|
||||
|
||||
const std::string& GetPlayerName() const { return m_PlayerName; }
|
||||
};
|
||||
|
||||
class WorldBeginDataPacket : public Packet {
|
||||
private:
|
||||
WorldHeader m_Header;
|
||||
public:
|
||||
WorldBeginDataPacket() {}
|
||||
WorldBeginDataPacket(const game::World* world) {
|
||||
m_Header.m_World = world;
|
||||
}
|
||||
virtual ~WorldBeginDataPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldBeginData; }
|
||||
|
||||
const game::TowerTileColorPalette& GetTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
|
||||
const Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
||||
const std::vector<Color>& GetDecorationPalette() const { return m_Header.m_DecorationPalette; }
|
||||
const Color& GetBackgroundColor() const { return m_Header.m_Background; }
|
||||
|
||||
const game::Spawn& GetRedSpawn() const { return m_Header.m_RedSpawn; }
|
||||
const game::Spawn& GetBlueSpawn() const { return m_Header.m_BlueSpawn; }
|
||||
|
||||
const game::SpawnColorPalette& GetSpawnPalette() const { return m_Header.m_SpawnColorPalette; }
|
||||
|
||||
const game::TeamCastle& GetRedCastle() const { return m_Header.m_RedCastle; }
|
||||
const game::TeamCastle& GetBlueCastle() const { return m_Header.m_BlueCastle; }
|
||||
|
||||
const game::TilePalette GetTilePalette() const { return m_Header.m_TilePalette; }
|
||||
|
||||
void setWorldHeader(const WorldHeader& header) { m_Header = header; }
|
||||
};
|
||||
|
||||
class WorldDataPacket : public Packet {
|
||||
private:
|
||||
WorldData m_WorldData;
|
||||
|
||||
const game::World* m_World;
|
||||
public:
|
||||
WorldDataPacket() {}
|
||||
WorldDataPacket(const game::World* world) : m_World(world) {}
|
||||
virtual ~WorldDataPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldData; }
|
||||
|
||||
const std::unordered_map<game::ChunkCoord, game::ChunkPtr>& GetChunks() const { return m_WorldData.m_Chunks; }
|
||||
|
||||
DataBuffer SerializeCustom() const; // allow serialisation with invalid World member
|
||||
void SetWorldData(const WorldData& worldData) { m_WorldData = worldData; }
|
||||
};
|
||||
|
||||
class UpdateMoneyPacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_NewAmount;
|
||||
public:
|
||||
UpdateMoneyPacket() {}
|
||||
UpdateMoneyPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
|
||||
virtual ~UpdateMoneyPacket() {}
|
||||
|
||||
std::uint32_t GetGold() const { return m_NewAmount; }
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateMoney; }
|
||||
};
|
||||
|
||||
class UpdateExpPacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_NewAmount;
|
||||
public:
|
||||
UpdateExpPacket() {}
|
||||
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;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateEXP; }
|
||||
};
|
||||
|
||||
class UpdateLobbyTimePacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_RemainingTime;
|
||||
public:
|
||||
UpdateLobbyTimePacket() {}
|
||||
UpdateLobbyTimePacket(std::uint32_t remainingTime) : m_RemainingTime(remainingTime) {}
|
||||
virtual ~UpdateLobbyTimePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint32_t GetRemainingTime() const { return m_RemainingTime; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateLobbyTime; }
|
||||
};
|
||||
|
||||
class UpdateGameStatePacket : public Packet {
|
||||
private:
|
||||
game::GameState m_GameState;
|
||||
public:
|
||||
UpdateGameStatePacket() {}
|
||||
UpdateGameStatePacket(game::GameState gameState) : m_GameState(gameState) {}
|
||||
virtual ~UpdateGameStatePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::GameState GetGameState() const { return m_GameState; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateGameState; }
|
||||
};
|
||||
|
||||
struct PlayerInfo {
|
||||
std::string name;
|
||||
game::TeamColor team;
|
||||
};
|
||||
|
||||
class PlayerListPacket : public Packet {
|
||||
private:
|
||||
std::map<std::uint8_t, PlayerInfo> m_Players;
|
||||
public:
|
||||
PlayerListPacket() {}
|
||||
PlayerListPacket(std::map<std::uint8_t, PlayerInfo> players) : m_Players(players) {}
|
||||
virtual ~PlayerListPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::map<std::uint8_t, PlayerInfo>& GetPlayers() const { return m_Players; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerList; }
|
||||
};
|
||||
|
||||
class PlayerJoinPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
std::string m_PlayerName;
|
||||
public:
|
||||
PlayerJoinPacket() {}
|
||||
PlayerJoinPacket(std::uint8_t playerID, const std::string& playerName) : m_PlayerID(playerID), m_PlayerName(playerName) {}
|
||||
virtual ~PlayerJoinPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
const std::string& GetPlayerName() const { return m_PlayerName; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerJoin; }
|
||||
};
|
||||
|
||||
class PlayerLeavePacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
public:
|
||||
PlayerLeavePacket() {}
|
||||
PlayerLeavePacket(std::uint8_t playerID) : m_PlayerID(playerID) {}
|
||||
virtual ~PlayerLeavePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerLeave; }
|
||||
};
|
||||
|
||||
class ConnexionInfoPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_ConnectionID;
|
||||
public:
|
||||
ConnexionInfoPacket() {}
|
||||
ConnexionInfoPacket(std::uint8_t connectionID) : m_ConnectionID(connectionID) {}
|
||||
virtual ~ConnexionInfoPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetConnectionID() const { return m_ConnectionID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::ConnectionInfo; }
|
||||
};
|
||||
|
||||
class SelectTeamPacket : public Packet {
|
||||
private:
|
||||
game::TeamColor m_SelectedTeam;
|
||||
public:
|
||||
SelectTeamPacket() {}
|
||||
SelectTeamPacket(game::TeamColor selectedTeam) : m_SelectedTeam(selectedTeam) {}
|
||||
virtual ~SelectTeamPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SelectTeam; }
|
||||
};
|
||||
|
||||
class UpdatePlayerTeamPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
game::TeamColor m_SelectedTeam;
|
||||
public:
|
||||
UpdatePlayerTeamPacket() {}
|
||||
UpdatePlayerTeamPacket(std::uint8_t playerID, game::TeamColor selectedTeam) : m_PlayerID(playerID), m_SelectedTeam(selectedTeam) {}
|
||||
virtual ~UpdatePlayerTeamPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdatePlayerTeam; }
|
||||
};
|
||||
|
||||
class DisconnectPacket : public Packet {
|
||||
private:
|
||||
std::string m_Reason; // only when sent from server
|
||||
public:
|
||||
DisconnectPacket() {}
|
||||
DisconnectPacket(std::string reason) : m_Reason(reason) {}
|
||||
virtual ~DisconnectPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::string& GetReason() const { return m_Reason; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::Disconnect; }
|
||||
};
|
||||
|
||||
class ServerTpsPacket : public Packet {
|
||||
private:
|
||||
float m_TPS;
|
||||
float m_MSPT;
|
||||
std::uint64_t m_PacketSendTime; // used to calculate ping
|
||||
public:
|
||||
ServerTpsPacket() {}
|
||||
ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
|
||||
virtual ~ServerTpsPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
float GetTPS() const { return m_TPS; }
|
||||
float GetMSPT() const { return m_MSPT; }
|
||||
std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::ServerTps; }
|
||||
};
|
||||
|
||||
struct MobSend { // represents a mob send
|
||||
game::MobType mobType : 4;
|
||||
game::MobLevel mobLevel : 4;
|
||||
std::uint8_t mobCount; // the max is 12
|
||||
};
|
||||
|
||||
class SendMobsPacket : public Packet {
|
||||
private:
|
||||
std::vector<MobSend> m_MobSends;
|
||||
public:
|
||||
SendMobsPacket() {}
|
||||
SendMobsPacket(const std::vector<MobSend>& mobSends) : m_MobSends(mobSends) {}
|
||||
virtual ~SendMobsPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::vector<MobSend>& GetMobSends() const { return m_MobSends; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SendMobs; }
|
||||
};
|
||||
|
||||
class SpawnMobPacket : public Packet {
|
||||
private:
|
||||
game::MobID m_MobID;
|
||||
game::MobType m_MobType;
|
||||
game::MobLevel m_MobLevel;
|
||||
game::Direction m_MobDirection;
|
||||
game::PlayerID m_Sender;
|
||||
float m_MobX, m_MobY;
|
||||
public:
|
||||
SpawnMobPacket() {}
|
||||
SpawnMobPacket(game::MobID id, game::MobType type, std::uint8_t level, game::PlayerID sender,
|
||||
float x, float y, game::Direction dir) : m_MobID(id), m_MobType(type), m_MobLevel(level),
|
||||
m_MobDirection(dir), m_Sender(sender), m_MobX(x), m_MobY(y) {
|
||||
}
|
||||
virtual ~SpawnMobPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::MobID GetMobID() const { return m_MobID; }
|
||||
game::MobType GetMobType() const { return m_MobType; }
|
||||
game::MobLevel GetMobLevel() const { return m_MobLevel; }
|
||||
game::Direction GetMobDirection() const { return m_MobDirection; }
|
||||
game::PlayerID GetSender() const { return m_Sender; }
|
||||
float GetMobX() const { return m_MobX; }
|
||||
float GetMobY() const { return m_MobY; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SpawnMob; }
|
||||
};
|
||||
|
||||
class PlaceTowerPacket : public Packet {
|
||||
private:
|
||||
std::int32_t m_TowerX, m_TowerY;
|
||||
game::TowerType m_TowerType;
|
||||
public:
|
||||
PlaceTowerPacket() {}
|
||||
PlaceTowerPacket(std::int32_t x, std::int32_t y, game::TowerType type) :
|
||||
m_TowerX(x), m_TowerY(y), m_TowerType(type) {
|
||||
}
|
||||
virtual ~PlaceTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::int32_t GetTowerX() const { return m_TowerX; }
|
||||
std::int32_t GetTowerY() const { return m_TowerY; }
|
||||
game::TowerType GetTowerType() const { return m_TowerType; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlaceTower; }
|
||||
};
|
||||
|
||||
class WorldAddTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
std::int32_t m_TowerX, m_TowerY;
|
||||
game::TowerType m_TowerType;
|
||||
game::PlayerID m_Builder;
|
||||
public:
|
||||
WorldAddTowerPacket() {}
|
||||
WorldAddTowerPacket(game::TowerID id, std::int32_t x, std::int32_t y, game::TowerType type, game::PlayerID player) :
|
||||
m_TowerID(id), m_TowerX(x), m_TowerY(y), m_TowerType(type), m_Builder(player) {
|
||||
}
|
||||
virtual ~WorldAddTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
std::int32_t GetTowerX() const { return m_TowerX; }
|
||||
std::int32_t GetTowerY() const { return m_TowerY; }
|
||||
game::TowerType GetTowerType() const { return m_TowerType; }
|
||||
game::PlayerID GetBuilder() const { return m_Builder; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldAddTower; }
|
||||
};
|
||||
|
||||
class RemoveTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
public:
|
||||
RemoveTowerPacket() {}
|
||||
RemoveTowerPacket(game::TowerID id) : m_TowerID(id) {}
|
||||
virtual ~RemoveTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::RemoveTower; }
|
||||
};
|
||||
|
||||
class UpgradeTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
game::TowerLevel m_TowerLevel;
|
||||
public:
|
||||
UpgradeTowerPacket() {}
|
||||
UpgradeTowerPacket(game::TowerID tower, game::TowerLevel level) : m_TowerID(tower), m_TowerLevel(level) {}
|
||||
virtual ~UpgradeTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
game::TowerLevel GetTowerLevel() const { return m_TowerLevel; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpgradeTower; }
|
||||
};
|
||||
|
||||
class MobState {
|
||||
using Point = utils::shape::Point;
|
||||
private:
|
||||
game::MobID m_MobID;
|
||||
Point m_MobPosition;
|
||||
float m_MobLife;
|
||||
game::Direction m_MobDirection;
|
||||
public:
|
||||
MobState() {}
|
||||
MobState(game::MobID id, const Point& position, float life, game::Direction direction) :
|
||||
m_MobID(id), m_MobPosition(position), m_MobLife(life), m_MobDirection(direction) {
|
||||
}
|
||||
|
||||
game::MobID GetMobId() const { return m_MobID; }
|
||||
Point GetMobPosition() const { return m_MobPosition; }
|
||||
float GetMobLife() const { return m_MobLife; }
|
||||
game::Direction GetMobDirection() const { return m_MobDirection; }
|
||||
};
|
||||
|
||||
class UpdateMobStatesPacket : public Packet {
|
||||
private:
|
||||
std::vector<MobState> m_MobStates;
|
||||
public:
|
||||
UpdateMobStatesPacket() {}
|
||||
virtual ~UpdateMobStatesPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
void addMobState(MobState mobState) { m_MobStates.push_back(mobState); }
|
||||
|
||||
const std::vector<MobState>& GetMobStates() const { return m_MobStates; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateMobStates; }
|
||||
};
|
||||
|
||||
class UpdateCastleLifePacket : public Packet {
|
||||
private:
|
||||
std::uint16_t m_CastleLife;
|
||||
game::TeamColor m_Team;
|
||||
public:
|
||||
UpdateCastleLifePacket() {}
|
||||
UpdateCastleLifePacket(std::uint16_t life, game::TeamColor team) : m_CastleLife(life), m_Team(team) {}
|
||||
virtual ~UpdateCastleLifePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint16_t GetCastleLife() const { return m_CastleLife; }
|
||||
game::TeamColor GetTeamColor() const { return m_Team; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateCastleLife; }
|
||||
};
|
||||
|
||||
enum class ItemType : std::uint8_t {
|
||||
// Upgrades
|
||||
ClickerUpgrade,
|
||||
GoldPerSecUpgrade,
|
||||
|
||||
// Items
|
||||
};
|
||||
|
||||
/** Packet used by the client to buy items or upgrades
|
||||
Packet used by the server to confirm transaction */
|
||||
class PlayerBuyItemPacket : public Packet {
|
||||
private:
|
||||
ItemType m_ItemType;
|
||||
std::uint8_t m_Count;
|
||||
public:
|
||||
PlayerBuyItemPacket() {}
|
||||
PlayerBuyItemPacket(ItemType itemType, std::uint8_t count) : m_ItemType(itemType), m_Count(count) {}
|
||||
virtual ~PlayerBuyItemPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
ItemType GetItemType() const { return m_ItemType; }
|
||||
std::uint8_t GetCount() const { return m_Count; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerBuyItem; }
|
||||
};
|
||||
|
||||
/** Packet used by the client to buy mob upgrades
|
||||
Packet used by the server to confirm transaction */
|
||||
class PlayerBuyMobUpgradePacket : public Packet {
|
||||
private:
|
||||
game::MobType m_MobType;
|
||||
std::uint8_t m_MobLevel;
|
||||
public:
|
||||
PlayerBuyMobUpgradePacket() {}
|
||||
PlayerBuyMobUpgradePacket(game::MobType mobType, std::uint8_t level) : m_MobType(mobType), m_MobLevel(level) {}
|
||||
virtual ~PlayerBuyMobUpgradePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::MobType GetMobType() const { return m_MobType; }
|
||||
std::uint8_t GetLevel() const { return m_MobLevel; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerBuyMobUpgrade; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/ConnectionInfoPacket.h
Normal file
26
include/protocol/packets/ConnectionInfoPacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class ConnexionInfoPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_ConnectionID;
|
||||
public:
|
||||
ConnexionInfoPacket() {}
|
||||
ConnexionInfoPacket(std::uint8_t connectionID) : m_ConnectionID(connectionID) {}
|
||||
virtual ~ConnexionInfoPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetConnectionID() const { return m_ConnectionID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::ConnectionInfo; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/DisconnectPacket.h
Normal file
26
include/protocol/packets/DisconnectPacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class DisconnectPacket : public Packet {
|
||||
private:
|
||||
std::string m_Reason; // only when sent from server
|
||||
public:
|
||||
DisconnectPacket() {}
|
||||
DisconnectPacket(std::string reason) : m_Reason(reason) {}
|
||||
virtual ~DisconnectPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::string& GetReason() const { return m_Reason; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::Disconnect; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/KeepAlivePacket.h
Normal file
26
include/protocol/packets/KeepAlivePacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class KeepAlivePacket : public Packet {
|
||||
private:
|
||||
std::uint64_t m_AliveID;
|
||||
public:
|
||||
KeepAlivePacket() {}
|
||||
KeepAlivePacket(std::uint64_t aliveID) : m_AliveID(aliveID) {}
|
||||
virtual ~KeepAlivePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint64_t GetAliveID() const { return m_AliveID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::KeepAlive; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
32
include/protocol/packets/PlaceTowerPacket.h
Normal file
32
include/protocol/packets/PlaceTowerPacket.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class PlaceTowerPacket : public Packet {
|
||||
private:
|
||||
std::int32_t m_TowerX, m_TowerY;
|
||||
game::TowerType m_TowerType;
|
||||
public:
|
||||
PlaceTowerPacket() {}
|
||||
PlaceTowerPacket(std::int32_t x, std::int32_t y, game::TowerType type) :
|
||||
m_TowerX(x), m_TowerY(y), m_TowerType(type) {
|
||||
}
|
||||
virtual ~PlaceTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::int32_t GetTowerX() const { return m_TowerX; }
|
||||
std::int32_t GetTowerY() const { return m_TowerY; }
|
||||
game::TowerType GetTowerType() const { return m_TowerType; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlaceTower; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
38
include/protocol/packets/PlayerBuyItemPacket.h
Normal file
38
include/protocol/packets/PlayerBuyItemPacket.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
enum class ItemType : std::uint8_t {
|
||||
// Upgrades
|
||||
ClickerUpgrade,
|
||||
GoldPerSecUpgrade,
|
||||
|
||||
// Items
|
||||
};
|
||||
|
||||
/** Packet used by the client to buy items or upgrades
|
||||
Packet used by the server to confirm transaction */
|
||||
class PlayerBuyItemPacket : public Packet {
|
||||
private:
|
||||
ItemType m_ItemType;
|
||||
std::uint8_t m_Count;
|
||||
public:
|
||||
PlayerBuyItemPacket() {}
|
||||
PlayerBuyItemPacket(ItemType itemType, std::uint8_t count) : m_ItemType(itemType), m_Count(count) {}
|
||||
virtual ~PlayerBuyItemPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
ItemType GetItemType() const { return m_ItemType; }
|
||||
std::uint8_t GetCount() const { return m_Count; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerBuyItem; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
31
include/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal file
31
include/protocol/packets/PlayerBuyMobUpgradePacket.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
/** Packet used by the client to buy mob upgrades
|
||||
Packet used by the server to confirm transaction */
|
||||
class PlayerBuyMobUpgradePacket : public Packet {
|
||||
private:
|
||||
game::MobType m_MobType;
|
||||
std::uint8_t m_MobLevel;
|
||||
public:
|
||||
PlayerBuyMobUpgradePacket() {}
|
||||
PlayerBuyMobUpgradePacket(game::MobType mobType, std::uint8_t level) : m_MobType(mobType), m_MobLevel(level) {}
|
||||
virtual ~PlayerBuyMobUpgradePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::MobType GetMobType() const { return m_MobType; }
|
||||
std::uint8_t GetLevel() const { return m_MobLevel; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerBuyMobUpgrade; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
28
include/protocol/packets/PlayerJoinPacket.h
Normal file
28
include/protocol/packets/PlayerJoinPacket.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class PlayerJoinPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
std::string m_PlayerName;
|
||||
public:
|
||||
PlayerJoinPacket() {}
|
||||
PlayerJoinPacket(std::uint8_t playerID, const std::string& playerName) : m_PlayerID(playerID), m_PlayerName(playerName) {}
|
||||
virtual ~PlayerJoinPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
const std::string& GetPlayerName() const { return m_PlayerName; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerJoin; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/PlayerLeavePacket.h
Normal file
26
include/protocol/packets/PlayerLeavePacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class PlayerLeavePacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
public:
|
||||
PlayerLeavePacket() {}
|
||||
PlayerLeavePacket(std::uint8_t playerID) : m_PlayerID(playerID) {}
|
||||
virtual ~PlayerLeavePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerLeave; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
32
include/protocol/packets/PlayerListPacket.h
Normal file
32
include/protocol/packets/PlayerListPacket.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
struct PlayerInfo {
|
||||
std::string name;
|
||||
game::TeamColor team;
|
||||
};
|
||||
|
||||
class PlayerListPacket : public Packet {
|
||||
private:
|
||||
std::map<std::uint8_t, PlayerInfo> m_Players;
|
||||
public:
|
||||
PlayerListPacket() {}
|
||||
PlayerListPacket(std::map<std::uint8_t, PlayerInfo> players) : m_Players(players) {}
|
||||
virtual ~PlayerListPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::map<std::uint8_t, PlayerInfo>& GetPlayers() const { return m_Players; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerList; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/PlayerLoginPacket.h
Normal file
26
include/protocol/packets/PlayerLoginPacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class PlayerLoginPacket : public Packet {
|
||||
private:
|
||||
std::string m_PlayerName;
|
||||
public:
|
||||
PlayerLoginPacket() {}
|
||||
PlayerLoginPacket(std::string playerName) : m_PlayerName(playerName) {}
|
||||
virtual ~PlayerLoginPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::PlayerLogin; }
|
||||
|
||||
const std::string& GetPlayerName() const { return m_PlayerName; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
27
include/protocol/packets/RemoveTowerPacket.h
Normal file
27
include/protocol/packets/RemoveTowerPacket.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class RemoveTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
public:
|
||||
RemoveTowerPacket() {}
|
||||
RemoveTowerPacket(game::TowerID id) : m_TowerID(id) {}
|
||||
virtual ~RemoveTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::RemoveTower; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
27
include/protocol/packets/SelectTeamPacket.h
Normal file
27
include/protocol/packets/SelectTeamPacket.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class SelectTeamPacket : public Packet {
|
||||
private:
|
||||
game::TeamColor m_SelectedTeam;
|
||||
public:
|
||||
SelectTeamPacket() {}
|
||||
SelectTeamPacket(game::TeamColor selectedTeam) : m_SelectedTeam(selectedTeam) {}
|
||||
virtual ~SelectTeamPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SelectTeam; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
33
include/protocol/packets/SendMobsPacket.h
Normal file
33
include/protocol/packets/SendMobsPacket.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
struct MobSend { // represents a mob send
|
||||
game::MobType mobType : 4;
|
||||
game::MobLevel mobLevel : 4;
|
||||
std::uint8_t mobCount; // the max is 12
|
||||
};
|
||||
|
||||
class SendMobsPacket : public Packet {
|
||||
private:
|
||||
std::vector<MobSend> m_MobSends;
|
||||
public:
|
||||
SendMobsPacket() {}
|
||||
SendMobsPacket(const std::vector<MobSend>& mobSends) : m_MobSends(mobSends) {}
|
||||
virtual ~SendMobsPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
const std::vector<MobSend>& GetMobSends() const { return m_MobSends; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SendMobs; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
30
include/protocol/packets/ServerTpsPacket.h
Normal file
30
include/protocol/packets/ServerTpsPacket.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class ServerTpsPacket : public Packet {
|
||||
private:
|
||||
float m_TPS;
|
||||
float m_MSPT;
|
||||
std::uint64_t m_PacketSendTime; // used to calculate ping
|
||||
public:
|
||||
ServerTpsPacket() {}
|
||||
ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
|
||||
virtual ~ServerTpsPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
float GetTPS() const { return m_TPS; }
|
||||
float GetMSPT() const { return m_MSPT; }
|
||||
std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::ServerTps; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
41
include/protocol/packets/SpawnMobPacket.h
Normal file
41
include/protocol/packets/SpawnMobPacket.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class SpawnMobPacket : public Packet {
|
||||
private:
|
||||
game::MobID m_MobID;
|
||||
game::MobType m_MobType;
|
||||
game::MobLevel m_MobLevel;
|
||||
game::Direction m_MobDirection;
|
||||
game::PlayerID m_Sender;
|
||||
float m_MobX, m_MobY;
|
||||
public:
|
||||
SpawnMobPacket() {}
|
||||
SpawnMobPacket(game::MobID id, game::MobType type, std::uint8_t level, game::PlayerID sender,
|
||||
float x, float y, game::Direction dir) : m_MobID(id), m_MobType(type), m_MobLevel(level),
|
||||
m_MobDirection(dir), m_Sender(sender), m_MobX(x), m_MobY(y) {
|
||||
}
|
||||
virtual ~SpawnMobPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::MobID GetMobID() const { return m_MobID; }
|
||||
game::MobType GetMobType() const { return m_MobType; }
|
||||
game::MobLevel GetMobLevel() const { return m_MobLevel; }
|
||||
game::Direction GetMobDirection() const { return m_MobDirection; }
|
||||
game::PlayerID GetSender() const { return m_Sender; }
|
||||
float GetMobX() const { return m_MobX; }
|
||||
float GetMobY() const { return m_MobY; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::SpawnMob; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
29
include/protocol/packets/UpdateCastleLifePacket.h
Normal file
29
include/protocol/packets/UpdateCastleLifePacket.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdateCastleLifePacket : public Packet {
|
||||
private:
|
||||
std::uint16_t m_CastleLife;
|
||||
game::TeamColor m_Team;
|
||||
public:
|
||||
UpdateCastleLifePacket() {}
|
||||
UpdateCastleLifePacket(std::uint16_t life, game::TeamColor team) : m_CastleLife(life), m_Team(team) {}
|
||||
virtual ~UpdateCastleLifePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint16_t GetCastleLife() const { return m_CastleLife; }
|
||||
game::TeamColor GetTeamColor() const { return m_Team; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateCastleLife; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/UpdateExpPacket.h
Normal file
26
include/protocol/packets/UpdateExpPacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdateExpPacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_NewAmount;
|
||||
public:
|
||||
UpdateExpPacket() {}
|
||||
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;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateEXP; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
27
include/protocol/packets/UpdateGameStatePacket.h
Normal file
27
include/protocol/packets/UpdateGameStatePacket.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdateGameStatePacket : public Packet {
|
||||
private:
|
||||
game::GameState m_GameState;
|
||||
public:
|
||||
UpdateGameStatePacket() {}
|
||||
UpdateGameStatePacket(game::GameState gameState) : m_GameState(gameState) {}
|
||||
virtual ~UpdateGameStatePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::GameState GetGameState() const { return m_GameState; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateGameState; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/UpdateLobbyTimePacket.h
Normal file
26
include/protocol/packets/UpdateLobbyTimePacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdateLobbyTimePacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_RemainingTime;
|
||||
public:
|
||||
UpdateLobbyTimePacket() {}
|
||||
UpdateLobbyTimePacket(std::uint32_t remainingTime) : m_RemainingTime(remainingTime) {}
|
||||
virtual ~UpdateLobbyTimePacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
std::uint32_t GetRemainingTime() const { return m_RemainingTime; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateLobbyTime; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
47
include/protocol/packets/UpdateMobStatesPacket.h
Normal file
47
include/protocol/packets/UpdateMobStatesPacket.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class MobState {
|
||||
using Point = utils::shape::Point;
|
||||
private:
|
||||
game::MobID m_MobID;
|
||||
Point m_MobPosition;
|
||||
float m_MobLife;
|
||||
game::Direction m_MobDirection;
|
||||
public:
|
||||
MobState() {}
|
||||
MobState(game::MobID id, const Point& position, float life, game::Direction direction) :
|
||||
m_MobID(id), m_MobPosition(position), m_MobLife(life), m_MobDirection(direction) {
|
||||
}
|
||||
|
||||
game::MobID GetMobId() const { return m_MobID; }
|
||||
Point GetMobPosition() const { return m_MobPosition; }
|
||||
float GetMobLife() const { return m_MobLife; }
|
||||
game::Direction GetMobDirection() const { return m_MobDirection; }
|
||||
};
|
||||
|
||||
class UpdateMobStatesPacket : public Packet {
|
||||
private:
|
||||
std::vector<MobState> m_MobStates;
|
||||
public:
|
||||
UpdateMobStatesPacket() {}
|
||||
virtual ~UpdateMobStatesPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
void addMobState(MobState mobState) { m_MobStates.push_back(mobState); }
|
||||
|
||||
const std::vector<MobState>& GetMobStates() const { return m_MobStates; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateMobStates; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
26
include/protocol/packets/UpdateMoneyPacket.h
Normal file
26
include/protocol/packets/UpdateMoneyPacket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdateMoneyPacket : public Packet {
|
||||
private:
|
||||
std::uint32_t m_NewAmount;
|
||||
public:
|
||||
UpdateMoneyPacket() {}
|
||||
UpdateMoneyPacket(std::uint32_t newAmount) : m_NewAmount(newAmount) {}
|
||||
virtual ~UpdateMoneyPacket() {}
|
||||
|
||||
std::uint32_t GetGold() const { return m_NewAmount; }
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdateMoney; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
29
include/protocol/packets/UpdatePlayerTeamPacket.h
Normal file
29
include/protocol/packets/UpdatePlayerTeamPacket.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpdatePlayerTeamPacket : public Packet {
|
||||
private:
|
||||
std::uint8_t m_PlayerID;
|
||||
game::TeamColor m_SelectedTeam;
|
||||
public:
|
||||
UpdatePlayerTeamPacket() {}
|
||||
UpdatePlayerTeamPacket(std::uint8_t playerID, game::TeamColor selectedTeam) : m_PlayerID(playerID), m_SelectedTeam(selectedTeam) {}
|
||||
virtual ~UpdatePlayerTeamPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TeamColor GetSelectedTeam() const { return m_SelectedTeam; }
|
||||
std::uint8_t GetPlayerID() const { return m_PlayerID; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpdatePlayerTeam; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
29
include/protocol/packets/UpgradeTowerPacket.h
Normal file
29
include/protocol/packets/UpgradeTowerPacket.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class UpgradeTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
game::TowerLevel m_TowerLevel;
|
||||
public:
|
||||
UpgradeTowerPacket() {}
|
||||
UpgradeTowerPacket(game::TowerID tower, game::TowerLevel level) : m_TowerID(tower), m_TowerLevel(level) {}
|
||||
virtual ~UpgradeTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
game::TowerLevel GetTowerLevel() const { return m_TowerLevel; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::UpgradeTower; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
36
include/protocol/packets/WorldAddTowerPacket.h
Normal file
36
include/protocol/packets/WorldAddTowerPacket.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
class WorldAddTowerPacket : public Packet {
|
||||
private:
|
||||
game::TowerID m_TowerID;
|
||||
std::int32_t m_TowerX, m_TowerY;
|
||||
game::TowerType m_TowerType;
|
||||
game::PlayerID m_Builder;
|
||||
public:
|
||||
WorldAddTowerPacket() {}
|
||||
WorldAddTowerPacket(game::TowerID id, std::int32_t x, std::int32_t y, game::TowerType type, game::PlayerID player) :
|
||||
m_TowerID(id), m_TowerX(x), m_TowerY(y), m_TowerType(type), m_Builder(player) {
|
||||
}
|
||||
virtual ~WorldAddTowerPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::TowerID GetTowerID() const { return m_TowerID; }
|
||||
std::int32_t GetTowerX() const { return m_TowerX; }
|
||||
std::int32_t GetTowerY() const { return m_TowerY; }
|
||||
game::TowerType GetTowerType() const { return m_TowerType; }
|
||||
game::PlayerID GetBuilder() const { return m_Builder; }
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldAddTower; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
60
include/protocol/packets/WorldBeginDataPacket.h
Normal file
60
include/protocol/packets/WorldBeginDataPacket.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
struct WorldHeader {
|
||||
game::TowerTileColorPalette m_TowerPlacePalette;
|
||||
Color m_WalkablePalette;
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
game::SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
game::TilePalette m_TilePalette;
|
||||
|
||||
game::Spawn m_RedSpawn, m_BlueSpawn;
|
||||
game::TeamCastle m_RedCastle, m_BlueCastle;
|
||||
|
||||
const game::World* m_World;
|
||||
};
|
||||
|
||||
class WorldBeginDataPacket : public Packet {
|
||||
private:
|
||||
WorldHeader m_Header;
|
||||
public:
|
||||
WorldBeginDataPacket() {}
|
||||
WorldBeginDataPacket(const game::World* world) {
|
||||
m_Header.m_World = world;
|
||||
}
|
||||
virtual ~WorldBeginDataPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldBeginData; }
|
||||
|
||||
const game::TowerTileColorPalette& GetTowerTilePalette() const { return m_Header.m_TowerPlacePalette; }
|
||||
const Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; }
|
||||
const std::vector<Color>& GetDecorationPalette() const { return m_Header.m_DecorationPalette; }
|
||||
const Color& GetBackgroundColor() const { return m_Header.m_Background; }
|
||||
|
||||
const game::Spawn& GetRedSpawn() const { return m_Header.m_RedSpawn; }
|
||||
const game::Spawn& GetBlueSpawn() const { return m_Header.m_BlueSpawn; }
|
||||
|
||||
const game::SpawnColorPalette& GetSpawnPalette() const { return m_Header.m_SpawnColorPalette; }
|
||||
|
||||
const game::TeamCastle& GetRedCastle() const { return m_Header.m_RedCastle; }
|
||||
const game::TeamCastle& GetBlueCastle() const { return m_Header.m_BlueCastle; }
|
||||
|
||||
const game::TilePalette GetTilePalette() const { return m_Header.m_TilePalette; }
|
||||
|
||||
void setWorldHeader(const WorldHeader& header) { m_Header = header; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
36
include/protocol/packets/WorldDataPacket.h
Normal file
36
include/protocol/packets/WorldDataPacket.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol/Protocol.h"
|
||||
#include "game/BaseGame.h"
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
struct WorldData {
|
||||
std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
|
||||
};
|
||||
|
||||
class WorldDataPacket : public Packet {
|
||||
private:
|
||||
WorldData m_WorldData;
|
||||
|
||||
const game::World* m_World;
|
||||
public:
|
||||
WorldDataPacket() {}
|
||||
WorldDataPacket(const game::World* world) : m_World(world) {}
|
||||
virtual ~WorldDataPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
virtual PacketType GetType() const { return PacketType::WorldData; }
|
||||
|
||||
const std::unordered_map<game::ChunkCoord, game::ChunkPtr>& GetChunks() const { return m_WorldData.m_Chunks; }
|
||||
|
||||
DataBuffer SerializeCustom() const; // allow serialisation with invalid World member
|
||||
void SetWorldData(const WorldData& worldData) { m_WorldData = worldData; }
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
@@ -10,8 +10,6 @@
|
||||
#include "render/gui/MobTooltip.h"
|
||||
#include "render/gui/CastleTooltip.h"
|
||||
|
||||
#include "render/gui/imgui/imgui.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace client {
|
||||
@@ -20,7 +18,6 @@ class ClientGame;
|
||||
|
||||
} // namespace client
|
||||
|
||||
|
||||
namespace render {
|
||||
|
||||
class WorldRenderer : public game::WorldListener {
|
||||
@@ -48,8 +45,6 @@ public:
|
||||
|
||||
void LoadModels();
|
||||
|
||||
static ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
|
||||
13
include/render/gui/ImGuiTeamColor.h
Normal file
13
include/render/gui/ImGuiTeamColor.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "render/gui/imgui/imgui.h"
|
||||
#include "game/Team.h"
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
|
||||
Reference in New Issue
Block a user