* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::PAGE . "Page.php"); require_once(PATH::ENTITY . "Monster.php"); /** * Monster details page model. * * @category Page */ class Monster_Page extends Page{ /** * @var Monster[] Selected unit array. * * [0]: Unawakened monster (null if default purple). * [1]: Awakened monster (null if silver). * [2]: Second awakened monster (null if unavailaable). */ private $monster = []; /** * @var int[] IDs to other units of the family * @todo Implement. */ private $family = []; /** * @var bool Indicates a silver monster. */ private $silver = false; /** * @var bool Indicates a default purple (always awaken) monster. */ private $purple = false; /** * @var bool Indicates a monstes that can second awaken. */ private $red = false; /** * Constructor. * * Retrieves the data and initializes the variables. * * @param int $id Monster id. Can be any of the awakening stages */ public function __construct($id){ parent::__construct(); $this->set_public(true); $this->set_view("monster.php"); $this->set_canonical("monster/" . $id); $this->add_css("monster.css"); $title = ""; $monster = new Monster($id); if ($monster == null || $monster->get_id() == null){ $this->set_code(404); $this->set_message("Monster not found"); } else{ $this->set_code(200); $this->set_message("OK"); } $minimum_id = 0; if (! $monster->can_awaken()){ // Silver star monster. $this->silver = true; $this->monster[0] = $monster; $this->monster[1] = null; $this->monster[2] = null; $title = $this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name(); } elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() == null){ // Default purple (Rainbowmon or King Angelmon) $this->purple = true; $this->monster[0] = null; $this->monster[1] = $monster; $this->monster[2] = null; $minimum_id = 1; $title = $this->monster[1]->get_name(); } elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() != null){ // Normal monster, already awakened, no 2a. $this->monster[0] = new Monster($monster->get_awakens_from()); $this->monster[1] = $monster; $this->monster[2] = null; $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name(); $this->family_id= $this->monster[0]->get_family(); } elseif ($monster->can_awaken() && $monster->get_awakens_to() != null && $monster->get_awakens_from() == null){ // Normal monster, not awakened, may have 2a. $this->monster[0] = $monster; $this->monster[1] = new Monster($this->monster[0]->get_awakens_to()); if ($this->monster[1]->get_awakens_to() == null){ $this->monster[2] = null; } else{ $this->red = true; $this->monster[2] = new Monster($this->monster[1]->get_awakens_to()); } $this->family_id= $this->monster[1]->get_family(); $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name(); } // Load the monster family $statement = get_context()->get_db()->prepare(" SELECT id FROM monster WHERE family = :family AND id <> :id AND awakens_from IS NULL ORDER BY natural_stars DESC, element = :fire DESC, element = :water DESC, element = :wind DESC, element = :light DESC, element = :dark DESC; "); $statement->bindValue(":family", $this->monster[$minimum_id]->get_family(), SQLITE3_INTEGER); $statement->bindValue(":id", $this->monster[$minimum_id]->get_id(), SQLITE3_INTEGER); $statement->bindValue(":fire", ELEMENT_ID::FIRE, SQLITE3_INTEGER); $statement->bindValue(":water", ELEMENT_ID::WATER, SQLITE3_INTEGER); $statement->bindValue(":wind", ELEMENT_ID::WIND, SQLITE3_INTEGER); $statement->bindValue(":light", ELEMENT_ID::LIGHT, SQLITE3_INTEGER); $statement->bindValue(":dark", ELEMENT_ID::DARK, SQLITE3_INTEGER); $result_set = $statement->execute(); while ($result = $result_set->fetchArray(SQLITE3_ASSOC)){ array_push($this->family, new Monster($result["id"])); } $this->set_description(get_context()->get_player()->get_name() . "'s enchantments"); $this->set_title($title); $this->set_description($title . " details"); } /** * Retrieves the monster line to show. * * Index [0]: Unawakened monster (null if default purple). * Index [1]: Awakened monster (null if silver). * Index [2]: Second awakened monster (null if unavailaable). * * @return Monster[] */ public function get_monsters(){ return $this->monster; } /** * Retrieves the monster family. * * @return multitype:number */ public function get_family(){ return $this->family; } /** * Checks if the monster is default silver (non awakeable). * * @return bool True for silver monsters, false otherwise. */ public function is_silver(){ return $this->silver; } /** * Checks if the monster is default purple (always awaken). * * @return bool True for purple monsters, false otherwise. */ public function is_purple(){ return $this->purple; } /** * Checks if the monster can second awaken. * * @return bool True for monsters that can 2A, false otherwise. */ public function can_2a(){ return $this->red; } } ?>