Improve code
This commit is contained in:
@@ -80,53 +80,14 @@ 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;
|
||||||
|
|
||||||
if (normalBerry > 0)
|
if (normalBerry > 0) NormalizeOne(normalBerryChance, normalBerry, divideBy, difference);
|
||||||
{
|
if (poisonBerry > 0) NormalizeOne(poisonBerryChance, poisonBerry, divideBy, difference);
|
||||||
normalBerryChance.text = (normalBerry - (difference / divideBy)).ToString() + "%";
|
if (slowBerry > 0) NormalizeOne(slowBerryChance, slowBerry, divideBy, difference);
|
||||||
normalBerryChance.stringPosition = normalBerryChance.text.Length;
|
if (ultraBerry > 0) NormalizeOne(ultraBerryChance, ultraBerry, divideBy, difference);
|
||||||
}
|
if (speedyBerry > 0) NormalizeOne(speedyBerryChance, speedyBerry, divideBy, difference);
|
||||||
|
if (randomBerry > 0) NormalizeOne(randomBerryChance, randomBerry, divideBy, difference);
|
||||||
if (poisonBerry > 0)
|
if (antiBerry > 0) NormalizeOne(antiBerryChance, antiBerry, divideBy, difference);
|
||||||
{
|
if (nothingBerry > 0) NormalizeOne(nothingBerryChance, nothingBerry, divideBy, difference);
|
||||||
poisonBerryChance.text = (poisonBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
poisonBerryChance.stringPosition = poisonBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slowBerry > 0)
|
|
||||||
{
|
|
||||||
slowBerryChance.text = (slowBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
slowBerryChance.stringPosition = slowBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ultraBerry > 0)
|
|
||||||
{
|
|
||||||
ultraBerryChance.text = (ultraBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
ultraBerryChance.stringPosition = ultraBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (speedyBerry > 0)
|
|
||||||
{
|
|
||||||
speedyBerryChance.text = (speedyBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
speedyBerryChance.stringPosition = speedyBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (randomBerry > 0)
|
|
||||||
{
|
|
||||||
randomBerryChance.text = (randomBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
randomBerryChance.stringPosition = randomBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (antiBerry > 0)
|
|
||||||
{
|
|
||||||
antiBerryChance.text = (antiBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
antiBerryChance.stringPosition = antiBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nothingBerry > 0)
|
|
||||||
{
|
|
||||||
nothingBerryChance.text = (nothingBerry - (difference / divideBy)).ToString() + "%";
|
|
||||||
nothingBerryChance.stringPosition = nothingBerryChance.text.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
normalBerry = GetValueFrom(normalBerryChance);
|
normalBerry = GetValueFrom(normalBerryChance);
|
||||||
poisonBerry = GetValueFrom(poisonBerryChance);
|
poisonBerry = GetValueFrom(poisonBerryChance);
|
||||||
@@ -137,181 +98,59 @@ public class PlayMenu : MonoBehaviour
|
|||||||
antiBerry = GetValueFrom(antiBerryChance);
|
antiBerry = GetValueFrom(antiBerryChance);
|
||||||
nothingBerry = GetValueFrom(nothingBerryChance);
|
nothingBerry = GetValueFrom(nothingBerryChance);
|
||||||
|
|
||||||
if (normalBerry > 0)
|
if (normalBerry > 0) normalBerry = (float)Math.Floor(normalBerry);
|
||||||
{
|
if (poisonBerry > 0) poisonBerry = (float)Math.Floor(poisonBerry);
|
||||||
normalBerry = (float)Math.Floor(normalBerry);
|
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 (poisonBerry > 0)
|
if (randomBerry > 0) randomBerry = (float)Math.Floor(randomBerry);
|
||||||
{
|
if (antiBerry > 0) antiBerry = (float)Math.Floor(antiBerry);
|
||||||
poisonBerry = (float)Math.Floor(poisonBerry);
|
if (nothingBerry > 0) nothingBerry = (float)Math.Floor(nothingBerry);
|
||||||
}
|
|
||||||
|
|
||||||
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 addedChances2 = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry;
|
||||||
float difference2 = addedChances2 - 100f;
|
float difference2 = addedChances2 - 100f;
|
||||||
bool fixedValues = false;
|
bool fixedValues = false;
|
||||||
|
|
||||||
Debug.Log(difference2);
|
|
||||||
Debug.Log(normalBerry - difference2);
|
|
||||||
Debug.Log(poisonBerry - difference2);
|
|
||||||
|
|
||||||
if (normalBerry > 0)
|
if (normalBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(normalBerryChance, fixedValues, normalBerry, difference2);
|
||||||
{
|
|
||||||
normalBerryChance.text = (normalBerry - difference2).ToString() + "%";
|
|
||||||
normalBerryChance.stringPosition = normalBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
normalBerryChance.text = normalBerry.ToString() + "%";
|
|
||||||
normalBerryChance.stringPosition = normalBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (poisonBerry > 0)
|
if (poisonBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(poisonBerryChance, fixedValues, poisonBerry, difference2);
|
||||||
{
|
|
||||||
poisonBerryChance.text = (poisonBerry - difference2).ToString() + "%";
|
|
||||||
poisonBerryChance.stringPosition = poisonBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
poisonBerryChance.text = poisonBerry.ToString() + "%";
|
|
||||||
poisonBerryChance.stringPosition = poisonBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slowBerry > 0)
|
if (slowBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(slowBerryChance, fixedValues, slowBerry, difference2);
|
||||||
{
|
|
||||||
slowBerryChance.text = (slowBerry - difference2).ToString() + "%";
|
|
||||||
slowBerryChance.stringPosition = slowBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
slowBerryChance.text = slowBerry.ToString() + "%";
|
|
||||||
slowBerryChance.stringPosition = slowBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ultraBerry > 0)
|
if (ultraBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(ultraBerryChance, fixedValues, ultraBerry, difference2);
|
||||||
{
|
|
||||||
ultraBerryChance.text = (ultraBerry - difference2).ToString() + "%";
|
|
||||||
ultraBerryChance.stringPosition = ultraBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ultraBerryChance.text = ultraBerry.ToString() + "%";
|
|
||||||
ultraBerryChance.stringPosition = ultraBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (speedyBerry > 0)
|
if (speedyBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(speedyBerryChance, fixedValues, speedyBerry, difference2);
|
||||||
{
|
|
||||||
speedyBerryChance.text = (speedyBerry - difference2).ToString() + "%";
|
|
||||||
speedyBerryChance.stringPosition = speedyBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
speedyBerryChance.text = speedyBerry.ToString() + "%";
|
|
||||||
speedyBerryChance.stringPosition = speedyBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (randomBerry > 0)
|
if (randomBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(randomBerryChance, fixedValues, randomBerry, difference2);
|
||||||
{
|
|
||||||
randomBerryChance.text = (randomBerry - difference2).ToString() + "%";
|
|
||||||
randomBerryChance.stringPosition = randomBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
randomBerryChance.text = randomBerry.ToString() + "%";
|
|
||||||
randomBerryChance.stringPosition = randomBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (antiBerry > 0)
|
if (antiBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(antiBerryChance, fixedValues, antiBerry, difference2);
|
||||||
{
|
|
||||||
antiBerryChance.text = (antiBerry - difference2).ToString() + "%";
|
|
||||||
antiBerryChance.stringPosition = antiBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
antiBerryChance.text = antiBerry.ToString() + "%";
|
|
||||||
antiBerryChance.stringPosition = antiBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nothingBerry > 0)
|
if (nothingBerry > 0)
|
||||||
{
|
{
|
||||||
if (!fixedValues)
|
NormalizeTwo(nothingBerryChance, fixedValues, nothingBerry, difference2);
|
||||||
{
|
|
||||||
nothingBerryChance.text = (nothingBerry - difference2).ToString() + "%";
|
|
||||||
nothingBerryChance.stringPosition = nothingBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
nothingBerryChance.text = nothingBerry.ToString() + "%";
|
|
||||||
nothingBerryChance.stringPosition = nothingBerryChance.text.Length;
|
|
||||||
fixedValues = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidateTotal();
|
ValidateTotal();
|
||||||
});
|
});
|
||||||
@@ -413,4 +252,24 @@ public class PlayMenu : MonoBehaviour
|
|||||||
inputField.text = value + "%";
|
inputField.text = value + "%";
|
||||||
ValidateTotal();
|
ValidateTotal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NormalizeOne(TMP_InputField inputField, float berryChance, int divideBy, float difference)
|
||||||
|
{
|
||||||
|
inputField.text = (berryChance - (difference / divideBy)).ToString() + "%";
|
||||||
|
inputField.stringPosition = inputField.text.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NormalizeTwo(TMP_InputField inputField, bool fixedValues, float berryChance, float difference2)
|
||||||
|
{
|
||||||
|
if (!fixedValues)
|
||||||
|
{
|
||||||
|
inputField.text = (berryChance - difference2).ToString() + "%";
|
||||||
|
inputField.stringPosition = inputField.text.Length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inputField.text = berryChance.ToString() + "%";
|
||||||
|
inputField.stringPosition = inputField.text.Length;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user