Monster_Info_Page.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "K_Monster.php");
  4. /**
  5. * Monster details page.
  6. */
  7. class Monster_Info_Page extends Page{
  8. /**
  9. * Selected @{see Monster}0
  10. * [0]: Unawakened monster (null if default purple).
  11. * [1]: Awakened monster (null if silver).
  12. * [2]: Second awakened monster (null if unavailaable).
  13. */
  14. public $monster = [];
  15. /**
  16. * IDs to other monsters of thef family
  17. */
  18. public $family = [
  19. "Fire" => null,
  20. "Water" => null,
  21. "Wind" => null,
  22. "Light" => null,
  23. "Dark" => null,
  24. ];
  25. /**
  26. * Constructor.
  27. *
  28. * Retrieves the data and initializes the variables.
  29. *
  30. * @param SQLite3 $db Connection to the database.
  31. * @param string $id Monster id. Can be any of the awakening stages
  32. */
  33. public function __construct($db, $id){
  34. global $path;
  35. global $root;
  36. parent::__construct($db);
  37. $this->view = $path["view"] . "monster_info.php";
  38. $title = "";
  39. $monster = new K_Monster($db, $id);
  40. if ($monster->can_awaken == 0){
  41. // Silver star monster.
  42. $this->monster[0] = $monster;
  43. $this->monster[1] = null;
  44. $this->monster[2] = null;
  45. $title = $this->monster[0]->element . " " . $this->monster[0]->name;
  46. }
  47. elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from == ""){
  48. // Default purple (Rainbowmon or King Angelmon)
  49. $this->monster[0] = null;
  50. $this->monster[1] = $monster;
  51. $this->monster[2] = null;
  52. $title = $this->monster[1]->name;
  53. }
  54. elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && strlen($monster->awakens_from) > 0){
  55. // Normal monster, already awakened, no 2a.
  56. $this->monster[0] = new K_Monster($db, $monster->awakens_from);
  57. $this->monster[1] = $monster;
  58. $this->monster[2] = null;
  59. $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
  60. $monster = $this->monster[0];
  61. }
  62. elseif ($monster->can_awaken == 1 && strlen($monster->awakens_to) > 0 && $monster->awakens_from == ""){
  63. // Normal monster, not awakened, may have 2a.
  64. $this->monster[0] = $monster;
  65. $this->monster[1] = new K_Monster($db, $this->monster[0]->awakens_to);
  66. if ($this->monster[1]->awakens_to == ""){
  67. $this->monster[2] = null;
  68. }
  69. else{
  70. $this->monster[2] = new K_Monster($db, $this->monster[1]->awakens_to);
  71. }
  72. $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
  73. }
  74. $s =
  75. "SELECT " .
  76. " id, " .
  77. " element " .
  78. "FROM k_monster " .
  79. "WHERE " .
  80. " family_id = " . $monster->family_id . " AND " .
  81. " element <> '" . $monster->element . "';";
  82. $q_mon = $this->db->query($s);
  83. while ($r = $q_mon->fetchArray(SQLITE3_ASSOC)){
  84. $this->family[$r["element"]] = $r["id"];
  85. }
  86. $this->title = $title ." - SWDB";
  87. $this->description = $title . " info - SWDB";
  88. $this->canonical = $root . "monster_info/" . $id;
  89. }
  90. }
  91. ?>