diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index ca7a0e87..eb4ebc16 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -33,6 +33,7 @@ #include "Network/EDisplayServerlist.h" #include "Network/EConnectRequest.h" #include "Network/EPlayerDisconnected.h" +#include "Game/Events/EReset.h" class Client : public Network { diff --git a/include/Engine/Network/Server.h b/include/Engine/Network/Server.h index 1f4fb114..6b5802c5 100644 --- a/include/Engine/Network/Server.h +++ b/include/Engine/Network/Server.h @@ -26,6 +26,7 @@ #include "Network/EPlayerConnected.h" #include "Network/EKillDeath.h" #include "Core/EWin.h" +#include "Game/Events/EReset.h" class Server : public Network { diff --git a/include/Game/Events/ERestart.h b/include/Game/Events/EReset.h similarity index 61% rename from include/Game/Events/ERestart.h rename to include/Game/Events/EReset.h index 4557f6fb..39281f8e 100644 --- a/include/Game/Events/ERestart.h +++ b/include/Game/Events/EReset.h @@ -1,5 +1,5 @@ -#ifndef Restart_h__ -#define Restart_h__ +#ifndef Reset_h__ +#define Reset_h__ #include "Core/EventBroker.h" #include "Core/EntityWrapper.h" @@ -7,7 +7,7 @@ namespace Events { -struct Restart : Event +struct Reset : Event { }; diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 6211ad49..0cba5401 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -9,6 +9,7 @@ #include "Engine/Collision/ETrigger.h" #include "Core/ECaptured.h" #include "Core/EWin.h" +#include "Game/Events/EReset.h" #include #include @@ -23,6 +24,7 @@ public: virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; private: + void Init(); //methods which will take care of specific events EventRelay m_ETriggerTouch; bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); @@ -30,6 +32,8 @@ private: bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); EventRelay m_ECaptured; bool CapturePointSystem::OnCaptured(const Events::Captured& e); + EventRelay m_EReset; + bool CapturePointSystem::OnReset(const Events::Reset& e); void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner); bool m_WinnerWasFound = false; diff --git a/include/Game/Systems/SpectatorCameraSystem.h b/include/Game/Systems/SpectatorCameraSystem.h index bc7aa860..6ba7294d 100644 --- a/include/Game/Systems/SpectatorCameraSystem.h +++ b/include/Game/Systems/SpectatorCameraSystem.h @@ -4,6 +4,7 @@ #include "Core/System.h" #include "Input/EInputCommand.h" #include "Network/EPlayerDisconnected.h" +#include "Game/Events/EReset.h" class SpectatorCameraSystem : public ImpureSystem { @@ -15,11 +16,14 @@ public: private: int m_PickedTeam; bool m_CamSetToTeamPick; + void reset(); EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); EventRelay m_EDisconnect; bool OnDisconnect(const Events::PlayerDisconnected& e); + EventRelay m_EReset; + bool OnReset(const Events::Reset& e); }; #endif \ No newline at end of file diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index d25a131f..480e2653 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -342,7 +342,8 @@ void Client::parseAmmoPickup(Packet & packet) void Client::parseRemoveWorld(Packet & packet) { removeWorld(); - + Events::Reset e; + m_EventBroker->Publish(e); } void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 25d9b666..ec4ee000 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -545,9 +545,12 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e) bool Server::OnWin(const Events::Win & e) { + Events::Reset reset; + m_EventBroker->Publish(reset); Packet removeMap(MessageType::RemoveWorld); reliableBroadcast(removeMap); removeWorld(); + // Hardcoded for now. auto entityFile = ResourceManager::Load("Schema/Entities/CP_Rocky2.xml"); entityFile->MergeInto(m_World); Packet newWorld(MessageType::Snapshot); diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 4a511301..b311e0dc 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -11,7 +11,25 @@ CapturePointSystem::CapturePointSystem(SystemParams params) EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); } + EVENT_SUBSCRIBE_MEMBER(m_EReset, &CapturePointSystem::OnReset); + Init(); +} +void CapturePointSystem::Init() +{ + m_WinnerWasFound = false; + //need to track these variables for the captureSystem to work as per design! + m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; + m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; + m_RedTeamHomeCapturePoint = m_NotACapturePoint; + m_BlueTeamHomeCapturePoint = m_NotACapturePoint; + m_NumberOfCapturePoints = 0; + m_ResetTimers = false; + m_RecentlyCapturedNeedNextCapturePointNow = false; + m_CapturePointNumberToEntityMap.clear(); + //vectors which will keep track of enter/leave changes + m_ETriggerTouchVector.clear(); + m_ETriggerLeaveVector.clear(); } //here all capturepoints will update their component @@ -24,6 +42,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp if (m_WinnerWasFound) { return; } + if (!capturePointEntity.Valid()) { + return; + } const int capturePointNumber = cCapturePoint["CapturePointNumber"]; const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); @@ -60,7 +81,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } //if we havent received all capturepoints yet, just return - if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { + if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints > m_CapturePointNumberToEntityMap.size()) { m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); return; } @@ -232,10 +253,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } -void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) { +void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) +{ (bool&)capturePointModels["Model"]["Visible"] = isOwner; - for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) - { + for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) { if (capModel.HasComponent("Model")) { (bool&)capModel["Model"]["Visible"] = isOwner; } @@ -269,3 +290,9 @@ bool CapturePointSystem::OnCaptured(const Events::Captured& e) m_ResetTimers = true; return true; } + +bool CapturePointSystem::OnReset(const Events::Reset& e) +{ + Init(); + return true; +} \ No newline at end of file diff --git a/src/Game/Systems/SpectatorCameraSystem.cpp b/src/Game/Systems/SpectatorCameraSystem.cpp index 23dfb164..bfc401c5 100644 --- a/src/Game/Systems/SpectatorCameraSystem.cpp +++ b/src/Game/Systems/SpectatorCameraSystem.cpp @@ -27,6 +27,14 @@ void SpectatorCameraSystem::Update(double dt) } } +void SpectatorCameraSystem::reset() +{ + m_CamSetToTeamPick = false; + // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); +} + bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) { // Only the client should do this, and only if player is not spawned. @@ -95,10 +103,13 @@ bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e) // If local player gets disconnected, they should be set to // the spectator camera next time a map loads that has one. if (e.Entity == LocalPlayer.ID) { - m_CamSetToTeamPick = false; - // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. - Events::UnlockMouse unlock; - m_EventBroker->Publish(unlock); + reset(); } return true; } + +bool SpectatorCameraSystem::OnReset(const Events::Reset & e) +{ + reset(); + return true; +}