AgentStats.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using UnityEngine;
  2. /// <summary>
  3. /// Holds agent stats and provides utility methods
  4. /// Each stat is 1-100, total pool is (number of stats * 100) / 10 = 40 for 4 stats
  5. /// </summary>
  6. public class AgentStats
  7. {
  8. public int Strength { get; private set; }
  9. public int Speed { get; private set; }
  10. public int Magic { get; private set; }
  11. public int Dexterity { get; private set; }
  12. public int Intelligence { get; private set; }
  13. public int Constitution { get; private set; }
  14. /// <summary>
  15. /// Health is derived from Constitution: 10 + Constitution (range: 11–110)
  16. /// </summary>
  17. public int Health => 10 + Constitution;
  18. private const int STAT_TOTAL_POOL = 60; // (6 stats * 100) / 10
  19. private const int NUM_STATS = 6;
  20. private const int MAX_STAT_VALUE = 100;
  21. private const int MIN_STAT_VALUE = 1;
  22. public AgentStats()
  23. {
  24. GenerateRandomStats();
  25. }
  26. /// <summary>
  27. /// Generates random stats by creating 4 random values and shuffling them
  28. /// This ensures all stats get a fair distribution
  29. /// </summary>
  30. private void GenerateRandomStats()
  31. {
  32. int[] stats = new int[NUM_STATS];
  33. // Generate 4 random values between 1 and 100
  34. for (int i = 0; i < NUM_STATS; i++)
  35. {
  36. stats[i] = Random.Range(MIN_STAT_VALUE, MAX_STAT_VALUE + 1);
  37. }
  38. // Shuffle the stats array to randomly assign values
  39. for (int i = NUM_STATS - 1; i > 0; i--)
  40. {
  41. int randomIndex = Random.Range(0, i + 1);
  42. // Swap
  43. int temp = stats[i];
  44. stats[i] = stats[randomIndex];
  45. stats[randomIndex] = temp;
  46. }
  47. Strength = stats[0];
  48. Speed = stats[1];
  49. Magic = stats[2];
  50. Dexterity = stats[3];
  51. Intelligence = stats[4];
  52. Constitution = stats[5];
  53. // Normalize to fit within pool
  54. NormalizeStats();
  55. }
  56. /// <summary>
  57. /// Normalizes stats to roughly fit within the STAT_TOTAL_POOL
  58. /// </summary>
  59. private void NormalizeStats()
  60. {
  61. int total = Strength + Speed + Magic + Dexterity + Intelligence;
  62. if (total > STAT_TOTAL_POOL)
  63. {
  64. float scale = (float)STAT_TOTAL_POOL / total;
  65. Strength = Mathf.Max(MIN_STAT_VALUE, (int)(Strength * scale));
  66. Speed = Mathf.Max(MIN_STAT_VALUE, (int)(Speed * scale));
  67. Magic = Mathf.Max(MIN_STAT_VALUE, (int)(Magic * scale));
  68. Dexterity = Mathf.Max(MIN_STAT_VALUE, (int)(Dexterity * scale));
  69. Intelligence = Mathf.Max(MIN_STAT_VALUE, (int)(Intelligence * scale));
  70. Constitution = Mathf.Max(MIN_STAT_VALUE, (int)(Constitution * scale));
  71. }
  72. }
  73. public int GetTotalStats()
  74. {
  75. return Strength + Speed + Magic + Dexterity + Intelligence + Constitution;
  76. }
  77. /// <summary>
  78. /// 0-1 chance to consider joining a group instead of going solo.
  79. /// Higher intelligence = more willing to team up strategically.
  80. /// </summary>
  81. public float GroupUpAffinity => Intelligence / 100f;
  82. /// <summary>
  83. /// 0-1 risk tolerance when evaluating fights or dangerous rooms.
  84. /// High intelligence = lower tolerance (more cautious).
  85. /// </summary>
  86. public float RiskTolerance => 1f - (Intelligence / 100f);
  87. public override string ToString()
  88. {
  89. return $"STR: {Strength} | SPD: {Speed} | MAG: {Magic} | DEX: {Dexterity} | INT: {Intelligence} | CON: {Constitution} | Total: {GetTotalStats()}";
  90. }
  91. }