using TMPro; using UdonSharp; using UnityEngine; using VRC.Dynamics; using VRC.SDK3.UdonNetworkCalling; using VRC.SDKBase; using VRC.Udon; using VRC.Udon.Common.Interfaces; [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] public class LocationBoard : UdonSharpBehaviour { [UdonSynced, FieldChangeCallback(nameof(LootLocation))] private int _LootLocation = 0; [UdonSynced, FieldChangeCallback(nameof(WarrantLocation))] private int _WarrantLocation = 0; [UdonSynced, FieldChangeCallback(nameof(CrookLocation))] private int _CrookLocation = 0; public GameObject[] LocationPanelsEmpty; public GameObject[] LocationPanelsLoot; public GameObject[] LocationPanelsWarrant; public GameObject[] LocationPanelsCrook; public TextMeshProUGUI[] LocationPanelText; private Animator _Animator; [UdonSynced] private int _ActiveSpinners = 0; [UdonSynced] private bool[] _OrderIsCorrect = new bool[3]; [UdonSynced] private bool[] _HasBeenCheckedBefore; private void Start() { _HasBeenCheckedBefore = new bool[LocationPanelsEmpty.Length]; _Animator = GetComponent(); // ********** DEBUG ********** RandomiseLocation(); // ******** END DEBUG ******** } [NetworkCallable] public void RevealPanel(int Panel) { if (_ActiveSpinners < 3) { _Animator.SetBool("Flip " + Panel, true); switch (_ActiveSpinners) { case 0: { if (Panel == LootLocation) { _OrderIsCorrect[0] = true; Debug.LogWarning("On the right track..."); } else if (Panel == WarrantLocation || Panel == CrookLocation) { _OrderWarning(); } } break; case 1: { if (Panel == WarrantLocation) { _OrderIsCorrect[1] = (Panel == WarrantLocation); Debug.LogWarning("Almost there..."); } else if (Panel == LootLocation || Panel == CrookLocation) { _OrderWarning(); } else if (_HasBeenCheckedBefore[Panel - 1] && (_OrderIsCorrect[0] == false)) { _StrategyComment(); } } break; case 2: { if (Panel == CrookLocation) { _OrderIsCorrect[2] = (Panel == CrookLocation); Debug.LogWarning("You got it!"); } else if (Panel == LootLocation || Panel == WarrantLocation) { _OrderWarning(); } else if (_HasBeenCheckedBefore[Panel - 1] && (_OrderIsCorrect[0] == false && _OrderIsCorrect[1] == false)) { _StrategyComment(); } } break; } _ActiveSpinners++; if (Panel == LootLocation || Panel == WarrantLocation || Panel == CrookLocation) { if (_OrderIsCorrect[0] && _OrderIsCorrect[1] && _OrderIsCorrect[2]) { _ActiveSpinners = 3; SendCustomEventDelayedSeconds(nameof(GameWasWon), 1.0f); } else if (_ActiveSpinners >= 3) { SendCustomEventDelayedSeconds(nameof(ResetPanelBoard), 1.0f); } } else { _ActiveSpinners = 3; SendCustomEventDelayedSeconds(nameof(ResetPanelBoard), 1.0f); } } _HasBeenCheckedBefore[Panel - 1] = true; } public void GameWasWon() { Debug.LogError("Game was won!"); } private void _OrderWarning() { Debug.LogWarning("Remember the order: loot, warrant, crook. Use some strategy."); } private void _StrategyComment() { Debug.Log("Nice strategy."); } [NetworkCallable] public void ResetPanelBoard() { for (int i = 1; i <= 15; i++) { _Animator.SetBool("Flip " + i, false); } _ActiveSpinners = 0; _OrderIsCorrect[0] = _OrderIsCorrect[1] = _OrderIsCorrect[2] = false; } public void RandomiseLocation() { Random.InitState(Networking.GetServerTimeInMilliseconds()); LootLocation = Random.Range(0, LocationPanelsLoot.Length) + 1; int TempWarrantLocation = _LootLocation; while (TempWarrantLocation == _LootLocation) { TempWarrantLocation = Random.Range(0, LocationPanelsWarrant.Length) + 1; } WarrantLocation = TempWarrantLocation; int TempCrookLocation = _WarrantLocation; while (TempCrookLocation == _WarrantLocation || TempCrookLocation == _LootLocation) { TempCrookLocation = Random.Range(0, LocationPanelsCrook.Length) + 1; } CrookLocation = TempCrookLocation; for (int i = 0; i < LocationPanelsEmpty.Length; i++) { _HasBeenCheckedBefore[i] = false; } RequestSerialization(); } private void PlaceEmpty(int Panel) { if (Panel > 0) { LocationPanelsLoot[Panel - 1].SetActive(false); LocationPanelsWarrant[Panel - 1].SetActive(false); LocationPanelsCrook[Panel - 1].SetActive(false); LocationPanelsEmpty[Panel - 1].SetActive(true); } } private void PlaceLoot(int Panel) { if (Panel > 0) { LocationPanelsEmpty[Panel - 1].SetActive(false); LocationPanelsWarrant[Panel - 1].SetActive(false); LocationPanelsCrook[Panel - 1].SetActive(false); LocationPanelsLoot[Panel - 1].SetActive(true); } } private void PlaceWarrant(int Panel) { if (Panel > 0) { LocationPanelsEmpty[Panel - 1].SetActive(false); LocationPanelsLoot[Panel - 1].SetActive(false); LocationPanelsCrook[Panel - 1].SetActive(false); LocationPanelsWarrant[Panel - 1].SetActive(true); } } private void PlaceCrook(int Panel) { if (Panel > 0) { LocationPanelsEmpty[Panel - 1].SetActive(false); LocationPanelsLoot[Panel - 1].SetActive(false); LocationPanelsWarrant[Panel - 1].SetActive(false); LocationPanelsCrook[Panel - 1].SetActive(true); } } public void Button_RevealPanel1() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 1); } public void Button_RevealPanel2() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 2); } public void Button_RevealPanel3() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 3); } public void Button_RevealPanel4() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 4); } public void Button_RevealPanel5() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 5); } public void Button_RevealPanel6() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 6); } public void Button_RevealPanel7() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 7); } public void Button_RevealPanel8() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 8); } public void Button_RevealPanel9() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 9); } public void Button_RevealPanel10() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 10); } public void Button_RevealPanel11() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 11); } public void Button_RevealPanel12() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 12); } public void Button_RevealPanel13() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 13); } public void Button_RevealPanel14() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 14); } public void Button_RevealPanel15() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "RevealPanel", 15); } public void Button_ResetPanelBoard() { NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)this, NetworkEventTarget.All, "ResetPanelBoard"); } public int LootLocation { set { PlaceEmpty(_LootLocation); _LootLocation = value; PlaceLoot(value); } get => _LootLocation; } public int WarrantLocation { set { PlaceEmpty(_WarrantLocation); _WarrantLocation = value; PlaceWarrant(_WarrantLocation); } get => _WarrantLocation; } public int CrookLocation { set { PlaceEmpty(_CrookLocation); _CrookLocation = value; PlaceCrook(_CrookLocation); } get => _CrookLocation; } }