Unit.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. class Unit():
  15. """
  16. A unit.
  17. Parameters
  18. ----------
  19. id : str
  20. Unit identifier.
  21. name : str
  22. Unit name. For Homunculus, the given name.
  23. stars : int
  24. Unit grade,from 1 to 6.
  25. level : int
  26. Unit level, from 1 to 40.
  27. in_storage : bool
  28. Indicates if the unit is in storage
  29. base_stats : StatSet
  30. Unit base stats, without runes, artifacts or bonus towers.
  31. stats : StatSet
  32. Unit base stats, with runes but without artifacts or bonus towers.
  33. has_runes : bool
  34. Indicates if the unit has any runes equiped.
  35. team_ids : str[]
  36. List of IDs of the team the unit is on.
  37. in_teams : bool
  38. Indicates if the unit is in any team.
  39. priority : int
  40. Unit priority.
  41. Methods
  42. -------
  43. populateUnitList(event)
  44. Populates the unit list.
  45. goToOptimizer(event)
  46. Prepares the optimizer panel with the selected unit and redirects.
  47. unitSelected(event)
  48. Loads a unit info.
  49. processResults(jsonData)
  50. Processes data obtained from RuneOptimizer.
  51. """
  52. _id = None
  53. _name = ""
  54. _stars = 1
  55. _level = 1
  56. _in_storage = False
  57. _base_stats = StatSet()
  58. _stats = StatSet()
  59. _runes = [None, None, None, None, None, None]
  60. _has_runes = False
  61. _teams = []
  62. _in_teams = False
  63. _priority = 0
  64. def __init__(self, id=None):
  65. if id != None:
  66. self._load(id)
  67. def _load(self, id):
  68. cursor = conn.execute("""
  69. SELECT
  70. id, -- 0
  71. name,
  72. stars,
  73. level,
  74. storage,
  75. base_hp, -- 5
  76. base_atk,
  77. base_def,
  78. base_spd,
  79. base_crr,
  80. base_crd, -- 10
  81. base_res,
  82. base_acc,
  83. current_hp,
  84. current_atk,
  85. current_def, --15
  86. current_spd,
  87. current_crr,
  88. current_crd,
  89. current_res,
  90. current_acc --20
  91. FROM units
  92. WHERE
  93. id = ?;
  94. """, (id,))
  95. row = cursor.fetchone()
  96. if row != None:
  97. self._base_stats = StatSet()
  98. self._stats = StatSet()
  99. self._id = str(row[0])
  100. self._name = str(row[1])
  101. self._stars = int(row[2])
  102. self._level = int(row[3])
  103. if int(row[4]) == 1:
  104. self._storage = True
  105. else:
  106. self._storage = False
  107. self._base_stats.hp = int(row[5])
  108. #print("BASE HP FOR " + self._name + ": " + str(self._base_stats.hp))
  109. self._base_stats.atk = int(row[6])
  110. self._base_stats.dfc = int(row[7])
  111. self._base_stats.spd = int(row[8])
  112. self._base_stats.crr = int(row[9])
  113. self._base_stats.crd = int(row[10])
  114. self._base_stats.res = int(row[11])
  115. self._base_stats.acc = int(row[12])
  116. self._stats.hp = int(row[13])
  117. self._stats.atk = int(row[14])
  118. self._stats.dfc = int(row[15])
  119. self._stats.spd = int(row[16])
  120. self._stats.crr = int(row[17])
  121. self._stats.crd = int(row[18])
  122. self._stats.res = int(row[19])
  123. self._stats.acc = int(row[20])
  124. # Get runes
  125. self._runes = [None, None, None, None, None, None]
  126. cursor = conn.execute(
  127. "SELECT id, slot FROM runes WHERE unit = ?", (self._id,)
  128. )
  129. rows = cursor.fetchall()
  130. for row in rows:
  131. self._runes[int(row[1]) - 1] = Rune(str(row[0]))
  132. self._has_runes = True
  133. # Get teams
  134. self._teams = []
  135. cursor = conn.execute(
  136. "SELECT DISTINCT team FROM units_teams WHERE unit = ?",
  137. (self._id,)
  138. )
  139. rows = cursor.fetchall()
  140. for row in rows:
  141. team = UnitTeam(str(row[0]))
  142. self._priority += team.priority
  143. self._teams.append(team)
  144. self._in_teams = True
  145. @property
  146. def id(self):
  147. return self._id
  148. @property
  149. def name(self):
  150. return self._name
  151. @property
  152. def stars(self):
  153. return self._stars
  154. @property
  155. def level(self):
  156. return self._level
  157. @property
  158. def in_storage(self):
  159. return self._in_storage
  160. @property
  161. def base_stats(self):
  162. return self._base_stats
  163. @property
  164. def stats(self):
  165. return self._stats
  166. @property
  167. def runes(self):
  168. return self._runes
  169. @property
  170. def has_runes(self):
  171. return self._has_runes
  172. @property
  173. def teams(self):
  174. return self._teams
  175. @property
  176. def in_teams(self):
  177. return self._in_teams
  178. @property
  179. def priority(self):
  180. return self._priority