2021-12-21 04:38:59 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2021-12-23 22:39:03 +00:00
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
2021-12-21 04:38:59 +00:00
|
|
|
namespace RhythmHeavenMania.Games.ClappyTrio
|
|
|
|
{
|
2021-12-24 03:36:16 +00:00
|
|
|
public class ClappyTrio : Minigame
|
2021-12-21 04:38:59 +00:00
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
public int lionCount = 3;
|
|
|
|
|
|
|
|
public List<GameObject> Lion;
|
2021-12-23 22:39:03 +00:00
|
|
|
|
|
|
|
[SerializeField] private Sprite[] faces;
|
|
|
|
|
|
|
|
private bool isClapping;
|
|
|
|
private float currentClappingLength;
|
|
|
|
private float lastClapStart;
|
|
|
|
private int clapIndex;
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
private ClappyTrioPlayer ClappyTrioPlayer;
|
|
|
|
|
|
|
|
public bool playerHitLast = false;
|
|
|
|
|
2021-12-23 22:39:03 +00:00
|
|
|
public static ClappyTrio instance { get; set; }
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2022-03-01 00:46:55 +00:00
|
|
|
float startPos = -3.066667f;
|
|
|
|
float maxWidth = 12.266668f;
|
2021-12-24 08:35:54 +00:00
|
|
|
|
2022-03-01 00:46:55 +00:00
|
|
|
for (int i = 0; i < lionCount; i++)
|
2021-12-24 08:35:54 +00:00
|
|
|
{
|
2022-03-01 00:46:55 +00:00
|
|
|
GameObject lion;
|
|
|
|
if (i == 0)
|
|
|
|
lion = Lion[0];
|
|
|
|
else
|
|
|
|
lion = Instantiate(Lion[0], Lion[0].transform.parent);
|
2021-12-24 08:35:54 +00:00
|
|
|
|
2022-03-01 00:46:55 +00:00
|
|
|
lion.transform.localPosition = new Vector3(startPos + ((maxWidth / (lionCount + 1)) * (i + 1)), 0);
|
2021-12-24 08:35:54 +00:00
|
|
|
|
2022-03-01 00:46:55 +00:00
|
|
|
if (i > 0)
|
|
|
|
Lion.Add(lion);
|
2021-12-24 08:35:54 +00:00
|
|
|
|
|
|
|
if (i == lionCount - 1)
|
|
|
|
ClappyTrioPlayer = lion.AddComponent<ClappyTrioPlayer>();
|
|
|
|
}
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (isClapping)
|
|
|
|
{
|
|
|
|
float songPosBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
2021-12-24 08:35:54 +00:00
|
|
|
for (int i = 0; i < Lion.Count; i++)
|
|
|
|
{
|
2021-12-25 02:37:03 +00:00
|
|
|
float length = currentClappingLength * (i);
|
|
|
|
float lengthplusone = (currentClappingLength * (i + 1));
|
2021-12-24 08:35:54 +00:00
|
|
|
|
|
|
|
// i spent like 25 minutes trying to figure out what was wrong with this when i forgot to subtract the currentClapLength :(
|
|
|
|
if (i == Lion.Count - 1)
|
2021-12-25 02:37:03 +00:00
|
|
|
{
|
|
|
|
length = 0;
|
|
|
|
}
|
2021-12-24 08:35:54 +00:00
|
|
|
|
2021-12-25 02:37:03 +00:00
|
|
|
if (songPosBeat > lastClapStart + length && songPosBeat < lastClapStart + lengthplusone && clapIndex == i)
|
2021-12-24 08:35:54 +00:00
|
|
|
{
|
|
|
|
if (i == Lion.Count - 1)
|
|
|
|
{
|
2021-12-25 02:37:03 +00:00
|
|
|
ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * (i - 1)), currentClappingLength);
|
2021-12-24 08:35:54 +00:00
|
|
|
|
|
|
|
clapIndex = 0;
|
|
|
|
isClapping = false;
|
|
|
|
currentClappingLength = 0;
|
|
|
|
ClappyTrioPlayer.clapStarted = false;
|
2022-03-01 00:46:55 +00:00
|
|
|
} else
|
2021-12-24 08:35:54 +00:00
|
|
|
{
|
|
|
|
SetFace(i, 4);
|
|
|
|
Lion[i].GetComponent<Animator>().Play("Clap", 0, 0);
|
2021-12-27 04:48:39 +00:00
|
|
|
|
|
|
|
// lazy fix rn
|
|
|
|
if (i > 0)
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/middleClap");
|
|
|
|
else
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/leftClap");
|
|
|
|
|
2021-12-24 08:35:54 +00:00
|
|
|
clapIndex++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clap(float beat, float length)
|
|
|
|
{
|
2021-12-24 03:36:16 +00:00
|
|
|
ClappyTrioPlayer.clapStarted = true;
|
|
|
|
ClappyTrioPlayer.canHit = true; // this is technically a lie, this just restores the ability to hit
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
playerHitLast = false;
|
2021-12-23 22:39:03 +00:00
|
|
|
isClapping = true;
|
|
|
|
lastClapStart = beat;
|
|
|
|
currentClappingLength = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Prepare(int type)
|
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
for (int i = 0; i < Lion.Count; i++)
|
|
|
|
{
|
|
|
|
SetFace(i, type);
|
|
|
|
}
|
2021-12-24 00:58:48 +00:00
|
|
|
PlayAnimationAll("Prepare");
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/ready");
|
|
|
|
}
|
|
|
|
|
2021-12-28 02:36:27 +00:00
|
|
|
public void Bop(float beat)
|
2021-12-24 00:58:48 +00:00
|
|
|
{
|
|
|
|
if (playerHitLast)
|
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
for (int i = 0; i < Lion.Count; i++)
|
|
|
|
{
|
|
|
|
SetFace(i, 1);
|
|
|
|
}
|
2022-03-01 00:46:55 +00:00
|
|
|
} else
|
2021-12-24 03:36:16 +00:00
|
|
|
{
|
2021-12-28 02:36:27 +00:00
|
|
|
var a = EventCaller.GetAllInGameManagerList("clappyTrio", new string[] { "clap" });
|
|
|
|
var b = a.FindAll(c => c.beat < beat);
|
|
|
|
|
|
|
|
if (b.Count > 0)
|
2021-12-24 08:35:54 +00:00
|
|
|
{
|
2021-12-28 02:36:27 +00:00
|
|
|
for (int i = 0; i < Lion.Count; i++)
|
2021-12-24 08:35:54 +00:00
|
|
|
{
|
2021-12-28 02:36:27 +00:00
|
|
|
if (i == Lion.Count - 1)
|
|
|
|
{
|
|
|
|
SetFace(i, 0);
|
2022-03-01 00:46:55 +00:00
|
|
|
} else
|
2021-12-28 02:36:27 +00:00
|
|
|
{
|
|
|
|
SetFace(i, 2);
|
|
|
|
}
|
2021-12-24 08:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
}
|
2021-12-24 00:58:48 +00:00
|
|
|
PlayAnimationAll("Bop");
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void PlayAnimationAll(string anim)
|
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
for (int i = 0; i < Lion.Count; i++)
|
|
|
|
{
|
|
|
|
Lion[i].GetComponent<Animator>().Play(anim, -1, 0);
|
|
|
|
}
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
public void SetFace(int lion, int type)
|
2021-12-21 04:38:59 +00:00
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
Lion[lion].transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = faces[type];
|
2021-12-21 04:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|