HeavenStudio/Assets/Scripts/Games/FrogHop/FrogHop.cs
ThePurpleAnon 32b84ab85b a frogge
2024-04-23 20:43:18 -05:00

223 lines
7.3 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("hop", "Hop")
{
preFunction = delegate {
var e = eventCaller.currentEntity;
if (eventCaller.gameManager.minigameObj.TryGetComponent(out FrogHop instance)) {
instance.Hop(e.beat, e.length);
}
},
defaultLength = 4.0f,
resizable = true,
},
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,
},
}
);
}
}
}
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();
[NonSerialized] public int globalAnimSide = -1;
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);
}
public void Update()
{
if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress))
{
PlayerFrog.Hop();
}
}
#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 Hop (double beat, double length)
{
var actions = new List<BeatAction.Action>();
for (int i = 0; i < length; i++)
{
actions.Add(new(beat + i, delegate { NPCHop(AllFrogs); }));
ScheduleInput(beat - 1, i + 1, InputAction_BasicPress, PlayerHopNormal, PlayerMiss, Nothing);
}
BeatAction.New(this, actions);
}
public void TwoHop (double beat)
{
var actions = new List<BeatAction.Action>();
var sounds = new List<MultiSound.Sound>();
//call
actions.Add(new(beat + 0.0, delegate { NPCHop(FrontFrogs); }));
actions.Add(new(beat + 0.5, delegate { NPCHop(FrontFrogs, true); }));
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); }));
actions.Add(new(beat + 2.5, delegate { NPCHop(BackFrogs, true); }));
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 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 PlayerHop(bool isLong = false)
{
globalAnimSide *= -1;
PlayerFrog.Hop(globalAnimSide, isLong);
}
public void PlayerMiss(PlayerActionEvent caller)
{
globalAnimSide *= -1;
}
public void Nothing(PlayerActionEvent caller) { }
#endregion
}
}