HeavenStudio/Assets/Scripts/Games/FrogHop/FrogHop.cs
ThePurpleAnon 3cab5d3d32 le froge
2024-04-25 01:25:35 -05:00

400 lines
16 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);
}
},
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);
}
},
defaultLength = 4.0f,
},
new GameAction("mouthwide", "Open Mouth (Wide)")
{
function = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Sing(0, "Wide", e.beat + e.length - 0.5);
}
},
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(0, "Narrow", e.beat + e.length - 0.5);
}
},
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;
public List<ntrFrog> AllFrogs = new();
public List<ntrFrog> FrontFrogs = new();
public List<ntrFrog> BackFrogs = new();
public List<ntrFrog> whoToInputKTB = new();
public int globalAnimSide = -1;
public double wantHop = double.MinValue;
public List<double> queuedHops = new();
public bool keepHopping;
public double startBackHop = double.MinValue;
public double startNoHop = double.MinValue;
public 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)
{
startBackHop = beat;
startNoHop = beat + 2;
startRegularHop = beat + 4;
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.0); }));
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.0); }));
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)
{
startBackHop = beat;
startNoHop = beat + 2;
startRegularHop = beat + 4;
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 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(int whichFrog, string syllable, double animEnd)
{
var FrogsToTalk = new List<ntrFrog>() { SingerFrog }; //TO DO: make this customizeable
Talk(FrogsToTalk, syllable, animEnd);
}
#endregion
}
}