AgentStats.cs 3.1 KB

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