AgentStats.cs 3.3 KB

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