|
|
@@ -29,7 +29,7 @@
|
|
|
#include <string.h>
|
|
|
#include <sqlite3.h>
|
|
|
#include <json-c/json.h>
|
|
|
-#include "../RuneOptimizer.h"
|
|
|
+#include "../runeoptimizer.h"
|
|
|
#include "../error/error.h"
|
|
|
#include "../db/db.h"
|
|
|
#include "update.h"
|
|
|
@@ -120,7 +120,7 @@ extern int update_json(
|
|
|
int unit_count = json_object_array_length(unit_list);
|
|
|
for (int i = 0; i < unit_count; i++){
|
|
|
idx = json_object_array_get_idx(unit_list, i);
|
|
|
-
|
|
|
+
|
|
|
status = update_json_unit(
|
|
|
idx, six_stars, with_runes, &total_runes, &total_stats
|
|
|
);
|
|
|
@@ -137,11 +137,11 @@ extern int update_json(
|
|
|
json_object_get_string(wizard_level)
|
|
|
);
|
|
|
if (SUCCESS != status) return(status);
|
|
|
-
|
|
|
+
|
|
|
// All parsed
|
|
|
- printf("%d units saved.\n", total_units);
|
|
|
- printf("%d runes saved.\n", total_runes);
|
|
|
- printf("%d rune stats saved.\n", total_stats);
|
|
|
+ printf("%u units saved.\n", total_units);
|
|
|
+ printf("%u runes saved.\n", total_runes);
|
|
|
+ printf("%u rune stats saved.\n", total_stats);
|
|
|
printf("Player info updated\n");
|
|
|
|
|
|
return(SUCCESS);
|
|
|
@@ -151,7 +151,7 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
int total_stats = 0;
|
|
|
DB_Rune rune;
|
|
|
char *query_parameters[43];
|
|
|
- for (int i = 1; i < 43; i ++) query_parameters[i] = malloc(5);
|
|
|
+ for (int i = 1; i < 43; i ++) query_parameters[i] = malloc(35);
|
|
|
// Rune ID
|
|
|
json_object *rune_id = json_object_object_get(rune_json, "rune_id");
|
|
|
strcpy((char *) rune.id, json_object_get_string(rune_id));
|
|
|
@@ -196,11 +196,11 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
json_object *sec_eff = json_object_object_get(rune_json, "sec_eff");
|
|
|
// Loop stats
|
|
|
int stat_count = json_object_array_length(sec_eff);
|
|
|
- json_object *stat_json;
|
|
|
+
|
|
|
rune.stat_count = 0;
|
|
|
for (int i = 0; i < stat_count && i < 4; i++){
|
|
|
rune.stat_count ++;
|
|
|
- stat_json = json_object_array_get_idx(sec_eff, i);
|
|
|
+ json_object *stat_json = json_object_array_get_idx(sec_eff, i);
|
|
|
json_object *stat = json_object_array_get_idx(stat_json, 0);
|
|
|
rune.stats[i].stat = json_object_get_int(stat);
|
|
|
json_object *value = json_object_array_get_idx(stat_json, 1);
|
|
|
@@ -225,39 +225,39 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
sprintf(query_parameters[7], "%f", rune.efficiency);
|
|
|
sprintf(query_parameters[8], "%f", rune.max_efficiency);
|
|
|
sprintf(query_parameters[9], "%d", rune.main.stat);
|
|
|
- sprintf(query_parameters[10], "%d", rune.current_hp_percent);
|
|
|
- sprintf(query_parameters[11], "%d", rune.current_atk_percent);
|
|
|
- sprintf(query_parameters[12], "%d", rune.current_def_percent);
|
|
|
- sprintf(query_parameters[13], "%d", rune.current_hp_flat);
|
|
|
- sprintf(query_parameters[14], "%d", rune.current_atk_flat);
|
|
|
- sprintf(query_parameters[15], "%d", rune.current_def_flat);
|
|
|
- sprintf(query_parameters[16], "%d", rune.current_spd);
|
|
|
- sprintf(query_parameters[17], "%d", rune.current_crr);
|
|
|
- sprintf(query_parameters[18], "%d", rune.current_crd);
|
|
|
- sprintf(query_parameters[19], "%d", rune.current_acc);
|
|
|
- sprintf(query_parameters[20], "%d", rune.current_res);
|
|
|
- sprintf(query_parameters[21], "%d", rune.lv12_hp_percent);
|
|
|
- sprintf(query_parameters[22], "%d", rune.lv12_atk_percent);
|
|
|
- sprintf(query_parameters[23], "%d", rune.lv12_def_percent);
|
|
|
- sprintf(query_parameters[24], "%d", rune.lv12_hp_flat);
|
|
|
- sprintf(query_parameters[25], "%d", rune.lv12_atk_flat);
|
|
|
- sprintf(query_parameters[26], "%d", rune.lv12_def_flat);
|
|
|
- sprintf(query_parameters[27], "%d", rune.lv12_spd);
|
|
|
- sprintf(query_parameters[28], "%d", rune.lv12_crr);
|
|
|
- sprintf(query_parameters[29], "%d", rune.lv12_crd);
|
|
|
- sprintf(query_parameters[30], "%d", rune.lv12_acc);
|
|
|
- sprintf(query_parameters[31], "%d", rune.lv12_res);
|
|
|
- sprintf(query_parameters[32], "%d", rune.lv15_hp_percent);
|
|
|
- sprintf(query_parameters[33], "%d", rune.lv15_atk_percent);
|
|
|
- sprintf(query_parameters[34], "%d", rune.lv15_def_percent);
|
|
|
- sprintf(query_parameters[35], "%d", rune.lv15_hp_flat);
|
|
|
- sprintf(query_parameters[36], "%d", rune.lv15_atk_flat);
|
|
|
- sprintf(query_parameters[37], "%d", rune.lv15_def_flat);
|
|
|
- sprintf(query_parameters[38], "%d", rune.lv15_spd);
|
|
|
- sprintf(query_parameters[39], "%d", rune.lv15_crr);
|
|
|
- sprintf(query_parameters[40], "%d", rune.lv15_crd);
|
|
|
- sprintf(query_parameters[41], "%d", rune.lv15_acc);
|
|
|
- sprintf(query_parameters[42], "%d", rune.lv15_res);
|
|
|
+ sprintf(query_parameters[10], "%u", rune.current_hp_percent);
|
|
|
+ sprintf(query_parameters[11], "%u", rune.current_atk_percent);
|
|
|
+ sprintf(query_parameters[12], "%u", rune.current_def_percent);
|
|
|
+ sprintf(query_parameters[13], "%u", rune.current_hp_flat);
|
|
|
+ sprintf(query_parameters[14], "%u", rune.current_atk_flat);
|
|
|
+ sprintf(query_parameters[15], "%u", rune.current_def_flat);
|
|
|
+ sprintf(query_parameters[16], "%u", rune.current_spd);
|
|
|
+ sprintf(query_parameters[17], "%u", rune.current_crr);
|
|
|
+ sprintf(query_parameters[18], "%u", rune.current_crd);
|
|
|
+ sprintf(query_parameters[19], "%u", rune.current_acc);
|
|
|
+ sprintf(query_parameters[20], "%u", rune.current_res);
|
|
|
+ sprintf(query_parameters[21], "%u", rune.lv12_hp_percent);
|
|
|
+ sprintf(query_parameters[22], "%u", rune.lv12_atk_percent);
|
|
|
+ sprintf(query_parameters[23], "%u", rune.lv12_def_percent);
|
|
|
+ sprintf(query_parameters[24], "%u", rune.lv12_hp_flat);
|
|
|
+ sprintf(query_parameters[25], "%u", rune.lv12_atk_flat);
|
|
|
+ sprintf(query_parameters[26], "%u", rune.lv12_def_flat);
|
|
|
+ sprintf(query_parameters[27], "%u", rune.lv12_spd);
|
|
|
+ sprintf(query_parameters[28], "%u", rune.lv12_crr);
|
|
|
+ sprintf(query_parameters[29], "%u", rune.lv12_crd);
|
|
|
+ sprintf(query_parameters[30], "%u", rune.lv12_acc);
|
|
|
+ sprintf(query_parameters[31], "%u", rune.lv12_res);
|
|
|
+ sprintf(query_parameters[32], "%u", rune.lv15_hp_percent);
|
|
|
+ sprintf(query_parameters[33], "%u", rune.lv15_atk_percent);
|
|
|
+ sprintf(query_parameters[34], "%u", rune.lv15_def_percent);
|
|
|
+ sprintf(query_parameters[35], "%u", rune.lv15_hp_flat);
|
|
|
+ sprintf(query_parameters[36], "%u", rune.lv15_atk_flat);
|
|
|
+ sprintf(query_parameters[37], "%u", rune.lv15_def_flat);
|
|
|
+ sprintf(query_parameters[38], "%u", rune.lv15_spd);
|
|
|
+ sprintf(query_parameters[39], "%u", rune.lv15_crr);
|
|
|
+ sprintf(query_parameters[40], "%u", rune.lv15_crd);
|
|
|
+ sprintf(query_parameters[41], "%u", rune.lv15_acc);
|
|
|
+ sprintf(query_parameters[42], "%u", rune.lv15_res);
|
|
|
if (
|
|
|
SUCCESS !=
|
|
|
db_execute(
|
|
|
@@ -293,7 +293,7 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
//query_parameters[0] = rune.id; // No need, already has id
|
|
|
query_parameters[1] = "-1"; // Main stat
|
|
|
sprintf(query_parameters[2], "%d", rune.main.stat);
|
|
|
- sprintf(query_parameters[3], "%d", rune.main.value);
|
|
|
+ sprintf(query_parameters[3], "%u", rune.main.value);
|
|
|
query_parameters[4] = "0"; // Mains can't be grinded.
|
|
|
query_parameters[5] = "0"; // Mains can't be enchanted.
|
|
|
if (
|
|
|
@@ -316,7 +316,7 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
//query_parameters[0] = rune.id; // No need, already has id
|
|
|
query_parameters[1] = "0"; // Main stat
|
|
|
sprintf(query_parameters[2], "%d", rune.innate.stat);
|
|
|
- sprintf(query_parameters[3], "%d", rune.innate.value);
|
|
|
+ sprintf(query_parameters[3], "%u", rune.innate.value);
|
|
|
query_parameters[4] = "0"; // Innates can't be grinded.
|
|
|
query_parameters[5] = "0"; // Innates can't be enchanted.
|
|
|
if (
|
|
|
@@ -344,9 +344,9 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
sprintf(query_parameters[1], "%d", s + 1); // 1-4
|
|
|
query_parameters[2] = malloc(5);
|
|
|
sprintf(query_parameters[2], "%d", rune.stats[s].stat);
|
|
|
- sprintf(query_parameters[3], "%d", rune.stats[s].value);
|
|
|
+ sprintf(query_parameters[3], "%u", rune.stats[s].value);
|
|
|
query_parameters[4] = malloc(5);
|
|
|
- sprintf(query_parameters[4], "%d", rune.stats[s].grind);
|
|
|
+ sprintf(query_parameters[4], "%u", rune.stats[s].grind);
|
|
|
query_parameters[5] = malloc(5);
|
|
|
sprintf(query_parameters[5], "%d", rune.stats[s].enchant);
|
|
|
if (
|
|
|
@@ -365,14 +365,15 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
// Now that everything is in the database, I can calculate efficiencies
|
|
|
float efficiency = 0.0f;
|
|
|
float max_efficiency = 0.0f;
|
|
|
update_efficiency(query_parameters[0], &efficiency, &max_efficiency);
|
|
|
strcpy(query_parameters[2], query_parameters[0]); //ID
|
|
|
- sprintf(query_parameters[0], "%6.2f", efficiency);
|
|
|
- sprintf(query_parameters[1], "%6.2f", max_efficiency);
|
|
|
+ query_parameters[1] = malloc(35);
|
|
|
+ query_parameters[2] = malloc(35);
|
|
|
+ sprintf(query_parameters[0], "%3.2f", efficiency);
|
|
|
+ sprintf(query_parameters[1], "%3.2f", max_efficiency);
|
|
|
if (
|
|
|
SUCCESS !=
|
|
|
db_execute(
|
|
|
@@ -385,7 +386,6 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
);
|
|
|
return(-1);
|
|
|
}
|
|
|
-
|
|
|
return(total_stats);
|
|
|
}
|
|
|
|
|
|
@@ -448,12 +448,11 @@ static int update_json_unit(
|
|
|
// Parse unit runes
|
|
|
json_object *unit_runes = json_object_object_get(unit_json, "runes");
|
|
|
int rune_count = json_object_array_length(unit_runes);
|
|
|
- json_object *idx;
|
|
|
for (int i = 0; i < rune_count; i++){
|
|
|
unit_has_runes = TRUE;
|
|
|
// TODO: Test this: reference or value?
|
|
|
total_runes ++;
|
|
|
- idx = json_object_array_get_idx(unit_runes, i);
|
|
|
+ json_object *idx = json_object_array_get_idx(unit_runes, i);
|
|
|
int status = update_json_rune(idx, unit.id);
|
|
|
if (status != -1) *total_stats += status;
|
|
|
}
|
|
|
@@ -469,27 +468,27 @@ static int update_json_unit(
|
|
|
query_parameters[1] = (char *) unit.name;
|
|
|
sprintf(query_parameters[2], "%d", unit.stars);
|
|
|
sprintf(query_parameters[3], "%d", unit.level);
|
|
|
- sprintf(query_parameters[4], "%d", unit.base_hp);
|
|
|
- sprintf(query_parameters[5], "%d", unit.base_atk);
|
|
|
- sprintf(query_parameters[6], "%d", unit.base_def);
|
|
|
- sprintf(query_parameters[7], "%d", unit.base_spd);
|
|
|
- sprintf(query_parameters[8], "%d", unit.base_crr);
|
|
|
- sprintf(query_parameters[9], "%d", unit.base_crd);
|
|
|
- sprintf(query_parameters[10], "%d", unit.base_res);
|
|
|
- sprintf(query_parameters[11], "%d", unit.base_acc);
|
|
|
+ sprintf(query_parameters[4], "%u", unit.base_hp);
|
|
|
+ sprintf(query_parameters[5], "%u", unit.base_atk);
|
|
|
+ sprintf(query_parameters[6], "%u", unit.base_def);
|
|
|
+ sprintf(query_parameters[7], "%u", unit.base_spd);
|
|
|
+ sprintf(query_parameters[8], "%u", unit.base_crr);
|
|
|
+ sprintf(query_parameters[9], "%u", unit.base_crd);
|
|
|
+ sprintf(query_parameters[10], "%u", unit.base_res);
|
|
|
+ sprintf(query_parameters[11], "%u", unit.base_acc);
|
|
|
// Insert current stats as base stats.
|
|
|
// They will be updated later.
|
|
|
- sprintf(query_parameters[12], "%d", unit.base_hp);
|
|
|
- sprintf(query_parameters[13], "%d", unit.base_atk);
|
|
|
- sprintf(query_parameters[14], "%d", unit.base_def);
|
|
|
- sprintf(query_parameters[15], "%d", unit.base_spd);
|
|
|
- sprintf(query_parameters[16], "%d", unit.base_crr);
|
|
|
- sprintf(query_parameters[17], "%d", unit.base_crd);
|
|
|
- sprintf(query_parameters[18], "%d", unit.base_res);
|
|
|
- sprintf(query_parameters[19], "%d", unit.base_acc);
|
|
|
+ sprintf(query_parameters[12], "%u", unit.base_hp);
|
|
|
+ sprintf(query_parameters[13], "%u", unit.base_atk);
|
|
|
+ sprintf(query_parameters[14], "%u", unit.base_def);
|
|
|
+ sprintf(query_parameters[15], "%u", unit.base_spd);
|
|
|
+ sprintf(query_parameters[16], "%u", unit.base_crr);
|
|
|
+ sprintf(query_parameters[17], "%u", unit.base_crd);
|
|
|
+ sprintf(query_parameters[18], "%u", unit.base_res);
|
|
|
+ sprintf(query_parameters[19], "%u", unit.base_acc);
|
|
|
// TODO: Get storage status. But how??
|
|
|
sprintf(query_parameters[20], "%d", 0);
|
|
|
- sprintf(query_parameters[21], "%d", unit.monster);
|
|
|
+ sprintf(query_parameters[21], "%u", unit.monster);
|
|
|
if (
|
|
|
SUCCESS !=
|
|
|
db_execute(
|