| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Monster.php");
- /**
- * Monster view page.
- */
- class Monster_Page extends Page{
- /**
- * Selected @{see Monster}.
- */
- public $monsters;
- /**
- * Stats gained by building.
- */
- public $building_stats = [
- "atk" => 0,
- "def" => 0,
- "hp" => 0,
- "spd" => 0,
- "crd" => 0,
- "elm" => [
- "Fire" => 0,
- "Water" => 0,
- "Wind" => 0,
- "Light" => 0,
- "Dark" => 0
- ]
- ];
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @param SQLite3 $db Connection to the database.
- * @param string $id Monster id
- */
- public function __construct($db, $id){
- global $path;
- global $root;
- parent::__construct($db);
- $this->view = $path["view"] . "monster.php";
- $this->calculate_buildings();
- $this->monster = new Monster($db, $id);
- $this->title = $this->monster->monster->name ." - SWDB";
- $this->description = "Owned " . $this->monster->monster->name;
- $this->canonical = $root . "monster/" . $id;
- }
- /**
- * Calculates the stats gained from bulding upgrades and populates the
- * $building_stats array.
- */
- private function calculate_buildings(){
- $s =
- "SELECT " .
- " affected_stat, " .
- " bonus, " .
- " element " .
- "FROM " .
- " k_building, " .
- " k_building_level, " .
- " building " .
- "WHERE " .
- " k_building.id = building.building AND " .
- " building.building = k_building_level.building AND " .
- " building.level = k_building_level.level AND " .
- " area = 'Everywhere' AND " .
- " affected_stat IN ('ATK', 'DEF', 'HP', 'SPD', 'CRI Dmg');";
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- switch($r["affected_stat"]){
- case "DEF":
- $this->building_stats["def"] += $r["bonus"];
- break;
- case "HP":
- $this->building_stats["hp"] += $r["bonus"];
- break;
- case "SPD":
- $this->building_stats["spd"] += $r["bonus"];
- break;
- case "CRI Dmg":
- $this->building_stats["crd"] += $r["bonus"];
- break;
- case "ATK":
- if(strlen($r["element"]) > 0){
- $this->building_stats["elm"][$r["element"]] += $r["bonus"];
- }
- else{
- $this->building_stats["atk"] += $r["bonus"];
- }
- break;
- }
- }
- }
- }
- ?>
|