Scoring System Preparation (#235)

* add calculation for accuracy

* record accuracy for playthrough

* implement forced miss scoring to some games
This commit is contained in:
minenice55 2023-01-24 22:54:19 -05:00 committed by GitHub
parent 7dc9aad090
commit 6a61b9d87a
16 changed files with 171 additions and 62 deletions

View file

@ -60,6 +60,7 @@ namespace HeavenStudio
public static GameManager instance { get; private set; }
private EventCaller eventCaller;
// average input accuracy (msec)
List<int> inputOffsetSamples = new List<int>();
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,14 @@ namespace HeavenStudio
}
}
public void ScoreInputAccuracy(double accuracy, bool late, double weight = 1)
{
totalInputs += weight;
totalPlayerAccuracy += accuracy * weight;
// push the hit event to the timing display
}
public void SeekAheadAndPreload(double start, float seekTime = 8f)
{
//seek ahead to preload games that have assetbundles
@ -369,6 +390,10 @@ namespace HeavenStudio
canInput = true;
inputOffsetSamples.Clear();
averageInputOffset = 0;
totalInputs = 0;
totalPlayerAccuracy = 0;
StartCoroutine(PlayCo(beat));
onBeatChanged?.Invoke(beat);
}
@ -409,6 +434,7 @@ namespace HeavenStudio
KillAllSounds();
Debug.Log($"Average input offset for playthrough: {averageInputOffset}ms");
Debug.Log($"Accuracy for playthrough: {(PlayerAccuracy * 100) : 0.00}");
if (playOnStart)
{

View file

@ -28,6 +28,7 @@ namespace HeavenStudio.Games.Scripts_ClappyTrio
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
{
Clap(false);
game.ScoreMiss();
}
}

View file

@ -28,7 +28,10 @@ namespace HeavenStudio.Games.Scripts_CropStomp
if (stomp == null && cond.isPlaying)
{
if (GameManager.instance.currentGame == "cropStomp")
{
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
}
if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
@ -52,6 +55,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
nextStompBeat += 2f;
stomp?.Disable();
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
private void Out(PlayerActionEvent caller) {}
@ -73,6 +77,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp
nextStompBeat += 2f;
stomp?.Disable();
stomp = game.ScheduleUserInput(nextStompBeat - 1f, 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
stomp.countsForAccuracy = false;
}
}
}

View file

@ -232,6 +232,7 @@ namespace HeavenStudio.Games
{
student.OnMissHoldForPlayerInput();
student.isHolding = true;
ScoreMiss();
}
else if(PlayerInput.PressedUp() && !IsExpectingInputNow() && student.isHolding) //Let go during hold
{

View file

@ -102,6 +102,7 @@ namespace HeavenStudio.Games.Scripts_FanClub
if (!FanClub.instance.IsExpectingInputNow(InputType.STANDARD_DOWN))
{
ClapStart(false);
FanClub.instance.ScoreMiss();
}
}
if (PlayerInput.Pressing())
@ -118,6 +119,7 @@ namespace HeavenStudio.Games.Scripts_FanClub
if (clappingStartTime != Single.MinValue && cond.songPositionInBeats > clappingStartTime + 2f && stopCharge && !FanClub.instance.IsExpectingInputNow(InputType.STANDARD_UP))
{
JumpStart(false);
FanClub.instance.ScoreMiss();
}
else
{

View file

@ -152,6 +152,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
{
//start a forced-fail combo sequence
ForceFailCombo(cond.songPositionInBeats);
KarateMan.instance.ScoreMiss(2);
}
}
else if (PlayerInput.AltPressedUp())

View file

@ -156,6 +156,7 @@ namespace HeavenStudio.Games
var stepPlayerAnim = (beatAnimCheck % 2 != 0 ? "OffbeatMarch" : "OnbeatMarch");
Jukebox.PlayOneShotGame("lockstep/miss");
stepswitcherP.DoScaledAnimationAsync(stepPlayerAnim, 0.5f);
ScoreMiss();
}
}

View file

@ -154,6 +154,7 @@ namespace HeavenStudio.Games
Jukebox.PlayOneShot("miss");
Sarge.DoScaledAnimationAsync("Anger", 0.5f);
Steam.DoScaledAnimationAsync("Steam", 0.5f);
ScoreMiss();
marchPlayerCount += 1;
var marchPlayerAnim = (marchPlayerCount % 2 != 0 ? "MarchR" : "MarchL");

View file

@ -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<Minigame.Eligible> EligibleHits = new List<Minigame.Eligible>();
@ -171,7 +172,7 @@ namespace HeavenStudio.Games
public static float AceStartTime()
{
return 1f + ScaleTimingMargin(aceEarlyTime);
return 1f - ScaleTimingMargin(aceEarlyTime);
}
public static float AceEndTime()
@ -250,6 +251,11 @@ namespace HeavenStudio.Games
return null;
}
public void ScoreMiss(double weight = 1f)
{
GameManager.instance.ScoreInputAccuracy(0, true, weight);
}
private void OnDestroy() {
foreach (var evt in scheduledInputs)
{

View file

@ -53,6 +53,7 @@ namespace HeavenStudio.Games.Scripts_PajamaParty
{
Jukebox.PlayOneShot("miss");
PlayerJump(cond.songPositionInBeats, true, false);
PajamaParty.instance.ScoreMiss();
}
if (PlayerInput.AltPressed() && canCharge)
{
@ -62,6 +63,7 @@ namespace HeavenStudio.Games.Scripts_PajamaParty
{
Jukebox.PlayOneShot("miss");
EndCharge(cond.songPositionInBeats, false, false);
PajamaParty.instance.ScoreMiss();
}
// mako jumping logic

View file

@ -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);
@ -34,6 +35,8 @@ namespace HeavenStudio.Games
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)
{
this.OnHit = OnHit;
@ -60,31 +63,27 @@ 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())
{
// push an ace event
}
Hit(stateProg, normalizedTime);
}
else if (state.early && !perfectOnly)
{
Hit(-1f);
Hit(-1f, normalizedTime);
}
else if (state.late && !perfectOnly)
{
Hit(1f);
Hit(1f, normalizedTime);
}
else
{
@ -95,18 +94,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 +137,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);
CleanUp();
if (countsForAccuracy && !(noAutoplay || autoplayOnly))
GameManager.instance.ScoreInputAccuracy(TimeToAccuracy(time), time > 1.0, 1.0);
} 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()
@ -172,6 +229,8 @@ namespace HeavenStudio.Games
}
CleanUp();
if (countsForAccuracy && !(noAutoplay || autoplayOnly))
GameManager.instance.ScoreInputAccuracy(0, true, 1.0);
}
public void Blank()

View file

@ -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())

View file

@ -8,7 +8,8 @@ namespace HeavenStudio.Games.Loaders
using static Minigames;
public static class PcoSomenLoader
{
public static Minigame AddGame(EventCaller eventCaller) {
public static Minigame AddGame(EventCaller eventCaller)
{
return new Minigame("rhythmSomen", "Rhythm Sōmen", "99CC34", false, false, new List<GameAction>()
{
new GameAction("crane (far)", "Far Crane")
@ -74,6 +75,7 @@ namespace HeavenStudio.Games
Jukebox.PlayOneShotGame("rhythmSomen/somen_mistake");
FrontArm.Play("ArmPluck", -1, 0);
EffectSweat.Play("BlobSweating", -1, 0);
ScoreMiss();
}
}

View file

@ -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;

View file

@ -84,9 +84,9 @@ namespace HeavenStudio.Games.Scripts_NtrSamurai
launchProg = SamuraiSliceNtr.instance.ScheduleInput(startBeat, 2f, InputType.STANDARD_ALT_DOWN, LaunchSuccess, LaunchMiss, LaunchThrough);
//autoplay: launch anim
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat, 2f, InputType.STANDARD_ALT_DOWN, DoLaunchAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat, 2f, InputType.STANDARD_ALT_DOWN, DoLaunchAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
//autoplay: unstep
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat, 1.75f, InputType.STANDARD_ALT_UP, DoUnStepAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat, 1.75f, InputType.STANDARD_ALT_UP, DoUnStepAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
currentCurve = SamuraiSliceNtr.instance.InCurve;
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (360f * startBeat));
@ -216,9 +216,9 @@ namespace HeavenStudio.Games.Scripts_NtrSamurai
{
flyProg = 2;
launchProg = SamuraiSliceNtr.instance.ScheduleInput(startBeat + 2f, 2f, InputType.STANDARD_ALT_DOWN, LaunchSuccess, LaunchMiss, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 2f, InputType.STANDARD_ALT_DOWN, DoLaunchAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 2f, InputType.STANDARD_ALT_DOWN, DoLaunchAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
//autoplay: unstep
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 1.75f, InputType.STANDARD_ALT_UP, DoUnStepAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 1.75f, InputType.STANDARD_ALT_UP, DoUnStepAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
currentCurve = null;
Jukebox.PlayOneShotGame("samuraiSliceNtr/holy_mackerel" + UnityEngine.Random.Range(1, 4), pitch: UnityEngine.Random.Range(0.95f, 1.05f), volume: 0.8f);
@ -227,13 +227,13 @@ namespace HeavenStudio.Games.Scripts_NtrSamurai
case (int) SamuraiSliceNtr.ObjectType.Demon:
flyProg = 1;
hitProg = SamuraiSliceNtr.instance.ScheduleInput(startBeat + 2f, 4f, InputType.STANDARD_DOWN, HitSuccess, HitMiss, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 4f, InputType.STANDARD_DOWN, DoSliceAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 4f, InputType.STANDARD_DOWN, DoSliceAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
currentCurve = SamuraiSliceNtr.instance.LaunchHighCurve;
break;
default:
flyProg = 1;
hitProg = SamuraiSliceNtr.instance.ScheduleInput(startBeat + 2f, 2f, InputType.STANDARD_DOWN, HitSuccess, HitMiss, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 2f, InputType.STANDARD_DOWN, DoSliceAutoplay, LaunchThrough, LaunchThrough);
SamuraiSliceNtr.instance.ScheduleAutoplayInput(startBeat + 2f, 2f, InputType.STANDARD_DOWN, DoSliceAutoplay, LaunchThrough, LaunchThrough).countsForAccuracy = false;
currentCurve = SamuraiSliceNtr.instance.LaunchCurve;
break;
}

View file

@ -162,6 +162,7 @@ namespace HeavenStudio.Games
Jukebox.PlayOneShotGame($"tambourine/player/shake/{UnityEngine.Random.Range(1, 6)}");
sweatAnimator.Play("Sweating", 0, 0);
SummonFrog();
ScoreMiss();
if (!intervalStarted)
{
sadFace.SetActive(true);
@ -173,6 +174,7 @@ namespace HeavenStudio.Games
Jukebox.PlayOneShotGame($"tambourine/player/hit/{UnityEngine.Random.Range(1, 6)}");
sweatAnimator.Play("Sweating", 0, 0);
SummonFrog();
ScoreMiss();
if (!intervalStarted)
{
sadFace.SetActive(true);