HeavenStudioPlus/Assets/Scripts/Games/FanClub/NtrIdolFan.cs

291 lines
9.5 KiB
C#
Raw Normal View History

2022-03-15 00:54:54 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Starpelly;
using NaughtyBezierCurves;
2022-03-15 00:54:54 +00:00
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_FanClub
{
public class NtrIdolFan : PlayerActionObject
2022-03-15 00:54:54 +00:00
{
[Header("References")]
[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;
public GameObject shadow;
2022-03-15 00:54:54 +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;
bool stopCharge = false;
bool hasJumped = false;
float clappingStartTime = 0f;
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;
}
}
private void Update()
{
var cond = Conductor.instance;
// 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);
}
if (player)
{
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);
}
}
if (PlayerInput.Pressed())
{
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;
}
if (PlayerInput.Pressing())
{
if (cond.songPositionInBeats > clappingStartTime + 1.5f && !stopCharge)
{
animator.Play("FanClapCharge", 0, 0);
stopCharge = true;
}
}
if (PlayerInput.PressedUp())
{
if (stopCharge)
{
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;
}
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)
{
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
{
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)
2022-03-17 19:13:48 +00:00
{}
else
{
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
2022-03-17 19:13:48 +00:00
public bool IsJumping()
{
var cond = Conductor.instance;
return (cond.songPositionInBeats >= jumpStartTime && cond.songPositionInBeats < jumpStartTime + 1f);
}
2022-03-15 00:54:54 +00:00
public void Bop()
{
if (!stopBeat)
2022-03-17 19:13:48 +00:00
animator.Play("FanBeat");
2022-03-15 00:54:54 +00:00
}
public void ClapParticle()
{
fanClapEffect.Play();
}
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
}
}