prepare(" SELECT id, type, attribute, archetype, level, quality, original_quality, value, efficiency, max_efficiency, locked FROM artifact WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->id = $r["id"]; $this->type = $r["type"]; $this->element = $r["attribute"]; $this->archetype = $r["archetype"]; $this->level = $r["level"]; $this->quality = $r["quality"]; $this->original_quality = $r["original_quality"]; $this->value = $r["value"]; $this->efficiency = $r["efficiency"]; $this->max_efficiency = $r["max_efficiency"]; $this->locked = $r["locked"]; $this->quality_name = $this->get_quality_name($this->quality); $this->original_quality_name = $this->get_quality_name($this->original_quality); // Get stat $this->stat = new Artifact_Stat($this->id); // Get effects $statement = $db->prepare(" SELECT slot FROM artifact_effect WHERE artifact = :artifact ORDER BY slot; "); $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->effects, new Artifact_Effect($this->id, $r["slot"])); } // Get efficiencies, or calculate them if not yet set. if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){ $this->efficiency = $this->calculate_efficiency(); $this->max_efficiency = $this->calculate_maximum_efficiency(); $statement = $db->prepare(" UPDATE artifact SET efficiency = :efficiency, max_efficiency = :max_efficiency WHERE id = :artifact "); $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT); $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT); $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER); $q = $statement->execute(); } } } /** * Gets the quality name from the mappings. * * @param int $q Quality id. * @return string Quality (Uppercase) */ private function get_quality_name($q){ switch ($q){ case QUALITY_ID::NORMAL: return "NORMAL"; case QUALITY_ID::MAGIC: return "MAGIC"; case QUALITY_ID::RARE: return "RARE"; case QUALITY_ID::HERO: return "HERO"; case QUALITY_ID::LEGEND: return "LEGEND"; default: return ""; } } /** * Calcuates the efficiency of the artifact. * * @return float Efficiency */ private function calculate_efficiency(){ global $db; $eff = [0.0, 0.0, 0.0, 0.0]; $query = " SELECT min, max FROM k_artifact_roll_type, k_artifact_stat_roll WHERE k_artifact_roll_type.id = k_artifact_stat_roll.type AND k_artifact_roll_type.initial = :initial AND k_artifact_roll_type.upgrade = :upgrade AND k_artifact_stat_roll.effect = :effect "; for ($i = 0; $i <= 3; $i ++){ if (sizeof($this->effects) > $i && $this->effects[$i] != null && $this->effects[$i]->value > 0){ $value = $this->effects[$i]->value; $value = $this->effects[$i]->value; $statement = $db->prepare($query); $statement->bindValue(':initial', 1, SQLITE3_TEXT); $statement->bindValue(':upgrade', 1, SQLITE3_TEXT); $statement->bindValue(':effect', $this->effects[$i]->effect, SQLITE3_TEXT); $r_roll = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r_roll ){ $min_initial = 0;//$r_initial["min"]; $max_initial = $r_roll["max"]; $min_upgrade = 0;//$r_upgrade["min"]; $max_upgrade = $r_roll["max"]; $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 8 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade)))); } } } $efficiency = 0.0; for ($i = 0; $i <= 3; $i ++){ $efficiency += $eff[$i]; } $efficiency *= 100; return $efficiency; } /** * Calcuates the maximum efficiency of the artifact. * * @return float Efficiency */ private function calculate_maximum_efficiency(){ $max_efficiency = $this->efficiency; if ($this->level < 12){ $max_efficiency += (1/8); } if ($this->level < 9){ $max_efficiency += (1/8); } if ($this->level < 6){ $max_efficiency += (1/8); } if ($this->level < 3){ $max_efficiency += (1/8); } return $max_efficiency; } } ?>