Monster_Page.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Monster details page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::PAGE . "Page.php");
  12. require_once(PATH::ENTITY . "Monster.php");
  13. /**
  14. * Monster details page model.
  15. *
  16. * @category Page
  17. */
  18. class Monster_Page extends Page{
  19. /**
  20. * @var Monster[] Selected unit array.
  21. *
  22. * [0]: Unawakened monster (null if default purple).
  23. * [1]: Awakened monster (null if silver).
  24. * [2]: Second awakened monster (null if unavailaable).
  25. */
  26. private $monster = [];
  27. /**
  28. * @var int[] IDs to other units of the family
  29. * @todo Implement.
  30. */
  31. private $family = [];
  32. /**
  33. * @var bool Indicates a silver monster.
  34. */
  35. private $silver = false;
  36. /**
  37. * @var bool Indicates a default purple (always awaken) monster.
  38. */
  39. private $purple = false;
  40. /**
  41. * @var bool Indicates a monstes that can second awaken.
  42. */
  43. private $red = false;
  44. /**
  45. * Constructor.
  46. *
  47. * Retrieves the data and initializes the variables.
  48. *
  49. * @param int $id Monster id. Can be any of the awakening stages
  50. */
  51. public function __construct($id){
  52. $this->view = PATH::VIEW . "monster.php";
  53. $title = "";
  54. $monster = new Monster($id);
  55. if (! $monster->can_awaken()){
  56. // Silver star monster.
  57. $this->silver = true;
  58. $this->monster[0] = $monster;
  59. $this->monster[1] = null;
  60. $this->monster[2] = null;
  61. $title = $this->monster[0]->element_name . " " . $this->monster[0]->name;
  62. }
  63. elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() == null){
  64. // Default purple (Rainbowmon or King Angelmon)
  65. $this->purple = true;
  66. $this->monster[0] = null;
  67. $this->monster[1] = $monster;
  68. $this->monster[2] = null;
  69. $title = $this->monster[1]->name;
  70. }
  71. elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() != null){
  72. // Normal monster, already awakened, no 2a.
  73. $this->monster[0] = new Monster($monster->get_awakens_from());
  74. $this->monster[1] = $monster;
  75. $this->monster[2] = null;
  76. $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name();
  77. $monster = $this->monster[0];
  78. }
  79. elseif ($monster->can_awaken() && $monster->get_awakens_to() != null && $monster->get_awakens_from() == null){
  80. // Normal monster, not awakened, may have 2a.
  81. $this->monster[0] = $monster;
  82. $this->monster[1] = new Monster($this->monster[0]->get_awakens_to());
  83. if ($this->monster[1]->get_awakens_to() == null){
  84. $this->monster[2] = null;
  85. }
  86. else{
  87. $this->red = true;
  88. $this->monster[2] = new Monster($this->monster[1]->get_awakens_to());
  89. }
  90. $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name();
  91. }
  92. $this->title = $title ." - SWDB";
  93. $this->description = $title . " info - SWDB";
  94. $this->canonical = URL::BASE . "monster_info/" . $id;
  95. }
  96. /**
  97. * Retrieves the monster line to show.
  98. *
  99. * Index [0]: Unawakened monster (null if default purple).
  100. * Index [1]: Awakened monster (null if silver).
  101. * Index [2]: Second awakened monster (null if unavailaable).
  102. *
  103. * @return Monster[]
  104. */
  105. public function get_monsters(){
  106. return $this->monster;
  107. }
  108. /**
  109. * Retrieves the monster family.
  110. *
  111. * @return multitype:number
  112. */
  113. public function get_family(){
  114. return $this->family;
  115. }
  116. /**
  117. * Checks if the monster is default silver (non awakeable).
  118. *
  119. * @return bool True for silver monsters, false otherwise.
  120. */
  121. public function is_silver(){
  122. return $this->silver;
  123. }
  124. /**
  125. * Checks if the monster is default purple (always awaken).
  126. *
  127. * @return bool True for purple monsters, false otherwise.
  128. */
  129. public function is_purple(){
  130. return $this->purple;
  131. }
  132. /**
  133. * Checks if the monster can second awaken.
  134. *
  135. * @return bool True for monsters that can 2A, false otherwise.
  136. */
  137. public function can_2a(){
  138. return $this->red;
  139. }
  140. }
  141. ?>