HeavenStudio/Assets/Scripts/Games/FrogHop/FrogHop.cs
2024-04-25 21:37:04 -05:00

464 lines
19 KiB
C#

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
using HeavenStudio.InputSystem;
using Jukebox;
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
public static class NtrFrogHopLoader
{
public static Minigame AddGame(EventCaller eventCaller)
{
return new Minigame("FrogHop", "Frog Hop", "ffffff", false, false, new List<GameAction>()
{
new GameAction("bop", "Bop")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Bop(e.beat, e.length, e["bop"]);
}
},
resizable = true,
parameters = new List<Param>()
{
new Param("bop", FrogHop.WhoBops.All, "Bop", "Set the character(s) to bop for the duration of this event."),
}
},
new GameAction("count", "Count In")
{
preFunction = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Count(e.beat, e["start"]);
}
},
parameters = new List<Param>()
{
new Param("start", true, "Start Shaking", "Start shaking after the count in."),
},
defaultLength = 4.0f,
},
new GameAction("hop", "Start Shaking")
{
preFunction = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Hop(e.beat);
}
},
},
new GameAction("twoshake", "Ya-hoo!")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.TwoHop(e.beat, e["spotlights"]);
}
},
parameters = new List<Param>()
{
new Param("spotlights", true, "Automatic Spotlights", "Handles spotlight switching automatically."),
},
defaultLength = 4.0f,
},
new GameAction("threeshake", "Yeah yeah yeah!")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.ThreeHop(e.beat, e["spotlights"]);
}
},
parameters = new List<Param>()
{
new Param("spotlights", true, "Automatic Spotlights", "Handles spotlight switching automatically."),
},
defaultLength = 4.0f,
},
new GameAction("spotlights", "Spotlights")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Spotlights(e["front"], e["back"], e["dark"]);
}
},
parameters = new List<Param>()
{
new Param("front", true, "Front Lights", "Enables the spotlights on the front frogs."),
new Param("back", false, "Back Lights", "Enables the spotlights on the back frogs."),
new Param("dark", true, "Darken Stage", "Darkens the stage, allowing the spotlights to be seen."),
},
defaultLength = 0.5f,
},
new GameAction("mouthwide", "Open Mouth (Wide)")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Sing("Wide", e.beat + e.length - 0.5, e["blue"], e["orange"], e["greens"]);
}
},
parameters = new List<Param>()
{
new Param("blue", true, "Blue Sings", "Make Blue Frog sing during this event."),
new Param("orange", false, "Orange Sings", "Make Orange Frog sing during this event."),
new Param("greens", false, "Group Sings", "Make the frogs in the back sing during this event."),
},
defaultLength = 0.5f,
resizable = true,
},
new GameAction("mouthnarrow", "Open Mouth (Narrow)")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Sing("Narrow", e.beat + e.length - 0.5, e["blue"], e["orange"], e["greens"]);
}
},
parameters = new List<Param>()
{
new Param("blue", true, "Blue Sings", "Make Blue Frog sing during this event."),
new Param("orange", false, "Orange Sings", "Make Orange Frog sing during this event."),
new Param("greens", false, "Group Sings", "Make the frogs in the back sing during this event."),
},
defaultLength = 0.5f,
resizable = true,
},
}
);
}
}
}
namespace HeavenStudio.Games
{
using HeavenStudio.Games.Loaders;
using Scripts_FrogHop;
public class FrogHop : Minigame
{
//definitions
#region Definitions
[SerializeField] public ntrFrog PlayerFrog;
[SerializeField] public List<ntrFrog> OtherFrogs = new List<ntrFrog>();
[SerializeField] public ntrFrog LeaderFrog;
[SerializeField] public ntrFrog SingerFrog;
[SerializeField] public GameObject Darkness;
[SerializeField] public GameObject SpotlightFront;
[SerializeField] public GameObject SpotlightBack;
List<ntrFrog> AllFrogs = new();
List<ntrFrog> FrontFrogs = new();
List<ntrFrog> BackFrogs = new();
List<ntrFrog> whoToInputKTB = new();
int globalAnimSide = -1;
double wantHop = double.MinValue;
List<double> queuedHops = new();
bool keepHopping;
double startBackHop = double.MinValue;
double startNoHop = double.MinValue;
double startRegularHop = double.MinValue;
public enum WhoBops
{
Front,
Back,
All,
None,
}
#endregion
//global methods
#region Global Methods
public void Awake()
{
AllFrogs.Add(PlayerFrog);
AllFrogs.AddRange(OtherFrogs);
AllFrogs.Add(LeaderFrog);
AllFrogs.Add(SingerFrog);
FrontFrogs.Add(LeaderFrog);
FrontFrogs.Add(SingerFrog);
BackFrogs.Add(PlayerFrog);
BackFrogs.AddRange(OtherFrogs);
whoToInputKTB = AllFrogs;
}
public void LateUpdate()
{
//whiff stuff below
if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress))
{
PlayerFrog.Hop();
}
//ktb stuff below
if (wantHop != double.MinValue)
{
queuedHops.Add(wantHop);
keepHopping = true;
wantHop = double.MinValue;
}
if (Conductor.instance.isPlaying && !Conductor.instance.isPaused)
{
if (queuedHops.Count > 0)
{
foreach (var hop in queuedHops)
{
var actions = new List<BeatAction.Action>();
bool betweenHopValues = hop + 1 < startRegularHop && hop + 1 >= startNoHop;
if (!betweenHopValues) ScheduleInput(hop, 1, InputAction_BasicPress, PlayerHopNormal, PlayerMiss, Nothing);
betweenHopValues = hop + 1 < startRegularHop && hop + 1 >= startNoHop;
if (!betweenHopValues) actions.Add(new BeatAction.Action(hop + 1, delegate { NPCHop(BackFrogs); }));
betweenHopValues = hop + 1 < startRegularHop && hop + 1 >= startBackHop;
if (!betweenHopValues) actions.Add(new BeatAction.Action(hop + 1, delegate {
betweenHopValues = hop + 1 < startRegularHop && hop + 1 >= startBackHop;
if (!betweenHopValues) NPCHop(FrontFrogs);
}));
if (keepHopping) actions.Add(new BeatAction.Action(hop, delegate { queuedHops.Add(hop + 1); }));
BeatAction.New(this, actions);
}
queuedHops.Clear();
}
}
}
#endregion
//frog hop methods
#region Frog Hop Methods
public void Bop(double beat, float length, int bop)
{
var bopInterp = new List<ntrFrog>();
switch (bop)
{
case 0: bopInterp = FrontFrogs; break;
case 1: bopInterp = BackFrogs; break;
case 2: bopInterp = AllFrogs; break;
default: break;
}
var actions = new List<BeatAction.Action>();
for (int i = 0; i < length; i++)
{
actions.Add(new(beat + i, delegate { BopAnimation(bopInterp); }));
}
BeatAction.New(this, actions);
}
public void BopAnimation(List<ntrFrog> FrogsToBop)
{
foreach (var a in FrogsToBop) { a.Bop(); }
}
public void Count(double beat, bool start)
{
var actions = new List<BeatAction.Action>();
var sounds = new List<MultiSound.Sound>();
actions.Add(new(beat + 0.0, delegate { Talk(new List<ntrFrog>() { LeaderFrog }, "Wide", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_COUNT1", beat + 0.0));
actions.Add(new(beat + 1.0, delegate { Talk(new List<ntrFrog>() { LeaderFrog }, "Wide", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_COUNT2", beat + 1.0));
actions.Add(new(beat + 2.0, delegate { Talk(new List<ntrFrog>() { LeaderFrog }, "Wide", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_COUNT3", beat + 2.0));
actions.Add(new(beat + 3.0, delegate { Talk(new List<ntrFrog>() { LeaderFrog }, "Wide", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_COUNT4", beat + 3.0));
BeatAction.New(this, actions);
MultiSound.Play(sounds.ToArray());
if (start) Hop(beat + 4.0);
}
public void Hop (double beat)
{
wantHop = beat - 1;
}
public void TwoHop (double beat, bool spotlights)
{
CueCommon(beat, spotlights);
var actions = new List<BeatAction.Action>();
var sounds = new List<MultiSound.Sound>();
//call
actions.Add(new(beat + 0.0, delegate { NPCHop(FrontFrogs); Talk(new List<ntrFrog>() { LeaderFrog }, "Wide", beat); }));
actions.Add(new(beat + 0.5, delegate { NPCHop(FrontFrogs, true); Talk(new List<ntrFrog>() { LeaderFrog }, "Narrow", beat + 1.5); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_T_HA", beat));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_POP_DEFAULT", beat));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_T_HAAI", beat + 0.5));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_POP_HAAI", beat + 0.5));
//response
actions.Add(new(beat + 2.0, delegate { NPCHop(BackFrogs); Talk(BackFrogs, "Wide", beat); }));
actions.Add(new(beat + 2.5, delegate { NPCHop(BackFrogs, true); Talk(BackFrogs, "Narrow", beat + 3.5); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_E_HA", beat + 2.0));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_E_HAAI", beat + 2.5));
//inputs
ScheduleInput(beat, 2.0, InputAction_BasicPress, PlayerHopYa, PlayerMiss, Nothing);
ScheduleInput(beat, 2.5, InputAction_BasicPress, PlayerHopHoo, PlayerMiss, Nothing);
BeatAction.New(this, actions);
MultiSound.Play(sounds.ToArray());
}
public void ThreeHop (double beat, bool spotlights)
{
CueCommon(beat, spotlights);
var actions = new List<BeatAction.Action>();
var sounds = new List<MultiSound.Sound>();
//call
actions.Add(new(beat + 0.0, delegate { NPCHop(FrontFrogs); Talk(new List<ntrFrog>() { LeaderFrog }, "Narrow", beat); }));
actions.Add(new(beat + 0.5, delegate { NPCHop(FrontFrogs); Talk(new List<ntrFrog>() { LeaderFrog }, "Narrow", beat); }));
actions.Add(new(beat + 1.0, delegate { NPCHop(FrontFrogs, true); Talk(new List<ntrFrog>() { LeaderFrog }, "Narrow", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_T_HAI", beat));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_POP_DEFAULT", beat));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_T_HAI", beat + 0.5));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_POP_DEFAULT", beat + 0.5));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_T_HAI", beat + 1.0));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_POP_DEFAULT", beat + 1.0));
//response
actions.Add(new(beat + 2.0, delegate { NPCHop(BackFrogs); Talk(BackFrogs, "Narrow", beat); }));
actions.Add(new(beat + 2.5, delegate { NPCHop(BackFrogs); Talk(BackFrogs, "Narrow", beat); }));
actions.Add(new(beat + 3.0, delegate { NPCHop(BackFrogs, true); Talk(BackFrogs, "Narrow", beat); }));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_E_HAI", beat + 2.0));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_E_HAI", beat + 2.5));
sounds.Add(new MultiSound.Sound("frogHop/SE_NTR_FROG_EN_E_HAI", beat + 3.0));
//inputs
ScheduleInput(beat, 2.0, InputAction_BasicPress, PlayerHopYeah, PlayerMiss, Nothing);
ScheduleInput(beat, 2.5, InputAction_BasicPress, PlayerHopYeah, PlayerMiss, Nothing);
ScheduleInput(beat, 3.0, InputAction_BasicPress, PlayerHopYeahAccent, PlayerMiss, Nothing);
BeatAction.New(this, actions);
MultiSound.Play(sounds.ToArray());
}
public void CueCommon(double beat, bool spotlights = true)
{
startBackHop = beat;
startNoHop = beat + 2;
startRegularHop = beat + 4;
if (!spotlights) return;
var actions = new List<BeatAction.Action>();
actions.Add(new(beat + 1.5, delegate { Spotlights(false, true); }));
actions.Add(new(beat + 3.5, delegate { Spotlights(true, false); }));
BeatAction.New(this, actions);
}
public void Spotlights(bool front, bool back, bool dark = true)
{
foreach (var a in FrontFrogs) { a.Darken(front || !dark); }
Darkness.SetActive(dark);
SpotlightFront.SetActive(front);
SpotlightBack.SetActive(back);
}
public void NPCHop(List<ntrFrog> FrogsToHop, bool isThisLong = false)
{
foreach (var a in FrogsToHop) { if (a != PlayerFrog) a.Hop(isLong: isThisLong); }
}
public void PlayerHopNormal(PlayerActionEvent caller, float state)
{
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_P_BEAT");
PlayerHop();
}
public void PlayerHopYa(PlayerActionEvent caller, float state)
{
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_P_HA");
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_POP_DEFAULT");
PlayerHop();
}
public void PlayerHopHoo(PlayerActionEvent caller, float state)
{
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_P_HAAI");
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_POP_HAAI");
PlayerHop(true);
}
public void PlayerHopYeah(PlayerActionEvent caller, float state)
{
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_P_HAI");
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_POP_DEFAULT");
PlayerHop();
}
public void PlayerHopYeahAccent(PlayerActionEvent caller, float state)
{
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_P_HAI");
SoundByte.PlayOneShotGame("frogHop/SE_NTR_FROG_EN_POP_DEFAULT");
PlayerHop(true);
}
public void PlayerHop(bool isLong = false)
{
globalAnimSide *= -1;
PlayerFrog.Hop(globalAnimSide, isLong);
}
public void PlayerMiss(PlayerActionEvent caller)
{
globalAnimSide *= -1;
}
public void Nothing(PlayerActionEvent caller) { }
public void Talk(List<ntrFrog> FrogsToTalk, string syllable, double animEnd)
{
foreach (var a in FrogsToTalk) { a.Talk(syllable, animEnd); }
}
public void Sing(string syllable, double animEnd, bool blue, bool orange, bool greens)
{
var FrogsToTalk = new List<ntrFrog>();
if (blue) FrogsToTalk.Add(SingerFrog);
if (orange) FrogsToTalk.Add(LeaderFrog);
if (greens) FrogsToTalk.AddRange(BackFrogs);
Talk(FrogsToTalk, syllable, animEnd);
}
#endregion
}
}