备份,准备做双端
This commit is contained in:
@@ -85,11 +85,33 @@ public class GameServerBridge : MonoBehaviour
|
||||
|
||||
int chartScore = 0, idolScore = 0;
|
||||
long totalScore = 0;
|
||||
float accuracyPercent = 0f;
|
||||
int maxCombo = 0, perfectCount = 0, greatCount = 0, goodCount = 0, missCount = 0;
|
||||
|
||||
if (scoreManager != null)
|
||||
{
|
||||
chartScore = scoreManager.allSum_pmScore;
|
||||
idolScore = scoreManager.allSum_idolScore;
|
||||
totalScore = chartScore + idolScore;
|
||||
|
||||
// 新增:采集准确率、连击、判定分布
|
||||
int totalNotes = scoreManager.countPerfect + scoreManager.countGreat + scoreManager.countGood + scoreManager.countMiss;
|
||||
if (totalNotes > 0)
|
||||
{
|
||||
float weighted = scoreManager.countPerfect * 1f
|
||||
+ scoreManager.countGreat * 0.667f
|
||||
+ scoreManager.countGood * 0.333f;
|
||||
accuracyPercent = (weighted / totalNotes) * 100f;
|
||||
}
|
||||
|
||||
maxCombo = InGamePerformanceManager.Instance != null
|
||||
? InGamePerformanceManager.Instance.HighestComboThisRun
|
||||
: 0;
|
||||
|
||||
perfectCount = scoreManager.countPerfect;
|
||||
greatCount = scoreManager.countGreat;
|
||||
goodCount = scoreManager.countGood;
|
||||
missCount = scoreManager.countMiss;
|
||||
}
|
||||
|
||||
string grade = GetGrade(totalScore);
|
||||
@@ -135,7 +157,8 @@ public class GameServerBridge : MonoBehaviour
|
||||
Debug.Log("╚══════════════════════════════════════════════════════╝");
|
||||
|
||||
string result = await nm.PushSettlement(songId, difficulty, chartScore, idolScore,
|
||||
totalScore, grade, runtime, playedAt, hmac);
|
||||
totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
|
||||
// ── 结果日志 ──
|
||||
if (result == "OK")
|
||||
@@ -149,7 +172,8 @@ public class GameServerBridge : MonoBehaviour
|
||||
{
|
||||
Debug.LogWarning("[Bridge] ⏳ 服务器繁忙,稍后重试...");
|
||||
_hasSubmitted = false;
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
}
|
||||
else if (result == "OPT_OUT")
|
||||
{
|
||||
@@ -162,7 +186,8 @@ public class GameServerBridge : MonoBehaviour
|
||||
Debug.LogWarning($"║ ❌ 上传失败!服务器返回: {result}");
|
||||
Debug.LogWarning($"╚══════════════════════════════════════════════════════╝");
|
||||
_hasSubmitted = false;
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,14 +206,16 @@ public class GameServerBridge : MonoBehaviour
|
||||
/// 重试上传逻辑:3次重试,每次间隔20秒,失败后缓存到本地
|
||||
/// </summary>
|
||||
private async Task RetrySubmission(string songId, string difficulty, int chartScore, int idolScore,
|
||||
long totalScore, string grade, double runtime, string playedAt, string hmac)
|
||||
long totalScore, string grade, double runtime, string playedAt, string hmac,
|
||||
float accuracyPercent, int maxCombo, int perfectCount, int greatCount, int goodCount, int missCount)
|
||||
{
|
||||
_currentRetryCount++;
|
||||
|
||||
if (_currentRetryCount >= 3)
|
||||
{
|
||||
Debug.LogWarning($"[Bridge] 已重试 {_currentRetryCount} 次仍失败,缓存到本地待下次启动重试");
|
||||
PendingScoreCache.CacheScore(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
PendingScoreCache.CacheScore(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
_currentRetryCount = 0;
|
||||
return;
|
||||
}
|
||||
@@ -200,7 +227,8 @@ public class GameServerBridge : MonoBehaviour
|
||||
if (nm == null)
|
||||
{
|
||||
Debug.LogWarning("[Bridge] NetworkManager 不存在,缓存到本地");
|
||||
PendingScoreCache.CacheScore(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
PendingScoreCache.CacheScore(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
_currentRetryCount = 0;
|
||||
return;
|
||||
}
|
||||
@@ -209,7 +237,8 @@ public class GameServerBridge : MonoBehaviour
|
||||
try
|
||||
{
|
||||
string result = await nm.PushSettlement(songId, difficulty, chartScore, idolScore,
|
||||
totalScore, grade, runtime, playedAt, hmac);
|
||||
totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
|
||||
if (result == "OK")
|
||||
{
|
||||
@@ -219,13 +248,15 @@ public class GameServerBridge : MonoBehaviour
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[Bridge] 第 {_currentRetryCount} 次重试失败: {result}");
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"[Bridge] 第 {_currentRetryCount} 次重试异常: {ex.Message}");
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac);
|
||||
await RetrySubmission(songId, difficulty, chartScore, idolScore, totalScore, grade, runtime, playedAt, hmac,
|
||||
accuracyPercent, maxCombo, perfectCount, greatCount, goodCount, missCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,14 @@ namespace GameServer.Client
|
||||
[JsonProperty("play_count")] public int play_count;
|
||||
[JsonProperty("keep_on_time")] public int keep_on_time;
|
||||
[JsonProperty("room_status_text")] public string room_status_text;
|
||||
|
||||
// 新增:准确率、最大连击、判定分布(服务端可选返回,向后兼容)
|
||||
[JsonProperty("accuracy_percent")] public float accuracy_percent;
|
||||
[JsonProperty("max_combo")] public int max_combo;
|
||||
[JsonProperty("perfect_count")] public int perfect_count;
|
||||
[JsonProperty("great_count")] public int great_count;
|
||||
[JsonProperty("good_count")] public int good_count;
|
||||
[JsonProperty("miss_count")] public int miss_count;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -188,6 +196,14 @@ namespace GameServer.Client
|
||||
[JsonProperty("runtime_seconds")] public double runtime_seconds;
|
||||
[JsonProperty("played_at")] public string played_at;
|
||||
[JsonProperty("hmac")] public string hmac;
|
||||
|
||||
// 新增:准确率、最大连击、判定分布(可选,服务端向后兼容)
|
||||
[JsonProperty("accuracy_percent")] public float accuracy_percent;
|
||||
[JsonProperty("max_combo")] public int max_combo;
|
||||
[JsonProperty("perfect_count")] public int perfect_count;
|
||||
[JsonProperty("great_count")] public int great_count;
|
||||
[JsonProperty("good_count")] public int good_count;
|
||||
[JsonProperty("miss_count")] public int miss_count;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -229,7 +229,13 @@ public class NetworkManager : MonoBehaviour
|
||||
score.grade,
|
||||
score.runtimeSeconds,
|
||||
score.playedAt,
|
||||
hmac);
|
||||
hmac,
|
||||
score.accuracyPercent,
|
||||
score.maxCombo,
|
||||
score.perfectCount,
|
||||
score.greatCount,
|
||||
score.goodCount,
|
||||
score.missCount);
|
||||
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
@@ -724,7 +730,9 @@ public class NetworkManager : MonoBehaviour
|
||||
|
||||
public async Task<string> PushSettlement(string songId, string difficulty,
|
||||
int chartScore, int idolScore, long totalScore, string grade,
|
||||
double runtimeSeconds, string playedAt, string hmac = "")
|
||||
double runtimeSeconds, string playedAt, string hmac = "",
|
||||
float accuracyPercent = 0f, int maxCombo = 0,
|
||||
int perfectCount = 0, int greatCount = 0, int goodCount = 0, int missCount = 0)
|
||||
{
|
||||
if (OnlineModeSettings.IsLocalOnlyMode)
|
||||
{
|
||||
@@ -753,7 +761,14 @@ public class NetworkManager : MonoBehaviour
|
||||
grade = grade,
|
||||
runtime_seconds = runtimeSeconds,
|
||||
played_at = playedAt,
|
||||
hmac = hmac
|
||||
hmac = hmac,
|
||||
// 新增字段
|
||||
accuracy_percent = accuracyPercent,
|
||||
max_combo = maxCombo,
|
||||
perfect_count = perfectCount,
|
||||
great_count = greatCount,
|
||||
good_count = goodCount,
|
||||
miss_count = missCount
|
||||
};
|
||||
|
||||
ScoreAckResponse resp = await PostJson<ScoreAckResponse>(BuildApiUrl("/api/submit"), req, CancellationToken.None);
|
||||
|
||||
@@ -26,6 +26,14 @@ namespace GameServer.Client
|
||||
public string hmac;
|
||||
public int retryCount;
|
||||
public string cachedAt;
|
||||
|
||||
// 新增字段(向后兼容:旧缓存文件读取时默认为 0)
|
||||
public float accuracyPercent;
|
||||
public int maxCombo;
|
||||
public int perfectCount;
|
||||
public int greatCount;
|
||||
public int goodCount;
|
||||
public int missCount;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -46,7 +54,13 @@ namespace GameServer.Client
|
||||
string grade,
|
||||
double runtimeSeconds,
|
||||
string playedAt,
|
||||
string hmac)
|
||||
string hmac,
|
||||
float accuracyPercent = 0f,
|
||||
int maxCombo = 0,
|
||||
int perfectCount = 0,
|
||||
int greatCount = 0,
|
||||
int goodCount = 0,
|
||||
int missCount = 0)
|
||||
{
|
||||
lock (FileLock)
|
||||
{
|
||||
@@ -62,6 +76,12 @@ namespace GameServer.Client
|
||||
existing.grade = grade;
|
||||
existing.runtimeSeconds = runtimeSeconds;
|
||||
existing.hmac = hmac;
|
||||
existing.accuracyPercent = accuracyPercent;
|
||||
existing.maxCombo = maxCombo;
|
||||
existing.perfectCount = perfectCount;
|
||||
existing.greatCount = greatCount;
|
||||
existing.goodCount = goodCount;
|
||||
existing.missCount = missCount;
|
||||
if (string.IsNullOrWhiteSpace(existing.cachedAt))
|
||||
{
|
||||
existing.cachedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -81,7 +101,13 @@ namespace GameServer.Client
|
||||
playedAt = playedAt,
|
||||
hmac = hmac,
|
||||
retryCount = 0,
|
||||
cachedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
cachedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
accuracyPercent = accuracyPercent,
|
||||
maxCombo = maxCombo,
|
||||
perfectCount = perfectCount,
|
||||
greatCount = greatCount,
|
||||
goodCount = goodCount,
|
||||
missCount = missCount
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,7 +148,13 @@ namespace GameServer.Client
|
||||
runtimeSeconds = cached.runtimeSeconds,
|
||||
playedAt = cached.playedAt,
|
||||
hmac = cached.hmac,
|
||||
retryCount = cached.retryCount
|
||||
retryCount = cached.retryCount,
|
||||
accuracyPercent = cached.accuracyPercent,
|
||||
maxCombo = cached.maxCombo,
|
||||
perfectCount = cached.perfectCount,
|
||||
greatCount = cached.greatCount,
|
||||
goodCount = cached.goodCount,
|
||||
missCount = cached.missCount
|
||||
});
|
||||
}
|
||||
|
||||
@@ -289,5 +321,13 @@ namespace GameServer.Client
|
||||
public string playedAt;
|
||||
public string hmac;
|
||||
public int retryCount;
|
||||
|
||||
// 新增字段
|
||||
public float accuracyPercent;
|
||||
public int maxCombo;
|
||||
public int perfectCount;
|
||||
public int greatCount;
|
||||
public int goodCount;
|
||||
public int missCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user