| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * File for the optimization action.
- *
- * Implements an action function to be called from the {@see Controller}.
- *
- * @category Action
- */
- /**
- * Executes the optimization action.
- *
- * Reads the POST parameters looking for the following KEYS:
- * mail
- * pass + currentPass
- * api
- * Then it updates the selected info with the prameter vlue. Multiple
- * itemas can be updated at the same time.
- *
- * @return int|string 0 on success, negative values on error. If the API
- * key has been updated, the new key.
- * @category Action
- */
- function action(){
- // Increase max execution time.
- set_time_limit(60);
-
- $runes = [];
- $response = null;
- $uid = filter_input(INPUT_POST, 'uid');
- if ($uid == null){
- return -1;
- }
- $unit_id = filter_input(INPUT_POST, 'unit');
- if ($unit_id == null){
- return -2;
- }
- $unit = new Unit($unit_id, true, $uid);
- $tuning = filter_input(INPUT_POST, 'tuning');
- if ($tuning == null){
- return -1;
- }
- $options = json_decode(filter_input(INPUT_POST, 'options'), true);
- if ($options == null){
- return -2;
- }
- foreach ($options as $option){
- $set = [
- "runes" => [],
- "stats" => [
- "attack" => $unit->attack,
- "defense" => $unit->defense,
- "hp" => $unit->hp,
- "speed" => $unit->speed,
- "crit_rate" => $unit->crit_rate,
- "crit_damage" => $unit->crit_damage,
- "accuracy" => $unit->accuracy,
- "resistance" => $unit->resistance,
- "ehp" => 0,
- "dmg" => 0
- ]
- ];
- foreach ($option["runes"] as $rune_option){
- $rune = new Rune($rune_option["ID"]);
- $r = [
- "id" => $rune_option["ID"],
- "html" => HTML::rune_table($rune)
- ];
-
- // Calculate stat increment
- // TODO: Main stat at level!
- $stat_ids = [
- $rune->main_stat,
- $rune->innate_stat,
- $rune->substat_1,
- $rune->substat_2,
- $rune->substat_3,
- $rune->substat_4
- ];
- $main_value = $rune->main_stat_value;
- switch ($tuning){
- case 1: // All +12
- if ($rune->level < 12){
- $main_value = $rune->get_main_stat_at_level(12);
- }
- break;
- case 2: // Even +15, Odd + 12
- if ($rune->level < 15 && $rune->slot % 2 == 0){
- $main_value = $rune->get_main_stat_at_level(15);
- }
- elseif ($rune->level < 12 && $rune->slot % 2 != 0){
- $main_value = $rune->get_main_stat_at_level(12);
- }
- break;
- case 3: // All +15
- if ($rune->level < 15){
- $main_value = $rune->get_main_stat_at_level(15);
- }
- break;
- }
- $stat_values = [
- $main_value,
- $rune->innate_stat_value,
- $rune->substat_1_value + $rune->substat_1_craft,
- $rune->substat_2_value + $rune->substat_2_craft,
- $rune->substat_3_value + $rune->substat_3_craft,
- $rune->substat_4_value + $rune->substat_4_craft
- ];
- for ($i = 0; $i < 6; $i ++){
- switch ($stat_ids[$i]){
- case RUNE_STAT_ID::ATK:
- $set["stats"]["attack"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::ATK_P:
- $set["stats"]["attack"] += ceil($unit->attack * $stat_values[$i] / 100);
- break;
- case RUNE_STAT_ID::DEF:
- $set["stats"]["defense"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::DEF_P:
- $set["stats"]["defense"] += ceil($unit->defense * $stat_values[$i] / 100);
- break;
- case RUNE_STAT_ID::HP:
- $set["stats"]["hp"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::HP_P:
- $set["stats"]["hp"] += ceil($unit->hp * $stat_values[$i] / 100);
- break;
- case RUNE_STAT_ID::SPD:
- $set["stats"]["speed"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::CRR:
- $set["stats"]["crit_rate"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::CRD:
- $set["stats"]["crit_damage"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::ACC:
- $set["stats"]["accuracy"] += $stat_values[$i];
- break;
- case RUNE_STAT_ID::CRR:
- $set["stats"]["resistance"] += $stat_values[$i];
- break;
- }
- }
- // Calculate EHP and DMG
- $set["stats"]["ehp"] = ceil(((($set["stats"]["def"] * 3.5) + 1140) * $set["stats"]["hp"]) / 1000);
- $atk = $set["stats"]["attack"];
- $crr = $set["stats"]["crit_rate"];
- if ($crr > 100){
- $crr = 100;
- }
- $crd = $set["stats"]["crit_damage"];
- $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
- $set["stats"]["dmg"] = $edmg;
- // Add to the array
- array_push($set["runes"], $r);
-
- }
- array_push($runes, $set);
- }
- // Send back the response
- $response = json_encode($runes);
- if ($response == null){
- return 0;
- }
- else{
- return $response;
- }
- }
- ?>
|