optimize_get_options.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. error_log("ATK" . $unit->attack);
  40. $options = json_decode(filter_input(INPUT_POST, 'options'), true);
  41. if ($options == null){
  42. error_log("NO JSON");
  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. $stat_ids = [
  69. $rune->main_stat,
  70. $rune->innate_stat,
  71. $rune->substat_1,
  72. $rune->substat_2,
  73. $rune->substat_3,
  74. $rune->substat_4
  75. ];
  76. $stat_values = [
  77. $rune->main_stat_value,
  78. $rune->innate_stat_value,
  79. $rune->substat_1_value + $rune->substat_1_craft,
  80. $rune->substat_2_value + $rune->substat_2_craft,
  81. $rune->substat_3_value + $rune->substat_3_craft,
  82. $rune->substat_4_value + $rune->substat_4_craft
  83. ];
  84. for ($i = 0; $i < 6; $i ++){
  85. switch ($stat_ids[$i]){
  86. case RUNE_STAT_ID::ATK:
  87. $set["stats"]["attack"] += $stat_values[$i];
  88. break;
  89. case RUNE_STAT_ID::ATK_P:
  90. $set["stats"]["attack"] += ceil($unit->attack * $stat_values[$i] / 100);
  91. break;
  92. case RUNE_STAT_ID::DEF:
  93. $set["stats"]["defense"] += $stat_values[$i];
  94. break;
  95. case RUNE_STAT_ID::DEF_P:
  96. $set["stats"]["defense"] += ceil($unit->defense * $stat_values[$i] / 100);
  97. break;
  98. case RUNE_STAT_ID::HP:
  99. $set["stats"]["hp"] += $stat_values[$i];
  100. break;
  101. case RUNE_STAT_ID::HP_P:
  102. $set["stats"]["hp"] += ceil($unit->hp * $stat_values[$i] / 100);
  103. break;
  104. case RUNE_STAT_ID::SPD:
  105. $set["stats"]["speed"] += $stat_values[$i];
  106. break;
  107. case RUNE_STAT_ID::CRR:
  108. $set["stats"]["crit_rate"] += $stat_values[$i];
  109. break;
  110. case RUNE_STAT_ID::CRD:
  111. $set["stats"]["crit_damage"] += $stat_values[$i];
  112. break;
  113. case RUNE_STAT_ID::ACC:
  114. $set["stats"]["accuracy"] += $stat_values[$i];
  115. break;
  116. case RUNE_STAT_ID::CRR:
  117. $set["stats"]["resistance"] += $stat_values[$i];
  118. break;
  119. }
  120. }
  121. $set["stats"]["ehp"] = ceil(((($set["stats"]["def"] * 3.5) + 1140) * $set["stats"]["hp"]) / 1000);
  122. $atk = $set["stats"]["attack"];
  123. $crr = $set["stats"]["crit_rate"];
  124. if ($crr > 100){
  125. $crr = 100;
  126. }
  127. $crd = $set["stats"]["crit_damage"];
  128. $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
  129. $set["stats"]["dmg"] = $edmg;
  130. // TODO calculte ehp, dmg
  131. array_push($set["runes"], $r);
  132. }
  133. array_push($runes, $set);
  134. }
  135. $response = json_encode($runes);
  136. if ($response == null){
  137. return 0;
  138. }
  139. else{
  140. return $response;
  141. }
  142. }
  143. ?>