| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?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");
- /**
- * Owned artifact.
- *
- * Represents an object from the table 'artifac'.
- *
- * @category Entity
- */
- class Artifact extends Entity{
- /**
- * @var int Owner identifier.
- */
- public $uid;
- /**
- * @var int Artifact identifier.
- */
- public $id;
- /**
- * @var int ID of the monster the rune is assigned to.
- */
- public $assigned_to;
- /**
- * @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 int Main stat of the artifact.
- *
- * @see STAT_ID
- */
- public $main_stat;
- /**
- * @var string Main stat name (uppercase).
- */
- public $main_stat_name;
- /**
- * @var int Main stat value of the artifact.
- */
- public $main_stat_value;
- /**
- * @var string Extra stat value of the artifact.
- */
- public $innate_stat_value;
- /**
- * @var int Number of substats.
- */
- public $substats;
- /**
- * @var int Effect 1 of the artifact.
- */
- public $effect_1;
- /**
- * @var int Effect 1 value of the artifact.
- */
- public $effect_1_value;
- /**
- * @var string Effect 1 description.
- */
- public $effect_1_description;
- /**
- * @var int Effect 2 of the artifact.
- */
- public $effect_2;
- /**
- * @var int Effect 2 value of the artifact.
- */
- public $effect_2_value;
- /**
- * @var string Effect 2 description.
- */
- public $effect_2_description;
- /**
- * @var int Effect 3 of the artifact.
- */
- public $effect_3;
- /**
- * @var int Effect 3 value of the artifact.
- */
- public $effect_3_value;
- /**
- * @var string Effect 3 description.
- */
- public $effect_3_description;
- /**
- * @var int Effect 4 of the artifact.
- */
- public $effect_4;
- /**
- * @var int Effect 4 value of the artifact.
- */
- public $effect_4_value;
- /**
- * @var string Effect 4 description.
- */
- public $effect_4_description;
- /**
- * 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,
- assigned_to,
- type,
- attribute,
- archetype,
- level,
- quality,
- original_quality,
- value,
- efficiency,
- max_efficiency,
- main_stat,
- main_stat_value,
- effect_1,
- effect_1_value,
- effect_1_enchant,
- effect_1_grind,
- effect_2,
- effect_2_value,
- effect_2_enchant,
- effect_2_grind,
- effect_3,
- effect_3_value,
- effect_3_enchant,
- effect_3_grind,
- effect_4,
- effect_4_value,
- effect_4_enchant,
- effect_4_grind
- FROM artifact
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_INTEGER);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->assigned_to = $r["assigned_to"];
- $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->main_stat = $r["main_stat"];
- $this->main_stat_value = $r["main_stat_value"];
- $this->effect_1 = $r["effect_1"];
- $this->effect_1_value = $r["effect_1_value"];
- $this->effect_2 = $r["effect_2"];
- $this->effect_2_value = $r["effect_2_value"];
- $this->effect_3 = $r["effect_3"];
- $this->effect_3_value = $r["effect_3_value"];
- $this->effect_4 = $r["effect_4"];
- $this->effect_4_value = $r["effect_4_value"];
- $this->refresh_names();
- }
- }
- /**
- * Calculates name variables.
- */
- public function refresh_names(){
- $this->main_stat_name = $this->stat_name($this->main_stat);
- $this->effect_1_description = $this->effect_description($this->effect_1, $this->effect_1_value);
- $this->effect_2_description = $this->effect_description($this->effect_2, $this->effect_2_value);
- $this->effect_3_description = $this->effect_description($this->effect_3, $this->effect_3_value);
- $this->effect_4_description = $this->effect_description($this->effect_4, $this->effect_4_value);
- $this->quality_name = $this->get_quality_name($this->quality);
- $this->original_quality_name = $this->get_quality_name($this->original_quality);
- }
- /**
- * Gets a stat name from the mappings.
- *
- * @param int $stat Stat id.
- * @return string Stat name (Uppercase)
- */
- private function stat_name($stat){
- switch ($stat){
- case ARTIFACT_STAT_ID::HP:
- return "HP";
- case ARTIFACT_STAT_ID::ATK:
- return "ATK";
- case ARTIFACT_STAT_ID::DEF:
- return "DEF";
- default:
- return "";
- }
- }
- /**
- * Composes an effect description.
- *
- * @param int $effect Effect id.
- * @param int $value Effect value.
- * @return string Effect description, null if unavailable.
- * @global resource Database connection.
- */
- private function effect_description($effect, $value){
- global $db;
- $statement = $db->prepare("
- SELECT name
- FROM k_artifact_effect
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $effect, SQLITE3_INTEGER);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- return str_replace("{}", $value, $r["name"]);
- }
- else{
- return null;
- }
- }
- /**
- * 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 "";
- }
- }
- }
- ?>
|