拼ui 一些业务逻辑x实现
This commit is contained in:
@@ -150,6 +150,7 @@ public class settlementController : MonoBehaviour
|
||||
private Vector3 cachedIntroMvpBaseLocalPos;
|
||||
private bool hasCachedIntroMvpBaseLocalPos;
|
||||
private bool settlementHistoryRecorded;
|
||||
private bool settlementHeroStatsRecorded;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -187,6 +188,7 @@ public class settlementController : MonoBehaviour
|
||||
|
||||
RegisterCurrentLineupDeployCount();
|
||||
settlementHistoryRecorded = false;
|
||||
settlementHeroStatsRecorded = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -303,6 +305,179 @@ public class settlementController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void RecordSettlementHeroStats()
|
||||
{
|
||||
if (settlementHeroStatsRecorded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
settlementHeroStatsRecorded = true;
|
||||
|
||||
List<AllyHero_SO> lineupHeroes = ResolveCurrentLineupHeroSOs();
|
||||
for (int i = 0; i < lineupHeroes.Count; i++)
|
||||
{
|
||||
AllyHero_SO hero = lineupHeroes[i];
|
||||
if (hero == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hero.IncrementFinishCount();
|
||||
}
|
||||
|
||||
AllyHero_SO mvpHero = ResolveMvpHeroFromTopScorer();
|
||||
if (mvpHero != null)
|
||||
{
|
||||
mvpHero.IncrementMvpCount();
|
||||
}
|
||||
}
|
||||
|
||||
private List<AllyHero_SO> ResolveCurrentLineupHeroSOs()
|
||||
{
|
||||
List<AllyHero_SO> result = new List<AllyHero_SO>();
|
||||
HashSet<int> uniqueHeroIds = new HashSet<int>();
|
||||
|
||||
if (teamUIController.Instance != null && teamUIController.Instance.allySlotIds != null)
|
||||
{
|
||||
for (int i = 0; i < teamUIController.Instance.allySlotIds.Count; i++)
|
||||
{
|
||||
int heroId = teamUIController.Instance.allySlotIds[i];
|
||||
if (heroId > 0)
|
||||
{
|
||||
uniqueHeroIds.Add(heroId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uniqueHeroIds.Count == 0)
|
||||
{
|
||||
for (int slotIndex = 1; slotIndex <= 5; slotIndex++)
|
||||
{
|
||||
int heroId = PlayerPrefs.GetInt("selected_heroSlot0" + slotIndex + "_heroID", 0);
|
||||
if (heroId > 0)
|
||||
{
|
||||
uniqueHeroIds.Add(heroId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnsureCachedAllyHeroSOs();
|
||||
|
||||
foreach (int heroId in uniqueHeroIds)
|
||||
{
|
||||
AllyHero_SO hero = FindAllyHeroSOById(heroId);
|
||||
if (hero != null)
|
||||
{
|
||||
result.Add(hero);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private AllyHero_SO ResolveMvpHeroFromTopScorer()
|
||||
{
|
||||
int topIndex = -1;
|
||||
int[] scores = new int[5];
|
||||
|
||||
if (sm != null)
|
||||
{
|
||||
scores[0] = sm.red_idolScore_sum;
|
||||
scores[1] = sm.green_idolScore_sum;
|
||||
scores[2] = sm.yellow_idolScore_sum;
|
||||
scores[3] = sm.purple_idolScore_sum;
|
||||
scores[4] = sm.blue_idolScore_sum;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
GameObject go = GameObject.Find($"ally_0{i + 1}");
|
||||
if (go != null)
|
||||
{
|
||||
AllyCombatant ac = go.GetComponent<AllyCombatant>();
|
||||
scores[i] = ac != null ? ac.currentScore : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scores[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = -1;
|
||||
for (int i = 0; i < scores.Length; i++)
|
||||
{
|
||||
if (scores[i] > max)
|
||||
{
|
||||
max = scores[i];
|
||||
topIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (topIndex < 0 || max <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AllyHero_SO heroSO = null;
|
||||
if (SkillBuilder.Instance != null)
|
||||
{
|
||||
try { heroSO = SkillBuilder.Instance.GetAllyHeroSOBySlot(topIndex); }
|
||||
catch { heroSO = null; }
|
||||
}
|
||||
|
||||
if (heroSO == null && teamUIController.Instance != null && teamUIController.Instance.allySlotIds != null)
|
||||
{
|
||||
int allyId = -1;
|
||||
if (topIndex >= 0 && topIndex < teamUIController.Instance.allySlotIds.Count)
|
||||
{
|
||||
allyId = teamUIController.Instance.allySlotIds[topIndex];
|
||||
}
|
||||
|
||||
if (allyId > 0)
|
||||
{
|
||||
heroSO = FindAllyHeroSOById(allyId);
|
||||
}
|
||||
}
|
||||
|
||||
return heroSO;
|
||||
}
|
||||
|
||||
private static void EnsureCachedAllyHeroSOs()
|
||||
{
|
||||
if (_cachedAllyHeroSOs == null || _cachedAllyHeroSOs.Length == 0)
|
||||
{
|
||||
_cachedAllyHeroSOs = Resources.LoadAll<AllyHero_SO>(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private static AllyHero_SO FindAllyHeroSOById(int allyId)
|
||||
{
|
||||
if (allyId <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
EnsureCachedAllyHeroSOs();
|
||||
if (_cachedAllyHeroSOs == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _cachedAllyHeroSOs.Length; i++)
|
||||
{
|
||||
AllyHero_SO hero = _cachedAllyHeroSOs[i];
|
||||
if (hero != null && hero.ally_heroID == allyId)
|
||||
{
|
||||
return hero;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void startSettlement_uiUpdate()
|
||||
{
|
||||
if (settlementUiInitialized)
|
||||
@@ -312,6 +487,7 @@ public class settlementController : MonoBehaviour
|
||||
}
|
||||
settlementUiInitialized = true;
|
||||
settlementHistoryRecorded = false;
|
||||
settlementHeroStatsRecorded = false;
|
||||
|
||||
// Documentation text normalized.
|
||||
InitializeSettlementCanvas();
|
||||
@@ -518,6 +694,7 @@ public class settlementController : MonoBehaviour
|
||||
|
||||
// Documentation text normalized.
|
||||
// Documentation text normalized.
|
||||
RecordSettlementHeroStats();
|
||||
SetMvpHeroImageFromTopScorer();
|
||||
StartMusicTransition();
|
||||
|
||||
@@ -537,6 +714,7 @@ public class settlementController : MonoBehaviour
|
||||
var record = new RecentPlayRecord
|
||||
{
|
||||
playedAt = System.DateTime.Now.ToString("MM-dd, HH:mm"),
|
||||
playedAtUtc = System.DateTime.UtcNow.ToString("o"),
|
||||
songID = thisSong_so != null ? thisSong_so.songID : 0,
|
||||
songName = thisSong_so != null && !string.IsNullOrWhiteSpace(thisSong_so.songName)
|
||||
? thisSong_so.songName
|
||||
@@ -545,6 +723,12 @@ public class settlementController : MonoBehaviour
|
||||
accuracy = targetAccuracyPercent,
|
||||
srks = CalculateSongRankingScore(noteCountRaw),
|
||||
totalScore = targetTotalScore,
|
||||
chartScore = targetPmScore,
|
||||
idolScore = targetIdolScore,
|
||||
hasScoreBreakdown = true,
|
||||
rankIndex = CalculateRankIndex(targetTotalScore),
|
||||
rankTierCount = GetRankTierCount(),
|
||||
hasRankMarker = true,
|
||||
scoreReadable = true,
|
||||
wasEarlySettlement = IsEarlySettlement(noteCountRaw),
|
||||
wasAllPerfect = IsAllPerfectRun(noteCountRaw)
|
||||
@@ -598,6 +782,48 @@ public class settlementController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private int GetRankTierCount()
|
||||
{
|
||||
if (rankConfig == null || rankConfig.thresholds == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Mathf.Max(0, rankConfig.thresholds.Count);
|
||||
}
|
||||
|
||||
private int CalculateRankIndex(int score)
|
||||
{
|
||||
if (rankConfig == null || rankConfig.thresholds == null || rankConfig.thresholds.Count == 0 || score <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bestLevel = 0;
|
||||
float highestMatchingPercent = -1f;
|
||||
int thresholdCount = rankConfig.thresholds.Count;
|
||||
|
||||
for (int i = 0; i < thresholdCount; i++)
|
||||
{
|
||||
RankThreshold threshold = rankConfig.thresholds[i];
|
||||
if (threshold == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float requiredScore = rankConfig.baseScore * threshold.thresholdPercent;
|
||||
if (score < requiredScore || threshold.thresholdPercent <= highestMatchingPercent)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
highestMatchingPercent = threshold.thresholdPercent;
|
||||
bestLevel = thresholdCount - i;
|
||||
}
|
||||
|
||||
return bestLevel;
|
||||
}
|
||||
|
||||
private float CalculateSongRankingScore(int noteCountRaw)
|
||||
{
|
||||
int totalNotes = Mathf.Max(1, noteCountRaw);
|
||||
|
||||
Reference in New Issue
Block a user