HeavenStudioPlus/Assets/Scripts/Games/PlayerActionObject.cs

157 lines
4.8 KiB
C#
Raw Normal View History

2021-12-29 06:52:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Games
{
public class PlayerActionObject : MonoBehaviour
{
public bool inList = false;
public int lastState;
public Minigame.Eligible state = new Minigame.Eligible();
2021-12-30 08:26:18 +00:00
public bool isEligible;
2021-12-29 06:52:48 +00:00
public List<Minigame.Eligible> eligibleHitsList = new List<Minigame.Eligible>();
2022-01-23 03:40:53 +00:00
private int aceTimes;
public void PlayerActionInit(GameObject g, float createBeat, List<Minigame.Eligible> eligibleHitsList)
2021-12-29 06:52:48 +00:00
{
state.gameObject = g;
state.createBeat = createBeat;
this.eligibleHitsList = eligibleHitsList;
2021-12-29 06:52:48 +00:00
}
2022-01-23 03:40:53 +00:00
private void CheckForAce(float normalizedBeat)
{
if (aceTimes == 0)
{
if (GameManager.instance.autoplay && normalizedBeat > 0.99f)
{
OnAce();
AceVisuals();
aceTimes++;
}
}
}
2021-12-29 06:52:48 +00:00
// could possibly add support for custom early, perfect, and end times if needed.
public void StateCheck(float normalizedBeat)
2021-12-29 06:52:48 +00:00
{
2022-01-23 03:40:53 +00:00
CheckForAce(normalizedBeat);
2021-12-29 06:52:48 +00:00
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastState == 0)
{
MakeEligible(true, false, false);
2021-12-29 06:52:48 +00:00
lastState++;
}
// Perfect State
else if (normalizedBeat > Minigame.PerfectTime() && normalizedBeat < Minigame.LateTime() && lastState == 1)
{
MakeEligible(false, true, false);
2021-12-29 06:52:48 +00:00
lastState++;
}
// Late State
else if (normalizedBeat > Minigame.LateTime() && normalizedBeat < Minigame.EndTime() && lastState == 2)
{
MakeEligible(false, false, true);
2021-12-29 06:52:48 +00:00
lastState++;
}
else if (normalizedBeat < Minigame.EarlyTime() || normalizedBeat > Minigame.EndTime())
{
MakeInEligible();
2021-12-29 06:52:48 +00:00
}
}
public void MakeEligible(bool early, bool perfect, bool late)
2021-12-29 06:52:48 +00:00
{
if (!inList)
{
state.early = early;
state.perfect = perfect;
state.late = late;
2021-12-29 06:52:48 +00:00
eligibleHitsList.Add(state);
2021-12-29 06:52:48 +00:00
inList = true;
}
else
{
Minigame.Eligible es = eligibleHitsList[eligibleHitsList.IndexOf(state)];
2021-12-29 06:52:48 +00:00
es.early = early;
es.perfect = perfect;
es.late = late;
}
}
public void MakeInEligible()
2021-12-29 06:52:48 +00:00
{
2022-01-23 03:40:53 +00:00
state.early = false;
state.perfect = false;
state.late = false;
2021-12-29 06:52:48 +00:00
if (!inList) return;
eligibleHitsList.Remove(state);
2021-12-29 06:52:48 +00:00
inList = false;
}
public void RemoveObject(int currentHitInList, bool destroyObject = false)
2021-12-29 06:52:48 +00:00
{
if (currentHitInList < eligibleHitsList.Count)
2021-12-29 06:52:48 +00:00
{
eligibleHitsList.Remove(eligibleHitsList[currentHitInList]);
2021-12-29 06:52:48 +00:00
currentHitInList++;
if (destroyObject) Destroy(this.gameObject);
2021-12-29 06:52:48 +00:00
}
}
// No list
public void StateCheckNoList(float normalizedBeat)
{
2022-01-23 03:40:53 +00:00
CheckForAce(normalizedBeat);
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastState == 0)
{
ModifyState(true, false, false);
lastState++;
}
// Perfect State
else if (normalizedBeat > Minigame.PerfectTime() && normalizedBeat < Minigame.LateTime() && lastState == 1)
{
ModifyState(false, true, false);
lastState++;
}
// Late State
else if (normalizedBeat > Minigame.LateTime() && normalizedBeat < Minigame.EndTime() && lastState == 2)
{
ModifyState(false, false, true);
lastState++;
}
else if (normalizedBeat < Minigame.EarlyTime() || normalizedBeat > Minigame.EndTime())
{
// ineligible
}
}
2022-01-23 03:40:53 +00:00
public virtual void OnAce()
{
}
private void AceVisuals()
{
if (Editor.Timeline.instance != null)
{
Editor.Timeline.instance.AutoplayBTN.GetComponent<Animator>().Play("Ace", 0, 0);
}
}
private void ModifyState(bool early, bool perfect, bool late)
{
state.early = early;
state.perfect = perfect;
state.late = late;
}
private void OnDestroy()
{
MakeInEligible();
}
2021-12-29 06:52:48 +00:00
}
}