Jamie Greunbaum e557398084 - Maps now properly reset when randomised.
- Some countries are now "hard mode" options, and are not chosen by default.
- Map dot switched to a quad to save on triangles.
- Map borders SDF updated to be more repeatable when making new maps.
- Added looping options to SFX.
- Added a "Carmen In Jail" SFX event.
- Added a curved TV monitor model for video player.
- Added a loot image URL setting for the case list entries.
2025-06-30 02:37:34 -04:00

146 lines
3.6 KiB
C#

using System.Linq;
using UdonSharp;
using VRC.SDKBase;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class FloorMap : UdonSharpBehaviour
{
public FloorMapCountry[] Countries;
[UdonSynced] private int _CurrentCountry = 0;
[UdonSynced, FieldChangeCallback(nameof(RandomisedCountriesAndCities))] private int[] _RandomisedCountriesAndCities;
private string[] _ChosenCountries = new string[MAX_SELECTED_COUNTRIES];
private string[] _ChosenCities = new string[MAX_SELECTED_COUNTRIES];
private const int MAX_SELECTED_COUNTRIES = 13;
public void RandomiseCountries()
{
_CurrentCountry = 0;
for (int i = 0; i < Countries.Length; i++)
{
Countries[i].gameObject.SetActive(false);
}
UnityEngine.Random.InitState(Networking.GetServerTimeInMilliseconds());
int[] NewRandomCountries = new int[MAX_SELECTED_COUNTRIES];
int[] NewRandomCities = new int[MAX_SELECTED_COUNTRIES];
// Fill the countries array with a value too big to be valid.
int NumberOfCountries = Countries.Length;
for (int i = 0; i < MAX_SELECTED_COUNTRIES; i++)
{
NewRandomCountries[i] = NumberOfCountries;
}
for (int i = 0; i < MAX_SELECTED_COUNTRIES; i++)
{
int NewPulledIndex = NumberOfCountries;
while (CountryIsAlreadyInArray(NewRandomCountries, NewPulledIndex) || Countries[NewPulledIndex].HardModeSelection)
{
NewPulledIndex = UnityEngine.Random.Range(0, NumberOfCountries);
}
NewRandomCountries[i] = NewPulledIndex;
NewRandomCities[i] = UnityEngine.Random.Range(0, Countries[NewPulledIndex].Locations.Length);
}
// We're syncing the countries and cities as one array to keep
// things simple to sync all at once.
// Array format is all countries first, then all cities.
int[] NewRandomCountriesAndCities = new int[MAX_SELECTED_COUNTRIES * 2];
NewRandomCountries.CopyTo(NewRandomCountriesAndCities, 0);
NewRandomCities.CopyTo(NewRandomCountriesAndCities, MAX_SELECTED_COUNTRIES);
RandomisedCountriesAndCities = NewRandomCountriesAndCities;
RequestSerialization();
}
private bool CountryIsAlreadyInArray(int[] Countries, int IndexToCheck)
{
for (int i = 0; i < MAX_SELECTED_COUNTRIES; i++)
{
if (Countries[i] == IndexToCheck)
{
return true;
}
}
return false;
}
private void AssignRandomCountriesAndCities()
{
DisableAllLocations();
_CurrentCountry = 0;
for (int i = 0; i < MAX_SELECTED_COUNTRIES; i++)
{
FloorMapCountry Country = Countries[RandomisedCountriesAndCities[i]];
Country.gameObject.SetActive(true);
FloorMapLocation Location = Country.Locations[RandomisedCountriesAndCities[MAX_SELECTED_COUNTRIES + i]];
Location.gameObject.SetActive(true);
_ChosenCountries[i] = Location.Country;
_ChosenCities[i] = Location.City;
}
}
public int NextCountry()
{
_CurrentCountry++;
if (_CurrentCountry >= MAX_SELECTED_COUNTRIES)
{
// We ran out of countries. Just end the game here.
return -1;
}
return _CurrentCountry;
}
public int GetCurrentCountryIndex()
{
return _CurrentCountry;
}
public string GetCurrentCountry()
{
return _ChosenCountries[_CurrentCountry];
}
public string GetCurrentCity()
{
return _ChosenCities[_CurrentCountry];
}
private void DisableAllLocations()
{
for (int i = 0; i < Countries.Length; i++)
{
FloorMapCountry Country = Countries[i];
for (int j = 0; j < Country.Locations.Length; j++)
{
Country.Locations[j].gameObject.SetActive(false);
}
Country.gameObject.SetActive(false);
}
}
public int[] RandomisedCountriesAndCities
{
set
{
_RandomisedCountriesAndCities = value;
AssignRandomCountriesAndCities();
}
get => _RandomisedCountriesAndCities;
}
}