| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <?php
- /**
- * Upgradeable runes report page file.
- *
- * Provides a class with all the properties and methods to display the page.
- *
- * @category Page
- */
- /**
- * Require dependent files if not present.
- */
- require_once(PATH::PAGE . "Page.php");
- require_once(PATH::ENTITY . "Unit.php");
- require_once(PATH::ENTITY . "Rune.php");
- require_once(PATH::ENTITY . "Enchantment.php");
- /**
- * Upgradeable runes report page model.
- *
- * @category Page
- */
- class Report_Rune_Enchantment_Page extends Page{
- /**
- * @var mixed[] List of available upgrades.
- *
- * Can be described as:
- * $upgrades = [
- * [
- * unit (Unit),
- * upgrade = [
- * [
- * rune (Rune),
- * enchant = [(Enchantment)]
- * ]
- * ]
- * ]
- * ]
- */
- public $upgrades = [];
- /**
- * @var mixed[] Default filter values.
- */
- public $filters = [
- "MONSTER_NAME" => "",
- "MONSTER_MIN_STARS" => 5,
- "MONSTER_MAX_STARS" => 6,
- "MONSTER_IN_STORAGE" => false,
- "RUNE_MIN_STARS" => 5,
- "RUNE_MAX_STARS" => 6,
- "RUNE_MIN_LEVEL" => 0,
- "RUNE_MAX_LEVEL" => 15,
- "RUNE_MIN_QUALITY" => QUALITY_ID::HERO,
- "RUNE_MAX_QUALITY" => QUALITY_ID::LEGEND,
- "RUNE_MIN_ORIGINAL_QUALITY" => QUALITY_ID::HERO,
- "RUNE_MAX_ORIGINAL_QUALITY" => QUALITY_ID::LEGEND,
- "RUNE_MIN_EFFICIENCY" => 0,
- "RUNE_MAX_EFFICIENCY" => 100,
- "RUNE_MIN_MAX_EFFICIENCY" => 0,
- "RUNE_MAX_MAX_EFFICIENCY" => 100,
- "RUNE_SLOT" => [],
- "GRIND" => 1,
- "GRIND_MIN_QUALITY" => QUALITY_ID::RARE,
- "GRIND_STAT" => [
- RUNE_STAT_ID::HP_P,
- RUNE_STAT_ID::ATK_P,
- RUNE_STAT_ID::DEF_P,
- RUNE_STAT_ID::SPD,
- RUNE_STAT_ID::CRD,
- RUNE_STAT_ID::CRR,
- RUNE_STAT_ID::ACC
- ],
- "GEM" => 1,
- "GEM_MIN_QUALITY" => QUALITY_ID::RARE,
- "GEM_STAT_FROM" => [
- RUNE_STAT_ID::HP,
- RUNE_STAT_ID::ATK,
- RUNE_STAT_ID::DEF,
- RUNE_STAT_ID::RES
- ],
- "GEM_STAT_TO" => [
- RUNE_STAT_ID::HP_P,
- RUNE_STAT_ID::ATK_P,
- RUNE_STAT_ID::DEF_P,
- RUNE_STAT_ID::SPD,
- RUNE_STAT_ID::CRD,
- RUNE_STAT_ID::CRR,
- RUNE_STAT_ID::ACC
- ]
- ];
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @global resource Database connection.
- */
- public function __construct(){
- global $db;
- $this->view = PATH::VIEW . "report_rune_enchantment.php";
- $this->parse_filters();
- $s = $this->build_query();
- $q = $db->query($s);
- $prev_monster = "";
- $prev_rune = "";
- $upgrade = null;
- $rupgrade = null;
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- if ($r["unit"] != $prev_monster){
- if ($prev_rune != ""){
- array_push($upgrade["upgrade"], $rupgrade);
- }
- if ($prev_monster != ""){
- array_push($this->upgrades, $upgrade);
- }
- $prev_monster = $r["unit"];
- $prev_rune = "";
- $upgrade = [
- "unit" => new Unit($r["unit"]),
- "upgrade" => [],
- ];
- $rupgrade = [
- "rune" => new Rune($r["rune"]),
- "enchantment" => [],
- ];
- }
- if ($r["rune"] != $prev_rune){
- if ($prev_rune != ""){
- array_push($upgrade["upgrade"], $rupgrade);
- }
- $prev_rune = $r["rune"];
- $rupgrade = [
- "rune" => new Rune($r["rune"]),
- "enchantment" => [],
- ];
- }
- $enchantment= new Enchantment($r["enchantment"]);
- array_push($rupgrade["enchantment"], $enchantment);
- }
- // Last entries
- array_push($upgrade["upgrade"], $rupgrade);
- array_push($this->upgrades, $upgrade);
- $this->title = "Rune enchantment - SWDB";
- $this->description = "Find runes that can be upgraded via enchantments.";
- $this->canonical = URL::BASE . "report/rune_enchantment/";
- }
- /**
- * Parses the filters passed in the request and sets $filters.
- * Filters must be in $_GET, nd the available ones are max_stars (1-6),
- * min_stars (1-6) and in_storage (on/off).
- */
- private function parse_filters(){
- // Monster
- if (isset($_GET["monster_min_stars"]) && intval($_GET["monster_min_stars"]) > 0 && intval($_GET["monster_min_stars"]) < 7){
- $this->filters["MONSTER_MIN_STARS"] = $_GET["monster_min_stars"];
- }
- if (isset($_GET["monster_max_stars"]) && intval($_GET["monster_max_stars"]) > 0 && intval($_GET["monster_max_stars"]) < 7){
- $this->filters["MONSTER_MAX_STARS"] = $_GET["monster_max_stars"];
- }
- if (isset($_GET["monster_in_storage"]) && $_GET["monster_in_storage"] == "on"){
- $this->filters["MONSTER_IN_STORAGE"] = true;
- }
- else{
- $this->filters["MONSTER_IN_STORAGE"] = false;
- }
- if (isset($_GET["monster_name"]) && strlen($_GET["monster_name"]) > 0){
- $this->filters["MONSTER_NAME"] = SQLite3::escapeString($_GET["monster_name"]);
- }
- // Runes
- if (isset($_GET["rune_min_stars"]) && intval($_GET["rune_min_stars"]) > 0 && intval($_GET["rune_min_stars"]) < 7){
- $this->filters["RUNE_MIN_STARS"] = $_GET["rune_min_stars"];
- }
- if (isset($_GET["rune_max_stars"]) && intval($_GET["rune_max_stars"]) > 0 && intval($_GET["rune_max_stars"]) < 7){
- $this->filters["RUNE_MAX_STARS"] = $_GET["rune_max_stars"];
- }
- if (isset($_GET["rune_min_level"]) && intval($_GET["rune_min_level"]) >= 0 && intval($_GET["rune_min_level"]) <= 15){
- $this->filters["RUNE_MIN_LEVEL"] = $_GET["rune_min_level"];
- }
- if (isset($_GET["rune_max_level"]) && intval($_GET["rune_max_level"]) >= 0 && intval($_GET["rune_max_level"]) <= 15){
- $this->filters["RUNE_MAX_LEVEL"] = $_GET["rune_max_level"];
- }
- if (isset($_GET["rune_min_quality"]) && intval($_GET["rune_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_min_quality"]) <= QUALITY_ID::LEGEND){
- $this->filters["RUNE_MIN_QUALITY"] = $_GET["rune_min_quality"];
- }
- if (isset($_GET["rune_max_quality"]) && intval($_GET["rune_max_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_max_quality"]) <= QUALITY_ID::LEGEND){
- $this->filters["RUNE_MAX_QUALITY"] = $_GET["rune_max_quality"];
- }
- if (isset($_GET["rune_min_original_quality"]) && intval($_GET["rune_min_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_min_original_quality"]) <= QUALITY_ID::LEGEND){
- $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] = $_GET["rune_min_original_quality"];
- }
- if (isset($_GET["rune_max_original_quality"]) && intval($_GET["rune_max_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_max_original_quality"]) <= QUALITY_ID::LEGEND){
- $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] = $_GET["rune_max_original_quality"];
- }
- if (isset($_GET["rune_min_efficiency"]) && intval($_GET["rune_min_efficiency"]) >= 0 && intval($_GET["rune_min_efficiency"]) <= 100){
- $this->filters["RUNE_MIN_EFFICIENCY"] = $_GET["rune_min_efficiency"];
- }
- if (isset($_GET["rune_max_efficiency"]) && intval($_GET["rune_max_efficiency"]) >= 0 && intval($_GET["rune_max_efficiency"]) <= 100){
- $this->filters["RUNE_MAX_EFFICIENCY"] = $_GET["rune_max_efficiency"];
- }
- if (isset($_GET["rune_min_max_efficiency"]) && intval($_GET["rune_min_max_efficiency"]) >= 0 && intval($_GET["rune_min_max_efficiency"]) <= 100){
- $this->filters["RUNE_MIN_MAX_EFFICIENCY"] = $_GET["rune_min_max_efficiency"];
- }
- if (isset($_GET["rune_max_max_efficiency"]) && intval($_GET["rune_max_max_efficiency"]) >= 0 && intval($_GET["rune_max_max_efficiency"]) <= 100){
- $this->filters["RUNE_MAX_MAX_EFFICIENCY"] = $_GET["rune_max_max_efficiency"];
- }
- if (isset($_GET["rune_slot"])){
- $slots = $_GET["rune_slot"];
- foreach ($slots as $slot){
- if (intval($slot) >= 1 && intval($slot) < 7){
- array_push($this->filters["RUNE_SLOT"], intval($slot));
- }
- }
- }
- // Grindstones
- if (isset($_GET["grind_min_quality"]) && intval($_GET["grind_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["grind_min_quality"]) < QUALITY_ID::LEGEND){
- $this->filters["GRIND_MIN_QUALITY"] = $_GET["grind_min_quality"];
- }
- if (isset($_GET["grind_stat"])){
- $stats = $_GET["grind_stat"];
- $this->filters["GRIND_STAT"] = [];
- foreach ($stats as $stat){
- array_push($this->filters["GRIND_STAT"], intval($stat));
- }
- }
- if (isset($_GET["gem_stat_from"])){
- $stats = $_GET["gem_stat_from"];
- $this->filters["GEM_STAT_FROM"] = [];
- foreach ($stats as $stat){
- array_push($this->filters["GEM_STAT_FROM"], intval($stat));
- }
- }
- if (isset($_GET["gem_stat_to"])){
- $stats = $_GET["gem_stat_to"];
- $this->filters["GEM_STAT_TO"] = [];
- foreach ($stats as $stat){
- array_push($this->filters["GEM_STAT_TO"], intval($stat));
- }
- }
- return;
- }
- /**
- * Builds the query for the page, using the providded or default filters.
- *
- * @return string The query to be executed.
- * @global int Player ID.
- */
- private function build_query(){
- global $UID;
- global $MODE;
- $s = "
- SELECT DISTINCT
- unit.id AS unit,
- rune.id AS rune,
- enchantment.id AS enchantment
- FROM
- unit,
- k_unit,
- rune,
- unit_rune,
- enchantment,
- k_enchantment_type
- WHERE
- unit.uid = '$UID'
- AND rune.uid = '$UID'
- AND enchantment.uid = '$UID'
- AND unit.id = unit_rune.unit
- AND rune.id = unit_rune.rune
- AND unit_rune.rta = $MODE
- AND unit.unit = k_unit.id
- AND enchantment.type = k_enchantment_type.id
- -- RUNE FILTERS
- AND unit.stars >= " . $this->filters["RUNE_MIN_STARS"] . "
- AND unit.stars <= " . $this->filters["RUNE_MAX_STARS"] . "
- AND rune.quality >= " . $this->filters["RUNE_MIN_QUALITY"] . "
- AND rune.quality <= " . $this->filters["RUNE_MAX_QUALITY"] . "
- AND rune.level >= " . $this->filters["RUNE_MIN_LEVEL"] . "
- AND rune.level <= " . $this->filters["RUNE_MAX_LEVEL"] . "
- AND rune.stars >= " . $this->filters["RUNE_MIN_STARS"] . "
- AND rune.stars <= " . $this->filters["RUNE_MAX_STARS"] . "
- AND rune.original_quality >= " . $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] . "
- AND rune.original_quality <= " . $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] . "
- AND rune.efficiency >= " . $this->filters["RUNE_MIN_EFFICIENCY"] . "
- AND rune.efficiency <= " . $this->filters["RUNE_MAX_EFFICIENCY"] . "
- AND rune.max_efficiency >= " . $this->filters["RUNE_MIN_MAX_EFFICIENCY"] . "
- AND rune.max_efficiency <= " . $this->filters["RUNE_MAX_MAX_EFFICIENCY"] . "
- AND (
- rune.type = enchantment.rune
- OR k_enchantment_type.inmemorial = 1
- )
- AND k_enchantment_type.ancient = rune.ancient
- ";
- // Monster name
- $cond = "";
- if (strlen($this->filters["MONSTER_NAME"]) > 0){
- $cond = "AND upper(k_unit.name) LIKE upper('%" . $this->filters["MONSTER_NAME"] . "%') ";
- }
- $s .= $cond . " -- MONSTER NAME \n";
- // Monsters in storage
- $cond = "";
- if (!$this->filters["MONSTER_IN_STORAGE"]){
- $cond = "AND unit.building <> " . BUILDING_ID::MONSTER_STORAGE . " ";
- }
- $s .= $cond . " -- STORAGE \n";
- // Rune slot
- $cond = "";
- if (count($this->filters["RUNE_SLOT"]) > 0){
- $in = "(";
- foreach($this->filters["RUNE_SLOT"] as $t){
- $in .= "$t, ";
- }
- $in = rtrim($in, ", ") . ")";
- $cond = "AND rune.slot IN $in";
- }
- $s .= $cond . " -- RUNE SLOT \n";
- // Nevermind the type, discard enchantments with the same stat as
- // the main or inate substat
- $s .= "
- AND enchantment.stat NOT IN (
- SELECT stat
- FROM rune_stat
- WHERE
- rune_stat.rune = rune.id
- AND (
- rune_stat.slot = " . RUNE_STAT_SLOT_ID::MAIN . "
- OR rune_stat.slot = " . RUNE_STAT_SLOT_ID::INNATE . "
- )
- )
- ";
- // Begin type switch block
- $s .= " AND ( -- TYPE SWITCH \n";
- // Begin grindstone block
- $s .= "
- (
- k_enchantment_type.gem = 0
- AND enchantment.stat IN (SELECT stat FROM rune_stat WHERE rune_stat.rune = rune.id)
- AND enchantment.quality >= " . $this->filters["GRIND_MIN_QUALITY"] . " -- GRINDSTONE QUALITY
- ";
- // Grindstone stat
- $cond = "";
- if (count($this->filters["GRIND_STAT"]) > 0){
- $in = "(";
- foreach($this->filters["GRIND_STAT"] as $t){
- $in .= "$t, ";
- }
- $in = rtrim($in, ", ") . ")";
- $cond = "AND enchantment.stat IN $in";
- }
- $s .= $cond . " -- GRINDSTONE STAT \n";
- $s .= "
- )\n
- ";
- // Begin gem block
- $s .= " OR (
- k_enchantment_type.gem = 1
- AND enchantment.stat NOT IN (SELECT stat FROM rune_stat WHERE rune_stat.rune = rune.id)
- AND enchantment.quality >= " . $this->filters["GEM_MIN_QUALITY"] . " -- GEM QUALITY
- ";
- // Gem stat to
- $cond = "";
- if (count($this->filters["GEM_STAT_TO"]) > 0){
- $in = "(";
- foreach($this->filters["GEM_STAT_TO"] as $t){
- $in .= "$t, ";
- }
- $in = rtrim($in, ", ") . ")";
- $cond = "AND enchantment.stat IN $in";
- }
- $s .= $cond . " -- GEM STAT TO \n";
- // Gem stat from
- $cond = "";
- if (count($this->filters["GEM_STAT_FROM"]) > 0){
- $in = "(";
- foreach($this->filters["GEM_STAT_FROM"] as $t){
- $in .= "$t, ";
- }
- $in = rtrim($in, ", ") . ")";
- $cond = "
- AND rune.id IN(
- SELECT DISTINCT rune
- FROM rune_stat
- WHERE
- rune_stat.rune = rune.id
- AND stat IN $in
- )
- ";
- }
- $s .= $cond . " -- GEM STAT FROM \n";
- $s .= "
- )\n
- ";
- // End type switch block
- $s .= " ) -- END TYPE SWITCH \n";
- return $s;
- }
- }
- ?>
|