view = PATH::VIEW . "report_skillup.php"; $this->parse_filters(); $s = $this->build_query(); $q = $db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->units, new Unit($r["id"])); } $this->title = "Urgent skill-ups - SWDB"; $this->description = "Monster in need of skilling up"; $this->canonical = URL::BASE . "report/skillups"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ $this->filters = FILTER::SKILLUP; if (isset($_GET["min_stars"]) && intval($_GET["min_stars"]) > 0 && intval($_GET["min_stars"]) < 7){ $this->filters["MIN_STARS"] = $_GET["min_stars"]; } if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) < 7){ $this->filters["MAX_STARS"] = $_GET["max_stars"]; } if (isset($_GET["min_natural_stars"]) && intval($_GET["min_natural_stars"]) > 0 && intval($_GET["min_natural_stars"]) < 6){ $this->filters["MIN_NATURAL_STARS"] = $_GET["min_natural_stars"]; } if (isset($_GET["max_natural_stars"]) && intval($_GET["max_natural_stars"]) > 0 && intval($_GET["max_natural_stars"]) < 6){ $this->filters["MAX_NATURAL_STARS"] = $_GET["max_natural_stars"]; } if (isset($_GET["in_storage"]) && $_GET["in_storage"] == "on"){ $this->filters["IN_STORAGE"] = true; } if (isset($_GET["without_runes"]) && $_GET["without_runes"] == "on"){ $this->filters["WITHOUT_RUNES"] = true; } if (isset($_GET["family"]) && $_GET["family"] == "on"){ $this->filters["FAMILY"] = true; } if (isset($_GET["maxed"]) && $_GET["maxed"] == "on"){ $this->filters["MAXED"] = true; } if (isset($_GET["2a"]) && $_GET["2a"] == "on"){ $this->filters["2A"] = true; } if (isset($_GET["homunculus"]) && $_GET["homunculus"] == "on"){ $this->filters["HOMUNCULUS"] = true; } return; } /** * Builds the query to the rune table using the selected or default * filters. * * @return string The query to be executed. * @global int Player ID. */ private function build_query(){ global $UID; $s = " SELECT DISTINCT unit.id AS id, sum(unit_skill.level * (CAST(k_skill.slot + 1 AS FLOAT) / 2.0)) AS ponderated_lvl, sum(unit_skill.level) AS lvl, sum(k_skill.max_level * (CAST(k_skill.slot + 1 AS FLOAT) / 2.0)) AS ponderated_max_lvl, sum(k_skill.max_level) AS max_lvl FROM unit, k_unit, unit_skill, k_unit_skill, k_skill WHERE unit.uid = '$UID' AND unit.unit = k_unit.id AND unit_skill.unit = unit.id AND --unit_skill.skill = k_unit_skill.skill AND k_unit.id = k_unit_skill.unit AND k_skill.id = k_unit_skill.skill AND k_skill.max_level > 1 AND unit.stars >= " . $this->filters["MIN_STARS"] . " AND unit.stars <= " . $this->filters["MAX_STARS"] ; if ($this->filters["2A"]){ $s = $s . " AND (( k_unit.natural_stars >= " . $this->filters["MIN_NATURAL_STARS"] . " AND k_unit.natural_stars <= " . $this->filters["MAX_NATURAL_STARS"] . " ) OR ( k_unit.base_stars - k_unit.natural_stars > 1 )) "; } else{ $s = $s . " AND k_unit.natural_stars >= " . $this->filters["MIN_NATURAL_STARS"] . " AND k_unit.natural_stars <= " . $this->filters["MAX_NATURAL_STARS"] ; } if (!$this->filters["IN_STORAGE"]){ $s = $s . " AND unit.building <> " . BUILDING_ID::MONSTER_STORAGE; } if (!$this->filters["WITHOUT_RUNES"]){ $s = $s . " AND unit.id IN (SELECT DISTINCT assigned_to FROM rune) "; } if (!$this->filters["FAMILY"]){ $s = $s . " AND unit.unit NOT IN (SELECT id FROM k_unit m WHERE family IN (SELECT family FROM k_unit k WHERE k.family = m.family AND k.natural_stars < m.natural_stars AND k.natural_stars < " . $this->filters["MIN_NATURAL_STARS"] . ")) "; // Special case: Eirgar (Dark Vampire lord). Nat5 can be powered with 4 star Vampires. if ($this->filters["MIN_NATURAL_STARS"] >= 5){ $s = $s . " AND k_unit.id <> 19114 AND k_unit.id <> 19104 "; } // Special case: Fran (Light Fairy Queen). Nat3 can be powered with 2 star Fairies. if ($this->filters["MIN_NATURAL_STARS"] >= 3){ $s = $s . " AND k_unit.id <> 23015 AND k_unit.id <> 23005 "; } } if (!$this->filters["HOMUNCULUS"]){ $s = $s . " AND k_unit.homunculus <> 1 "; } $s = $s . "GROUP BY unit.id "; if (!$this->filters["MAXED"]){ $s = $s . " HAVING ponderated_lvl < ponderated_max_lvl "; } $s = $s . " ORDER BY CAST(ponderated_lvl AS FLOAT) / CAST(ponderated_max_lvl AS FLOAT), unit.stars DESC, unit.level DESC, CAST(lvl AS FLOAT) / CAST(max_lvl AS FLOAT), max_lvl - lvl DESC; "; return $s; } } ?>