特效新内容。修复gameplay致命bug和分数保存bug
This commit is contained in:
@@ -304,6 +304,50 @@ public class SongData : ScriptableObject
|
||||
CalculateHighestPersonalRecord();
|
||||
}
|
||||
|
||||
public void ApplySettlementResult(int difficulty, int pmScore, int idolScore, int maxScoreSum)
|
||||
{
|
||||
if (difficulty < 0) return;
|
||||
|
||||
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
|
||||
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
|
||||
if (chartScoreMap == null) chartScoreMap = new Dictionary<int, int>();
|
||||
|
||||
int total = pmScore + idolScore;
|
||||
int currentBestTotal = GetPersonalRecord(difficulty) + GetIdolRecord(difficulty);
|
||||
bool isNewTotalRecord = total > currentBestTotal;
|
||||
|
||||
if (isNewTotalRecord)
|
||||
{
|
||||
personalRecordMap[difficulty] = pmScore;
|
||||
idolRecordMap[difficulty] = idolScore;
|
||||
}
|
||||
|
||||
ChartFileEntry entry = chartFiles != null ? chartFiles.Find(e => e != null && e.difficulty == difficulty) : null;
|
||||
if (entry != null)
|
||||
{
|
||||
if (isNewTotalRecord)
|
||||
{
|
||||
entry.chartPersonalRecordForThisDifficulty = pmScore;
|
||||
entry.idolPersonalRecordForThisDifficulty = idolScore;
|
||||
entry.totalPersonalRecordForThisDifficulty = total;
|
||||
}
|
||||
|
||||
float newProgress = maxScoreSum > 0 ? Mathf.Clamp01((float)total / (float)maxScoreSum) : 0f;
|
||||
if (newProgress > entry.levelProgressForThisDifficulty)
|
||||
{
|
||||
entry.levelProgressForThisDifficulty = newProgress;
|
||||
}
|
||||
|
||||
entry.lastScoreForThisDifficulty = total;
|
||||
}
|
||||
|
||||
chartScoreMap[difficulty] = total;
|
||||
|
||||
UpdateOverallRecordsFromEntries();
|
||||
ApplySerializableRoundTrip();
|
||||
SavePersistent();
|
||||
}
|
||||
|
||||
public void GetAbsoluteHighestScore(out int highestScore, out int bestDifficulty, out string bestDifficultyName)
|
||||
{
|
||||
highestScore = 0;
|
||||
@@ -375,6 +419,62 @@ public class SongData : ScriptableObject
|
||||
CalculateHighestPersonalRecord();
|
||||
}
|
||||
|
||||
private void UpdateOverallRecordsFromEntries()
|
||||
{
|
||||
int highestTotal = 0;
|
||||
float highestProgress = 0f;
|
||||
|
||||
if (chartFiles != null && chartFiles.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < chartFiles.Count; i++)
|
||||
{
|
||||
ChartFileEntry entry = chartFiles[i];
|
||||
if (entry == null) continue;
|
||||
|
||||
int total = entry.totalPersonalRecordForThisDifficulty;
|
||||
if (total <= 0)
|
||||
{
|
||||
int p = GetPersonalRecord(entry.difficulty);
|
||||
int idol = GetIdolRecord(entry.difficulty);
|
||||
total = p + idol;
|
||||
}
|
||||
|
||||
if (total > highestTotal)
|
||||
{
|
||||
highestTotal = total;
|
||||
}
|
||||
|
||||
if (entry.levelProgressForThisDifficulty > highestProgress)
|
||||
{
|
||||
highestProgress = entry.levelProgressForThisDifficulty;
|
||||
}
|
||||
}
|
||||
|
||||
personalRecord = highestTotal;
|
||||
current_levelProgress = highestProgress;
|
||||
return;
|
||||
}
|
||||
|
||||
if (personalRecordMap != null && personalRecordMap.Count > 0)
|
||||
{
|
||||
foreach (var kvp in personalRecordMap)
|
||||
{
|
||||
int diff = kvp.Key;
|
||||
int total = kvp.Value + GetIdolRecord(diff);
|
||||
if (total > highestTotal) highestTotal = total;
|
||||
}
|
||||
personalRecord = highestTotal;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySerializableRoundTrip()
|
||||
{
|
||||
SongDataSerializable serializable = new SongDataSerializable(this);
|
||||
string json = JsonUtility.ToJson(serializable);
|
||||
SongDataSerializable roundTrip = JsonUtility.FromJson<SongDataSerializable>(json);
|
||||
if (roundTrip != null) roundTrip.ApplyTo(this);
|
||||
}
|
||||
|
||||
public void UpdateIdolRecord(int difficulty, int newIdolScore)
|
||||
{
|
||||
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
|
||||
|
||||
Reference in New Issue
Block a user