| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Monster.php");
- /**
- * Urgent Skillup report page.
- */
- class Report_Skillup_Page extends Page{
- /**
- * Array of @{see Monsters}s.
- */
- public $monsters = [];
- /**
- * The filters the page can handle.
- */
- public $filters = [
- "min_stars" => 5,
- "max_stars" => 6,
- "min_natural_stars" => 5,
- "max_natural_stars" => 5,
- "in_storage" => false,
- "without_runes" => false,
- "family" => false,
- "maxed" => false,
- "2a" => false
- ];
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @param SQLite3 $db Connection to the database.
- */
- public function __construct($db){
- global $path;
- global $root;
- parent::__construct($db);
- $this->view = $path["view"] . "report_skillup.php";
- $this->parse_filters();
- $s_mon = $this->build_query();
- error_log($s_mon);
- $q_mon = $this->db->query($s_mon);
- while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
- array_push($this->monsters, new Monster($db, $r_mon["id"]));
- }
- $this->title = "Urgent skill-ups - SWDB";
- $this->description = "Monster in need os skilling up";
- $this->canonical = $root . "report/skillups";
- }
- /**
- * Parses the request looking for the selected filters, validates them
- * and adds them to the $filters array.
- */
- private function parse_filters(){
- 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;
- }
- return;
- }
- /**
- * Builds the query to the rune table using the selected or default
- * filters.
- *
- * @return The query to be executed.
- */
- private function build_query(){
- $s =
- "SELECT DISTINCT " .
- " monster.id AS id, " .
- " sum( " .
- " CASE k_skill.slot " .
- " WHEN 1 THEN (monster.skill_1_level - 1) * 1 " .
- " WHEN 2 THEN (monster.skill_2_level - 1) * 1.5 " .
- " WHEN 3 THEN (monster.skill_3_level - 1) * 2 " .
- " WHEN 4 THEN (monster.skill_4_level - 1) * 2.5 " .
- " END " .
- " ) AS ponderated_level, " .
- " sum( " .
- " CASE k_skill.slot " .
- " WHEN 1 THEN (monster.skill_1_level - 1) " .
- " WHEN 2 THEN (monster.skill_2_level - 1) " .
- " WHEN 3 THEN (monster.skill_3_level - 1) " .
- " WHEN 4 THEN (monster.skill_4_level - 1) " .
- " END " .
- " ) AS level, " .
- " sum( " .
- " CASE k_skill.slot " .
- " WHEN 1 THEN (k_skill.max_level - 1) * 1 " .
- " WHEN 2 THEN (k_skill.max_level - 1) * 1.5 " .
- " WHEN 3 THEN (k_skill.max_level - 1) * 2 " .
- " WHEN 4 THEN (k_skill.max_level - 1) * 2.5 " .
- " END " .
- " ) AS ponderated_max_level, " .
- " sum( " .
- " CASE k_skill.slot " .
- " WHEN 1 THEN (k_skill.max_level - 1) " .
- " WHEN 2 THEN (k_skill.max_level - 1) " .
- " WHEN 3 THEN (k_skill.max_level - 1) " .
- " WHEN 4 THEN (k_skill.max_level - 1) " .
- " END " .
- " ) AS max_level " .
- "FROM " .
- " monster, " .
- " k_monster_skill, " .
- " k_skill, " .
- " k_monster " .
- "WHERE " .
- " monster.monster = k_monster_skill.monster AND " .
- " k_skill.id = k_monster_skill.skill AND " .
- " k_monster.id = monster.monster AND " .
- " k_skill.max_level > 1 AND " .
- " monster.stars >= " . $this->filters["min_stars"] . " AND " .
- " monster.stars <= " . $this->filters["max_stars"] . " AND " .
- " k_monster.natural_stars >= " . $this->filters["min_natural_stars"] . " AND " .
- " k_monster.natural_stars <= " . $this->filters["max_natural_stars"] . " ";
- if (!$this->filters["in_storage"]){
- $s = $s . " AND monster.in_storage = 0 ";
- }
- if (!$this->filters["without_runes"]){
- $s = $s . " AND monster.id IN (SELECT DISTINCT monster FROM monster_rune) ";
- }
- if ($this->filters["family"]){
- $s = $s . " AND monster.monster NOT IN (SELECT id FROM k_monster m WHERE family_id IN (SELECT family_id FROM k_monster k WHERE k.family_id = m.family_id 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_monster.id <> 1279 AND k_monster.id <> 1280 ";
- }
- // 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_monster.id <> 417 AND k_monster.id <> 418 ";
- }
- }
- if (!$this->filters["2a"]){
- $s = $s . " AND (k_monster.awakens_from IS NULL OR k_monster.awakens_to IS NOT NULL OR k_monster.base_stars - k_monster.natural_stars = 1) ";
- }
- $s = $s .
- "GROUP BY monster.id ";
- if (!$this->filters["maxed"]){
- $s = $s . " HAVING ponderated_level < ponderated_max_level ";
- }
- $s = $s .
- "ORDER BY " .
- " ponderated_level * 100 / ponderated_max_level, " .
- " monster.stars DESC, " .
- " monster.level DESC, " .
- " level * 100 / max_level, " .
- " max_level - level DESC; ";
- return $s;
- }
- }
- ?>
|