2022-03-03 23:33:22 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2022-03-06 16:35:23 +00:00
|
|
|
using System.Linq;
|
2022-03-03 23:33:22 +00:00
|
|
|
using UnityEngine;
|
2022-03-04 03:30:08 +00:00
|
|
|
using System;
|
2024-02-16 06:17:16 +00:00
|
|
|
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2023-10-29 19:44:47 +00:00
|
|
|
using HeavenStudio.InputSystem;
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2022-04-12 16:14:46 +00:00
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class AgbWaltzLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller) {
|
2023-04-02 02:28:23 +00:00
|
|
|
return new Minigame("wizardsWaltz", "Wizard's Waltz \n<color=#adadad>(Mahou Tsukai)</color>", "ffef9c", false, false, new List<GameAction>()
|
2022-04-12 16:14:46 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("start interval", "Start Interval")
|
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
preFunction = delegate { var e = eventCaller.currentEntity; WizardsWaltz.PreInterval(e.beat, e.length, e["auto"]); },
|
2023-04-12 22:34:15 +00:00
|
|
|
defaultLength = 6f,
|
2023-01-19 02:31:08 +00:00
|
|
|
resizable = true,
|
2023-07-17 15:09:58 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("auto", true, "Auto Pass Turn", "Toggle if the turn should be passed automatically at the end of the start interval.")
|
2023-07-17 15:09:58 +00:00
|
|
|
},
|
|
|
|
preFunctionLength = 1
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
|
|
|
new GameAction("plant", "Plant")
|
|
|
|
{
|
|
|
|
defaultLength = 0.5f,
|
|
|
|
},
|
2023-07-17 15:09:58 +00:00
|
|
|
new GameAction("passTurn", "Pass Turn")
|
|
|
|
{
|
|
|
|
preFunction = delegate { var e = eventCaller.currentEntity; WizardsWaltz.PrePassTurn(e.beat); },
|
|
|
|
preFunctionLength = 1
|
|
|
|
}
|
2023-05-28 17:34:44 +00:00
|
|
|
},
|
|
|
|
new List<string>() {"agb", "repeat"},
|
|
|
|
"agbwizard", "en",
|
|
|
|
new List<string>() {}
|
|
|
|
);
|
2022-04-12 16:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
using Jukebox;
|
2022-03-12 04:10:13 +00:00
|
|
|
using Scripts_WizardsWaltz;
|
|
|
|
|
2022-03-03 23:33:22 +00:00
|
|
|
public class WizardsWaltz : Minigame
|
|
|
|
{
|
2022-03-04 03:30:08 +00:00
|
|
|
[Header("References")]
|
2022-03-04 00:15:56 +00:00
|
|
|
public Wizard wizard;
|
2022-03-04 05:16:38 +00:00
|
|
|
public Girl girl;
|
2022-03-04 03:30:08 +00:00
|
|
|
public GameObject plantHolder;
|
|
|
|
public GameObject plantBase;
|
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
[Header("Properties")]
|
|
|
|
[NonSerialized] public float beatInterval = 6f;
|
|
|
|
[NonSerialized] public double intervalStartBeat;
|
2023-06-10 19:13:29 +00:00
|
|
|
public double wizardBeatOffset = 0f;
|
2023-07-17 15:09:58 +00:00
|
|
|
public float xRange = 5;
|
|
|
|
public float zRange = 5;
|
|
|
|
public float yRange = 0.5f;
|
|
|
|
public float plantYOffset = -2f;
|
2023-07-17 17:10:14 +00:00
|
|
|
[NonSerialized] public List<Plant> currentPlants = new();
|
2022-03-04 00:15:56 +00:00
|
|
|
|
|
|
|
public static WizardsWaltz instance;
|
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private static CallAndResponseHandler crHandlerInstance;
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
protected static bool IA_PadAnyDown(out double dt)
|
|
|
|
{
|
|
|
|
return PlayerInput.GetPadDown(InputController.ActionsPad.East, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Up, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Down, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Left, out dt)
|
|
|
|
|| PlayerInput.GetPadDown(InputController.ActionsPad.Right, out dt);
|
|
|
|
}
|
|
|
|
public static PlayerInput.InputAction InputAction_Press =
|
|
|
|
new("AgbWizardPress", new int[] { IAPressCat, IAPressCat, IAPressCat },
|
|
|
|
IA_PadAnyDown, IA_TouchBasicPress, IA_BatonBasicPress);
|
|
|
|
|
2022-03-04 00:15:56 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2022-03-26 02:08:46 +00:00
|
|
|
wizard.Init();
|
2023-07-17 15:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPlay(double beat)
|
|
|
|
{
|
|
|
|
SetWizardOffset(beat);
|
|
|
|
crHandlerInstance = null;
|
2024-01-15 19:22:26 +00:00
|
|
|
queuedIntervals.Clear();
|
|
|
|
passedTurns.Clear();
|
2023-07-17 15:09:58 +00:00
|
|
|
}
|
2022-03-04 00:15:56 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
public override void OnGameSwitch(double beat)
|
|
|
|
{
|
|
|
|
SetWizardOffset(beat);
|
|
|
|
if (queuedIntervals.Count > 0)
|
|
|
|
{
|
|
|
|
foreach (var interval in queuedIntervals)
|
|
|
|
{
|
|
|
|
SetIntervalStart(interval.beat, interval.interval, beat, interval.autoPassTurn);
|
|
|
|
}
|
|
|
|
queuedIntervals.Clear();
|
|
|
|
}
|
|
|
|
if (crHandlerInstance != null && crHandlerInstance.queuedEvents.Count > 0)
|
|
|
|
{
|
|
|
|
if (crHandlerInstance.queuedEvents.Find(x => x.beat >= beat) != null)
|
|
|
|
{
|
|
|
|
crHandlerInstance = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach (var crEvent in crHandlerInstance.queuedEvents)
|
|
|
|
{
|
|
|
|
SpawnFlower(crEvent.beat, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-06 16:35:23 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private void SetWizardOffset(double beat)
|
|
|
|
{
|
|
|
|
var allIntervals = EventCaller.GetAllInGameManagerList("wizardsWaltz", new string[] { "start interval" });
|
|
|
|
var tempEvents = allIntervals.FindAll(x => x.beat >= beat);
|
|
|
|
if (tempEvents.Count > 0)
|
2022-03-06 16:39:05 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
wizardBeatOffset = tempEvents[0].beat;
|
|
|
|
beatInterval = tempEvents[0].length;
|
2022-03-06 16:39:05 +00:00
|
|
|
}
|
2022-03-06 16:35:23 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 03:30:08 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
if (Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
2022-03-04 03:30:08 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
if (passedTurns.Count > 0)
|
|
|
|
{
|
|
|
|
foreach (var pass in passedTurns)
|
|
|
|
{
|
|
|
|
PassTurnStandalone(pass);
|
|
|
|
}
|
|
|
|
passedTurns.Clear();
|
|
|
|
}
|
2022-03-04 03:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private List<RiqEntity> GetAllPlantsBetweenBeat(double beat, double endBeat)
|
|
|
|
{
|
|
|
|
return EventCaller.GetAllInGameManagerList("wizardsWaltz", new string[] { "plant" }).FindAll(x => x.beat >= beat && x.beat < endBeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetIntervalStart(double beat, float interval, double gameSwitchBeat, bool autoPassTurn)
|
2022-03-05 04:28:56 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
wizardBeatOffset = beat;
|
|
|
|
intervalStartBeat = beat;
|
|
|
|
beatInterval = interval;
|
|
|
|
|
|
|
|
CallAndResponseHandler newHandler = new();
|
|
|
|
crHandlerInstance = newHandler;
|
|
|
|
crHandlerInstance.StartInterval(beat, interval);
|
|
|
|
var relevantPlantEvents = GetAllPlantsBetweenBeat(beat, beat + interval);
|
|
|
|
foreach (var plant in relevantPlantEvents)
|
2022-03-05 04:28:56 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
crHandlerInstance.AddEvent(plant.beat);
|
|
|
|
SpawnFlower(plant.beat, plant.beat < gameSwitchBeat);
|
|
|
|
}
|
2022-03-05 04:28:56 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
if (autoPassTurn)
|
|
|
|
{
|
|
|
|
PassTurn(beat + interval, newHandler);
|
|
|
|
}
|
|
|
|
}
|
2022-03-05 04:28:56 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
public static void PreInterval(double beat, float interval, bool autoPassTurn)
|
|
|
|
{
|
|
|
|
if (GameManager.instance.currentGame == "wizardsWaltz")
|
|
|
|
{
|
|
|
|
instance.SetIntervalStart(beat, interval, beat, autoPassTurn);
|
2022-03-05 04:28:56 +00:00
|
|
|
}
|
2023-07-17 15:09:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
queuedIntervals.Add(new QueuedInterval()
|
|
|
|
{
|
|
|
|
beat = beat,
|
|
|
|
interval = interval,
|
|
|
|
autoPassTurn = autoPassTurn
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-03-05 04:28:56 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private void PassTurnStandalone(double beat)
|
|
|
|
{
|
|
|
|
if (crHandlerInstance != null) PassTurn(beat, crHandlerInstance);
|
2022-03-05 04:28:56 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
public static void PrePassTurn(double beat)
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
if (GameManager.instance.currentGame == "wizardsWaltz")
|
|
|
|
{
|
|
|
|
instance.PassTurnStandalone(beat);
|
|
|
|
}
|
|
|
|
else
|
2022-03-04 03:30:08 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
passedTurns.Add(beat);
|
2022-03-04 03:30:08 +00:00
|
|
|
}
|
2023-07-17 15:09:58 +00:00
|
|
|
}
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private static List<double> passedTurns = new();
|
|
|
|
|
|
|
|
private void PassTurn(double beat, CallAndResponseHandler crHandler)
|
|
|
|
{
|
2023-09-11 22:28:04 +00:00
|
|
|
BeatAction.New(this, new List<BeatAction.Action>()
|
2023-07-17 15:09:58 +00:00
|
|
|
{
|
|
|
|
new BeatAction.Action(beat - 0.25, delegate
|
|
|
|
{
|
|
|
|
beatInterval = crHandler.intervalLength;
|
|
|
|
wizardBeatOffset = beat;
|
|
|
|
intervalStartBeat = beat;
|
|
|
|
foreach (var plant in currentPlants)
|
|
|
|
{
|
|
|
|
var songPos = (float)(plant.createBeat - wizardBeatOffset);
|
|
|
|
var am = (beatInterval / 2f);
|
|
|
|
var x = Mathf.Sin(Mathf.PI * songPos / am) * xRange;
|
|
|
|
var y = plantYOffset + Mathf.Cos(Mathf.PI * songPos / am) * (yRange * 1.5f);
|
|
|
|
var z = Mathf.Cos(Mathf.PI * songPos / am) * zRange;
|
|
|
|
/*var scale = 1 - Mathf.Cos(Mathf.PI * songPos / am) * 0.35f;
|
|
|
|
var xscale = scale;
|
|
|
|
if (y > -3.5f) xscale *= -1;*/
|
|
|
|
|
|
|
|
plant.transform.localPosition = new Vector3(x, y, z);
|
|
|
|
//plant.transform.localScale = new Vector3(xscale, scale, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var crEvent in crHandler.queuedEvents)
|
|
|
|
{
|
|
|
|
Plant plantToInput = currentPlants.Find(x => x.createBeat == crEvent.beat);
|
|
|
|
plantToInput.StartInput(beat - 0.25, (float)crEvent.relativeBeat + 0.25f);
|
|
|
|
}
|
|
|
|
crHandler.queuedEvents.Clear();
|
|
|
|
})
|
|
|
|
});
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
private static List<QueuedInterval> queuedIntervals = new();
|
|
|
|
|
|
|
|
private struct QueuedInterval
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
2023-07-17 15:09:58 +00:00
|
|
|
public double beat;
|
|
|
|
public float interval;
|
|
|
|
public bool autoPassTurn;
|
|
|
|
}
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
public void SpawnFlower(double beat, bool spawnedInactive)
|
|
|
|
{
|
|
|
|
if (!spawnedInactive) SoundByte.PlayOneShotGame("wizardsWaltz/plant", beat);
|
2022-03-04 03:30:08 +00:00
|
|
|
Plant plant = Instantiate(plantBase, plantHolder.transform).GetComponent<Plant>();
|
2023-07-17 15:09:58 +00:00
|
|
|
currentPlants.Add(plant);
|
|
|
|
var songPos = (float)(beat - wizardBeatOffset);
|
2022-03-04 03:30:08 +00:00
|
|
|
var am = (beatInterval / 2f);
|
2023-07-17 15:09:58 +00:00
|
|
|
var x = Mathf.Sin(Mathf.PI * songPos / am) * xRange;
|
|
|
|
var y = plantYOffset + Mathf.Cos(Mathf.PI * songPos / am) * (yRange * 1.5f);
|
|
|
|
var z = Mathf.Cos(Mathf.PI * songPos / am) * zRange;
|
|
|
|
/*var scale = 1 - Mathf.Cos(Mathf.PI * songPos / am) * 0.35f;
|
2022-03-04 03:30:08 +00:00
|
|
|
var xscale = scale;
|
2023-07-17 15:09:58 +00:00
|
|
|
if (y > -3.5f) xscale *= -1;*/
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
plant.transform.localPosition = new Vector3(x, y, z);
|
|
|
|
//plant.transform.localScale = new Vector3(xscale, scale, 1);
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2023-07-17 15:09:58 +00:00
|
|
|
//plant.order = (int)Math.Round((scale - 1) * 1000);
|
|
|
|
plant.order = (int)Math.Round(z * -1);
|
2022-03-04 03:30:08 +00:00
|
|
|
|
|
|
|
plant.createBeat = beat;
|
2023-07-17 15:09:58 +00:00
|
|
|
|
2023-09-11 22:28:04 +00:00
|
|
|
BeatAction.New(this, new List<BeatAction.Action>()
|
2023-07-17 15:09:58 +00:00
|
|
|
{
|
|
|
|
new BeatAction.Action(beat, delegate
|
|
|
|
{
|
|
|
|
plant.gameObject.SetActive(true);
|
|
|
|
plant.Init(spawnedInactive);
|
|
|
|
})
|
|
|
|
});
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
|
|
|
}
|