0, "def" => 0, "hp" => 0, "spd" => 0, "crd" => 0, "elm" => [ 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 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->unit = new Unit($db, $id); $this->title = $this->unit->unit->name ." - SWDB"; $this->description = "Owned " . $this->unit->unit->name; $this->canonical = $root . "monster/" . $id; } /** * Calculates the stats gained from bulding upgrades and populates the * $building_stats array. */ private function calculate_buildings(){ global $EFFECT_AREA; $s = "SELECT " . " affected_stat, " . " bonus, " . " element " . "FROM " . " k_decoration, " . " k_decoration_level, " . " decoration " . "WHERE " . " k_decoration.id = decoration.decoration AND " . " decoration.decoration = k_decoration_level.decoration AND " . " decoration.level = k_decoration_level.level AND " . " area = " . $EFFECT_AREA["GENERAL"] . " AND " . " affected_stat IS NOT NULL;"; $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; } } } } ?>