optimize.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. /**
  3. * File for the optimization action.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @category Action
  8. */
  9. /**
  10. * Executes the optimization action.
  11. *
  12. * Reads the POST parameters looking for the following KEYS:
  13. * mail
  14. * pass + currentPass
  15. * api
  16. * Then it updates the selected info with the prameter vlue. Multiple
  17. * itemas can be updated at the same time.
  18. *
  19. * @return int|string 0 on success, negative values on error. If the API
  20. * key has been updated, the new key.
  21. * @category Action
  22. * @global resource Database connection.
  23. */
  24. function action(){
  25. global $db;
  26. $HARD_LIMIT = 100;
  27. // Increase max execution time.
  28. set_time_limit(30);
  29. $candidates = [
  30. 1 => [],
  31. 2 => [],
  32. 3 => [],
  33. 4 => [],
  34. 5 => [],
  35. 6 => []
  36. ];
  37. $options = [];
  38. $response = null;
  39. $uid = filter_input(INPUT_POST, 'uid');
  40. if ($uid == null){
  41. return -1;
  42. }
  43. $unit_id = filter_input(INPUT_POST, 'unit');
  44. if ($unit_id == null){
  45. return -2;
  46. }
  47. // Sets
  48. $sets = [];
  49. foreach ($_POST["set"] as $x){
  50. array_push($sets, intval($x));
  51. }
  52. if (sizeof($sets) < 2 || sizeof($sets) > 3){
  53. return -3;
  54. }
  55. // Main stats in even slots.
  56. $stats = [];
  57. foreach ($_POST["stat"] as $x){
  58. array_push($stats, intval($x));
  59. }
  60. $source = filter_input(INPUT_POST, 'source');
  61. if ($source == null){
  62. return -4;
  63. }
  64. $limit = intval(filter_input(INPUT_POST, 'limit'));
  65. if ($limit == 0){
  66. return -5;
  67. }
  68. $tuning = filter_input(INPUT_POST, 'tuning');
  69. if ($tuning == null){
  70. return -6;
  71. }
  72. $min = [
  73. "attack" => intval(filter_input(INPUT_POST, 'min_attack')),
  74. "defense" => intval(filter_input(INPUT_POST, 'min_defense')),
  75. "hp" => intval(filter_input(INPUT_POST, 'min_hp')),
  76. "speed" => intval(filter_input(INPUT_POST, 'min_speed')),
  77. "crit_rate" => intval(filter_input(INPUT_POST, 'min_crit_rate')),
  78. "crit_damage" => intval(filter_input(INPUT_POST, 'min_crit_damage')),
  79. "accuracy" => intval(filter_input(INPUT_POST, 'min_accuracy')),
  80. "resistance" => intval(filter_input(INPUT_POST, 'min_resistance')),
  81. "ehp" => intval(filter_input(INPUT_POST, 'min_ehp')),
  82. "dmg" => intval(filter_input(INPUT_POST, 'min_dmg'))
  83. ];
  84. // Get Buld query:
  85. $s = "
  86. SELECT
  87. id,
  88. slot
  89. FROM rune
  90. WHERE
  91. uid = $uid AND
  92. type IN (
  93. ";
  94. foreach ($sets as $set){
  95. $s .= ($set . ",");
  96. }
  97. $s .= "-1) AND ";
  98. switch ($source){
  99. case 0: // Storage only (or itself)
  100. $s .= "
  101. (
  102. assigned_to = $unit_id OR
  103. assigned_to IS NULL
  104. )";
  105. break;
  106. case 1: // Units in no teams (or itself)
  107. $s .= "
  108. (
  109. assigned_to = $unit_id OR
  110. assigned_to IS NULL OR
  111. assigned_to NOT IN (SELECT DISTINCT unit FROM team_unit)
  112. )
  113. ";
  114. break;
  115. case 2: // Units in teams with 0 score (or itself)
  116. $s .= "
  117. (
  118. assigned_to = $unit_id OR
  119. assigned_to IS NULL OR
  120. assigned_to NOT IN (SELECT DISTINCT unit FROM team_unit) OR
  121. assigned_to NOT IN (
  122. SELECT DISTINCT unit
  123. FROM
  124. team,
  125. team_unit
  126. WHERE
  127. team.id = team_unit.team AND
  128. team.score > 0
  129. )
  130. )
  131. ";
  132. break;
  133. case 3: // Units with lower overall score (or itself)
  134. // TODO
  135. break;
  136. case 4: // All runes - dont filter
  137. $s .= " 1 = 1 ";
  138. break;
  139. default: // Invalid options - return nothing
  140. $s .= " 1 = 0 ";
  141. }
  142. // Even slots stats
  143. $s .= "
  144. AND
  145. (
  146. slot <> 2 OR
  147. (
  148. slot = 2 AND
  149. main_stat = " . $stats[0] . "
  150. )
  151. ) AND
  152. (
  153. slot <> 4 OR
  154. (
  155. slot = 4 AND
  156. main_stat = " . $stats[1] . "
  157. )
  158. ) AND
  159. (
  160. slot <> 6 OR
  161. (
  162. slot = 6 AND
  163. main_stat = " . $stats[2] . "
  164. )
  165. )
  166. ";
  167. $q = $db->query($s);
  168. $total_candidates = 0;
  169. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  170. array_push($candidates[$r["slot"]], new Rune($r["id"]));
  171. $total_candidates ++;
  172. }
  173. $max_combinations = sizeof($candidates[1]) * sizeof($candidates[2]) * sizeof($candidates[3]) * sizeof($candidates[4]) * sizeof($candidates[5]) * sizeof($candidates[6]);
  174. if ($max_combinations == 0){
  175. $res = [
  176. "total" => 0,
  177. "options" => []
  178. ];
  179. $response = json_encode($res);
  180. return $response;
  181. }
  182. /*elseif ($max_combinations > 50000000){
  183. http_response_code(413); // Payload too large;
  184. die();
  185. return;
  186. }*/
  187. // Get the unit and its base stats
  188. $unit = new Unit($unit_id, true, $uid);
  189. $unit_attack = $unit->attack + $unit->artifact_attack + $unit->building_attack;
  190. $unit_base_attack = $unit->attack;
  191. $unit_defense = $unit->defense + $unit->artifact_defense + $unit->building_defense;
  192. $unit_base_defense = $unit->defense;
  193. $unit_hp = $unit->hp + $unit->artifact_hp + $unit->building_hp;
  194. $unit_base_hp = $unit->hp;
  195. $unit_speed = $unit->speed + $unit->artifact_speed + $unit->building_speed;
  196. $unit_base_speed = $unit->speed;
  197. $unit_crit_rate = $unit->crit_rate + $unit->artifact_crit_rate + $unit->building_crit_rate;
  198. $unit_base_crit_rate = $unit->crit_rate;
  199. $unit_crit_damage = $unit->crit_damage + $unit->artifact_crit_damage + $unit->building_crit_damage;
  200. $unit_base_crit_damage = $unit->crit_damage;
  201. $unit_accuracy = $unit->accuracy + $unit->artifact_accuracy + $unit->building_accuracy;
  202. $unit_base_accuracy = $unit->accuracy;
  203. $unit_resistance = $unit->resistance + $unit->artifact_resistance + $unit->building_resistance;
  204. $unit_base_resistance = $unit->resistance;
  205. $i = [0, 0, 0, 0, 0, 0, 0]; // 7, so I can start with 1
  206. while (true){
  207. // Check if set combination is valid
  208. if (valid_sets($candidates, $i, $sets) == true){
  209. // Do things
  210. $iteration = [
  211. "attack" => $unit_attack,
  212. "defense" => $unit_defense,
  213. "hp" => $unit_hp,
  214. "speed" => $unit_speed,
  215. "crit_rate" => $unit_crit_rate,
  216. "crit_damage" => $unit_crit_damage,
  217. "accuracy" => $unit_accuracy,
  218. "resistance" => $unit_resistance,
  219. "ehp" => 0,
  220. "dmg" => 0,
  221. ];
  222. for ($r = 1; $r <= 6; $r ++){
  223. // Loop selected runes and calculate stats
  224. // TODO Consider main stat at selected level
  225. $main_value = $candidates[$r][$i[$r]]->main_stat_value;
  226. if ($tuning == 1){ // All +12
  227. if ($candidates[$r][$i[$r]]->level < 12){
  228. $main_value = $candidates[$r][$i[$r]]->get_main_stat_at_level(12);
  229. }
  230. }
  231. elseif ($tuning == 2){ // Even +15, Odd + 12
  232. if ($candidates[$r][$i[$r]]->level < 15 && $candidates[$r][$i[$r]]->slot % 2 == 0){
  233. $main_value = $candidates[$r][$i[$r]]->get_main_stat_at_level(15);
  234. }
  235. elseif ($candidates[$r][$i[$r]]->level < 12 && $candidates[$r][$i[$r]]->slot % 2 != 0){
  236. $main_value = $candidates[$r][$i[$r]]->get_main_stat_at_level(12);
  237. }
  238. }
  239. if ($tuning == 3){ // All +15
  240. if ($candidates[$r][$i[$r]]->level < 15){
  241. $main_value = $candidates[$r][$i[$r]]->get_main_stat_at_level(15);
  242. }
  243. }
  244. sum_rune_stat(
  245. $candidates[$r][$i[$r]]->main_stat,
  246. $main_value,
  247. $iteration,
  248. $unit_base_attack,
  249. $unit_base_defense,
  250. $unit_base_hp,
  251. );
  252. sum_rune_stat(
  253. $candidates[$r][$i[$r]]->innate_stat,
  254. $candidates[$r][$i[$r]]->innate_stat_value,
  255. $iteration,
  256. $unit_base_attack,
  257. $unit_base_defense,
  258. $unit_base_hp,
  259. );
  260. sum_rune_stat(
  261. $candidates[$r][$i[$r]]->substat_1,
  262. $candidates[$r][$i[$r]]->substat_1_value,
  263. $iteration,
  264. $unit_base_attack,
  265. $unit_base_defense,
  266. $unit_base_hp,
  267. );
  268. sum_rune_stat(
  269. $candidates[$r][$i[$r]]->substat_2,
  270. $candidates[$r][$i[$r]]->substat_2_value,
  271. $iteration,
  272. $unit_base_attack,
  273. $unit_base_defense,
  274. $unit_base_hp,
  275. );
  276. sum_rune_stat(
  277. $candidates[$r][$i[$r]]->substat_3,
  278. $candidates[$r][$i[$r]]->substat_3_value,
  279. $iteration,
  280. $unit_base_attack,
  281. $unit_base_defense,
  282. $unit_base_hp,
  283. );
  284. sum_rune_stat(
  285. $candidates[$r][$i[$r]]->substat_4,
  286. $candidates[$r][$i[$r]]->substat_4_value,
  287. $iteration,
  288. $unit_base_attack,
  289. $unit_base_defense,
  290. $unit_base_hp,
  291. );
  292. }
  293. // Calculate EHP and DMG
  294. // Calculate effective_hp
  295. $hp = $iteration["hp"];
  296. $def = $iteration["defense"];
  297. $ehp = ceil(((($def * 3.5) + 1140) * $hp) / 1000);
  298. $iteration["ehp"] = $ehp;
  299. // Calculate effective_dmg
  300. $atk = $iteration["attack"];
  301. $crr = $iteration["crit_rate"];
  302. if ($crr > 100){
  303. $crr = 100;
  304. }
  305. $crd = $iteration["crit_damage"];
  306. $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
  307. $iteration["dmg"] = $edmg;
  308. // Compare with filters:
  309. if (
  310. $iteration["attack"] >= $min["attack"] &&
  311. $iteration["defense"] >= $min["defense"] &&
  312. $iteration["hp"] >= $min["hp"] &&
  313. $iteration["speed"] >= $min["speed"] &&
  314. $iteration["crit_rate"] >= $min["crit_rate"] &&
  315. $iteration["crit_damage"] >= $min["crit_damage"] &&
  316. $iteration["accuracy"] >= $min["accuracy"] &&
  317. $iteration["resistance"] >= $min["resistance"] &&
  318. $iteration["ehp"] >= $min["ehp"] &&
  319. $iteration["dmg"] >= $min["dmg"]
  320. ){
  321. // Calculate the variation
  322. $variation = 0;
  323. $variation += (($iteration["attack"] - $unit->total_attack) * 1);
  324. $variation += (($iteration["defense"] - $unit->total_defense) * 1);
  325. $variation += (($iteration["hp"] - $unit->total_hp) * (1 / 15));
  326. $variation += (($iteration["speed"] - $unit->total_speed) * 1.5);
  327. $variation += (($iteration["crit_rate"] - $unit->total_crit_rate) * 0.85);
  328. $variation += (($iteration["crit_damage"] - $unit->total_crit_damage) * 0.9);
  329. $variation += (($iteration["accuracy"] - $unit->total_accuracy) * 0.85);
  330. $variation += (($iteration["resistance"] - $unit->total_resistance) * 0.85);
  331. $variation = ceil($variation);
  332. // Build the array
  333. $option = [
  334. "variation" => $variation,
  335. "runes" => [
  336. [
  337. "id" => $candidates[1][$i[1]]->id,
  338. "html" => (HTML::rune_table($candidates[1][$i[1]]))
  339. ],
  340. [
  341. "id" => $candidates[2][$i[2]]->id,
  342. "html" => (HTML::rune_table($candidates[2][$i[2]]))
  343. ],
  344. [
  345. "id" => $candidates[3][$i[3]]->id,
  346. "html" => (HTML::rune_table($candidates[3][$i[3]]))
  347. ],
  348. [
  349. "id" => $candidates[4][$i[4]]->id,
  350. "html" => (HTML::rune_table($candidates[4][$i[4]]))
  351. ],
  352. [
  353. "id" => $candidates[5][$i[5]]->id,
  354. "html" => (HTML::rune_table($candidates[5][$i[5]]))
  355. ],
  356. [
  357. "id" => $candidates[1][$i[1]]->id,
  358. "html" => HTML::rune_table($candidates[6][$i[6]])
  359. ]
  360. ],
  361. "stats" => [
  362. "attack" => ceil($iteration["attack"]),
  363. "defense" => ceil($iteration["defense"]),
  364. "hp" => ceil($iteration["hp"]),
  365. "speed" => ceil($iteration["speed"]),
  366. "crit_rate" => ceil($iteration["crit_rate"]),
  367. "crit_damage" => ceil($iteration["crit_damage"]),
  368. "accuracy" => ceil($iteration["accuracy"]),
  369. "attack" => ceil($iteration["attack"]),
  370. "resistance" => ceil($iteration["resistance"]),
  371. "ehp" => ceil($iteration["ehp"]),
  372. "dmg" => ceil($iteration["dmg"])
  373. ]
  374. ];
  375. array_push($options, $option);
  376. if (sizeof($options) > 5000){
  377. http_response_code(413); // Payload too large;
  378. die();
  379. return;
  380. }
  381. }
  382. }
  383. // Increase counters
  384. $i[6] ++;
  385. if ($i[6] == sizeof($candidates[6])){
  386. $i[6] = 0;
  387. $i[5] ++;
  388. }
  389. if ($i[5] == sizeof($candidates[5])){
  390. $i[5] = 0;
  391. $i[4] ++;
  392. }
  393. if ($i[4] == sizeof($candidates[4])){
  394. $i[4] = 0;
  395. $i[3] ++;
  396. }
  397. if ($i[3] == sizeof($candidates[3])){
  398. $i[3] = 0;
  399. $i[2] ++;
  400. }
  401. if ($i[2] == sizeof($candidates[2])){
  402. $i[2] = 0;
  403. $i[1] ++;
  404. }
  405. // Calculate exit condition
  406. if (
  407. $i[1] >= sizeof($candidates[1]) - 1 &&
  408. $i[2] >= sizeof($candidates[2]) - 1 &&
  409. $i[3] >= sizeof($candidates[3]) - 1 &&
  410. $i[4] >= sizeof($candidates[4]) - 1 &&
  411. $i[5] >= sizeof($candidates[5]) - 1 &&
  412. $i[6] >= sizeof($candidates[6]) - 1
  413. ){
  414. break;
  415. }
  416. }
  417. // Sort options by variation
  418. usort($options, "sortOptions");
  419. // Limit the array to the top options
  420. while (sizeof($options) > $limit || sizeof($options) > $HARD_LIMIT){
  421. array_pop($options);
  422. }
  423. $res = [
  424. "total" => sizeof($options),
  425. "options" => $options
  426. ];
  427. $response = json_encode($res);
  428. if ($response == null){
  429. return 0;
  430. }
  431. else{
  432. return $response;
  433. }
  434. }
  435. /**
  436. * Validates a rune combination.
  437. *
  438. * Checks that set numbers are OK.
  439. *
  440. * @param \Rune[][] $candidates Candidate runes.
  441. * @param int[] $indexes Currently selected indexes.
  442. */
  443. function valid_sets($candidates, $indexes, $requested){
  444. $sets = [
  445. RUNE_SET_ID::ENERGY => 0,
  446. RUNE_SET_ID::GUARD => 0,
  447. RUNE_SET_ID::SWIFT => 0,
  448. RUNE_SET_ID::BLADE => 0,
  449. RUNE_SET_ID::RAGE => 0,
  450. RUNE_SET_ID::FOCUS => 0,
  451. RUNE_SET_ID::ENDURE => 0,
  452. RUNE_SET_ID::FATAL => 0,
  453. RUNE_SET_ID::DESPAIR => 0,
  454. RUNE_SET_ID::VAMPIRE => 0,
  455. RUNE_SET_ID::VIOLENT => 0,
  456. RUNE_SET_ID::NEMESIS => 0,
  457. RUNE_SET_ID::WILL => 0,
  458. RUNE_SET_ID::SHIELD => 0,
  459. RUNE_SET_ID::REVENGE => 0,
  460. RUNE_SET_ID::DESTROY => 0,
  461. RUNE_SET_ID::FIGHT => 0,
  462. RUNE_SET_ID::DETERMINATION => 0,
  463. RUNE_SET_ID::ENHANCE => 0,
  464. RUNE_SET_ID::ACCURACY => 0,
  465. RUNE_SET_ID::TOLERANCE => 0
  466. ];
  467. for ($i = 1; $i <= 6; $i++){
  468. $sets[$candidates[$i][$indexes[$i]]->type->id] ++;
  469. }
  470. for ($i = 0; $i < sizeof($sets); $i ++){
  471. switch ($i){
  472. case RUNE_SET_ID::ENERGY:
  473. case RUNE_SET_ID::GUARD:
  474. case RUNE_SET_ID::NEMESIS:
  475. case RUNE_SET_ID::BLADE:
  476. case RUNE_SET_ID::FOCUS:
  477. case RUNE_SET_ID::ENDURE:
  478. case RUNE_SET_ID::WILL:
  479. case RUNE_SET_ID::SHIELD:
  480. case RUNE_SET_ID::REVENGE:
  481. case RUNE_SET_ID::DESTROY:
  482. case RUNE_SET_ID::FIGHT:
  483. case RUNE_SET_ID::DETERMINATION:
  484. case RUNE_SET_ID::ENHANCE:
  485. case RUNE_SET_ID::ACCURACY:
  486. case RUNE_SET_ID::TOLERANCE:
  487. if ($sets[$i] % 2 != 0){
  488. return false;
  489. }
  490. break;
  491. case RUNE_SET_ID::DESPAIR:
  492. case RUNE_SET_ID::SWIFT:
  493. case RUNE_SET_ID::RAGE:
  494. case RUNE_SET_ID::FATAL:
  495. case RUNE_SET_ID::VAMPIRE:
  496. case RUNE_SET_ID::VIOLENT:
  497. if ($sets[$i] != 4 && $sets[$i != 0]){
  498. return false;
  499. }
  500. break;
  501. }
  502. }
  503. // Sets are valid, now check if they comply with filters
  504. $requested_sets = [
  505. RUNE_SET_ID::ENERGY => 0,
  506. RUNE_SET_ID::GUARD => 0,
  507. RUNE_SET_ID::SWIFT => 0,
  508. RUNE_SET_ID::BLADE => 0,
  509. RUNE_SET_ID::RAGE => 0,
  510. RUNE_SET_ID::FOCUS => 0,
  511. RUNE_SET_ID::ENDURE => 0,
  512. RUNE_SET_ID::FATAL => 0,
  513. RUNE_SET_ID::DESPAIR => 0,
  514. RUNE_SET_ID::VAMPIRE => 0,
  515. RUNE_SET_ID::VIOLENT => 0,
  516. RUNE_SET_ID::NEMESIS => 0,
  517. RUNE_SET_ID::WILL => 0,
  518. RUNE_SET_ID::SHIELD => 0,
  519. RUNE_SET_ID::REVENGE => 0,
  520. RUNE_SET_ID::DESTROY => 0,
  521. RUNE_SET_ID::FIGHT => 0,
  522. RUNE_SET_ID::DETERMINATION => 0,
  523. RUNE_SET_ID::ENHANCE => 0,
  524. RUNE_SET_ID::ACCURACY => 0,
  525. RUNE_SET_ID::TOLERANCE => 0
  526. ];
  527. for ($i = 0; $i < sizeof($requested); $i ++){
  528. switch ($requested[$i]){
  529. case RUNE_SET_ID::ENERGY:
  530. case RUNE_SET_ID::GUARD:
  531. case RUNE_SET_ID::NEMESIS:
  532. case RUNE_SET_ID::BLADE:
  533. case RUNE_SET_ID::FOCUS:
  534. case RUNE_SET_ID::ENDURE:
  535. case RUNE_SET_ID::WILL:
  536. case RUNE_SET_ID::SHIELD:
  537. case RUNE_SET_ID::REVENGE:
  538. case RUNE_SET_ID::DESTROY:
  539. case RUNE_SET_ID::FIGHT:
  540. case RUNE_SET_ID::DETERMINATION:
  541. case RUNE_SET_ID::ENHANCE:
  542. case RUNE_SET_ID::ACCURACY:
  543. case RUNE_SET_ID::TOLERANCE:
  544. $requested_sets[$requested[$i]] += 2;
  545. break;
  546. case RUNE_SET_ID::DESPAIR:
  547. case RUNE_SET_ID::SWIFT:
  548. case RUNE_SET_ID::RAGE:
  549. case RUNE_SET_ID::FATAL:
  550. case RUNE_SET_ID::VAMPIRE:
  551. case RUNE_SET_ID::VIOLENT:
  552. $requested_sets[$requested[$i]] += 4;
  553. break;
  554. }
  555. }
  556. if ($sets === $requested_sets){
  557. return true;
  558. }
  559. else{
  560. return false;
  561. }
  562. }
  563. /**
  564. * Calculates the stat increase by a rune property.
  565. *
  566. * @param string $stat Stat type.
  567. * @param int $value Stat increase value.
  568. * @param int[] Reference to iteration stats array.
  569. */
  570. function sum_rune_stat($stat, $value, &$iteration, $base_atk, $base_def, $base_hp){
  571. switch ($stat){
  572. case RUNE_STAT_ID::ATK:
  573. $iteration["attack"] += $value;
  574. break;
  575. case RUNE_STAT_ID::DEF:
  576. $iteration["defense"] += $value;
  577. break;
  578. case RUNE_STAT_ID::HP:
  579. $iteration["hp"] += $value;
  580. break;
  581. case RUNE_STAT_ID::SPD:
  582. $iteration["speed"] += $value;
  583. break;
  584. case RUNE_STAT_ID::CRR:
  585. $iteration["crit_rate"] += $value;
  586. break;
  587. case RUNE_STAT_ID::CRD:
  588. $iteration["crit_damage"] += $value;
  589. break;
  590. case RUNE_STAT_ID::ACC:
  591. $iteration["accuracy"] += $value;
  592. break;
  593. case RUNE_STAT_ID::RES:
  594. $iteration["resistance"] += $value;
  595. break;
  596. case RUNE_STAT_ID::ATK_P:
  597. $iteration["attack"] += ($base_atk * $value / 100);
  598. break;
  599. case RUNE_STAT_ID::DEF_P:
  600. $iteration["defense"] += ($base_def * $value / 100);
  601. break;
  602. case RUNE_STAT_ID::HP_P:
  603. $iteration["hp"] += ($base_hp * $value / 100);
  604. break;
  605. }
  606. }
  607. /**
  608. * Function to sort arrays based on the "increment" key.
  609. *
  610. * @param $a An array
  611. * @param $b Other array
  612. * @return int Positive if $b before $a, negative otherwise.
  613. */
  614. function sortOptions($a, $b) {
  615. return $b["variation"] - $a["variation"];
  616. }
  617. ?>