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;
|
|
|
|
using Starpelly;
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
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) {
|
|
|
|
return new Minigame("wizardsWaltz", "Wizard's Waltz \n<color=#adadad>(Mahou Tsukai)</color>", "FFEF9C", false, false, new List<GameAction>()
|
|
|
|
{
|
|
|
|
new GameAction("start interval", delegate { WizardsWaltz.instance.SetIntervalStart(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); }, 4f, true),
|
|
|
|
new GameAction("plant", delegate { WizardsWaltz.instance.SpawnFlower(eventCaller.currentEntity.beat); }, 0.5f, false),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
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;
|
2022-03-05 04:28:56 +00:00
|
|
|
public GameObject fxHolder;
|
|
|
|
public GameObject fxBase;
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2022-03-05 04:28:56 +00:00
|
|
|
private int timer = 0;
|
2022-03-04 03:30:08 +00:00
|
|
|
public float beatInterval = 4f;
|
|
|
|
float intervalStartBeat;
|
|
|
|
bool intervalStarted;
|
|
|
|
public float wizardBeatOffset = 0f;
|
|
|
|
|
2022-03-27 18:13:13 +00:00
|
|
|
[NonSerialized] public int plantsLeft = 0; //this variable is unused
|
2022-03-04 00:15:56 +00:00
|
|
|
|
|
|
|
public static WizardsWaltz instance;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2022-03-26 02:08:46 +00:00
|
|
|
wizard.Init();
|
2022-03-04 00:15:56 +00:00
|
|
|
|
2022-03-27 18:13:13 +00:00
|
|
|
Beatmap.Entity nextStart = GameManager.instance.Beatmap.entities.Find(c => c.datamodel == "wizardsWaltz/start interval" && c.beat + c.length >= Conductor.instance.songPositionInBeats);
|
2022-03-06 16:35:23 +00:00
|
|
|
|
2022-03-27 18:13:13 +00:00
|
|
|
if (nextStart != null)
|
2022-03-06 16:39:05 +00:00
|
|
|
{
|
2022-03-27 18:13:13 +00:00
|
|
|
EventCaller.instance.CallEvent(nextStart, true);
|
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()
|
|
|
|
{
|
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused && intervalStarted)
|
|
|
|
{
|
|
|
|
intervalStarted = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 04:28:56 +00:00
|
|
|
private void FixedUpdate()
|
|
|
|
{
|
|
|
|
if (timer % 8 == 0 || UnityEngine.Random.Range(0,8) == 0)
|
|
|
|
{
|
2022-03-06 16:35:23 +00:00
|
|
|
var songPos = Conductor.instance.songPositionInBeats - wizardBeatOffset;
|
2022-03-05 04:28:56 +00:00
|
|
|
var am = beatInterval / 2f;
|
|
|
|
var x = Mathf.Sin(Mathf.PI * songPos / am) * 6 + UnityEngine.Random.Range(-0.5f, 0.5f);
|
2022-03-06 16:35:23 +00:00
|
|
|
var y = Mathf.Cos(Mathf.PI * songPos / am) * 0.5f + UnityEngine.Random.Range(-0.5f, 0.5f);
|
2022-03-27 18:13:13 +00:00
|
|
|
var scale = 1 - Mathf.Cos(Mathf.PI * songPos / am) * 0.35f + UnityEngine.Random.Range(-0.2f, 0.2f);
|
2022-03-05 04:28:56 +00:00
|
|
|
|
|
|
|
MagicFX magic = Instantiate(fxBase, fxHolder.transform).GetComponent<MagicFX>();
|
|
|
|
|
2022-03-06 16:35:23 +00:00
|
|
|
magic.transform.position = new Vector3(x, 2f + y, 0);
|
2022-03-05 04:28:56 +00:00
|
|
|
magic.transform.localScale = wizard.gameObject.transform.localScale;
|
|
|
|
magic.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
timer++;
|
|
|
|
}
|
|
|
|
|
2022-03-04 03:30:08 +00:00
|
|
|
public void SetIntervalStart(float beat, float interval = 4f)
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
2022-03-04 03:30:08 +00:00
|
|
|
// Don't do these things if the interval was already started.
|
|
|
|
if (!intervalStarted)
|
|
|
|
{
|
|
|
|
plantsLeft = 0;
|
|
|
|
intervalStarted = true;
|
|
|
|
}
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2022-03-06 16:35:23 +00:00
|
|
|
wizardBeatOffset = beat;
|
2022-03-04 03:30:08 +00:00
|
|
|
intervalStartBeat = beat;
|
|
|
|
beatInterval = interval;
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 03:30:08 +00:00
|
|
|
public void SpawnFlower(float beat)
|
2022-03-03 23:33:22 +00:00
|
|
|
{
|
2022-03-04 03:30:08 +00:00
|
|
|
// If interval hasn't started, assume this is the first hair of the interval.
|
|
|
|
if (!intervalStarted)
|
|
|
|
SetIntervalStart(beat, beatInterval);
|
2022-03-03 23:33:22 +00:00
|
|
|
|
2022-03-04 03:30:08 +00:00
|
|
|
Jukebox.PlayOneShotGame("wizardsWaltz/plant", beat);
|
|
|
|
Plant plant = Instantiate(plantBase, plantHolder.transform).GetComponent<Plant>();
|
|
|
|
|
2022-03-06 16:35:23 +00:00
|
|
|
var songPos = Conductor.instance.songPositionInBeats - wizardBeatOffset;
|
2022-03-04 03:30:08 +00:00
|
|
|
var am = (beatInterval / 2f);
|
|
|
|
var x = Mathf.Sin(Mathf.PI * songPos / am) * 6;
|
2022-03-05 17:46:10 +00:00
|
|
|
var y = -3f + Mathf.Cos(Mathf.PI * songPos / am) * 1.5f;
|
2022-03-04 05:16:38 +00:00
|
|
|
var scale = 1 - Mathf.Cos(Mathf.PI * songPos / am) * 0.35f;
|
2022-03-04 03:30:08 +00:00
|
|
|
var xscale = scale;
|
2022-03-04 05:16:38 +00:00
|
|
|
if (y > -3.5f) xscale *= -1;
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2022-03-05 17:46:10 +00:00
|
|
|
plant.transform.localPosition = new Vector3(x, y, 0);
|
2022-03-04 03:30:08 +00:00
|
|
|
plant.transform.localScale = new Vector3(xscale, scale, 1);
|
|
|
|
|
2022-03-05 17:46:10 +00:00
|
|
|
plant.order = (int)Math.Round((scale - 1) * 1000);
|
2022-03-04 03:30:08 +00:00
|
|
|
plant.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
plant.createBeat = beat;
|
|
|
|
plantsLeft++;
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
2022-03-04 03:30:08 +00:00
|
|
|
|
2022-03-03 23:33:22 +00:00
|
|
|
}
|
|
|
|
}
|