302 lines
6.5 KiB
C#
302 lines
6.5 KiB
C#
|
|
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
|
|
{
|
|
[SerializeField] private GameManagerRound2 _GameManager;
|
|
[SerializeField] private AudioManager _AudioManager;
|
|
|
|
[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<Animator>();
|
|
|
|
// ********** DEBUG **********
|
|
RandomiseLocation();
|
|
// ******** END DEBUG ********
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void RevealPanel(int Panel)
|
|
{
|
|
if (_ActiveSpinners < 3)
|
|
{
|
|
_Animator.SetBool("Flip " + Panel, true);
|
|
|
|
switch (_ActiveSpinners)
|
|
{
|
|
case 0:
|
|
{
|
|
_OrderIsCorrect[0] = (Panel == LootLocation);
|
|
|
|
if (_OrderIsCorrect[0])
|
|
{
|
|
_GameManager.OnTheRightTrack();
|
|
}
|
|
else if (Panel == WarrantLocation)
|
|
{
|
|
_GameManager.OutOfOrder(PanelType.Warrant);
|
|
}
|
|
else if (Panel == CrookLocation)
|
|
{
|
|
_GameManager.OutOfOrder(PanelType.Crook);
|
|
}
|
|
else if (_HasBeenCheckedBefore[Panel - 1])
|
|
{
|
|
_GameManager.AlreadyTried();
|
|
}
|
|
else
|
|
{
|
|
_GameManager.NothingThere();
|
|
}
|
|
} break;
|
|
case 1:
|
|
{
|
|
_OrderIsCorrect[1] = (Panel == WarrantLocation);
|
|
|
|
if (_OrderIsCorrect[1])
|
|
{
|
|
if (!_OrderIsCorrect[0])
|
|
{
|
|
_GameManager.OutOfOrder(PanelType.Warrant);
|
|
}
|
|
else
|
|
{
|
|
_GameManager.AlmostThere();
|
|
}
|
|
}
|
|
else if (Panel == LootLocation)
|
|
{
|
|
_GameManager.OutOfOrder(PanelType.Loot);
|
|
}
|
|
else if (Panel == CrookLocation)
|
|
{
|
|
_GameManager.OutOfOrder(PanelType.Crook);
|
|
}
|
|
else if (_HasBeenCheckedBefore[Panel - 1])
|
|
{
|
|
if (!_OrderIsCorrect[0])
|
|
{
|
|
_GameManager.NiceStrategy();
|
|
}
|
|
else
|
|
{
|
|
_GameManager.AlreadyTried();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_GameManager.NothingThere();
|
|
}
|
|
} break;
|
|
case 2:
|
|
{
|
|
_OrderIsCorrect[2] = (Panel == CrookLocation);
|
|
|
|
if (_HasBeenCheckedBefore[Panel - 1])
|
|
{
|
|
if (!_OrderIsCorrect[0] || !_OrderIsCorrect[1])
|
|
{
|
|
_GameManager.NiceStrategy();
|
|
}
|
|
else
|
|
{
|
|
_GameManager.AlreadyTried();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_GameManager.NothingThere();
|
|
}
|
|
} break;
|
|
}
|
|
|
|
_ActiveSpinners++;
|
|
|
|
if (Panel == LootLocation || Panel == WarrantLocation || Panel == CrookLocation)
|
|
{
|
|
if (Panel == LootLocation)
|
|
{
|
|
SendCustomEventDelayedSeconds(nameof(PlayTheLoot), 0.35f);
|
|
}
|
|
//else if (Panel == WarrantLocation)
|
|
//{
|
|
//}
|
|
//else if (Panel == CrookLocation)
|
|
//{
|
|
//}
|
|
|
|
if (_OrderIsCorrect[0] && _OrderIsCorrect[1] && _OrderIsCorrect[2])
|
|
{
|
|
_GameManager.YoureWinner();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SendCustomEventDelayedSeconds(nameof(InitiateBoardReset), 1.0f);
|
|
}
|
|
}
|
|
|
|
_HasBeenCheckedBefore[Panel - 1] = true;
|
|
}
|
|
|
|
|
|
public void PlayTheLoot()
|
|
{
|
|
NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)_AudioManager,
|
|
NetworkEventTarget.All,
|
|
"PlaySFX", SFXEventType.TheLoot);
|
|
}
|
|
|
|
|
|
public void InitiateBoardReset() { _GameManager.LocationBoardReset(); }
|
|
|
|
[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 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;
|
|
}
|
|
}
|