diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 0d3b2b17a..3d8c53099 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -60,6 +60,7 @@ namespace HeavenStudio public static GameManager instance { get; private set; } private EventCaller eventCaller; + // average input accuracy (msec) List inputOffsetSamples = new List(); float averageInputOffset = 0; public float AvgInputOffset @@ -75,6 +76,18 @@ namespace HeavenStudio } } + // input accuracy (%) + double totalInputs = 0; + double totalPlayerAccuracy = 0; + public double PlayerAccuracy + { + get + { + if (totalInputs == 0) return 0; + return totalPlayerAccuracy / totalInputs; + } + } + private void Awake() { // autoplay = true; @@ -190,6 +203,11 @@ namespace HeavenStudio } } + public static void ScoreInputAccuracy(double accuracy, float weight = 1) + { + + } + public void SeekAheadAndPreload(double start, float seekTime = 8f) { //seek ahead to preload games that have assetbundles diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index 7fc05f890..367364f24 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -9,6 +9,7 @@ namespace HeavenStudio.Games public class Minigame : MonoBehaviour { public static float earlyTime = 0.07f, perfectTime = 0.04f, aceEarlyTime = 0.01f, aceLateTime = 0.01f, lateTime = 0.04f, endTime = 0.07f; + public static float rankHiThreshold = 0.8f, rankOkThreshold = 0.6f; [SerializeField] public SoundSequence.SequenceKeyValue[] SoundSequences; public List EligibleHits = new List(); @@ -171,7 +172,7 @@ namespace HeavenStudio.Games public static float AceStartTime() { - return 1f + ScaleTimingMargin(aceEarlyTime); + return 1f - ScaleTimingMargin(aceEarlyTime); } public static float AceEndTime() diff --git a/Assets/Scripts/Games/PlayerActionEvent.cs b/Assets/Scripts/Games/PlayerActionEvent.cs index f038b02d7..aa0639811 100644 --- a/Assets/Scripts/Games/PlayerActionEvent.cs +++ b/Assets/Scripts/Games/PlayerActionEvent.cs @@ -11,6 +11,7 @@ namespace HeavenStudio.Games public class PlayerActionEvent : PlayerActionObject { + public static bool EnableAutoplayCheat = false; public delegate void ActionEventCallback(PlayerActionEvent caller); public delegate void ActionEventCallbackState(PlayerActionEvent caller, float state); @@ -33,6 +34,8 @@ namespace HeavenStudio.Games public InputType inputType; //The type of input. Check the InputType class to see a list of all of them public bool perfectOnly = false; //Indicates that the input only recognize perfect inputs. + + public bool countsForAccuracy = true; //Indicates if the input counts for the accuracy or not. If set to false, it'll not be counted in the accuracy calculation public void setHitCallback(ActionEventCallbackState OnHit) { @@ -60,31 +63,31 @@ namespace HeavenStudio.Games if (noAutoplay && autoplayOnly) autoplayOnly = false; if (noAutoplay && triggersAutoplay){ triggersAutoplay = false; } - float normalizedBeat = GetNormalizedTime(); - float stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2; - StateCheck(normalizedBeat); + double normalizedTime = GetNormalizedTime(); + double stateProg = ((normalizedTime - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2; + StateCheck(normalizedTime); //BUGFIX: ActionEvents destroyed too early - if (normalizedBeat > Minigame.EndTime()) Miss(); + if (normalizedTime > Minigame.EndTime()) Miss(); if (IsCorrectInput() && !autoplayOnly) { if (state.perfect) { - Hit(stateProg); - if (normalizedBeat >= Minigame.AceStartTime() && normalizedBeat <= Minigame.AceEndTime()) + Hit(stateProg, normalizedTime); + if (normalizedTime >= Minigame.AceStartTime() && normalizedTime <= Minigame.AceEndTime()) { // push an ace event } } else if (state.early && !perfectOnly) { - Hit(-1f); + Hit(-1f, normalizedTime); } else if (state.late && !perfectOnly) { - Hit(1f); + Hit(1f, normalizedTime); } else { @@ -95,18 +98,18 @@ namespace HeavenStudio.Games public bool IsExpectingInputNow() { - float normalizedBeat = GetNormalizedTime(); + double normalizedBeat = GetNormalizedTime(); return normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.EndTime(); } - float GetNormalizedTime() + double GetNormalizedTime() { var cond = Conductor.instance; double currTime = cond.GetSongPosFromBeat(cond.songPositionInBeatsAsDouble); double targetTime = cond.GetSongPosFromBeat(startBeat + timer); double min = targetTime - 1f; double max = targetTime + 1f; - return 1f + (float)(((currTime - min) / (max - min))-0.5f)*2; + return 1f + (((currTime - min) / (max - min))-0.5f)*2; } public bool IsCorrectInput() @@ -138,30 +141,88 @@ namespace HeavenStudio.Games //For the Autoplay public override void OnAce() { - float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer); - // allows ace detection with this new system - float stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2; - Hit(stateProg); + if (EnableAutoplayCheat) + { + Hit(0f, 1f); + } + else + { + double normalizedBeat = GetNormalizedTime(); + double stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2; + Hit(stateProg, normalizedBeat); + } } //The state parameter is either -1 -> Early, 0 -> Perfect, 1 -> Late - public void Hit(float state) + public void Hit(double state, double time) { if (OnHit != null && enabled) { if(canHit) { - float normalized = GetNormalizedTime() - 1f; + double normalized = time - 1f; int offset = Mathf.CeilToInt((float)normalized * 1000); GameManager.instance.AvgInputOffset = offset; - OnHit(this, state); + OnHit(this, (float) state); + + if (countsForAccuracy && !(noAutoplay || autoplayOnly)) + TimeToAccuracy(time); CleanUp(); } else { Blank(); } } - + } + + double TimeToAccuracy(double time) + { + if (time >= Minigame.AceStartTime() && time <= Minigame.AceEndTime()) + { + // Ace + Debug.Log("Accuracy (Ace): " + 1.0); + return 1.0; + } + + double state = 0; + if (time >= Minigame.PerfectTime() && time <= Minigame.LateTime()) + { + // Good Hit + if (time > 1.0) + { + // late half of timing window + state = 1.0 - ((time - Minigame.AceEndTime()) / (Minigame.LateTime() - Minigame.AceEndTime())); + state *= 1.0 - Minigame.rankHiThreshold; + state += Minigame.rankHiThreshold; + Debug.Log("Accuracy (Late): " + state); + } + else + { + //early half of timing window + state = ((time - Minigame.PerfectTime()) / (Minigame.AceStartTime() - Minigame.PerfectTime())); + state *= 1.0 - Minigame.rankHiThreshold; + state += Minigame.rankHiThreshold; + Debug.Log("Accuracy (Early): " + state); + } + } + else + { + if (time > 1.0) + { + // late half of timing window + state = 1.0 - ((time - Minigame.LateTime()) / (Minigame.EndTime() - Minigame.LateTime())); + state *= Minigame.rankOkThreshold; + Debug.Log("Accuracy (Late NG): " + state); + } + else + { + //early half of timing window + state = ((time - Minigame.PerfectTime()) / (Minigame.AceStartTime() - Minigame.PerfectTime())); + state *= Minigame.rankOkThreshold; + Debug.Log("Accuracy (Early NG): " + state); + } + } + return state; } public void Miss() diff --git a/Assets/Scripts/Games/PlayerActionObject.cs b/Assets/Scripts/Games/PlayerActionObject.cs index fcd8ff649..5ba44e546 100644 --- a/Assets/Scripts/Games/PlayerActionObject.cs +++ b/Assets/Scripts/Games/PlayerActionObject.cs @@ -28,7 +28,7 @@ namespace HeavenStudio.Games autoPlayEnabledOnStart = GameManager.instance.autoplay; } - private void CheckForAce(float normalizedBeat, bool autoPlay = false) + private void CheckForAce(double normalizedBeat, bool autoPlay = false) { if (aceTimes == 0) { @@ -53,7 +53,7 @@ namespace HeavenStudio.Games } // could possibly add support for custom early, perfect, and end times if needed. - public void StateCheck(float normalizedBeat, bool autoPlay = false) + public void StateCheck(double normalizedBeat, bool autoPlay = false) { CheckForAce(normalizedBeat, autoPlay); if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime()) diff --git a/Assets/Scripts/Games/RhythmTweezers/LongHair.cs b/Assets/Scripts/Games/RhythmTweezers/LongHair.cs index f6d94a9a6..4c5a5accc 100644 --- a/Assets/Scripts/Games/RhythmTweezers/LongHair.cs +++ b/Assets/Scripts/Games/RhythmTweezers/LongHair.cs @@ -59,7 +59,7 @@ namespace HeavenStudio.Games.Scripts_RhythmTweezers // Auto-release if holding at release time. if (normalizedBeat >= 1f) - endEvent.Hit(0f); + endEvent.Hit(0f, 1f); } loop.transform.localScale = Vector2.one / holder.transform.localScale;