get_db()->prepare(" SELECT player, 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->player_id = $r["player"]; $this->id = $r["id"]; $this->type = $r["type"]; if ($r["type"] == ARTIFACT_TYPE::ARCHETYPE){ $this->archetypal = true; } elseif ($r["type"] == ARTIFACT_TYPE::ELEMENT){ $this->elemental = true; } $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->set_quality_name($this->quality); $this->original_quality_name = $this->set_quality_name($this->original_quality); // TODO: Get unit ID // TODO: Move efficiencies to a separate method, but the profile API must read it so it's saved. // 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 = get_context()->get_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); $statement->execute(); } } } /** * Gets the quality name from the mappings. * * @param int $q Quality id. * @return string Quality (Uppercase) */ private function set_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(){ $eff = [0.0, 0.0, 0.0, 0.0]; $query = " SELECT min, max FROM artifact_roll_type, artifact_effect_roll WHERE artifact_roll_type.id = artifact_effect_roll.type AND artifact_roll_type.initial = :initial AND artifact_roll_type.upgrade = :upgrade AND artifact_effect_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 = get_context()->get_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; } private function load_unit(){ $statement = get_context()->get_db()->prepare(" SELECT unit FROM unit_artifact WHERE artifact = :artifact AND rta = :rta; "); $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT); $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT); $q = $statement->execute(); $r = $q->fetchArray(SQLITE3_ASSOC); if ($r){ $this->unit_id = $r["unit"]; $this->unit = new Unit($r["unit"]); } $this->flag_unit = true; } private function load_stats(){ $this->stat = new Artifact_Stat($this->id); // Get effects $statement = get_context()->get_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"])); } $this->flag_stats = true; } /** * 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; } /** * Retrieves the owner's player identifier. * * @return int Player ID. */ public function get_player_id(){ return $this->player_id; } /** * Retrieves the artifact identifier. * * @return string Artifact ID. */ public function get_id(){ return $this->id; } /** * Checks if the artifact is elemental or archetiplal. * * @return int ARTIFACT_TYPE_ID::ELEMENT or ARTIFACT_TYPE:ARCHETYPE. */ public function get_type(){ return $this->type; } /** * Cheks if the artifact is an elemental one. * * @return boolean True for elemental artifacts, false for archetipal ones. */ public function is_elemental(){ return $this->elemental; } /** * Cheks if the artifact is an archetipal one. * * @return boolean True for archetipal artifacts, false for elemental ones. */ public function is_archetypal(){ return $this->archetypal; } /** * Retrieves the element of an elemental artifact. * * @see ELEMENT_ID * * @return int Element ID, null for archetipal artifacts. */ public function get_element(){ return $this->element; } /** * Retrieves the archetype of an archetipal artifact. * * @see ARCHETYPE_ID * * @return int Archetype ID, null for elemental artifacts. */ public function get_archetype(){ return $this->archetype; } /** * Retrieves the artifact level. * * @return int Artifact level (0-15). */ public function get_level(){ return $this->level; } /** * Retrieves the quality of the artifact. * * @see QUALITY_ID * * @return int Quality of the artifact. */ public function get_quality(){ return $this->quality; } /** * Retrieves the original quality of the artifact. * * @see QUALITY_ID * * @return int Original quality of the artifact. */ public function get_original_quality(){ return $this->original_quality; } /** * Retrieves the quality name. * * @return string Quality name, uppercase. */ public function get_quality_name(){ return $this->quality_name; } /** * Retrieves the original quality name. * * @return string Original quality name, uppercase. */ public function get_original_quality_name(){ return $this->original_quality_name; } /** * Retrieves the value of the artifact. * * @return int artifact value. */ public function get_value(){ return $this->value; } /** * Retrieves the efficiency of the artifact. * * @return float Artifact efficiency (0-100). */ public function get_efficiency(){ return $this->efficiency; } /** * Retrieves the maximum efficiency of the artifact. * * @return float Artifact maximum efficiency (0-100). */ public function get_max_efficiency(){ return $this->max_efficiency; } /** * Retrieves the artifact's main stat. * * @return Artifact_Stat Artifact main stat. */ public function get_stat(){ if (!$this->flag_stats){ $this->load_stats(); } return $this->stat; } /** * Retrieves a list of the artifact's effects. * * @return Artifact_Effect[] List of effects. */ public function get_effects(){ if (!$this->flag_stats){ $this->load_stats(); } return $this->effects; } /** * Retrieves the identifier of the unit who has eqquiped the artifact. * * @return string Unit ID. */ public function get_unit_id(){ if (!$this->flag_unit){ $this->load_unit(); } return $this->unit_id; } /** * Retrieves the unit who has eqquiped the artifact. * * @return Unit Unit who has equipped the artifact. */ public function get_unit(){ if (!$this->flag_unit){ $this->load_unit(); } return $this->unit; } } ?>