Artifact.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * Artifact entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. require_once(PATH::ENTITY . "Artifact_Stat.php");
  14. require_once(PATH::ENTITY . "Artifact_Effect.php");
  15. /**
  16. * Owned artifact.
  17. *
  18. * Represents an object from the table 'artifact'.
  19. *
  20. * @category Entity
  21. */
  22. class Artifact extends Entity{
  23. /**
  24. * @var int Owner identifier.
  25. */
  26. public $uid;
  27. /**
  28. * @var int Artifact identifier.
  29. */
  30. public $id;
  31. /**
  32. * @var int Artifact type (null if element artifact).
  33. *
  34. * @see ARTIFACT_TYPE
  35. */
  36. public $type;
  37. /**
  38. * @var int Artifact element (null if type artifact).
  39. *
  40. * @see ELEMENT_ID
  41. */
  42. public $element;
  43. /**
  44. * @var int Artifact archetype (null if elemental artifact).
  45. *
  46. * @see ARCHETYPE_ID
  47. */
  48. public $archetype;
  49. /**
  50. * @var int Level of the rune.
  51. */
  52. public $level;
  53. /**
  54. * @var int Artifact quality.
  55. *
  56. * @see QUALITY_ID
  57. */
  58. public $quality;
  59. /**
  60. * @var int Artifact original quality.
  61. *
  62. * @see QUALITY_ID
  63. */
  64. public $original_quality;
  65. /**
  66. * @var string Artifact quality name (uppercase).
  67. */
  68. public $quality_name;
  69. /**
  70. * @var string Artifact original quality name (uppercase).
  71. */
  72. public $original_quality_name;
  73. /**
  74. * @var int Price of the artifact.
  75. */
  76. public $value;
  77. /**
  78. * @var float Current efficiency of the artifact.
  79. */
  80. public $efficiency;
  81. /**
  82. * @var float Maximum potential efficiency of the artifact.
  83. */
  84. public $max_efficiency;
  85. /**
  86. * @var Artifact_Stat Main stat of the artifact.
  87. *
  88. * @see STAT_ID
  89. */
  90. public $stat;
  91. /**
  92. * @var \Artifact_Effect Effects of the artifact.
  93. */
  94. public $effects = [];
  95. /**
  96. * @var Unit Unit the artifact is assigned to.
  97. */
  98. public $unit;
  99. /**
  100. * Constructor.
  101. *
  102. * Searches the database and retrieves the information about the
  103. * artifact, populating it and it's items.
  104. *
  105. * @param int $id Artifact id.
  106. * @global resource Database connection.
  107. */
  108. public function __construct($id){
  109. global $db;
  110. $statement = $db->prepare("
  111. SELECT
  112. id,
  113. type,
  114. attribute,
  115. archetype,
  116. level,
  117. quality,
  118. original_quality,
  119. value,
  120. efficiency,
  121. max_efficiency,
  122. locked
  123. FROM artifact
  124. WHERE id = :id;
  125. ");
  126. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  127. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  128. if ($r){
  129. $this->id = $r["id"];
  130. $this->type = $r["type"];
  131. $this->element = $r["attribute"];
  132. $this->archetype = $r["archetype"];
  133. $this->level = $r["level"];
  134. $this->quality = $r["quality"];
  135. $this->original_quality = $r["original_quality"];
  136. $this->value = $r["value"];
  137. $this->efficiency = $r["efficiency"];
  138. $this->max_efficiency = $r["max_efficiency"];
  139. $this->locked = $r["locked"];
  140. $this->quality_name = $this->get_quality_name($this->quality);
  141. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  142. // Get stat
  143. $this->stat = new Artifact_Stat($this->id);
  144. // Get effects
  145. $statement = $db->prepare("
  146. SELECT slot
  147. FROM artifact_effect
  148. WHERE artifact = :artifact
  149. ORDER BY slot;
  150. ");
  151. $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT);
  152. $q = $statement->execute();
  153. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  154. array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
  155. }
  156. }
  157. }
  158. /**
  159. * Gets the quality name from the mappings.
  160. *
  161. * @param int $q Quality id.
  162. * @return string Quality (Uppercase)
  163. */
  164. private function get_quality_name($q){
  165. switch ($q){
  166. case QUALITY_ID::NORMAL:
  167. return "NORMAL";
  168. case QUALITY_ID::MAGIC:
  169. return "MAGIC";
  170. case QUALITY_ID::RARE:
  171. return "RARE";
  172. case QUALITY_ID::HERO:
  173. return "HERO";
  174. case QUALITY_ID::LEGEND:
  175. return "LEGEND";
  176. default:
  177. return "";
  178. }
  179. }
  180. }
  181. ?>