Add XP calculation to stats menu

This commit is contained in:
2026-02-05 18:26:43 -07:00
parent 0837cb73f7
commit eb9c332ab1
3 changed files with 3851 additions and 48 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
using System.Text;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -6,27 +6,54 @@ using UnityEngine.SceneManagement;
public class StatsMenu : MonoBehaviour
{
[SerializeField] private TMP_Text statText;
[SerializeField] private GameObject panel;
[SerializeField] private TMP_Text normalBerryStat;
[SerializeField] private TMP_Text poisonBerryStat;
[SerializeField] private TMP_Text slowBerryStat;
[SerializeField] private TMP_Text ultraBerryStat;
[SerializeField] private TMP_Text speedyBerryStat;
[SerializeField] private TMP_Text coinBerryStat;
[SerializeField] private TMP_Text randomBerryStat;
[SerializeField] private TMP_Text antiBerryStat;
[SerializeField] private TMP_Text coinStat;
[SerializeField] private TMP_Text xpUsernameText;
[SerializeField] private TMP_Text xpText;
[SerializeField] private TMP_Text xpLevelText;
[SerializeField] private RectTransform progressFilledRect;
void Start()
{
var text = new StringBuilder();
text.AppendLine("High Score: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreHighScore()));
text.AppendLine("Total Normal Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalNormalBerries()));
text.AppendLine("Total Poison Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalPoisonBerries()));
text.AppendLine("Total Slow Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSlowBerries()));
text.AppendLine("Total Ultra Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalUltraBerries()));
text.AppendLine("Total Speedy Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSpeedyBerries()));
text.AppendLine("Total Coin Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalCoinBerries()));
text.AppendLine("Total Random Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalRandomBerries()));
text.AppendLine("Total Anti Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalAntiBerries()));
text.AppendLine("Total Coins: " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance));
text.AppendLine("Total Attempts: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalAttepts()));
statText.text = text.ToString();
normalBerryStat.text = BazookaManager.Instance.GetGameStoreTotalNormalBerries().ToString();
poisonBerryStat.text = BazookaManager.Instance.GetGameStoreTotalPoisonBerries().ToString();
slowBerryStat.text = BazookaManager.Instance.GetGameStoreTotalSlowBerries().ToString();
ultraBerryStat.text = BazookaManager.Instance.GetGameStoreTotalUltraBerries().ToString();
speedyBerryStat.text = BazookaManager.Instance.GetGameStoreTotalSpeedyBerries().ToString();
coinBerryStat.text = BazookaManager.Instance.GetGameStoreTotalCoinBerries().ToString();
randomBerryStat.text = BazookaManager.Instance.GetGameStoreTotalRandomBerries().ToString();
antiBerryStat.text = BazookaManager.Instance.GetGameStoreTotalAntiBerries().ToString();
coinStat.text = BazookaManager.Instance.GetCustomBirdIconData().Balance.ToString();
var (_, level, currentXpInLevel, totalXpForLevel, percentDone) = Tools.GetLevelInfo();
xpUsernameText.text = BazookaManager.Instance.GetAccountName() ?? "";
xpText.text = currentXpInLevel.ToString() + "/" + totalXpForLevel.ToString() + " xp";
xpLevelText.text = "Level " + level.ToString();
SetXPProgressFilled((int)percentDone);
Tools.RefreshHierarchy(panel);
}
async void Update()
{
if (Keyboard.current.escapeKey.wasPressedThisFrame) await SceneManager.LoadSceneAsync("MainMenu");
}
void SetXPProgressFilled(int progress)
{
int newProgress = Math.Clamp(progress, 0, 100);
progressFilledRect.sizeDelta = new Vector2(newProgress * 3, progressFilledRect.sizeDelta.y);
progressFilledRect.anchoredPosition = new Vector2((newProgress * 3 - 300f) * 0.5f, progressFilledRect.anchoredPosition.y);
}
}

View File

@@ -77,4 +77,32 @@ public static class Tools
return sb.ToString();
}
public static (BigInteger totalXp, double level, BigInteger currentXpInLevel, BigInteger totalXpForLevel, double percentDone) GetLevelInfo()
{
BigInteger totalXp = 0;
totalXp += BazookaManager.Instance.GetGameStoreTotalNormalBerries();
totalXp -= BazookaManager.Instance.GetGameStoreTotalPoisonBerries();
totalXp -= BazookaManager.Instance.GetGameStoreTotalSlowBerries();
totalXp += BazookaManager.Instance.GetGameStoreTotalUltraBerries() * 5;
totalXp += BazookaManager.Instance.GetGameStoreTotalSpeedyBerries() * 10;
totalXp += BazookaManager.Instance.GetGameStoreTotalCoinBerries() * 10;
if (totalXp < 0) totalXp = 0;
double discriminant = 95 * 95 + 20.0 * (double)totalXp;
double level = (-95 + Math.Sqrt(discriminant)) / 10.0;
double flooredLevel = Math.Floor(level);
BigInteger xpAtStartOfLevel = (BigInteger)(5 * flooredLevel * flooredLevel + 95 * flooredLevel);
double nextLevel = flooredLevel + 1;
BigInteger xpAtNextLevel = (BigInteger)(5 * nextLevel * nextLevel + 95 * nextLevel);
BigInteger totalXpForLevel = xpAtNextLevel - xpAtStartOfLevel;
BigInteger currentXpInLevel = totalXp - xpAtStartOfLevel;
double percentDone = (double)currentXpInLevel / (double)totalXpForLevel * 100.0;
return (totalXp, flooredLevel, currentXpInLevel, totalXpForLevel, percentDone);
}
}