Made it work a bit better

if the amount of berries that are above 0 is an odd amount then it
doesnt work but this is the closest I have gotten to it working.
This commit is contained in:
2025-10-06 20:29:47 -07:00
parent f1043effbb
commit 546858b576

View File

@@ -78,136 +78,53 @@ public class PlayMenu : MonoBehaviour
float addedChances = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry; float addedChances = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry;
float difference = addedChances - 100f; float difference = addedChances - 100f;
float remainingDifference = difference;
int remainingCount = divideBy;
int sumAssigned = 0;
if (normalBerry > 0) if (normalBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; normalBerryChance.text = (normalBerry - (difference / divideBy)).ToString() + "%";
float newVal = normalBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
normalBerryChance.text = displayVal.ToString().Replace("%", "");
normalBerryChance.stringPosition = normalBerryChance.text.Length; normalBerryChance.stringPosition = normalBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (poisonBerry > 0) if (poisonBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; poisonBerryChance.text = (poisonBerry - (difference / divideBy)).ToString() + "%";
float newVal = poisonBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
poisonBerryChance.text = displayVal.ToString().Replace("%", "");
poisonBerryChance.stringPosition = poisonBerryChance.text.Length; poisonBerryChance.stringPosition = poisonBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (slowBerry > 0) if (slowBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; slowBerryChance.text = (slowBerry - (difference / divideBy)).ToString() + "%";
float newVal = slowBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
slowBerryChance.text = displayVal.ToString().Replace("%", "");
slowBerryChance.stringPosition = slowBerryChance.text.Length; slowBerryChance.stringPosition = slowBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (ultraBerry > 0) if (ultraBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; ultraBerryChance.text = (ultraBerry - (difference / divideBy)).ToString() + "%";
float newVal = ultraBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
ultraBerryChance.text = displayVal.ToString().Replace("%", "");
ultraBerryChance.stringPosition = ultraBerryChance.text.Length; ultraBerryChance.stringPosition = ultraBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (speedyBerry > 0) if (speedyBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; speedyBerryChance.text = (speedyBerry - (difference / divideBy)).ToString() + "%";
float newVal = speedyBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
speedyBerryChance.text = displayVal.ToString().Replace("%", "");
speedyBerryChance.stringPosition = speedyBerryChance.text.Length; speedyBerryChance.stringPosition = speedyBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (randomBerry > 0) if (randomBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; randomBerryChance.text = (randomBerry - (difference / divideBy)).ToString() + "%";
float newVal = randomBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
randomBerryChance.text = displayVal.ToString().Replace("%", "");
randomBerryChance.stringPosition = randomBerryChance.text.Length; randomBerryChance.stringPosition = randomBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (antiBerry > 0) if (antiBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; antiBerryChance.text = (antiBerry - (difference / divideBy)).ToString() + "%";
float newVal = antiBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
antiBerryChance.text = displayVal.ToString().Replace("%", "");
antiBerryChance.stringPosition = antiBerryChance.text.Length; antiBerryChance.stringPosition = antiBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
if (nothingBerry > 0) if (nothingBerry > 0)
{ {
float adjust = remainingCount > 0 ? (remainingDifference / remainingCount) : 0f; nothingBerryChance.text = (nothingBerry - (difference / divideBy)).ToString() + "%";
float newVal = nothingBerry - adjust;
int displayVal;
if (remainingCount == 1)
displayVal = 100 - sumAssigned;
else
displayVal = (int)System.Math.Round(newVal);
nothingBerryChance.text = displayVal.ToString().Replace("%", "");
nothingBerryChance.stringPosition = nothingBerryChance.text.Length; nothingBerryChance.stringPosition = nothingBerryChance.text.Length;
remainingDifference -= adjust;
remainingCount--;
sumAssigned += displayVal;
} }
ValidateTotal(); ValidateTotal();