optimize_get_options.php 6.6 KB

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