2021-12-29 06:52:48 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
using RhythmHeavenMania.Editor.Track;
|
|
|
|
|
2021-12-29 06:52:48 +00:00
|
|
|
namespace RhythmHeavenMania.Games
|
|
|
|
{
|
|
|
|
public class PlayerActionObject : MonoBehaviour
|
|
|
|
{
|
|
|
|
public bool inList = false;
|
|
|
|
public int lastState;
|
2022-01-02 12:09:15 +00:00
|
|
|
public Minigame.Eligible state = new Minigame.Eligible();
|
2021-12-29 06:52:48 +00:00
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
public List<Minigame.Eligible> eligibleHitsList = new List<Minigame.Eligible>();
|
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
//the variables below seem to be mostly unused (they are never used in any meaningful way)
|
|
|
|
public int aceTimes; //always set to 0 no matter what (also, the one time it's used doesn't seem to make sense)
|
|
|
|
public bool isEligible; //value never used for anything
|
|
|
|
private bool autoPlayEnabledOnStart; //value never used for anything
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2022-02-28 08:33:11 +00:00
|
|
|
public bool triggersAutoplay = true;
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
public void PlayerActionInit(GameObject g, float createBeat)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
2022-01-02 12:09:15 +00:00
|
|
|
state.gameObject = g;
|
2022-01-17 05:00:26 +00:00
|
|
|
state.createBeat = createBeat;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
autoPlayEnabledOnStart = GameManager.instance.autoplay;
|
2021-12-29 06:52:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 08:36:20 +00:00
|
|
|
private void CheckForAce(float normalizedBeat, bool autoPlay = false)
|
2022-01-23 03:40:53 +00:00
|
|
|
{
|
|
|
|
if (aceTimes == 0)
|
|
|
|
{
|
2022-03-01 07:27:49 +00:00
|
|
|
if (triggersAutoplay && (GameManager.instance.autoplay || autoPlay) && GameManager.instance.canInput && normalizedBeat > 0.99f)
|
2022-01-23 03:40:53 +00:00
|
|
|
{
|
|
|
|
OnAce();
|
2022-02-02 08:36:20 +00:00
|
|
|
if (!autoPlay)
|
|
|
|
AceVisuals();
|
2022-01-26 05:38:12 +00:00
|
|
|
// aceTimes++;
|
2022-01-23 03:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 02:15:23 +00:00
|
|
|
public void ResetAce()
|
|
|
|
{
|
|
|
|
aceTimes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetState()
|
|
|
|
{
|
|
|
|
lastState = 0;
|
2022-01-26 05:38:12 +00:00
|
|
|
ResetAce();
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 06:52:48 +00:00
|
|
|
// could possibly add support for custom early, perfect, and end times if needed.
|
2022-02-02 08:36:20 +00:00
|
|
|
public void StateCheck(float normalizedBeat, bool autoPlay = false)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
2022-02-02 08:36:20 +00:00
|
|
|
CheckForAce(normalizedBeat, autoPlay);
|
2021-12-29 06:52:48 +00:00
|
|
|
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastState == 0)
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
MakeEligible(false, false, true);
|
2021-12-29 06:52:48 +00:00
|
|
|
lastState++;
|
|
|
|
}
|
|
|
|
else if (normalizedBeat < Minigame.EarlyTime() || normalizedBeat > Minigame.EndTime())
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
MakeInEligible();
|
2021-12-29 06:52:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
public void MakeEligible(bool early, bool perfect, bool late)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
|
|
|
if (!inList)
|
|
|
|
{
|
2022-01-02 12:09:15 +00:00
|
|
|
state.early = early;
|
|
|
|
state.perfect = perfect;
|
|
|
|
state.late = late;
|
2021-12-29 06:52:48 +00:00
|
|
|
|
2022-01-02 12:09:15 +00:00
|
|
|
eligibleHitsList.Add(state);
|
2021-12-29 06:52:48 +00:00
|
|
|
inList = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-02 12:09:15 +00:00
|
|
|
Minigame.Eligible es = eligibleHitsList[eligibleHitsList.IndexOf(state)];
|
2021-12-29 06:52:48 +00:00
|
|
|
es.early = early;
|
|
|
|
es.perfect = perfect;
|
|
|
|
es.late = late;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
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;
|
|
|
|
|
2022-01-02 12:09:15 +00:00
|
|
|
eligibleHitsList.Remove(state);
|
2021-12-29 06:52:48 +00:00
|
|
|
inList = false;
|
|
|
|
}
|
|
|
|
|
2022-01-17 05:00:26 +00:00
|
|
|
public void RemoveObject(int currentHitInList, bool destroyObject = false)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
if (currentHitInList < eligibleHitsList.Count)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
eligibleHitsList.Remove(eligibleHitsList[currentHitInList]);
|
2021-12-29 06:52:48 +00:00
|
|
|
currentHitInList++;
|
2022-01-17 05:00:26 +00:00
|
|
|
if (destroyObject) Destroy(this.gameObject);
|
2021-12-29 06:52:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-02 12:09:15 +00:00
|
|
|
|
|
|
|
// No list
|
|
|
|
public void StateCheckNoList(float normalizedBeat)
|
|
|
|
{
|
2022-01-23 03:40:53 +00:00
|
|
|
CheckForAce(normalizedBeat);
|
2022-01-02 12:09:15 +00:00
|
|
|
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()
|
|
|
|
{
|
2022-01-28 02:50:57 +00:00
|
|
|
if (Timeline.instance != null)
|
2022-01-23 03:40:53 +00:00
|
|
|
{
|
2022-01-28 02:50:57 +00:00
|
|
|
Timeline.instance.AutoplayBTN.GetComponent<Animator>().Play("Ace", 0, 0);
|
2022-01-23 03:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 12:09:15 +00:00
|
|
|
private void ModifyState(bool early, bool perfect, bool late)
|
|
|
|
{
|
|
|
|
state.early = early;
|
|
|
|
state.perfect = perfect;
|
|
|
|
state.late = late;
|
|
|
|
}
|
2022-01-17 05:00:26 +00:00
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
MakeInEligible();
|
|
|
|
}
|
2021-12-29 06:52:48 +00:00
|
|
|
}
|
|
|
|
}
|