2022-03-07 03:17:46 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
using Starpelly;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class CtrDrummingLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
|
|
|
return new Minigame("drummingPractice", "Drumming Practice", "2BCF33", false, false, new List<GameAction>()
|
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("bop", "Bop")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; DrummingPractice.instance.SetBop(e.beat, e.length); },
|
2023-02-14 16:31:51 +00:00
|
|
|
defaultLength = 1f,
|
2022-08-21 03:13:52 +00:00
|
|
|
resizable = true
|
|
|
|
},
|
|
|
|
new GameAction("drum", "Hit Drum")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; DrummingPractice.instance.Prepare(e.beat, e["toggle"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 2f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("toggle", true, "Applause", "Whether or not an applause should be played on a successful hit")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("set mii", "Set Miis")
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; DrummingPractice.instance.SetMiis(e["type"], e["type2"], e["type3"], e["toggle"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("type", DrummingPractice.MiiType.Random, "Player Mii", "The Mii that the player will control"),
|
|
|
|
new Param("type2", DrummingPractice.MiiType.Random, "Left Mii", "The Mii on the left"),
|
|
|
|
new Param("type3", DrummingPractice.MiiType.Random, "Right Mii", "The Mii on the right"),
|
|
|
|
new Param("toggle", false, "Set All to Player", "Sets all Miis to the Player's Mii")
|
|
|
|
}
|
|
|
|
},
|
2023-02-14 16:31:51 +00:00
|
|
|
new GameAction("move npc drummers", "NPC Drummers Enter or Exit")
|
|
|
|
{
|
|
|
|
function = delegate {var e = eventCaller.currentEntity; DrummingPractice.instance.NPCDrummersEnterOrExit(e.beat, e.length, e["exit"], e["ease"]); },
|
|
|
|
defaultLength = 4f,
|
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("exit", false, "Exit?", "Should the NPC drummers exit or enter?"),
|
|
|
|
new Param("ease", EasingFunction.Ease.Linear, "Ease", "Which ease should the movement have?")
|
|
|
|
}
|
|
|
|
},
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("set background color", "Set Background Color")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate {var e = eventCaller.currentEntity; DrummingPractice.instance.SetBackgroundColor(e["colorA"], e["colorB"], e["colorC"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", new Color(43/255f, 207/255f, 51/255f), "Color A", "The top-most color of the background gradient"),
|
|
|
|
new Param("colorB", new Color(1, 1, 1), "Color B", "The bottom-most color of the background gradient"),
|
|
|
|
new Param("colorC", new Color(1, 247/255f, 0), "Streak Color", "The color of streaks that appear on a successful hit")
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 16:14:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-03-07 03:17:46 +00:00
|
|
|
{
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_DrummingPractice;
|
|
|
|
|
2022-03-07 03:17:46 +00:00
|
|
|
public class DrummingPractice : Minigame
|
|
|
|
{
|
2022-03-07 05:26:59 +00:00
|
|
|
public enum MiiType
|
|
|
|
{
|
2022-03-11 18:20:24 +00:00
|
|
|
Random = -1,
|
2022-03-07 05:26:59 +00:00
|
|
|
GuestA,
|
|
|
|
GuestB,
|
|
|
|
GuestC,
|
|
|
|
GuestD,
|
|
|
|
GuestE,
|
|
|
|
GuestF,
|
|
|
|
Matt,
|
|
|
|
Tsunku,
|
|
|
|
Marshal
|
|
|
|
}
|
|
|
|
|
2022-03-07 03:17:46 +00:00
|
|
|
[Header("References")]
|
2022-03-15 23:15:54 +00:00
|
|
|
public SpriteRenderer background;
|
2022-03-07 03:17:46 +00:00
|
|
|
public SpriteRenderer backgroundGradient;
|
2022-03-15 23:15:54 +00:00
|
|
|
public SpriteRenderer[] streaks;
|
2022-03-07 03:17:46 +00:00
|
|
|
public Drummer player;
|
|
|
|
public Drummer leftDrummer;
|
|
|
|
public Drummer rightDrummer;
|
2022-03-07 05:00:54 +00:00
|
|
|
public GameObject hitPrefab;
|
2023-02-14 16:31:51 +00:00
|
|
|
[SerializeField] Animator NPCDrummers;
|
|
|
|
|
|
|
|
[Header("Variables")]
|
|
|
|
float movingLength;
|
|
|
|
float movingStartBeat;
|
|
|
|
bool isMoving;
|
|
|
|
string moveAnim;
|
|
|
|
EasingFunction.Ease lastEase;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
2022-03-07 05:00:54 +00:00
|
|
|
public GameEvent bop = new GameEvent();
|
|
|
|
public int count = 0;
|
2022-03-07 03:17:46 +00:00
|
|
|
|
|
|
|
public static DrummingPractice instance;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2022-03-26 02:08:46 +00:00
|
|
|
SetMiis();
|
2022-03-07 03:17:46 +00:00
|
|
|
}
|
2022-03-26 02:08:46 +00:00
|
|
|
|
2022-03-27 18:13:13 +00:00
|
|
|
public override void OnGameSwitch(float beat)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
var changeMii = GameManager.instance.Beatmap.entities.FindLast(c => c.datamodel == "drummingPractice/set mii" && c.beat <= beat);
|
2022-03-27 18:13:13 +00:00
|
|
|
if(changeMii != null)
|
|
|
|
{
|
|
|
|
EventCaller.instance.CallEvent(changeMii, true);
|
|
|
|
}
|
2022-03-07 05:00:54 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 03:17:46 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2023-02-14 16:31:51 +00:00
|
|
|
var cond = Conductor.instance;
|
|
|
|
if (cond.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1))
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
2023-02-14 16:31:51 +00:00
|
|
|
if (cond.songPositionInBeats >= bop.startBeat && Conductor.instance.songPositionInBeats < bop.startBeat + bop.length)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
|
|
|
Bop();
|
|
|
|
}
|
|
|
|
}
|
2022-03-15 23:15:54 +00:00
|
|
|
|
2023-02-14 16:31:51 +00:00
|
|
|
if (isMoving && cond.isPlaying && !cond.isPaused)
|
|
|
|
{
|
|
|
|
float normalizedBeat = cond.GetPositionFromBeat(movingStartBeat, movingLength);
|
|
|
|
EasingFunction.Function func = EasingFunction.GetEasingFunction(lastEase);
|
|
|
|
float newPos = func(0f, 1f, normalizedBeat);
|
|
|
|
NPCDrummers.DoNormalizedAnimation(moveAnim, newPos);
|
|
|
|
}
|
|
|
|
|
2022-03-15 23:15:54 +00:00
|
|
|
foreach (SpriteRenderer streak in streaks)
|
|
|
|
{
|
|
|
|
Color col = streak.color;
|
|
|
|
streak.color = new Color(col.r, col.g, col.b, Mathf.Lerp(col.a, 0, 3.5f * Time.deltaTime));
|
|
|
|
}
|
2022-03-07 05:00:54 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 16:31:51 +00:00
|
|
|
public void NPCDrummersEnterOrExit(float beat, float length, bool exit, int ease)
|
|
|
|
{
|
|
|
|
movingStartBeat = beat;
|
|
|
|
movingLength = length;
|
|
|
|
moveAnim = exit ? "NPCDrummersExit" : "NPCDrummersEnter";
|
|
|
|
isMoving = true;
|
|
|
|
lastEase = (EasingFunction.Ease)ease;
|
|
|
|
BeatAction.New(instance.gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(beat + length - 0.01f, delegate { isMoving = false; })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-07 05:00:54 +00:00
|
|
|
public void SetBop(float beat, float length)
|
|
|
|
{
|
|
|
|
bop.startBeat = beat;
|
|
|
|
bop.length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bop()
|
|
|
|
{
|
|
|
|
player.Bop();
|
|
|
|
leftDrummer.Bop();
|
|
|
|
rightDrummer.Bop();
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:10:50 +00:00
|
|
|
public void Prepare(float beat, bool applause)
|
2022-03-07 05:00:54 +00:00
|
|
|
{
|
|
|
|
int type = count % 2;
|
|
|
|
player.Prepare(type);
|
|
|
|
leftDrummer.Prepare(type);
|
|
|
|
rightDrummer.Prepare(type);
|
|
|
|
count++;
|
|
|
|
|
|
|
|
SetFaces(0);
|
|
|
|
Jukebox.PlayOneShotGame("drummingPractice/prepare");
|
|
|
|
|
|
|
|
GameObject hit = Instantiate(hitPrefab);
|
|
|
|
hit.transform.parent = hitPrefab.transform.parent;
|
|
|
|
hit.SetActive(true);
|
|
|
|
DrummerHit h = hit.GetComponent<DrummerHit>();
|
|
|
|
h.startBeat = beat;
|
2022-03-07 17:10:50 +00:00
|
|
|
h.applause = applause;
|
2022-03-07 05:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFaces(int type)
|
|
|
|
{
|
|
|
|
player.SetFace(type);
|
|
|
|
leftDrummer.SetFace(type);
|
|
|
|
rightDrummer.SetFace(type);
|
2022-03-07 03:17:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 18:24:24 +00:00
|
|
|
public void SetMiis(int playerFace = (int) MiiType.Random, int leftFace = (int) MiiType.Random, int rightFace = (int) MiiType.Random, bool all = false)
|
2022-03-07 05:26:59 +00:00
|
|
|
{
|
2022-03-11 18:24:24 +00:00
|
|
|
if (playerFace == (int) MiiType.Random)
|
2022-03-11 18:20:24 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
player.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
|
|
|
|
}
|
|
|
|
while (player.mii == leftFace || player.mii == rightFace);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
player.mii = playerFace;
|
2022-03-07 05:26:59 +00:00
|
|
|
|
2022-03-11 18:20:24 +00:00
|
|
|
if (all && playerFace != -1)
|
2022-03-07 05:26:59 +00:00
|
|
|
{
|
|
|
|
leftDrummer.mii = playerFace;
|
|
|
|
rightDrummer.mii = playerFace;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-11 18:24:24 +00:00
|
|
|
if (leftFace == (int) MiiType.Random)
|
2022-03-07 05:26:59 +00:00
|
|
|
{
|
2022-03-11 18:20:24 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
leftDrummer.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
|
|
|
|
}
|
|
|
|
while (leftDrummer.mii == player.mii);
|
2022-03-07 05:26:59 +00:00
|
|
|
}
|
2022-03-11 18:20:24 +00:00
|
|
|
else
|
|
|
|
leftDrummer.mii = leftFace;
|
|
|
|
|
2022-03-11 18:24:24 +00:00
|
|
|
if (rightFace == (int) MiiType.Random)
|
2022-03-07 05:26:59 +00:00
|
|
|
{
|
2022-03-11 18:20:24 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
rightDrummer.mii = UnityEngine.Random.Range(0, player.miiFaces.Count);
|
|
|
|
}
|
|
|
|
while (rightDrummer.mii == leftDrummer.mii || rightDrummer.mii == player.mii);
|
2022-03-07 05:26:59 +00:00
|
|
|
}
|
2022-03-11 18:20:24 +00:00
|
|
|
else
|
|
|
|
rightDrummer.mii = rightFace;
|
2022-03-07 05:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetFaces(0);
|
|
|
|
}
|
|
|
|
|
2022-03-15 23:15:54 +00:00
|
|
|
public void SetBackgroundColor(Color col1, Color col2, Color col3)
|
|
|
|
{
|
|
|
|
backgroundGradient.color = col1;
|
|
|
|
background.color = col2;
|
|
|
|
foreach(SpriteRenderer streak in streaks)
|
|
|
|
{
|
|
|
|
streak.color = new Color(col3.r, col3.g, col3.b, streak.color.a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Streak()
|
|
|
|
{
|
|
|
|
foreach (SpriteRenderer streak in streaks)
|
|
|
|
{
|
|
|
|
Color col = streak.color;
|
|
|
|
streak.color = new Color(col.r, col.g, col.b, 0.7f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 03:17:46 +00:00
|
|
|
}
|
|
|
|
}
|