I’m prototyping an RPG engine and every time the XP gets up to the point it would break an Int it still breaks.
Also, as a side note, I can’t get it to display the numbers with commas. Did that change in 6?
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEditor.Rendering;
public class LevelMenu : MonoBehaviour
{
public long
totalLevelXPCost,
strengthXPCost,
agilityXPCost,
intelligenceXPCost,
willpowerXPCost,
levelXPCost;
public int
strengthLevel,
agilityLevel,
intelligenceLevel,
willpowerLevel,
totalLevel,
totalXP,
hp,
sp,
mp,
poise,
recovery,
movement,
attack,
awareness,
equipCarry,
skillCarry,
slashRes,
bashRes,
pierceRes,
bleedRes,
poisonRes,
diseaseRes,
fireRes,
iceRes,
lightningRes,
arcaneRes,
lightRes,
darkRes;
public TextMeshProUGUI
strengthText,
agilityText,
intelligenceText,
willpowerText,
strengthXPCostText,
agilityXPCostText,
intelligenceXPCostText,
willpowerXPCostText,
totalLevelText,
totalXPText;
private void Start()
{
}
public void LevelUpStrength()
{
strengthLevel += 1;
strengthText.text = strengthLevel.ToString();
UpdateCharacterSheet();
}
public void LevelDownStrength()
{
if (strengthLevel > 0) strengthLevel -= 1;
UpdateCharacterSheet();
}
public void LevelUpAgility()
{
agilityLevel += 1;
UpdateCharacterSheet();
}
public void LevelDownAgility()
{
if (agilityLevel > 0) agilityLevel -= 1;
UpdateCharacterSheet();
}
public void LevelUpIntelligence()
{
intelligenceLevel += 1;
UpdateCharacterSheet();
}
public void LevelDownIntelligence()
{
if (intelligenceLevel > 0) intelligenceLevel -= 1;
UpdateCharacterSheet();
}
public void LevelUpWillpower()
{
willpowerLevel += 1;
UpdateCharacterSheet();
}
public void LevelDownWillpower()
{
if (willpowerLevel > 0) willpowerLevel -= 1;
UpdateCharacterSheet();
}
public void UpdateCharacterSheet()
{
totalLevel = strengthLevel + agilityLevel + intelligenceLevel + willpowerLevel;
levelXPCost = CalcLevelXP();
//Calculate XP Cost
strengthXPCost = CalcAtributeXP(strengthLevel);
agilityXPCost = CalcAtributeXP(agilityLevel);
intelligenceXPCost = CalcAtributeXP(intelligenceLevel);
willpowerXPCost = CalcAtributeXP(willpowerLevel);
//Update UI
strengthText.text = strengthLevel.ToString();
agilityText.text = agilityLevel.ToString();
intelligenceText.text = intelligenceLevel.ToString();
willpowerText.text = willpowerLevel.ToString();
strengthXPCostText.text = strengthXPCost.ToString() + " XP";
agilityXPCostText.text = agilityXPCost.ToString() + " XP";
intelligenceXPCostText.text = intelligenceXPCost.ToString() + " XP";
willpowerXPCostText.text = willpowerXPCost.ToString() + " XP";
totalLevelText.text = "Level : " + totalLevel.ToString();
totalXPText.text = "Total XP : " + totalXP.ToString();
}
long CalcAtributeXP(int atr)
{
long xp = 100;
for (int i = 0; i < atr; i++)
{
xp = Mathf.RoundToInt(xp * 1.1f);
}
xp -= 100;
xp += levelXPCost;
return xp;
}
long CalcLevelXP()
{
long xp = 100;
for (int i = 0; i < totalLevel; i++)
{
xp = Mathf.RoundToInt(xp * 1.05f);
}
return xp;
}
}