optimize_get_options.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // Increase max execution time.
  27. set_time_limit(60);
  28. $runes = [];
  29. $response = null;
  30. $uid = filter_input(INPUT_POST, 'uid');
  31. if ($uid == null){
  32. return -1;
  33. }
  34. $unit_id = filter_input(INPUT_POST, 'unit');
  35. if ($unit_id == null){
  36. return -2;
  37. }
  38. $unit = new Unit($unit_id, true, $uid);
  39. $tuning = filter_input(INPUT_POST, 'tuning');
  40. if ($tuning == null){
  41. return -1;
  42. }
  43. $options = json_decode(filter_input(INPUT_POST, 'options'), true);
  44. if ($options == null){
  45. return -2;
  46. }
  47. foreach ($options as $option){
  48. $set = [
  49. "runes" => [],
  50. "stats" => [
  51. "attack" => $unit->attack,
  52. "defense" => $unit->defense,
  53. "hp" => $unit->hp,
  54. "speed" => $unit->speed,
  55. "crit_rate" => $unit->crit_rate,
  56. "crit_damage" => $unit->crit_damage,
  57. "accuracy" => $unit->accuracy,
  58. "resistance" => $unit->resistance,
  59. "ehp" => 0,
  60. "dmg" => 0
  61. ]
  62. ];
  63. foreach ($option["runes"] as $rune_option){
  64. $rune = new Rune($rune_option["ID"]);
  65. $r = [
  66. "id" => $rune_option["ID"],
  67. "html" => HTML::rune_table($rune)
  68. ];
  69. // Calculate stat increment
  70. // TODO: Main stat at level!
  71. $stat_ids = [
  72. $rune->main_stat,
  73. $rune->innate_stat,
  74. $rune->substat_1,
  75. $rune->substat_2,
  76. $rune->substat_3,
  77. $rune->substat_4
  78. ];
  79. $main_value = $rune->main_stat_value;
  80. switch ($tuning){
  81. case 1: // All +12
  82. if ($rune->level < 12){
  83. $main_value = $rune->get_main_stat_at_level(12);
  84. }
  85. break;
  86. case 2: // Even +15, Odd + 12
  87. if ($rune->level < 15 && $rune->slot % 2 == 0){
  88. $main_value = $rune->get_main_stat_at_level(15);
  89. }
  90. elseif ($rune->level < 12 && $rune->slot % 2 != 0){
  91. $main_value = $rune->get_main_stat_at_level(12);
  92. }
  93. break;
  94. case 3: // All +15
  95. if ($rune->level < 15){
  96. $main_value = $rune->get_main_stat_at_level(15);
  97. }
  98. break;
  99. }
  100. $stat_values = [
  101. $rune->main_stat_value,
  102. $rune->innate_stat_value,
  103. $rune->substat_1_value + $rune->substat_1_craft,
  104. $rune->substat_2_value + $rune->substat_2_craft,
  105. $rune->substat_3_value + $rune->substat_3_craft,
  106. $rune->substat_4_value + $rune->substat_4_craft
  107. ];
  108. for ($i = 0; $i < 6; $i ++){
  109. switch ($stat_ids[$i]){
  110. case RUNE_STAT_ID::ATK:
  111. $set["stats"]["attack"] += $stat_values[$i];
  112. break;
  113. case RUNE_STAT_ID::ATK_P:
  114. $set["stats"]["attack"] += ceil($unit->attack * $stat_values[$i] / 100);
  115. break;
  116. case RUNE_STAT_ID::DEF:
  117. $set["stats"]["defense"] += $stat_values[$i];
  118. break;
  119. case RUNE_STAT_ID::DEF_P:
  120. $set["stats"]["defense"] += ceil($unit->defense * $stat_values[$i] / 100);
  121. break;
  122. case RUNE_STAT_ID::HP:
  123. $set["stats"]["hp"] += $stat_values[$i];
  124. break;
  125. case RUNE_STAT_ID::HP_P:
  126. $set["stats"]["hp"] += ceil($unit->hp * $stat_values[$i] / 100);
  127. break;
  128. case RUNE_STAT_ID::SPD:
  129. $set["stats"]["speed"] += $stat_values[$i];
  130. break;
  131. case RUNE_STAT_ID::CRR:
  132. $set["stats"]["crit_rate"] += $stat_values[$i];
  133. break;
  134. case RUNE_STAT_ID::CRD:
  135. $set["stats"]["crit_damage"] += $stat_values[$i];
  136. break;
  137. case RUNE_STAT_ID::ACC:
  138. $set["stats"]["accuracy"] += $stat_values[$i];
  139. break;
  140. case RUNE_STAT_ID::CRR:
  141. $set["stats"]["resistance"] += $stat_values[$i];
  142. break;
  143. }
  144. }
  145. // Calculate EHP and DMG
  146. $set["stats"]["ehp"] = ceil(((($set["stats"]["def"] * 3.5) + 1140) * $set["stats"]["hp"]) / 1000);
  147. $atk = $set["stats"]["attack"];
  148. $crr = $set["stats"]["crit_rate"];
  149. if ($crr > 100){
  150. $crr = 100;
  151. }
  152. $crd = $set["stats"]["crit_damage"];
  153. $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
  154. $set["stats"]["dmg"] = $edmg;
  155. // Add to the array
  156. array_push($set["runes"], $r);
  157. }
  158. array_push($runes, $set);
  159. }
  160. // Send back the response
  161. $response = json_encode($runes);
  162. if ($response == null){
  163. return 0;
  164. }
  165. else{
  166. return $response;
  167. }
  168. }
  169. ?>