Collection_Portrait_Frame.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. require_once($path["frame"] . "Frame.php");
  3. require_once($path["entity"] . "Monster_Collection.php");
  4. /**
  5. * Collection page model.
  6. */
  7. class Collection_Portrait_Frame extends Frame{
  8. public $id;
  9. public $cur_name;
  10. public $name;
  11. public $name_aw;
  12. public $stars;
  13. public $default_stars;
  14. public $level;
  15. public $max_level;
  16. public $awaken;
  17. public $cur_img;
  18. public $img;
  19. public $img_aw;
  20. public $img_star;
  21. public $element;
  22. public $owned;
  23. public $skill;
  24. public $hp = 0;
  25. public $atk = 0;
  26. public $def = 0;
  27. public $spd = 0;
  28. public $crir = 0;
  29. public $crid = 0;
  30. public $res = 0;
  31. public $acc = 0;
  32. /**
  33. * Owned {@see Monster_Collection} of owned monsters.
  34. */
  35. public $collection;
  36. /**
  37. * Constructor.
  38. *
  39. * Retrieves the data and initializes the variables.
  40. *
  41. * @param SQLite3 $db Connection to the database.
  42. * @param Array $params Parameters array, containig at least 'id'.
  43. */
  44. public function __construct($db, $params){
  45. global $path;
  46. parent::__construct($db);
  47. $this->view = $path["view"] . "frame/portrait.php";
  48. $id = $params["id"];
  49. $s =
  50. "SELECT id " .
  51. "FROM monster_collection " .
  52. "WHERE id = " . $id . "; ";
  53. $q = $this->db->query($s);
  54. $r = $q->fetchArray(SQLITE3_ASSOC);
  55. if ($r){
  56. $this->collection = new Monster_Collection($this->db, $r["id"]);
  57. $this->id = $id;
  58. $this->name = $this->collection->monster->name;
  59. $this->name_aw = $this->collection->monster->name_aw;
  60. $this->stars = $this->collection->stars;
  61. $this->default_stars = $this->collection->monster->stars;
  62. $this->skill = $this->collection->monster->skill;
  63. $this->level = $this->collection->level;
  64. $this->max_level = 10 + (5 * $this->stars);
  65. $this->awaken = $this->collection->awaken;
  66. $this->img = $this->collection->monster->image;
  67. $this->img_aw = $this->collection->monster->image_aw;
  68. $this->element = $this->collection->monster->element;
  69. if ($this->level == 0 || $this->stars == 0){
  70. $this->owned = false;
  71. }
  72. if ($this->awaken == 1){
  73. $this->cur_name = $this->name_aw;
  74. $this->cur_img = $this->img_aw;
  75. $this->img_star = $star_src = $path["img"]["layout"] . "icon/star_aw.png";
  76. }
  77. else{
  78. $this->cur_name = $this->element . " " . $this->name;
  79. $this->cur_img = $this->img;
  80. $this->img_star = $star_src = $path["img"]["layout"] . "icon/star.png";
  81. }
  82. // Get stats
  83. $l = $this->level;
  84. $t = $this->stars;
  85. $i = $this->collection->monster->id;
  86. $w = $this->awaken;
  87. $s =
  88. "SELECT min + (((max - min) / ((stars + 2) * 5)) * ($l + $l / ((stars + 2) * 5))) AS stat " .
  89. "FROM monster_stat " .
  90. "WHERE " .
  91. " monster = $i AND " .
  92. " stars = $t AND " .
  93. " awake = $w AND " .
  94. " stat = 'HP'; ";
  95. error_log($s);
  96. $q = $this->db->query($s);
  97. $r = $q->fetchArray(SQLITE3_ASSOC);
  98. if ($r){
  99. $this->hp = $r["stat"];
  100. }
  101. $s =
  102. "SELECT min + (((max - min) / ((stars + 2) * 5)) * ($l + $l / ((stars + 2) * 5))) AS stat " .
  103. "FROM monster_stat " .
  104. "WHERE " .
  105. " monster = $i AND " .
  106. " stars = $t AND " .
  107. " awake = $w AND " .
  108. " stat = 'ATK'; ";
  109. $q = $this->db->query($s);
  110. $r = $q->fetchArray(SQLITE3_ASSOC);
  111. if ($r){
  112. $this->atk = $r["stat"];
  113. }
  114. $s =
  115. "SELECT min + (((max - min) / ((stars + 2) * 5)) * ($l + $l / ((stars + 2) * 5))) AS stat " .
  116. "FROM monster_stat " .
  117. "WHERE " .
  118. " monster = $i AND " .
  119. " stars = $t AND " .
  120. " awake = $w AND " .
  121. " stat = 'DEF'; ";
  122. $q = $this->db->query($s);
  123. $r = $q->fetchArray(SQLITE3_ASSOC);
  124. if ($r){
  125. $this->def = $r["stat"];
  126. }
  127. $s =
  128. "SELECT min AS stat " .
  129. "FROM monster_stat " .
  130. "WHERE " .
  131. " monster = $i AND " .
  132. " stars = $t AND " .
  133. " awake = $w AND " .
  134. " stat = 'SPD'; ";
  135. $q = $this->db->query($s);
  136. $r = $q->fetchArray(SQLITE3_ASSOC);
  137. if ($r){
  138. $this->spd = $r["stat"];
  139. }
  140. $s =
  141. "SELECT min AS stat " .
  142. "FROM monster_stat " .
  143. "WHERE " .
  144. " monster = $i AND " .
  145. " stars = $t AND " .
  146. " awake = $w AND " .
  147. " stat = 'CRIR'; ";
  148. $q = $this->db->query($s);
  149. $r = $q->fetchArray(SQLITE3_ASSOC);
  150. if ($r){
  151. $this->crir = $r["stat"];
  152. }
  153. $s =
  154. "SELECT min AS stat " .
  155. "FROM monster_stat " .
  156. "WHERE " .
  157. " monster = $i AND " .
  158. " stars = $t AND " .
  159. " awake = $w AND " .
  160. " stat = 'CRID'; ";
  161. $q = $this->db->query($s);
  162. $r = $q->fetchArray(SQLITE3_ASSOC);
  163. if ($r){
  164. $this->crid = $r["stat"];
  165. }
  166. $s =
  167. "SELECT min AS stat " .
  168. "FROM monster_stat " .
  169. "WHERE " .
  170. " monster = $i AND " .
  171. " stars = $t AND " .
  172. " awake = $w AND " .
  173. " stat = 'RES'; ";
  174. $q = $this->db->query($s);
  175. $r = $q->fetchArray(SQLITE3_ASSOC);
  176. if ($r){
  177. $this->res = $r["stat"];
  178. }
  179. $s =
  180. "SELECT min AS stat " .
  181. "FROM monster_stat " .
  182. "WHERE " .
  183. " monster = $i AND " .
  184. " stars = $t AND " .
  185. " awake = $w AND " .
  186. " stat = 'ACC'; ";
  187. $q = $this->db->query($s);
  188. $r = $q->fetchArray(SQLITE3_ASSOC);
  189. if ($r){
  190. $this->acc = $r["stat"];
  191. }
  192. }
  193. }
  194. }
  195. ?>