Stat.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. public sealed class Stats : IEquatable<Stats>
  2. {
  3. public SortedDictionary<Stat, int> Values { get; set; } = new SortedDictionary<Stat, int>();
  4. public int Count => Values.Sum(pair => Math.Abs(pair.Value));
  5. public int this[Stat stat]
  6. {
  7. get
  8. {
  9. return !Values.TryGetValue(stat, out int result) ? 0 : result;
  10. }
  11. set
  12. {
  13. if (value == 0)
  14. {
  15. if (Values.ContainsKey(stat))
  16. {
  17. Values.Remove(stat);
  18. }
  19. return;
  20. }
  21. Values[stat] = value;
  22. }
  23. }
  24. public Stats() { }
  25. public Stats(Stats stats)
  26. {
  27. foreach (KeyValuePair<Stat, int> pair in stats.Values)
  28. this[pair.Key] += pair.Value;
  29. }
  30. public Stats(BinaryReader reader, int version = int.MaxValue, int customVersion = int.MaxValue)
  31. {
  32. int count = reader.ReadInt32();
  33. for (int i = 0; i < count; i++)
  34. Values[(Stat)reader.ReadByte()] = reader.ReadInt32();
  35. }
  36. public void Add(Stats stats)
  37. {
  38. foreach (KeyValuePair<Stat, int> pair in stats.Values)
  39. this[pair.Key] += pair.Value;
  40. }
  41. public void Save(BinaryWriter writer)
  42. {
  43. writer.Write(Values.Count);
  44. foreach (KeyValuePair<Stat, int> pair in Values)
  45. {
  46. writer.Write((byte)pair.Key);
  47. writer.Write(pair.Value);
  48. }
  49. }
  50. public void Clear()
  51. {
  52. Values.Clear();
  53. }
  54. public bool Equals(Stats other)
  55. {
  56. if (Values.Count != other.Values.Count) return false;
  57. foreach (KeyValuePair<Stat, int> value in Values)
  58. if (other[value.Key] != value.Value) return false;
  59. return true;
  60. }
  61. }
  62. public enum StatFormula : byte
  63. {
  64. Health,
  65. Mana,
  66. Weight,
  67. Stat
  68. }
  69. public enum Stat : byte
  70. {
  71. MinAC = 0,
  72. MaxAC = 1,
  73. MinMAC = 2,
  74. MaxMAC = 3,
  75. MinDC = 4,
  76. MaxDC = 5,
  77. MinMC = 6,
  78. MaxMC = 7,
  79. MinSC = 8,
  80. MaxSC = 9,
  81. Accuracy = 10,
  82. Agility = 11,
  83. HP = 12,
  84. MP = 13,
  85. AttackSpeed = 14,
  86. Luck = 15,
  87. BagWeight = 16,
  88. HandWeight = 17,
  89. WearWeight = 18,
  90. Reflect = 19,
  91. Strong = 20,
  92. Holy = 21,
  93. Freezing = 22,
  94. PoisonAttack = 23,
  95. MagicResist = 30,
  96. PoisonResist = 31,
  97. HealthRecovery = 32,
  98. SpellRecovery = 33,
  99. PoisonRecovery = 34, //TODO - Should this be in seconds or milliseconds??
  100. CriticalRate = 35,
  101. CriticalDamage = 36,
  102. MaxACRatePercent = 40,
  103. MaxMACRatePercent = 41,
  104. MaxDCRatePercent = 42,
  105. MaxMCRatePercent = 43,
  106. MaxSCRatePercent = 44,
  107. AttackSpeedRatePercent = 45,
  108. HPRatePercent = 46,
  109. MPRatePercent = 47,
  110. HPDrainRatePercent = 48,
  111. ExpRatePercent = 100,
  112. ItemDropRatePercent = 101,
  113. GoldDropRatePercent = 102,
  114. MineRatePercent = 103,
  115. GemRatePercent = 104,
  116. FishRatePercent = 105,
  117. CraftRatePercent = 106,
  118. SkillGainMultiplier = 107,
  119. AttackBonus = 108,
  120. LoverExpRatePercent = 120,
  121. MentorDamageRatePercent = 121,
  122. MentorExpRatePercent = 123,
  123. DamageReductionPercent = 124,
  124. EnergyShieldPercent = 125,
  125. EnergyShieldHPGain = 126,
  126. ManaPenaltyPercent = 127,
  127. TeleportManaPenaltyPercent = 128,
  128. Hero = 129,
  129. Unknown = 255
  130. }