| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- /**
- * Artifact entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Artifact_Stat.php");
- require_once(PATH::ENTITY . "Artifact_Effect.php");
- /**
- * Owned artifact.
- *
- * Represents an object from the table 'artifact'.
- *
- * @category Entity
- */
- class Artifact extends Entity{
- /**
- * @var int Owner identifier.
- */
- public $uid;
- /**
- * @var int Artifact identifier.
- */
- public $id;
- /**
- * @var int Artifact type (null if element artifact).
- *
- * @see ARTIFACT_TYPE
- */
- public $type;
- /**
- * @var int Artifact element (null if type artifact).
- *
- * @see ELEMENT_ID
- */
- public $element;
- /**
- * @var int Artifact archetype (null if elemental artifact).
- *
- * @see ARCHETYPE_ID
- */
- public $archetype;
- /**
- * @var int Level of the rune.
- */
- public $level;
- /**
- * @var int Artifact quality.
- *
- * @see QUALITY_ID
- */
- public $quality;
- /**
- * @var int Artifact original quality.
- *
- * @see QUALITY_ID
- */
- public $original_quality;
- /**
- * @var string Artifact quality name (uppercase).
- */
- public $quality_name;
- /**
- * @var string Artifact original quality name (uppercase).
- */
- public $original_quality_name;
- /**
- * @var int Price of the artifact.
- */
- public $value;
- /**
- * @var float Current efficiency of the artifact.
- */
- public $efficiency;
- /**
- * @var float Maximum potential efficiency of the artifact.
- */
- public $max_efficiency;
- /**
- * @var Artifact_Stat Main stat of the artifact.
- *
- * @see STAT_ID
- */
- public $stat;
- /**
- * @var \Artifact_Effect Effects of the artifact.
- */
- public $effects = [];
- /**
- * @var Unit Unit the artifact is assigned to.
- */
- public $unit;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * artifact, populating it and it's items.
- *
- * @param int $id Artifact id.
- * @global resource Database connection.
- */
- public function __construct($id){
- global $db;
- $statement = $db->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_INTEGER);
- $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_INTEGER);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
- }
- }
- }
- /**
- * 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 "";
- }
- }
- }
- ?>
|