GameStateMatchEnded.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include <GameplayEffectsNotificationBus.h>
  8. #include <GameState/GameStateRequestBus.h>
  9. #include <Source/GameState/GameStateMatchEnded.h>
  10. #include <Source/GameState/GameStatePreparingMatch.h>
  11. namespace MultiplayerSample
  12. {
  13. GameStateMatchEnded::GameStateMatchEnded([[maybe_unused]] NetworkMatchComponentController* controller)
  14. {
  15. #if AZ_TRAIT_SERVER
  16. m_controller = controller;
  17. #endif
  18. }
  19. void GameStateMatchEnded::OnEnter()
  20. {
  21. #if AZ_TRAIT_SERVER
  22. m_controller->EndMatch();
  23. #endif
  24. m_finishingTime = AZ::TimeMs{ 3000 };
  25. m_finishingEvent.Enqueue(AZ::Time::ZeroTimeMs, true);
  26. GameplayEffectsNotificationBus::Broadcast(&GameplayEffectsNotificationBus::Events::OnEffect, SoundEffect::GameEnd);
  27. }
  28. void GameStateMatchEnded::OnExit()
  29. {
  30. m_finishingEvent.RemoveFromQueue();
  31. }
  32. void GameStateMatchEnded::OnFinishedMatchTick()
  33. {
  34. m_finishingTime -= m_finishingEvent.TimeInQueueMs();
  35. if (m_finishingTime <= AZ::Time::ZeroTimeMs)
  36. {
  37. m_finishingEvent.RemoveFromQueue();
  38. const auto state = GameState::GameStateRequests::CreateNewOverridableGameStateOfType<GameStatePreparingMatch>();
  39. GameState::GameStateRequestBus::Broadcast(&GameState::GameStateRequestBus::Events::ReplaceActiveGameState, state);
  40. }
  41. }
  42. }