0, "def" => 0, "hp" => 0, "spd" => 0, "crd" => 0, "elm" => [ 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0 ] ]; /** * @var int[] Stats gained by artifacts. */ public $artifact_stats = [ "atk" => 0, "def" => 0, "hp" => 0 ]; /** * Constructor. * * Retrieves the data and initializes the variables. * * @param string $id Selected unit id */ public function __construct($id){ $this->view = PATH::VIEW . "optimizer_unit.php"; $this->unit = new Unit($id); $this->calculate_buildings(); $this->calculate_artifacts(); $this->title = "Optimize " . $this->unit->unit->name . " - SWDB"; $this->description = "Optimize " . $this->unit->unit->name; $this->canonical = URL::BASE . "optmizer/$id"; } /** * Calculates the stats gained from bulding upgrades and populates the * $building_stats array. * * @gobal int User ID. * @global resource Database connection. */ private function calculate_buildings(){ global $UID; global $db; $s = " SELECT affected_stat, bonus, element FROM k_decoration, k_decoration_level, decoration WHERE decoration.uid = '$UID' AND k_decoration.id = decoration.decoration AND decoration.decoration = k_decoration_level.decoration AND decoration.level = k_decoration_level.level AND area = " . EFFECT_AREA_ID::GENERAL . " AND affected_stat IN (" . STAT_ID::ATK . ", " . STAT_ID::DEF . ", " . STAT_ID::HP . ", " . STAT_ID::SPD . ", " . STAT_ID::CRIT_DMG . "); "; $q = $db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ switch($r["affected_stat"]){ case STAT_ID::DEF: $this->building_stats["def"] += $r["bonus"]; break; case STAT_ID::HP: $this->building_stats["hp"] += $r["bonus"]; break; case STAT_ID::SPD: $this->building_stats["spd"] += $r["bonus"]; break; case STAT_ID::CRIT_DMG: $this->building_stats["crd"] += $r["bonus"]; break; case STAT_ID::ATK: if(strlen($r["element"]) > 0){ $this->building_stats["elm"][$r["element"]] += $r["bonus"]; } else{ $this->building_stats["atk"] += $r["bonus"]; } break; } } } private function calculate_artifacts(){ if ($this->unit->artifact_type != null){ switch ($this->unit->artifact_type->main_stat){ case ARTIFACT_STAT_ID::HP: $this->artifact_stats["hp"] += $this->unit->artifact_type->main_stat_value; break; case ARTIFACT_STAT_ID::DEF: $this->artifact_stats["def"] += $this->unit->artifact_type->main_stat_value; break; case ARTIFACT_STAT_ID::ATK: $this->artifact_stats["atk"] += $this->unit->artifact_type->main_stat_value; break; } } if ($this->unit->artifact_element != null){ switch ($this->unit->artifact_element->main_stat){ case ARTIFACT_STAT_ID::HP: $this->artifact_stats["hp"] += $this->unit->artifact_element->main_stat_value; break; case ARTIFACT_STAT_ID::DEF: $this->artifact_stats["def"] += $this->unit->artifact_element->main_stat_value; break; case ARTIFACT_STAT_ID::ATK: $this->artifact_stats["atk"] += $this->unit->artifact_element->main_stat_value; break; } } } } ?>