129 lines
3.7 KiB
C#
129 lines
3.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace Ichni.RhythmGame
|
||
{
|
||
/// <summary>
|
||
/// 单次演奏的运行时判定记录。
|
||
/// 本类随 GameScene 重建,只负责本局结算;长期最佳成绩由 SongSaveModule 写入 ES3,
|
||
/// 因此不要把此对象直接当作存档模型使用。
|
||
/// </summary>
|
||
public class PlayingRecorder
|
||
{
|
||
public int perfectCount;
|
||
public int goodCount;
|
||
public int badCount;
|
||
public int missCount;
|
||
public int totalCount;
|
||
|
||
public float accuracy;
|
||
|
||
public int currentCombo;
|
||
public int maxCombo;
|
||
|
||
/// <summary>本局判定偏差图数据,仅供当前 Summary 使用,不写入存档。</summary>
|
||
public List<float> resultData = new List<float>();
|
||
|
||
public bool isFullCombo;
|
||
public bool isAllPerfect;
|
||
|
||
/// <summary>
|
||
/// 在进入一局新演奏时重置全部瞬时状态。
|
||
/// 初始化为 100% / FC / AP 是为了让首个非 Perfect 判定能正确打破对应状态;
|
||
/// 无有效判定的空局不会被 SongSaveModule 写入成绩。
|
||
/// </summary>
|
||
public void Initialize()
|
||
{
|
||
if (resultData == null)
|
||
{
|
||
resultData = new List<float>();
|
||
}
|
||
else
|
||
{
|
||
resultData.Clear();
|
||
}
|
||
|
||
perfectCount = 0;
|
||
goodCount = 0;
|
||
badCount = 0;
|
||
missCount = 0;
|
||
totalCount = 0;
|
||
accuracy = 100f;
|
||
currentCombo = 0;
|
||
maxCombo = 0;
|
||
isFullCombo = true;
|
||
isAllPerfect = true;
|
||
}
|
||
|
||
private void UpdateAccuracy()
|
||
{
|
||
float baseValue = perfectCount + goodCount * 0.7f + badCount * 0.3f;
|
||
if (totalCount > 0)
|
||
{
|
||
accuracy = baseValue / totalCount * 100f;
|
||
}
|
||
else
|
||
{
|
||
accuracy = 100f; // 如果没有任何击打,准确率为100%
|
||
}
|
||
}
|
||
|
||
private void AddCombo()
|
||
{
|
||
currentCombo++;
|
||
maxCombo = Mathf.Max(maxCombo, currentCombo);
|
||
}
|
||
|
||
private void ResetCombo()
|
||
{
|
||
currentCombo = 0;
|
||
}
|
||
|
||
public void AddPerfect()
|
||
{
|
||
perfectCount++;
|
||
totalCount++;
|
||
AddCombo();
|
||
UpdateAccuracy();
|
||
GameManager.Instance.gameUICanvas.UpdateAccuracy(accuracy);
|
||
GameManager.Instance.gameUICanvas.UpdateCombo(currentCombo);
|
||
}
|
||
|
||
public void AddGood()
|
||
{
|
||
goodCount++;
|
||
totalCount++;
|
||
AddCombo();
|
||
UpdateAccuracy();
|
||
isAllPerfect = false;
|
||
GameManager.Instance.gameUICanvas.UpdateAccuracy(accuracy);
|
||
GameManager.Instance.gameUICanvas.UpdateCombo(currentCombo);
|
||
}
|
||
|
||
public void AddBad()
|
||
{
|
||
badCount++;
|
||
totalCount++;
|
||
ResetCombo();
|
||
UpdateAccuracy();
|
||
isFullCombo = false;
|
||
isAllPerfect = false;
|
||
GameManager.Instance.gameUICanvas.UpdateAccuracy(accuracy);
|
||
GameManager.Instance.gameUICanvas.UpdateCombo(currentCombo);
|
||
}
|
||
|
||
public void AddMiss()
|
||
{
|
||
missCount++;
|
||
totalCount++;
|
||
ResetCombo();
|
||
UpdateAccuracy();
|
||
isFullCombo = false;
|
||
isAllPerfect = false;
|
||
GameManager.Instance.gameUICanvas.UpdateAccuracy(accuracy);
|
||
GameManager.Instance.gameUICanvas.UpdateCombo(currentCombo);
|
||
}
|
||
}
|
||
}
|