Artifact.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. /**
  14. * Owned artifact.
  15. *
  16. * Represents an object from the table 'artifac'.
  17. *
  18. * @category Entity
  19. */
  20. class Artifact extends Entity{
  21. /**
  22. * @var int Owner identifier.
  23. */
  24. public $uid;
  25. /**
  26. * @var int Artifact identifier.
  27. */
  28. public $id;
  29. /**
  30. * @var int ID of the monster the rune is assigned to.
  31. */
  32. public $assigned_to;
  33. /**
  34. * @var int Artifact type (null if element artifact).
  35. *
  36. * @see ARTIFACT_TYPE
  37. */
  38. public $type;
  39. /**
  40. * @var int Artifact element (null if type artifact).
  41. *
  42. * @see ELEMENT_ID
  43. */
  44. public $element;
  45. /**
  46. * @var int Artifact archetype (null if elemental artifact).
  47. *
  48. * @see ARCHETYPE_ID
  49. */
  50. public $archetype;
  51. /**
  52. * @var int Level of the rune.
  53. */
  54. public $level;
  55. /**
  56. * @var int Artifact quality.
  57. *
  58. * @see QUALITY_ID
  59. */
  60. public $quality;
  61. /**
  62. * @var int Artifact original quality.
  63. *
  64. * @see QUALITY_ID
  65. */
  66. public $original_quality;
  67. /**
  68. * @var string Artifact quality name (uppercase).
  69. */
  70. public $quality_name;
  71. /**
  72. * @var string Artifact original quality name (uppercase).
  73. */
  74. public $original_quality_name;
  75. /**
  76. * @var int Price of the artifact.
  77. */
  78. public $value;
  79. /**
  80. * @var float Current efficiency of the artifact.
  81. */
  82. public $efficiency;
  83. /**
  84. * @var float Maximum potential efficiency of the artifact.
  85. */
  86. public $max_efficiency;
  87. /**
  88. * @var int Main stat of the artifact.
  89. *
  90. * @see STAT_ID
  91. */
  92. public $main_stat;
  93. /**
  94. * @var string Main stat name (uppercase).
  95. */
  96. public $main_stat_name;
  97. /**
  98. * @var int Main stat value of the artifact.
  99. */
  100. public $main_stat_value;
  101. /**
  102. * @var string Extra stat value of the artifact.
  103. */
  104. public $innate_stat_value;
  105. /**
  106. * @var int Number of substats.
  107. */
  108. public $substats;
  109. /**
  110. * @var int Effect 1 of the artifact.
  111. */
  112. public $effect_1;
  113. /**
  114. * @var int Effect 1 value of the artifact.
  115. */
  116. public $effect_1_value;
  117. /**
  118. * @var string Effect 1 description.
  119. */
  120. public $effect_1_description;
  121. /**
  122. * @var int Effect 2 of the artifact.
  123. */
  124. public $effect_2;
  125. /**
  126. * @var int Effect 2 value of the artifact.
  127. */
  128. public $effect_2_value;
  129. /**
  130. * @var string Effect 2 description.
  131. */
  132. public $effect_2_description;
  133. /**
  134. * @var int Effect 3 of the artifact.
  135. */
  136. public $effect_3;
  137. /**
  138. * @var int Effect 3 value of the artifact.
  139. */
  140. public $effect_3_value;
  141. /**
  142. * @var string Effect 3 description.
  143. */
  144. public $effect_3_description;
  145. /**
  146. * @var int Effect 4 of the artifact.
  147. */
  148. public $effect_4;
  149. /**
  150. * @var int Effect 4 value of the artifact.
  151. */
  152. public $effect_4_value;
  153. /**
  154. * @var string Effect 4 description.
  155. */
  156. public $effect_4_description;
  157. /**
  158. * Constructor.
  159. *
  160. * Searches the database and retrieves the information about the
  161. * artifact, populating it and it's items.
  162. *
  163. * @param int $id Artifact id.
  164. * @global resource Database connection.
  165. */
  166. public function __construct($id){
  167. global $db;
  168. $statement = $db->prepare("
  169. SELECT
  170. id,
  171. assigned_to,
  172. type,
  173. attribute,
  174. archetype,
  175. level,
  176. quality,
  177. original_quality,
  178. value,
  179. efficiency,
  180. max_efficiency,
  181. main_stat,
  182. main_stat_value,
  183. effect_1,
  184. effect_1_value,
  185. effect_1_enchant,
  186. effect_1_grind,
  187. effect_2,
  188. effect_2_value,
  189. effect_2_enchant,
  190. effect_2_grind,
  191. effect_3,
  192. effect_3_value,
  193. effect_3_enchant,
  194. effect_3_grind,
  195. effect_4,
  196. effect_4_value,
  197. effect_4_enchant,
  198. effect_4_grind
  199. FROM artifact
  200. WHERE id = :id;
  201. ");
  202. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  203. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  204. if ($r){
  205. $this->id = $r["id"];
  206. $this->assigned_to = $r["assigned_to"];
  207. $this->type = $r["type"];
  208. $this->element = $r["attribute"];
  209. $this->archetype = $r["archetype"];
  210. $this->level = $r["level"];
  211. $this->quality = $r["quality"];
  212. $this->original_quality = $r["original_quality"];
  213. $this->value = $r["value"];
  214. $this->efficiency = $r["efficiency"];
  215. $this->max_efficiency = $r["max_efficiency"];
  216. $this->main_stat = $r["main_stat"];
  217. $this->main_stat_value = $r["main_stat_value"];
  218. $this->effect_1 = $r["effect_1"];
  219. $this->effect_1_value = $r["effect_1_value"];
  220. $this->effect_2 = $r["effect_2"];
  221. $this->effect_2_value = $r["effect_2_value"];
  222. $this->effect_3 = $r["effect_3"];
  223. $this->effect_3_value = $r["effect_3_value"];
  224. $this->effect_4 = $r["effect_4"];
  225. $this->effect_4_value = $r["effect_4_value"];
  226. $this->refresh_names();
  227. }
  228. }
  229. /**
  230. * Calculates name variables.
  231. */
  232. public function refresh_names(){
  233. $this->main_stat_name = $this->stat_name($this->main_stat);
  234. $this->effect_1_description = $this->effect_description($this->effect_1, $this->effect_1_value);
  235. $this->effect_2_description = $this->effect_description($this->effect_2, $this->effect_2_value);
  236. $this->effect_3_description = $this->effect_description($this->effect_3, $this->effect_3_value);
  237. $this->effect_4_description = $this->effect_description($this->effect_4, $this->effect_4_value);
  238. $this->quality_name = $this->get_quality_name($this->quality);
  239. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  240. }
  241. /**
  242. * Gets a stat name from the mappings.
  243. *
  244. * @param int $stat Stat id.
  245. * @return string Stat name (Uppercase)
  246. */
  247. private function stat_name($stat){
  248. switch ($stat){
  249. case ARTIFACT_STAT_ID::HP:
  250. return "HP";
  251. case ARTIFACT_STAT_ID::ATK:
  252. return "ATK";
  253. case ARTIFACT_STAT_ID::DEF:
  254. return "DEF";
  255. default:
  256. return "";
  257. }
  258. }
  259. /**
  260. * Composes an effect description.
  261. *
  262. * @param int $effect Effect id.
  263. * @param int $value Effect value.
  264. * @return string Effect description, null if unavailable.
  265. * @global resource Database connection.
  266. */
  267. private function effect_description($effect, $value){
  268. global $db;
  269. $statement = $db->prepare("
  270. SELECT name
  271. FROM k_artifact_effect
  272. WHERE id = :id;
  273. ");
  274. $statement->bindValue(':id', $effect, SQLITE3_INTEGER);
  275. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  276. if ($r){
  277. return str_replace("{}", $value, $r["name"]);
  278. }
  279. else{
  280. return null;
  281. }
  282. }
  283. /**
  284. * Gets the quality name from the mappings.
  285. *
  286. * @param int $q Quality id.
  287. * @return string Quality (Uppercase)
  288. */
  289. private function get_quality_name($q){
  290. switch ($q){
  291. case QUALITY_ID::NORMAL:
  292. return "NORMAL";
  293. case QUALITY_ID::MAGIC:
  294. return "MAGIC";
  295. case QUALITY_ID::RARE:
  296. return "RARE";
  297. case QUALITY_ID::HERO:
  298. return "HERO";
  299. case QUALITY_ID::LEGEND:
  300. return "LEGEND";
  301. default:
  302. return "";
  303. }
  304. }
  305. }
  306. ?>