using UdonSharp; using UnityEngine; using VRC.SDK3.Data; using VRC.SDK3.UdonNetworkCalling; public enum ContinentMap { Africa, Asia, Europe, NorthAmerica, Oceania, SouthAmerica } [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] public class GameManagerRound3 : GameManagerBase { [SerializeField] private CaseManager _CaseManager; [SerializeField] private FloorMap[] _Maps; [SerializeField] private FloorMapMarker[] _Markers; [SerializeField] private AudioManager _AudioManager; private ContinentMap _ActiveMap = ContinentMap.Africa; private DataDictionary _ContinentData; private int _StageIndex = 0; private int _Timer = TIMER_LENGTH; private const int TIMER_LENGTH = 45; private int _SuccessCounter = 0; private int _FailureCounter = 0; private const int MAX_FAILURE_COUNT = 2; private const int MAX_SUCCESS_COUNT = 8; public override void InitialiseGameMode() { base.InitialiseGameMode(); } public override void LoadQuestionData(DataToken Data) { _ContinentData = Data.DataDictionary; if (_ContinentData.ContainsKey("Continent")) { _ActiveMap = (ContinentMap)(int)_ContinentData["Continent"].Number; for (int i = 0; i < _Maps.Length; i++) { FloorMap Map = _Maps[i]; if (Map != null) { Map.gameObject.SetActive(i == (int)_ActiveMap); } } GetCurrentMap().RandomiseCountries(); } else { Debug.LogError("Malformed round data. Ensure Round 3 contains a continent to use for the map."); } EnableInteraction("Start Game"); } private void DisplayBriefing() { HostCardCaptureCarmenExplainerInterface CaptureCarmenExplainerInterface = (HostCardCaptureCarmenExplainerInterface)GetHostCardInterface(RoundSegmentType.CaptureCarmenExplainer); CaptureCarmenExplainerInterface.HeaderUI.text = RoundSegmentTypeToString(RoundSegmentType.CaptureCarmenExplainer); } public void BeginRound() { UpdateInterface(); GetCurrentMarker().EnablePickup(true); } public void CorrectResponse() { PlayCorrectSound(); GetCurrentMarker().EnablePickup(false); _SuccessCounter++; if (_SuccessCounter >= MAX_SUCCESS_COUNT) { GameHasBeenWon(); } else { SetUpNextCountry(); } } public void IncorrectResponse() { _FailureCounter++; if (_FailureCounter >= MAX_FAILURE_COUNT) { _FailureCounter = 0; GetCurrentMarker().EnablePickup(false); SetUpNextCountry(); } PlayIncorrectSound(); } public FloorMap GetCurrentMap() { return _Maps[(int)_ActiveMap]; } public FloorMapMarker GetCurrentMarker() { return _Markers[GetCurrentMap().GetCurrentCountryIndex()]; } public string GetCurrentCountry() { return GetCurrentMap().GetCurrentCountry(); } public string GetCurrentCity() { return GetCurrentMap().GetCurrentCity(); } public void SetUpNextCountry() { int NextCountry = GetCurrentMap().NextCountry(); if (NextCountry < 0) { // If we ran out of countries, lose the game here. GameHasBeenLost(true); return; } _Markers[NextCountry].EnablePickup(true); UpdateInterface(); } public void GameHasBeenWon() { HostCardBetweenRoundsInterface GameWinInterface = (HostCardBetweenRoundsInterface)GetHostCardInterface(RoundSegmentType.BetweenSegments); GameWinInterface.HeaderUI.text = "The player has won the game."; } public void GameHasBeenLost(bool RanOutOfMarkers = false) { Debug.LogError("Game was lost. Ran out of " + (RanOutOfMarkers ? "markers" : "time") + "."); } public void PlayCorrectSound() { _AudioManager.PlaySFX(SFXEventType.MapCorrect); } public void PlayIncorrectSound() { _AudioManager.PlaySFX(SFXEventType.MapIncorrect); } private void UpdateInterface() { HostCardCaptureCarmenInterface CaptureCarmenInterface = (HostCardCaptureCarmenInterface)GetHostCardInterface(RoundSegmentType.CaptureCarmen); CaptureCarmenInterface.HeaderUI.text = RoundSegmentTypeToString(RoundSegmentType.CaptureCarmen); CaptureCarmenInterface.CommentUI.text = GetCurrentCity() + ", " + GetCurrentCountry(); } protected override HostCardInterfaceBase GetHostCardInterface(RoundSegmentType Question) { return _HostCard.EnableHostCardDisplay(RoundType.CaptureCarmen, Question); } protected override void _HostCardUseButtonDown_Internal() { _StageIndex++; switch (_StageIndex) { case 1: DisplayBriefing(); break; case 2: BeginRound(); break; } } }