diff --git a/include/td/protocol/PacketHandler.h b/include/td/protocol/PacketHandler.h index cd052c7..aef1b03 100644 --- a/include/td/protocol/PacketHandler.h +++ b/include/td/protocol/PacketHandler.h @@ -27,6 +27,7 @@ public: virtual void HandlePacket(const PlayerLeavePacket* packet) {} virtual void HandlePacket(const PlayerListPacket* packet) {} virtual void HandlePacket(const PlayerLoginPacket* packet) {} + virtual void HandlePacket(const RemoveMobPacket* packet) {} virtual void HandlePacket(const RemoveTowerPacket* packet) {} virtual void HandlePacket(const SelectTeamPacket* packet) {} virtual void HandlePacket(const SendMobsPacket* packet) {} diff --git a/include/td/protocol/Packets.h b/include/td/protocol/Packets.h index 4486f04..7e4afd5 100644 --- a/include/td/protocol/Packets.h +++ b/include/td/protocol/Packets.h @@ -8,6 +8,7 @@ #include "packets/PlayerLeavePacket.h" #include "packets/PlayerListPacket.h" #include "packets/PlayerLoginPacket.h" +#include "packets/RemoveMobPacket.h" #include "packets/RemoveTowerPacket.h" #include "packets/SelectTeamPacket.h" #include "packets/SendMobsPacket.h" diff --git a/include/td/protocol/PacketsForward.h b/include/td/protocol/PacketsForward.h index cdb522f..b6a4d2c 100644 --- a/include/td/protocol/PacketsForward.h +++ b/include/td/protocol/PacketsForward.h @@ -29,6 +29,7 @@ class UpdateCastleLifePacket; class UpdateMobStatesPacket; class PlayerBuyItemPacket; class PlayerBuyMobUpgradePacket; +class RemoveMobPacket; } // namespace protocol } // namespace td diff --git a/include/td/protocol/Protocol.h b/include/td/protocol/Protocol.h index de06870..361ea22 100644 --- a/include/td/protocol/Protocol.h +++ b/include/td/protocol/Protocol.h @@ -33,6 +33,7 @@ enum class PacketType : std::uint8_t { WorldAddTower, UpdateMobStates, UpdateCastleLife, + RemoveMob, // client <--> server KeepAlive, diff --git a/include/td/protocol/packets/RemoveMobPacket.h b/include/td/protocol/packets/RemoveMobPacket.h new file mode 100644 index 0000000..9b5c530 --- /dev/null +++ b/include/td/protocol/packets/RemoveMobPacket.h @@ -0,0 +1,27 @@ +#pragma once + +#include "td/protocol/Protocol.h" +#include "td/game/BaseGame.h" + +namespace td { +namespace protocol { + +class RemoveMobPacket : public Packet { +private: + game::MobID m_MobID; +public: + RemoveMobPacket() {} + RemoveMobPacket(game::MobID id) : m_MobID(id) {} + virtual ~RemoveMobPacket() {} + + 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; } + + virtual PacketType GetType() const { return PacketType::RemoveMob; } +}; + +} // namespace protocol +} // namespace td diff --git a/src/td/protocol/PacketFactory.cpp b/src/td/protocol/PacketFactory.cpp index c02de1d..1ec148d 100644 --- a/src/td/protocol/PacketFactory.cpp +++ b/src/td/protocol/PacketFactory.cpp @@ -36,6 +36,7 @@ static std::map packets = { {PacketType::UpdateMobStates, []() -> PacketPtr {return std::make_unique(); } }, {PacketType::PlayerBuyItem, []() -> PacketPtr {return std::make_unique(); } }, {PacketType::PlayerBuyMobUpgrade, []() -> PacketPtr {return std::make_unique(); } }, + {PacketType::RemoveMob, []() -> PacketPtr {return std::make_unique(); } }, }; PacketPtr CreatePacket(PacketType type, DataBuffer& buffer) { diff --git a/src/td/protocol/Protocol.cpp b/src/td/protocol/Protocol.cpp index 1e2651e..63934ef 100644 --- a/src/td/protocol/Protocol.cpp +++ b/src/td/protocol/Protocol.cpp @@ -39,6 +39,7 @@ REGISTER_DISPATCH_CLASS(UpdateCastleLifePacket) REGISTER_DISPATCH_CLASS(UpdateMobStatesPacket) REGISTER_DISPATCH_CLASS(PlayerBuyItemPacket) REGISTER_DISPATCH_CLASS(PlayerBuyMobUpgradePacket) +REGISTER_DISPATCH_CLASS(RemoveMobPacket) } // namespace protocol } // namespace td \ No newline at end of file diff --git a/src/td/protocol/packets/RemoveMobPacket.cpp b/src/td/protocol/packets/RemoveMobPacket.cpp new file mode 100644 index 0000000..89a6d3a --- /dev/null +++ b/src/td/protocol/packets/RemoveMobPacket.cpp @@ -0,0 +1,19 @@ +#include "td/protocol/packets/RemoveMobPacket.h" + +namespace td { +namespace protocol { + +DataBuffer RemoveMobPacket::Serialize(bool packetID) const { + DataBuffer data; + + WritePacketID(data, packetID); + data << m_MobID; + return data; +} + +void RemoveMobPacket::Deserialize(DataBuffer& data) { + data >> m_MobID; +} + +} // namespace protocol +} // namespace td