Artifact.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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
  59. */
  60. public $quality;
  61. /**
  62. * @var int Artifact original quality.
  63. *
  64. * @see QUALITY
  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. $s =
  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. $q = $db->query($s);
  202. $r = $q->fetchArray(SQLITE3_ASSOC);
  203. if ($r){
  204. $this->id = $r["id"];
  205. $this->assigned_to = $r["assigned_to"];
  206. $this->type = $r["type"];
  207. $this->element = $r["attribute"];
  208. $this->archetype = $r["archetype"];
  209. $this->level = $r["level"];
  210. $this->quality = $r["quality"];
  211. $this->original_quality = $r["original_quality"];
  212. $this->value = $r["value"];
  213. $this->efficiency = $r["efficiency"];
  214. $this->max_efficiency = $r["max_efficiency"];
  215. $this->main_stat = $r["main_stat"];
  216. $this->main_stat_value = $r["main_stat_value"];
  217. $this->effect_1 = $r["effect_1"];
  218. $this->effect_1_value = $r["effect_1_value"];
  219. //$this->effect_1_enchant = $r["effect_1_enchant"];
  220. //$this->effect_1_grind = $r["effect_1_grind"];
  221. $this->effect_2 = $r["effect_2"];
  222. $this->effect_2_value = $r["effect_2_value"];
  223. //$this->effect_2_enchant = $r["effect_2_enchant"];
  224. //$this->effect_2_grind = $r["effect_2_grind"];
  225. $this->effect_3 = $r["effect_3"];
  226. $this->effect_3_value = $r["effect_3_value"];
  227. //$this->effect_3_enchant = $r["effect_3_enchant"];
  228. //$this->effect_3_grind = $r["effect_3_grind"];
  229. $this->effect_4 = $r["effect_4"];
  230. $this->effect_4_value = $r["effect_4_value"];
  231. //$this->effect_4_enchant = $r["effect_4_enchant"];
  232. //$this->effect_4_grind = $r["effect_4_grind"];
  233. $this->refresh_names();
  234. }
  235. }
  236. /**
  237. * Calculates name variables.
  238. */
  239. public function refresh_names(){
  240. $this->main_stat_name = $this->stat_name($this->main_stat);
  241. $this->effect_1_description = $this->effect_description($this->effect_1, $this->effect_1_value);
  242. $this->effect_2_description = $this->effect_description($this->effect_2, $this->effect_2_value);
  243. $this->effect_3_description = $this->effect_description($this->effect_3, $this->effect_3_value);
  244. $this->effect_4_description = $this->effect_description($this->effect_4, $this->effect_4_value);
  245. $this->quality_name = $this->get_quality_name($this->quality);
  246. $this->original_quality_name = $this->get_quality_name($this->original_quality);
  247. }
  248. /**
  249. * Gets a stat name from the mappings.
  250. *
  251. * @param int $stat Stat id.
  252. * @return string Stat name (Uppercase)
  253. */
  254. private function stat_name($stat){
  255. switch ($stat){
  256. case ARTIFACT_STAT_ID::HP:
  257. return "HP";
  258. case ARTIFACT_STAT_ID::ATK:
  259. return "ATK";
  260. case ARTIFACT_STAT_ID::DEF:
  261. return "DEF";
  262. default:
  263. return "";
  264. }
  265. }
  266. /**
  267. * Composes an effect description.
  268. *
  269. * @param int $effect Effect id.
  270. * @param int $value Effect value.
  271. * @return string Effect description, null if unavailable.
  272. * @global resource Database connection.
  273. */
  274. private function effect_description($effect, $value){
  275. global $db;
  276. $s =
  277. "SELECT name " .
  278. "FROM k_artifact_effect " .
  279. "WHERE id = '$effect'; ";
  280. $q = $db->query($s);
  281. $r = $q->fetchArray(SQLITE3_ASSOC);
  282. if ($r){
  283. return str_replace("{}", $value, $r["name"]);
  284. }
  285. else{
  286. return null;
  287. }
  288. }
  289. /**
  290. * Gets the quality name from the mappings.
  291. *
  292. * @param int $q Quality id.
  293. * @return string Quality (Uppercase)
  294. */
  295. private function get_quality_name($q){
  296. switch ($q){
  297. case QUALITY_ID::NORMAL:
  298. return "NORMAL";
  299. case QUALITY_ID::MAGIC:
  300. return "MAGIC";
  301. case QUALITY_ID::RARE:
  302. return "RARE";
  303. case QUALITY_ID::HERO:
  304. return "HERO";
  305. case QUALITY_ID::LEGEND:
  306. return "LEGEND";
  307. default:
  308. return "";
  309. }
  310. }
  311. }
  312. ?>