StatSet.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. """
  2. This file is part of RuneOptimizer.
  3. RuneOptimizer is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation, either version 3 of the License, or (at your option)
  6. any later version.
  7. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  13. """
  14. import math
  15. class StatSet():
  16. """
  17. A set of stats.
  18. It can be used as a set of stats a unit has in any given moment. Compound
  19. stats EHP and DMG can't be set manually and are calculated as the stats
  20. they depend on are set. Values are validated on setting and capped
  21. automatically.
  22. Note that the value caps don't take into acount material monsters, which
  23. have uniquely low stats. But if you are optimizing your Angelmon runes, I
  24. can't help you.
  25. Parameters
  26. ----------
  27. hp : int
  28. Health points (HP) stat. Always equal or greater than 15.
  29. atk : int
  30. Attack stat. Always equal or greater than 1.
  31. dfc : int
  32. Defense stat. Always equal or greater than 1.
  33. spd : int
  34. Speed stat. Always equal or greater than 1.
  35. crr : int
  36. Critical rate stat. Between 15 and 100, both included.
  37. crd : int
  38. Critical damage stat. Always equal or greater than 50.
  39. res : int
  40. Resistance stat. Always equal or greater than 15.
  41. acc : int
  42. Accuracy stat. Between 0 and 85, both included.
  43. ehp : int
  44. Effective HP stat. Depends on HP and DEF. Always equal or greater than 1.
  45. dmg : int
  46. Damage stat. Depends on ATK, CRR and CRD. Always equal or greater than 1.
  47. """
  48. _hp = 0
  49. _atk = 0
  50. _dfc = 0
  51. _spd = 0
  52. _crr = 0
  53. _crd = 0
  54. _res = 0
  55. _acc = 0
  56. _ehp = 0
  57. _dmg = 0
  58. def __init__(self):
  59. pass
  60. @property
  61. def hp(self):
  62. return self._hp
  63. @hp.setter
  64. def hp(self, value):
  65. value = int(value)
  66. if value < 1:
  67. value = 1;
  68. self._hp = value
  69. self._calculate_ehp()
  70. @property
  71. def atk(self):
  72. return self._atk
  73. @atk.setter
  74. def atk(self, value):
  75. value = int(value)
  76. if value < 1:
  77. value = 1;
  78. self._atk = value
  79. self._calculate_dmg()
  80. @property
  81. def dfc(self):
  82. return self._dfc
  83. @dfc.setter
  84. def dfc(self, value):
  85. value = int(value)
  86. if value < 1:
  87. value = 1;
  88. self._dfc = value
  89. self._calculate_ehp()
  90. @property
  91. def spd(self):
  92. return self._spd
  93. @spd.setter
  94. def spd(self, value):
  95. value = int(value)
  96. if value < 1:
  97. value = 1;
  98. self._spd = value
  99. @property
  100. def crr(self):
  101. return self._crr
  102. @crr.setter
  103. def crr(self, value):
  104. value = int(value)
  105. if value < 15:
  106. value = 15;
  107. if value > 100:
  108. value = 100
  109. self._crr = value
  110. self._calculate_dmg()
  111. @property
  112. def crd(self):
  113. return self._crd
  114. @crd.setter
  115. def crd(self, value):
  116. value = int(value)
  117. if value < 50:
  118. value = 50;
  119. self._crd = value
  120. self._calculate_dmg()
  121. @property
  122. def res(self):
  123. return self._res
  124. @res.setter
  125. def res(self, value):
  126. value = int(value)
  127. if value < 15:
  128. value = 15;
  129. if value > 100:
  130. value = 100
  131. self._res = value
  132. @property
  133. def acc(self):
  134. return self._acc
  135. @acc.setter
  136. def acc(self, value):
  137. value = int(value)
  138. if value < 15:
  139. value = 15;
  140. if value > 85:
  141. value = 85
  142. self._acc = value
  143. @property
  144. def ehp(self):
  145. return self._ehp
  146. @property
  147. def dmg(self):
  148. return self._dmg
  149. def _calculate_ehp(self):
  150. """
  151. Recalculates _ehp.
  152. Uses _dfc and _hp, and it is called from automatically from their
  153. setters.
  154. """
  155. self._ehp = math.ceil((((self._dfc * 3.5) + 1140) * self._hp) / 1000)
  156. def _calculate_dmg(self):
  157. """
  158. Recalculates _dmg.
  159. Uses _atk, _crr and _crd, and it is called from automatically from
  160. their setters.
  161. """
  162. self._dmg = math.ceil( #Non-crit + crit
  163. (self._atk * (100 - self._crr) / 100) +
  164. (self._atk * ( self._crr / 100) * (self._crd + 100) / 100)
  165. )
  166. def values(self):
  167. """
  168. Gets all stats as an array.
  169. The order is: HP, ATK, DFC, SPD, CRR, CRD, RES, ACC, EHP, DMG
  170. """
  171. return [
  172. self._hp, self._atk, self._dfc, self._spd, self._crr,
  173. self._crd, self._res, self._acc, self._ehp, self._dmg
  174. ]