diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Game.hpp | 1 | ||||
-rw-r--r-- | src/GameState.cpp | 12 | ||||
-rw-r--r-- | src/GameState.hpp | 4 | ||||
-rw-r--r-- | src/Plugin.cpp | 3 | ||||
-rw-r--r-- | src/Render.cpp | 4 |
5 files changed, 19 insertions, 5 deletions
diff --git a/src/Game.hpp b/src/Game.hpp index f7efd11..74eeea9 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -13,6 +13,7 @@ enum class State { Paused, Inventory, Chat, + NeedRespawn, }; void RunGame(); diff --git a/src/GameState.cpp b/src/GameState.cpp index bb93c45..50a9004 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -456,9 +456,8 @@ void GameState::UpdatePacket(std::shared_ptr<Packet> ptr) { auto packet = std::static_pointer_cast<PacketUpdateHealth>(ptr); playerStatus.health = packet->Health; if (playerStatus.health <= 0) { - LOG(INFO) << "Player is dead. Respawning..."; - auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); - PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(packetPerformRespawn)); + LOG(INFO) << "Player is dead. Need respawn..."; + SetState(State::NeedRespawn); } break; } @@ -681,4 +680,9 @@ void GameState::PlaceBlock() { auto packet = std::static_pointer_cast<Packet>(packetPlace); PUSH_EVENT("SendPacket", packet); -}
\ No newline at end of file +} + +void GameState::PerformRespawn() { + auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); + PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(packetPerformRespawn)); +} diff --git a/src/GameState.hpp b/src/GameState.hpp index 0ca858f..ca2ea81 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -75,6 +75,8 @@ class GameState { bool receivedFirstPlayerPosAndLook = false; + std::shared_ptr<PacketRespawn> packetRespawn; + public: void Update(double deltaTime); @@ -89,6 +91,8 @@ public: void PlaceBlock(); + void PerformRespawn(); + enum MoveType { FORWARD, BACKWARD, LEFT, RIGHT, JUMP }; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f759d5f..64fc00b 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -174,7 +174,8 @@ void PluginSystem::Init() { "GetGameStatus", &GameState::GetGameStatus, "GetPlayerStatus", &GameState::GetPlayerStatus, "GetSelectionStatus", &GameState::GetSelectionStatus, - "GetInventory", &GameState::GetInventory); + "GetInventory", &GameState::GetInventory, + "PerformRespawn", &GameState::PerformRespawn); lua.new_usertype<TimeStatus>("TimeStatus", "interpolatedTimeOfDay", &TimeStatus::interpolatedTimeOfDay, diff --git a/src/Render.cpp b/src/Render.cpp index bee8ffb..6aecd88 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -498,6 +498,10 @@ void Render::InitEvents() { PluginSystem::CallOnChangeState("Chat"); SetMouseCapture(false); break; + case State::NeedRespawn: + PluginSystem::CallOnChangeState("NeedRespawn"); + SetMouseCapture(false); + break; } }); |