diff --git a/Assets/Scripts/PlayMenu.cs b/Assets/Scripts/PlayMenu.cs index a60036a..39b8adc 100644 --- a/Assets/Scripts/PlayMenu.cs +++ b/Assets/Scripts/PlayMenu.cs @@ -1,3 +1,4 @@ +using System; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; @@ -127,6 +128,191 @@ public class PlayMenu : MonoBehaviour nothingBerryChance.stringPosition = nothingBerryChance.text.Length; } + normalBerry = GetValueFrom(normalBerryChance); + poisonBerry = GetValueFrom(poisonBerryChance); + slowBerry = GetValueFrom(slowBerryChance); + ultraBerry = GetValueFrom(ultraBerryChance); + speedyBerry = GetValueFrom(speedyBerryChance); + randomBerry = GetValueFrom(randomBerryChance); + antiBerry = GetValueFrom(antiBerryChance); + nothingBerry = GetValueFrom(nothingBerryChance); + + if (normalBerry > 0) + { + normalBerry = (float)Math.Floor(normalBerry); + } + + if (poisonBerry > 0) + { + poisonBerry = (float)Math.Floor(poisonBerry); + } + + if (slowBerry > 0) + { + slowBerry = (float)Math.Floor(slowBerry); + } + + if (ultraBerry > 0) + { + ultraBerry = (float)Math.Floor(ultraBerry); + } + + if (speedyBerry > 0) + { + speedyBerry = (float)Math.Floor(speedyBerry); + } + + if (randomBerry > 0) + { + randomBerry = (float)Math.Floor(randomBerry); + } + + if (antiBerry > 0) + { + antiBerry = (float)Math.Floor(antiBerry); + } + + if (nothingBerry > 0) + { + nothingBerry = (float)Math.Floor(nothingBerry); + } + + float addedChances2 = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry; + float difference2 = addedChances2 - 100f; + bool fixedValues = false; + + Debug.Log(difference2); + Debug.Log(normalBerry - difference2); + Debug.Log(poisonBerry - difference2); + + if (normalBerry > 0) + { + if (!fixedValues) + { + normalBerryChance.text = (normalBerry - difference2).ToString() + "%"; + normalBerryChance.stringPosition = normalBerryChance.text.Length; + fixedValues = true; + } + else + { + normalBerryChance.text = normalBerry.ToString() + "%"; + normalBerryChance.stringPosition = normalBerryChance.text.Length; + fixedValues = true; + } + } + + if (poisonBerry > 0) + { + if (!fixedValues) + { + poisonBerryChance.text = (poisonBerry - difference2).ToString() + "%"; + poisonBerryChance.stringPosition = poisonBerryChance.text.Length; + fixedValues = true; + } + else + { + poisonBerryChance.text = poisonBerry.ToString() + "%"; + poisonBerryChance.stringPosition = poisonBerryChance.text.Length; + fixedValues = true; + } + } + + if (slowBerry > 0) + { + if (!fixedValues) + { + slowBerryChance.text = (slowBerry - difference2).ToString() + "%"; + slowBerryChance.stringPosition = slowBerryChance.text.Length; + fixedValues = true; + } + else + { + slowBerryChance.text = slowBerry.ToString() + "%"; + slowBerryChance.stringPosition = slowBerryChance.text.Length; + fixedValues = true; + } + } + + if (ultraBerry > 0) + { + if (!fixedValues) + { + ultraBerryChance.text = (ultraBerry - difference2).ToString() + "%"; + ultraBerryChance.stringPosition = ultraBerryChance.text.Length; + fixedValues = true; + } + else + { + ultraBerryChance.text = ultraBerry.ToString() + "%"; + ultraBerryChance.stringPosition = ultraBerryChance.text.Length; + fixedValues = true; + } + } + + if (speedyBerry > 0) + { + if (!fixedValues) + { + speedyBerryChance.text = (speedyBerry - difference2).ToString() + "%"; + speedyBerryChance.stringPosition = speedyBerryChance.text.Length; + fixedValues = true; + } + else + { + speedyBerryChance.text = speedyBerry.ToString() + "%"; + speedyBerryChance.stringPosition = speedyBerryChance.text.Length; + fixedValues = true; + } + } + + if (randomBerry > 0) + { + if (!fixedValues) + { + randomBerryChance.text = (randomBerry - difference2).ToString() + "%"; + randomBerryChance.stringPosition = randomBerryChance.text.Length; + fixedValues = true; + } + else + { + randomBerryChance.text = randomBerry.ToString() + "%"; + randomBerryChance.stringPosition = randomBerryChance.text.Length; + fixedValues = true; + } + } + + if (antiBerry > 0) + { + if (!fixedValues) + { + antiBerryChance.text = (antiBerry - difference2).ToString() + "%"; + antiBerryChance.stringPosition = antiBerryChance.text.Length; + fixedValues = true; + } + else + { + antiBerryChance.text = antiBerry.ToString() + "%"; + antiBerryChance.stringPosition = antiBerryChance.text.Length; + fixedValues = true; + } + } + + if (nothingBerry > 0) + { + if (!fixedValues) + { + nothingBerryChance.text = (nothingBerry - difference2).ToString() + "%"; + nothingBerryChance.stringPosition = nothingBerryChance.text.Length; + fixedValues = true; + } + else + { + nothingBerryChance.text = nothingBerry.ToString() + "%"; + nothingBerryChance.stringPosition = nothingBerryChance.text.Length; + fixedValues = true; + } + } + ValidateTotal(); }); customPlayButton.onClick.AddListener(async () =>