From 7d96bcfec07bd64a26a7532364381c285fd297c7 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Wed, 21 Jun 2023 19:00:50 +0200 Subject: [PATCH] Count In Added --- Assets/Resources/Games/nightWalkAgb.prefab | 5 +- .../Games/NightWalkAgb/JumpPlatform.prefab | 13 ++ .../Games/NightWalkAgb/AgbNightWalk.cs | 149 +++++++++++++++++- .../Scripts/Games/NightWalkAgb/AgbPlatform.cs | 13 ++ .../Games/NightWalkAgb/AgbPlatform.cs.meta | 11 ++ .../Games/NightWalkAgb/AgbPlatformHandler.cs | 12 +- .../Scripts/Games/NightWalkAgb/AgbPlayYan.cs | 20 +++ 7 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs create mode 100644 Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs.meta diff --git a/Assets/Resources/Games/nightWalkAgb.prefab b/Assets/Resources/Games/nightWalkAgb.prefab index 724674a58..33ad02d08 100644 --- a/Assets/Resources/Games/nightWalkAgb.prefab +++ b/Assets/Resources/Games/nightWalkAgb.prefab @@ -76,10 +76,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fc6d77daa4e399f4fbac22c2f7de8777, type: 3} m_Name: m_EditorClassIdentifier: - platformRef: {fileID: 1815905863429998752, guid: 73364b4dafdbd914f83c316a1fcf8dd7, type: 3} + platformRef: {fileID: 1558448204157038467, guid: 73364b4dafdbd914f83c316a1fcf8dd7, type: 3} defaultYPos: -11.76 platformDistance: 3.8 - platformAmount: 15 + playerXPos: -6.78 --- !u!1 &955264990193298390 GameObject: m_ObjectHideFlags: 0 @@ -679,6 +679,7 @@ MonoBehaviour: EligibleHits: [] scheduledInputs: [] firstEnable: 0 + playYan: {fileID: 1314280037714680423} --- !u!1 &4465275889429203320 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab index 9192e09e4..277382dd9 100644 --- a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab +++ b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab @@ -9,6 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 9016694733661613840} + - component: {fileID: 1558448204157038467} m_Layer: 0 m_Name: JumpPlatform m_TagString: Untagged @@ -33,6 +34,18 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1558448204157038467 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1815905863429998752} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2b6892a770a77394ca687ef93f8935db, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &4717417375749839996 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs index 57375cc03..d0f119ebb 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using HeavenStudio.Util; +using Jukebox; +using System; namespace HeavenStudio.Games.Loaders { @@ -13,7 +15,15 @@ namespace HeavenStudio.Games.Loaders { return new Minigame("nightWalkAgb", "Night Walk (GBA)", "FFFFFF", false, false, new List() { - + new GameAction("countIn", "Count In") + { + preFunction = delegate { if (!eventCaller.currentEntity["mute"] && AgbNightWalk.IsValidCountIn(eventCaller.currentEntity)) AgbNightWalk.CountInSound(eventCaller.currentEntity.beat); }, + defaultLength = 8, + parameters = new List() + { + new Param("mute", false, "Mute Cowbell") + } + } }); } } @@ -21,14 +31,151 @@ namespace HeavenStudio.Games.Loaders namespace HeavenStudio.Games { + using Scripts_AgbNightWalk; + public class AgbNightWalk : Minigame { public static AgbNightWalk instance; + [SerializeField] private AgbPlayYan playYan; + [NonSerialized] public double countInBeat = -1; private void Awake() { instance = this; } + + public override void OnGameSwitch(double beat) + { + SetCountInBeat(beat); + } + + public override void OnPlay(double beat) + { + SetCountInBeat(beat); + } + + private void SetCountInBeat(double beat) + { + List countInEvents = EventCaller.GetAllInGameManagerList("nightWalkAgb", new string[] { "countIn" }); + if (countInEvents.Count > 0) + { + var allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame" }); + if (allEnds.Count == 0) + { + countInBeat = countInEvents[0].beat; + } + else + { + allEnds.Sort((x, y) => x.beat.CompareTo(y.beat)); + double nextSwitchBeat = double.MaxValue; + foreach (var end in allEnds) + { + if (end.datamodel.Split(2) == "nightWalkAgb") continue; + if (end.beat > beat) + { + nextSwitchBeat = end.beat; + break; + } + } + List tempEvents = new(); + foreach (var countIn in countInEvents) + { + if (countIn.beat < nextSwitchBeat) + { + tempEvents.Add(countIn); + } + } + tempEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); + countInBeat = tempEvents[tempEvents.Count - 1].beat; + } + } + UpdateBalloons(beat); + } + + public static bool IsValidCountIn(RiqEntity countInEntity) + { + List countInEvents = EventCaller.GetAllInGameManagerList("nightWalkAgb", new string[] { "countIn" }); + if (countInEvents.Count > 0) + { + var allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame" }); + if (allEnds.Count == 0) + { + return countInEntity == countInEvents[0]; + } + else + { + allEnds.Sort((x, y) => x.beat.CompareTo(y.beat)); + List tempEnds = new(); + double beat = -1; + for (int i = 0; i < allEnds.Count; i++) + { + if (allEnds[i].datamodel.Split(2) == "nightWalkAgb") + { + if (allEnds[i].beat >= countInEntity.beat) + { + tempEnds.Add(allEnds[i]); + } + } + } + if (tempEnds.Count > 0) beat = tempEnds[0].beat; + double nextSwitchBeat = double.MaxValue; + foreach (var end in allEnds) + { + if (end.datamodel.Split(2) == "nightWalkAgb") continue; + if (end.beat > beat) + { + nextSwitchBeat = end.beat; + break; + } + } + List tempEvents = new(); + foreach (var countIn in countInEvents) + { + if (countIn.beat < nextSwitchBeat) + { + tempEvents.Add(countIn); + } + } + tempEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); + return countInEntity == tempEvents[tempEvents.Count - 1]; + } + } + return false; + } + + private void UpdateBalloons(double beat) + { + if (countInBeat != -1) + { + BeatAction.New(instance.gameObject, new List() + { + new BeatAction.Action(countInBeat, delegate { playYan.PopBalloon(0, beat >= countInBeat); }), + new BeatAction.Action(countInBeat + 2, delegate { playYan.PopBalloon(1, beat >= countInBeat + 2); }), + new BeatAction.Action(countInBeat + 4, delegate { playYan.PopBalloon(2, beat >= countInBeat + 4); }), + new BeatAction.Action(countInBeat + 5, delegate { playYan.PopBalloon(3, beat >= countInBeat + 5); }), + new BeatAction.Action(countInBeat + 6, delegate { playYan.PopBalloon(4, beat >= countInBeat + 6); }), + new BeatAction.Action(countInBeat + 7, delegate { playYan.PopBalloon(5, beat >= countInBeat + 7); }), + new BeatAction.Action(countInBeat + 8, delegate { playYan.PopBalloon(6, beat >= countInBeat + 8); }), + }); + } + else + { + playYan.PopAll(); + } + } + + public static void CountInSound(double beat) + { + MultiSound.Play(new MultiSound.Sound[] + { + new MultiSound.Sound("count-ins/cowbell", beat), + new MultiSound.Sound("count-ins/cowbell", beat + 2), + new MultiSound.Sound("count-ins/cowbell", beat + 4), + new MultiSound.Sound("count-ins/cowbell", beat + 5), + new MultiSound.Sound("count-ins/cowbell", beat + 6), + new MultiSound.Sound("count-ins/cowbell", beat + 7), + }, false, true); + } } } diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs new file mode 100644 index 000000000..9b3d33473 --- /dev/null +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace HeavenStudio.Games.Scripts_AgbNightWalk +{ + public class AgbPlatform : MonoBehaviour + { + + } +} + diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs.meta b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs.meta new file mode 100644 index 000000000..145f08aa4 --- /dev/null +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b6892a770a77394ca687ef93f8935db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs index f0728b9a7..b7a849e61 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs @@ -7,12 +7,12 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk public class AgbPlatformHandler : MonoBehaviour { [Header("Properties")] - [SerializeField] private GameObject platformRef; - [SerializeField] private float defaultYPos = -11.76f; - [SerializeField] private float platformDistance = 3.80f; - [SerializeField] private float playerXPos = -6.78f; - [Range(1, 100)] - [SerializeField] private int platformAmount = 15; + [SerializeField] private AgbPlatform platformRef; + public float defaultYPos = -11.76f; + public float platformDistance = 3.80f; + public float playerXPos = -6.78f; + + List platforms = new(); } } diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlayYan.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlayYan.cs index 82bc23263..a4bd210d9 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlayYan.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlayYan.cs @@ -1,3 +1,5 @@ +using HeavenStudio.Util; +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -17,6 +19,24 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk balloon.Play("Idle", 0, UnityEngine.Random.Range(0f, 1f)); } } + + public void PopBalloon(int index, bool instant) + { + if (instant) + { + balloons[index].DoNormalizedAnimation("Pop", 1); + return; + } + balloons[index].DoScaledAnimationAsync("Pop", 0.5f); + } + + public void PopAll() + { + foreach (var balloon in balloons) + { + balloon.DoNormalizedAnimation("Pop", 1); + } + } } }