GameStateMatchEnded.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include <AzCore/Time/ITime.h>
  12. namespace MultiplayerSample
  13. {
  14. GameStateMatchEnded::GameStateMatchEnded([[maybe_unused]] NetworkMatchComponentController* controller)
  15. : m_controller(controller)
  16. {
  17. }
  18. void GameStateMatchEnded::OnEnter()
  19. {
  20. m_controller->EndMatch();
  21. const AZ::TimeMs restBeforeNewMatch = AZ::SecondsToTimeMs(m_controller->GetRestDurationBetweenMatches());
  22. const AZ::TimeMs nextMatchStartTime = AZ::Interface<Multiplayer::IMultiplayer>::Get()->GetCurrentHostTimeMs() + restBeforeNewMatch;
  23. m_controller->SetMatchStartHostTime(nextMatchStartTime);
  24. m_finishingEvent.Enqueue(restBeforeNewMatch);
  25. GameplayEffectsNotificationBus::Broadcast(&GameplayEffectsNotificationBus::Events::OnEffect, SoundEffect::GameEnd);
  26. }
  27. void GameStateMatchEnded::OnExit()
  28. {
  29. m_finishingEvent.RemoveFromQueue();
  30. }
  31. void GameStateMatchEnded::OnFinishedMatch()
  32. {
  33. const auto state = GameState::GameStateRequests::CreateNewOverridableGameStateOfType<GameStatePreparingMatch>();
  34. GameState::GameStateRequestBus::Broadcast(&GameState::GameStateRequestBus::Events::ReplaceActiveGameState, state);
  35. }
  36. }