2021-12-21 04:38:59 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2021-12-23 22:39:03 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class AgbClapLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
|
|
|
return new Minigame("clappyTrio", "The Clappy Trio", "29E7FF", false, false, new List<GameAction>()
|
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("clap", "Clap")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
function = delegate { ClappyTrio.instance.Clap(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); },
|
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("bop", "Bop")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
function = delegate { ClappyTrio.instance.Bop(eventCaller.currentEntity.beat); }
|
|
|
|
},
|
|
|
|
new GameAction("prepare", "Prepare Stance")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { ClappyTrio.instance.Prepare(eventCaller.currentEntity["toggle"] ? 3 : 0); },
|
2022-08-21 03:13:52 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("toggle", false, "Alt", "Whether or not the alternate version should be played")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("change lion count", "Change Lion Count")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { ClappyTrio.instance.ChangeLionCount((int)eventCaller.currentEntity["valA"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("valA", new EntityTypes.Integer(3, 8, 3), "Lion Count", "The amount of lions")
|
|
|
|
}
|
|
|
|
},
|
2022-04-12 16:14:46 +00:00
|
|
|
// This is still here for backwards-compatibility but is hidden in the editor
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("prepare_alt", "")
|
|
|
|
{
|
|
|
|
function = delegate { ClappyTrio.instance.Prepare(3); },
|
|
|
|
hidden = true
|
|
|
|
},
|
2022-04-12 16:14:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2021-12-21 04:38:59 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_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; }
|
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
MultiSound clapSounds = null;
|
|
|
|
BeatAction clapAction = null;
|
|
|
|
|
2021-12-23 22:39:03 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2023-01-15 04:33:37 +00:00
|
|
|
clapSounds = null;
|
2022-03-27 00:53:34 +00:00
|
|
|
InitLions();
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
2022-03-27 18:13:13 +00:00
|
|
|
public override void OnGameSwitch(float beat)
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
DynamicBeatmap.DynamicEntity changeLion = GameManager.instance.Beatmap.entities.FindLast(c => c.datamodel == "clappyTrio/change lion count" && c.beat <= beat);
|
2022-03-27 18:13:13 +00:00
|
|
|
if(changeLion != null)
|
|
|
|
{
|
|
|
|
EventCaller.instance.CallEvent(changeLion, true);
|
|
|
|
}
|
|
|
|
}
|
2021-12-23 22:39:03 +00:00
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void InitLions()
|
2021-12-23 22:39:03 +00:00
|
|
|
{
|
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>();
|
|
|
|
}
|
2022-03-26 02:08:46 +00:00
|
|
|
|
2023-01-15 04:33:37 +00:00
|
|
|
if (clapSounds != null)
|
|
|
|
clapSounds.Delete();
|
|
|
|
|
|
|
|
if (clapAction != null)
|
|
|
|
clapAction.Delete();
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2021-12-24 08:35:54 +00:00
|
|
|
|
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;
|
2023-01-15 04:33:37 +00:00
|
|
|
|
|
|
|
// makes the other lions clap
|
|
|
|
List<MultiSound.Sound> sounds = new List<MultiSound.Sound>();
|
|
|
|
List<BeatAction.Action> actions = new List<BeatAction.Action>();
|
|
|
|
for (int i = 0; i < Lion.Count - 1; i++)
|
|
|
|
{
|
|
|
|
int idx = i;
|
|
|
|
sounds.Add(new MultiSound.Sound((i > 0) ? "clappyTrio/middleClap" : "clappyTrio/leftClap", beat + (length * i)));
|
|
|
|
actions.Add(new BeatAction.Action(beat + (length * i), delegate { SetFace(idx, 4); Lion[idx].GetComponent<Animator>().Play("Clap", 0, 0);}));
|
|
|
|
}
|
|
|
|
clapSounds = MultiSound.Play(sounds.ToArray());
|
|
|
|
clapAction = BeatAction.New(this.gameObject, actions);
|
|
|
|
|
|
|
|
// prepare player input
|
|
|
|
ClappyTrioPlayer.QueueClap(beat, length * (Lion.Count - 1));
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-01 01:11:01 +00:00
|
|
|
public void ChangeLionCount(int lions)
|
|
|
|
{
|
|
|
|
for(int i=1; i<lionCount; i++)
|
|
|
|
{
|
|
|
|
Destroy(Lion[i]);
|
|
|
|
}
|
|
|
|
Lion.RemoveRange(1, lionCount - 1);
|
|
|
|
lionCount = lions;
|
|
|
|
SetFace(0, 0);
|
2022-03-26 02:08:46 +00:00
|
|
|
InitLions();
|
2022-03-01 01:11:01 +00:00
|
|
|
PlayAnimationAll("Idle");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|