* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); /** * Artifact stat. * * Represents the artifact main stat. * * @category Entity */ class Artifact_Stat extends Entity{ /** * @var int Artifact stat ID ({@see ARTIFACT_STAT_ID}). */ private $stat; /** * @var string Artifact stat name. */ private $name; /** * @var int The value of the artifact stat. */ private $value; /** * Constructor. * * Retrieves the artifact stat information from the database. * * @param int $artifact_id Artifact id. */ public function __construct($artifact_id){ $statement = get_context()->get_db()->prepare(" SELECT stat, value FROM artifact_stat WHERE artifact = :artifact "); $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->stat = $r["stat"]; $this->value = $r["value"]; switch ($this->stat){ case ARTIFACT_STAT_ID::HP: $this->name = "HP"; break; case ARTIFACT_STAT_ID::ATK: $this->name = "ATK"; break; case ARTIFACT_STAT_ID::DEF: $this->name = "DEF"; break; } } else{ // Not found, maybe as a run drop? $statement = get_context()->get_db()->prepare(" SELECT stat, stat_value FROM run_drop_artifact WHERE id = :artifact "); $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->stat = $r["stat"]; $this->value = $r["stat_value"]; switch ($this->stat){ case ARTIFACT_STAT_ID::HP: $this->name = "HP"; break; case ARTIFACT_STAT_ID::ATK: $this->name = "ATK"; break; case ARTIFACT_STAT_ID::DEF: $this->name = "DEF"; break; } } } } /** * Retrieves the artifact stat identifier. * * @see ARTIFACT_STAT_ID * * @return int Artifact stat ID. */ public function get_stat(){ return $this->stat; } /** * Retrieves the artifact stat name. * * @return string Artifact stat name. */ public function get_name(){ return $this->name; } /** * Retrieves the value of the artifact stat value. * * @return int Stat value. */ public function get_value(){ return $this->value; } }