2022-03-15 00:54:54 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
using Starpelly;
|
2022-03-15 22:43:13 +00:00
|
|
|
using NaughtyBezierCurves;
|
2022-03-15 00:54:54 +00:00
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Scripts_FanClub
|
|
|
|
{
|
2022-03-16 21:41:46 +00:00
|
|
|
public class NtrIdolFan : PlayerActionObject
|
2022-03-15 00:54:54 +00:00
|
|
|
{
|
|
|
|
[Header("References")]
|
2022-03-15 22:43:13 +00:00
|
|
|
[SerializeField] private GameObject motionRoot;
|
|
|
|
[SerializeField] private GameObject headRoot;
|
2022-03-15 00:54:54 +00:00
|
|
|
public Animator animator;
|
|
|
|
public Animator headAnimator;
|
|
|
|
public ParticleSystem fanClapEffect;
|
2022-03-15 22:43:13 +00:00
|
|
|
public GameObject shadow;
|
2022-03-15 00:54:54 +00:00
|
|
|
|
2022-03-15 22:43:13 +00:00
|
|
|
[Header("Properties")]
|
|
|
|
[NonSerialized] public bool player = false;
|
|
|
|
[NonSerialized] public bool hitValid = false;
|
|
|
|
public float jumpStartTime = -99f;
|
2022-03-15 00:54:54 +00:00
|
|
|
bool stopBeat = false;
|
2022-03-15 22:43:13 +00:00
|
|
|
bool stopCharge = false;
|
|
|
|
bool hasJumped = false;
|
|
|
|
|
|
|
|
float clappingStartTime = 0f;
|
|
|
|
|
2022-03-16 21:41:46 +00:00
|
|
|
public Queue<KeyValuePair<float, int>> upcomingHits;
|
|
|
|
public float startBeat;
|
|
|
|
public int type;
|
|
|
|
public bool doCharge = false;
|
|
|
|
private bool inputHit = false;
|
|
|
|
private bool hasHit = false;
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
upcomingHits = new Queue<KeyValuePair<float, int>>(); // beat, type
|
|
|
|
|
|
|
|
inputHit = true;
|
|
|
|
hasHit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnAce()
|
|
|
|
{
|
|
|
|
Hit(true, type, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddHit(float beat, int type)
|
|
|
|
{
|
|
|
|
inputHit = false;
|
|
|
|
upcomingHits.Enqueue(new KeyValuePair<float, int>(beat, type));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Hit(bool _hit, int type = 0, bool fromAutoplay = false)
|
|
|
|
{
|
|
|
|
if (player && !hasHit)
|
|
|
|
{
|
|
|
|
if (type == 0)
|
|
|
|
ClapStart(_hit, true, doCharge, fromAutoplay);
|
|
|
|
else if (type == 1)
|
|
|
|
JumpStart(_hit, true, fromAutoplay);
|
|
|
|
|
|
|
|
hasHit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 22:43:13 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
2022-03-16 21:41:46 +00:00
|
|
|
// read cue queue and pop when needed
|
|
|
|
if (hasHit)
|
|
|
|
{
|
|
|
|
if (upcomingHits?.Count > 0)
|
|
|
|
{
|
|
|
|
var next = upcomingHits.Dequeue();
|
|
|
|
|
|
|
|
startBeat = next.Key;
|
|
|
|
type = next.Value == 2 ? 0 : next.Value;
|
|
|
|
doCharge = (next.Value == 2);
|
|
|
|
|
|
|
|
// reset our shit to prepare for next hit
|
|
|
|
hasHit = false;
|
|
|
|
ResetState();
|
|
|
|
}
|
|
|
|
else if (Conductor.instance.GetPositionFromBeat(startBeat, 1) >= Minigame.EndTime())
|
|
|
|
{
|
|
|
|
startBeat = Single.MinValue;
|
|
|
|
type = 0;
|
|
|
|
doCharge = false;
|
|
|
|
// DO NOT RESET, wait for future cues
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no input?
|
|
|
|
if (!hasHit && Conductor.instance.GetPositionFromBeat(startBeat, 1f) >= Minigame.EndTime())
|
|
|
|
{
|
|
|
|
FanClub.instance.AngerOnMiss();
|
|
|
|
hasHit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// dunno what this is for
|
|
|
|
if (!inputHit && Conductor.instance.GetPositionFromBeat(startBeat, 1) >= Minigame.EndTime())
|
|
|
|
{
|
|
|
|
inputHit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasHit)
|
|
|
|
{
|
|
|
|
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, 1);
|
|
|
|
StateCheck(normalizedBeat);
|
|
|
|
}
|
|
|
|
|
2022-03-15 22:43:13 +00:00
|
|
|
if (player)
|
|
|
|
{
|
2022-03-16 21:41:46 +00:00
|
|
|
if (PlayerInput.Pressed() && type == 0)
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Hit(true);
|
|
|
|
} else if (state.notPerfect())
|
|
|
|
{
|
|
|
|
Hit(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PlayerInput.PressedUp() && type == 1)
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Hit(true, type);
|
|
|
|
} else if (state.notPerfect())
|
|
|
|
{
|
|
|
|
Hit(false, type);
|
|
|
|
}
|
|
|
|
}
|
2022-03-15 22:43:13 +00:00
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
2022-03-16 21:41:46 +00:00
|
|
|
if (!hasHit || (upcomingHits?.Count == 0 && startBeat == Single.MinValue))
|
|
|
|
FanClub.instance.AngerOnMiss();
|
|
|
|
|
|
|
|
hasJumped = false;
|
|
|
|
stopBeat = true;
|
|
|
|
jumpStartTime = -99f;
|
|
|
|
animator.Play("FanClap", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/play_clap");
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/crap_impact");
|
|
|
|
clappingStartTime = cond.songPositionInBeats;
|
2022-03-15 22:43:13 +00:00
|
|
|
}
|
|
|
|
if (PlayerInput.Pressing())
|
|
|
|
{
|
2022-03-16 21:41:46 +00:00
|
|
|
if (cond.songPositionInBeats > clappingStartTime + 1.5f && !stopCharge)
|
2022-03-15 22:43:13 +00:00
|
|
|
{
|
|
|
|
animator.Play("FanClapCharge", 0, 0);
|
|
|
|
stopCharge = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PlayerInput.PressedUp())
|
|
|
|
{
|
|
|
|
if (stopCharge)
|
|
|
|
{
|
2022-03-16 21:41:46 +00:00
|
|
|
if (!hasHit || (upcomingHits?.Count == 0 && startBeat == Single.MinValue))
|
|
|
|
FanClub.instance.AngerOnMiss();
|
|
|
|
|
|
|
|
animator.Play("FanJump", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/play_jump");
|
|
|
|
jumpStartTime = cond.songPositionInBeats;
|
|
|
|
stopCharge = false;
|
2022-03-15 22:43:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
animator.Play("FanFree", 0, 0);
|
|
|
|
stopBeat = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float jumpPos = cond.GetPositionFromBeat(jumpStartTime, 1f);
|
|
|
|
if (cond.songPositionInBeats >= jumpStartTime && cond.songPositionInBeats < jumpStartTime + 1f)
|
|
|
|
{
|
|
|
|
hasJumped = true;
|
|
|
|
float yMul = jumpPos * 2f - 1f;
|
|
|
|
float yWeight = -(yMul*yMul) + 1f;
|
|
|
|
motionRoot.transform.localPosition = new Vector3(0, 3f * yWeight);
|
|
|
|
shadow.transform.localScale = new Vector3((1f-yWeight*0.8f) * 1.4f, (1f-yWeight*0.8f) * 1.4f, 1f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
motionRoot.transform.localPosition = new Vector3(0, 0);
|
|
|
|
shadow.transform.localScale = new Vector3(1.4f, 1.4f, 1f);
|
|
|
|
if (hasJumped && player)
|
|
|
|
{
|
|
|
|
animator.Play("FanPrepare", 0, 0);
|
|
|
|
stopBeat = false;
|
|
|
|
}
|
|
|
|
hasJumped = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ClapStart(bool hit, bool force = false, bool doCharge = false, bool fromAutoplay = false)
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
if (hit)
|
|
|
|
{
|
|
|
|
print("HIT");
|
|
|
|
if (doCharge)
|
|
|
|
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(cond.songPositionInBeats + 0.1f, delegate {
|
|
|
|
if (PlayerInput.Pressing() || fromAutoplay)
|
|
|
|
{
|
|
|
|
animator.Play("FanClapCharge", 0, 0);
|
|
|
|
stopCharge = true;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print("missed");
|
|
|
|
FanClub.instance.AngerOnMiss();
|
|
|
|
}
|
|
|
|
if (fromAutoplay || !force)
|
|
|
|
{
|
|
|
|
stopBeat = true;
|
|
|
|
jumpStartTime = -99f;
|
|
|
|
animator.Play("FanClap", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/play_clap");
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/crap_impact");
|
|
|
|
clappingStartTime = cond.songPositionInBeats;
|
|
|
|
}
|
|
|
|
if (fromAutoplay && !doCharge)
|
|
|
|
{
|
|
|
|
BeatAction.New(this.gameObject, new List<BeatAction.Action>()
|
|
|
|
{
|
|
|
|
new BeatAction.Action(cond.songPositionInBeats + 0.1f, delegate {
|
|
|
|
animator.Play("FanFree", 0, 0);
|
|
|
|
stopBeat = false;
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void JumpStart(bool hit, bool force = false, bool fromAutoplay = false)
|
|
|
|
{
|
|
|
|
var cond = Conductor.instance;
|
|
|
|
if (hit)
|
|
|
|
{
|
|
|
|
print("HIT");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print("missed");
|
|
|
|
FanClub.instance.AngerOnMiss();
|
|
|
|
}
|
|
|
|
if (fromAutoplay || !force)
|
|
|
|
{
|
|
|
|
animator.Play("FanJump", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("fanClub/play_jump");
|
|
|
|
jumpStartTime = cond.songPositionInBeats;
|
|
|
|
stopCharge = false;
|
|
|
|
}
|
|
|
|
}
|
2022-03-15 00:54:54 +00:00
|
|
|
|
|
|
|
public void Bop()
|
|
|
|
{
|
2022-03-15 22:43:13 +00:00
|
|
|
if (!stopBeat)
|
2022-03-15 00:54:54 +00:00
|
|
|
animator.Play("FanBeat", 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ClapParticle()
|
|
|
|
{
|
|
|
|
fanClapEffect.Play();
|
|
|
|
}
|
2022-03-15 22:43:13 +00:00
|
|
|
|
|
|
|
public void MakeAngry(bool flip = false)
|
|
|
|
{
|
|
|
|
headAnimator.Play("FanFaceAngry", 0, 0);
|
|
|
|
if (flip)
|
|
|
|
{
|
|
|
|
headRoot.transform.localScale = new Vector3(-1f, 1f, 1f);
|
|
|
|
}
|
|
|
|
}
|
2022-03-15 00:54:54 +00:00
|
|
|
}
|
2022-03-15 22:43:13 +00:00
|
|
|
}
|