From 2e86a2513ea4e99630c3ce16092f5eef01389a75 Mon Sep 17 00:00:00 2001
From: playinful <82474412+playinful@users.noreply.github.com>
Date: Mon, 11 Mar 2024 22:03:53 -0400
Subject: [PATCH] FreezeFrame randomness update
hey AJ so i was cleaning my room when i was struck by an idea for how to make the randomization more consistent without seeding. *yes unfortunately* it requires a static variable but i promise u i used it responsibly.
---
.../Scripts/Games/FreezeFrame/FreezeFrame.cs | 62 ++++++++++++++++---
1 file changed, 54 insertions(+), 8 deletions(-)
diff --git a/Assets/Scripts/Games/FreezeFrame/FreezeFrame.cs b/Assets/Scripts/Games/FreezeFrame/FreezeFrame.cs
index b5e50d7e8..ee9b9abcd 100644
--- a/Assets/Scripts/Games/FreezeFrame/FreezeFrame.cs
+++ b/Assets/Scripts/Games/FreezeFrame/FreezeFrame.cs
@@ -90,7 +90,7 @@ namespace HeavenStudio.Games.Loaders
// distractions
new GameAction("spawnPerson", "Spawn Walker")
{
- function = delegate { var e = eventCaller.currentEntity; FreezeFrame.SummonWalker(e.beat, e.length, e["personType"], e["direction"], e["layer"]); },
+ function = delegate { var e = eventCaller.currentEntity; FreezeFrame.SummonWalker(e); },
defaultLength = 4f,
resizable = true,
parameters = new List()
@@ -297,6 +297,8 @@ namespace HeavenStudio.Games
public List QueuedCars { get; set; } = new();
+ public static Dictionary WalkerDirections = new();
+
//protected static int? SuperSeed { get; set; }
// UNITY BUILTIN METHODS
@@ -446,6 +448,7 @@ namespace HeavenStudio.Games
// calculation
CalculateAutoShowPhotos();
CalculateCarSpawns();
+ PreRandomizeWalkers();
// setting local variables
RiqEntity e = GetLastEntityOfType(beat, "bop");
@@ -473,7 +476,7 @@ namespace HeavenStudio.Games
{
foreach (RiqEntity entity in eList)
{
- SummonWalker(entity.beat, entity.length, entity["personType"], entity["direction"], entity["layer"]);
+ SummonWalker(entity);
}
}
@@ -716,35 +719,48 @@ namespace HeavenStudio.Games
{
PhotoList.Clear();
}
- public static void SummonWalker(double beat, double length, int walkerType, int direction, int layer = 0)
+ public static void SummonWalker(RiqEntity e/*double beat, double length, int walkerType, int direction, int layer = 0*/)
{
if (Instance == null) return;
+ double beat = e.beat;
+ double length = e.length;
+ PersonType walkerType = (PersonType)e["personType"];
+ PersonDirection direction = (PersonDirection)e["direction"];
+ int layer = e["layer"];
+
GameObject walker = Instantiate(Instance.WalkerPrefab, Instance.WalkerSpawn.transform);
Animator animator = walker.GetComponent();
walker.GetComponent().sortingOrder = layer;
switch (walkerType)
{
- case (int)PersonType.Girlfriend:
+ case PersonType.Girlfriend:
animator.DoScaledAnimationAsync("Girlfriend", animLayer: 2);
break;
- case (int)PersonType.Dude2:
+ case PersonType.Dude2:
animator.DoScaledAnimationAsync("Dude2", animLayer: 2);
break;
- case (int)PersonType.Dude1:
+ case PersonType.Dude1:
default:
animator.DoScaledAnimationAsync("Dude1", animLayer: 2);
break;
}
- if (direction == (int)PersonDirection.Random)
+ /*if (direction == (int)PersonDirection.Random)
{
int seed = BitConverter.ToInt32(BitConverter.GetBytes((float)beat));
direction = new System.Random(seed).Next(1, 3);
+ }*/
+ if (direction == PersonDirection.Random)
+ {
+ if (WalkerDirections.ContainsKey(e))
+ direction = WalkerDirections[e];
+ else
+ direction = PersonDirection.Right;
}
- if (direction == (int)PersonDirection.Left)
+ if (direction == PersonDirection.Left)
Instance.Walkers.Add(new WalkerArgs(animator, beat, length, "EnterLeft"));
else
Instance.Walkers.Add(new WalkerArgs(animator, beat, length, "EnterRight"));
@@ -1141,6 +1157,36 @@ namespace HeavenStudio.Games
}
}
}
+ public void PreRandomizeWalkers()
+ {
+ IEnumerable walkers = EventCaller.GetAllInGameManagerList("freezeFrame", new string[] { "spawnPerson" }).Where(e => (PersonDirection)e["direction"] == PersonDirection.Random);
+ foreach (RiqEntity e in walkers)
+ {
+ if (!WalkerDirections.ContainsKey(e))
+ {
+ float rand = UnityEngine.Random.Range(0.0f, 1.0f);
+ if (rand >= 0.5)
+ {
+ WalkerDirections.Add(e, PersonDirection.Left);
+ }
+ else
+ {
+ WalkerDirections.Add(e, PersonDirection.Right);
+ }
+ }
+ }
+ List keysToRemove = new();
+ foreach (RiqEntity key in WalkerDirections.Keys)
+ {
+ if (!walkers.Contains(key))
+ keysToRemove.Add(key);
+ }
+ foreach (RiqEntity key in keysToRemove)
+ {
+ WalkerDirections.Remove(key);
+ }
+ Debug.Log($"Walker Count: {WalkerDirections.Count}");
+ }
public void CarbageCollection()
{
foreach (Transform child in FarCarSpawn)