MonsterRarityData.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. public struct MonsterRarityProfile
  5. {
  6. public double HpMultiplier;
  7. public double DefenseMultiplier;
  8. public double DamageMultiplier;
  9. public double ExpMultiplier;
  10. public double GoldMultiplier;
  11. public int ItemDropBonusPercent;
  12. public int GoldDropBonusPercent;
  13. public Color NameColour;
  14. }
  15. public static class MonsterRarityData
  16. {
  17. private static bool Enabled = true;
  18. private static readonly Dictionary<MonsterType, MonsterRarityProfile> Profiles = new()
  19. {
  20. [MonsterType.Normal] = new MonsterRarityProfile
  21. {
  22. HpMultiplier = 1.00,
  23. DefenseMultiplier = 1.00,
  24. DamageMultiplier = 1.00,
  25. ExpMultiplier = 1.00,
  26. GoldMultiplier = 1.00,
  27. ItemDropBonusPercent = 0,
  28. GoldDropBonusPercent = 0,
  29. NameColour = Color.White
  30. },
  31. [MonsterType.Uncommon] = new MonsterRarityProfile
  32. {
  33. HpMultiplier = 1.25,
  34. DefenseMultiplier = 1.15,
  35. DamageMultiplier = 1.15,
  36. ExpMultiplier = 1.20,
  37. GoldMultiplier = 1.25,
  38. ItemDropBonusPercent = 15,
  39. GoldDropBonusPercent = 15,
  40. NameColour = Color.LightGreen
  41. },
  42. [MonsterType.Rare] = new MonsterRarityProfile
  43. {
  44. HpMultiplier = 1.60,
  45. DefenseMultiplier = 1.30,
  46. DamageMultiplier = 1.35,
  47. ExpMultiplier = 1.60,
  48. GoldMultiplier = 1.75,
  49. ItemDropBonusPercent = 35,
  50. GoldDropBonusPercent = 35,
  51. NameColour = Color.DeepSkyBlue
  52. },
  53. [MonsterType.Elite] = new MonsterRarityProfile
  54. {
  55. HpMultiplier = 2.25,
  56. DefenseMultiplier = 1.55,
  57. DamageMultiplier = 1.65,
  58. ExpMultiplier = 2.20,
  59. GoldMultiplier = 2.50,
  60. ItemDropBonusPercent = 75,
  61. GoldDropBonusPercent = 75,
  62. NameColour = Color.Gold
  63. }
  64. };
  65. private static double EliteChancePercent = 0.1;
  66. private static double RareChancePercent = 0.75;
  67. private static double UncommonChancePercent = 3.0;
  68. public static void Configure(double uncommonChancePercent, double rareChancePercent, double eliteChancePercent)
  69. {
  70. UncommonChancePercent = ClampPercent(uncommonChancePercent);
  71. RareChancePercent = ClampPercent(rareChancePercent);
  72. EliteChancePercent = ClampPercent(eliteChancePercent);
  73. }
  74. public static void ConfigureProfile(MonsterType type, MonsterRarityProfile profile)
  75. {
  76. Profiles[type] = profile;
  77. }
  78. public static void ConfigureProfiles(IDictionary<MonsterType, MonsterRarityProfile> overrides)
  79. {
  80. if (overrides == null) return;
  81. foreach (var pair in overrides)
  82. Profiles[pair.Key] = pair.Value;
  83. }
  84. public static void SetEnabled(bool enabled)
  85. {
  86. Enabled = enabled;
  87. }
  88. public static MonsterRarityProfile GetProfile(MonsterType type)
  89. {
  90. return Profiles.TryGetValue(type, out var profile) ? profile : Profiles[MonsterType.Normal];
  91. }
  92. public static MonsterType Roll(Random random)
  93. {
  94. if (!Enabled)
  95. return MonsterType.Normal;
  96. if (random == null) random = new Random();
  97. int roll = random.Next(10000);
  98. int eliteChanceBp = PercentToBasisPoints(EliteChancePercent);
  99. int rareChanceBp = PercentToBasisPoints(RareChancePercent);
  100. int uncommonChanceBp = PercentToBasisPoints(UncommonChancePercent);
  101. if (roll < eliteChanceBp)
  102. return MonsterType.Elite;
  103. if (roll < eliteChanceBp + rareChanceBp)
  104. return MonsterType.Rare;
  105. if (roll < eliteChanceBp + rareChanceBp + uncommonChanceBp)
  106. return MonsterType.Uncommon;
  107. return MonsterType.Normal;
  108. }
  109. private static int PercentToBasisPoints(double percent)
  110. {
  111. return (int)Math.Round(ClampPercent(percent) * 100d, MidpointRounding.AwayFromZero);
  112. }
  113. private static double ClampPercent(double percent)
  114. {
  115. if (percent < 0) return 0;
  116. if (percent > 100) return 100;
  117. return percent;
  118. }
  119. }