sync player when joining mid game
This commit is contained in:
@@ -13,7 +13,6 @@ enum class PacketType : std::uint8_t {
|
|||||||
// client --> server
|
// client --> server
|
||||||
PlayerLogin = 0,
|
PlayerLogin = 0,
|
||||||
SelectTeam,
|
SelectTeam,
|
||||||
SpawnMob,
|
|
||||||
SendMobs,
|
SendMobs,
|
||||||
PlaceTower,
|
PlaceTower,
|
||||||
|
|
||||||
@@ -33,6 +32,7 @@ enum class PacketType : std::uint8_t {
|
|||||||
WorldAddTower,
|
WorldAddTower,
|
||||||
UpdateMobStates,
|
UpdateMobStates,
|
||||||
UpdateCastleLife,
|
UpdateCastleLife,
|
||||||
|
SpawnMob,
|
||||||
RemoveMob,
|
RemoveMob,
|
||||||
|
|
||||||
// client <--> server
|
// client <--> server
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "td/protocol/packets/RemoveTowerPacket.h"
|
#include "td/protocol/packets/RemoveTowerPacket.h"
|
||||||
#include "td/protocol/packets/SelectTeamPacket.h"
|
#include "td/protocol/packets/SelectTeamPacket.h"
|
||||||
#include "td/protocol/packets/SendMobsPacket.h"
|
#include "td/protocol/packets/SendMobsPacket.h"
|
||||||
|
#include "td/protocol/packets/SpawnMobPacket.h"
|
||||||
#include "td/protocol/packets/UpdatePlayerTeamPacket.h"
|
#include "td/protocol/packets/UpdatePlayerTeamPacket.h"
|
||||||
#include "td/protocol/packets/UpdateGameStatePacket.h"
|
#include "td/protocol/packets/UpdateGameStatePacket.h"
|
||||||
#include "td/protocol/packets/UpgradeTowerPacket.h"
|
#include "td/protocol/packets/UpgradeTowerPacket.h"
|
||||||
@@ -128,6 +129,20 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
|||||||
SendPacket(&headerDataPacket);
|
SendPacket(&headerDataPacket);
|
||||||
SendPacket(&dataPacket);
|
SendPacket(&dataPacket);
|
||||||
|
|
||||||
|
// place towers
|
||||||
|
for (auto tower : m_Server->GetGame().GetWorld()->GetTowers()) {
|
||||||
|
protocol::WorldAddTowerPacket packet(tower->GetID(), static_cast<std::int32_t>(tower->GetCenterX() - 0.5f),
|
||||||
|
static_cast<std::int32_t>(tower->GetCenterY() - 0.5f), tower->GetType(), tower->GetBuilder());
|
||||||
|
SendPacket(&packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// spawn mobs
|
||||||
|
for (auto mob : m_Server->GetGame().GetWorld()->GetMobList()) {
|
||||||
|
protocol::SpawnMobPacket packet(mob->GetMobID(), mob->GetType(), mob->GetLevel(), mob->GetSender(),
|
||||||
|
mob->GetCenterX(), mob->GetCenterY(), mob->GetDirection());
|
||||||
|
SendPacket(&packet);
|
||||||
|
// TODO : update health
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
void ServerConnexion::HandlePacket(const protocol::SelectTeamPacket* packet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user