|
@@ -56,9 +56,7 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id);
|
|
|
* stderr.
|
|
* stderr.
|
|
|
*
|
|
*
|
|
|
* @param[in] unit_json Unit json fragment.
|
|
* @param[in] unit_json Unit json fragment.
|
|
|
- * @param[in] six_stars Indicator to import only 6* units. Units with runes will
|
|
|
|
|
- * be saved anyway.
|
|
|
|
|
- * @param[in] with_runes Indicator to import only units with runes.
|
|
|
|
|
|
|
+ * @param[in] options Options passed to the updater.
|
|
|
* @param[out] total_runes Cunter for runes. Will be increased for each saved
|
|
* @param[out] total_runes Cunter for runes. Will be increased for each saved
|
|
|
* rune.
|
|
* rune.
|
|
|
* @param[out] total_stats Cunter for rune stats. Will be increased for each
|
|
* @param[out] total_stats Cunter for rune stats. Will be increased for each
|
|
@@ -67,20 +65,28 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id);
|
|
|
* the unit was not saved because it did not match the criteria. -1 on error.
|
|
* the unit was not saved because it did not match the criteria. -1 on error.
|
|
|
*/
|
|
*/
|
|
|
static int update_json_unit(
|
|
static int update_json_unit(
|
|
|
- json_object *unit_json, unsigned char six_stars,
|
|
|
|
|
- unsigned char with_runes, unsigned int *total_runes, unsigned int *total_stats
|
|
|
|
|
|
|
+ json_object *unit_json, Update_Options *options,
|
|
|
|
|
+ unsigned int *total_runes, unsigned int *total_stats
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
-extern int update_json(
|
|
|
|
|
- char file[], unsigned char six_stars,
|
|
|
|
|
- unsigned char with_runes, unsigned char clear_teams, unsigned char gui
|
|
|
|
|
-){
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Saves runes for RTA mode.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Unassigns every rune in the database, and then updates them from the json
|
|
|
|
|
+ * file.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param[in] runes world_arena_rune_equip_list object of the json.
|
|
|
|
|
+ * @return number of runes assigned in rta mode.
|
|
|
|
|
+ */
|
|
|
|
|
+static int save_rta_runes(json_object *runes);
|
|
|
|
|
+
|
|
|
|
|
+extern int update_json(char file[], Update_Options *options){
|
|
|
// Counters for objcts saved
|
|
// Counters for objcts saved
|
|
|
unsigned int total_units = 0;
|
|
unsigned int total_units = 0;
|
|
|
unsigned int total_runes = 0;
|
|
unsigned int total_runes = 0;
|
|
|
unsigned int total_stats = 0;
|
|
unsigned int total_stats = 0;
|
|
|
|
|
|
|
|
- if (gui == FALSE) printf("Updating from json file: %s\n", file);
|
|
|
|
|
|
|
+ if (!options->quiet) printf("Updating from json file: %s\n", file);
|
|
|
|
|
|
|
|
// Read the JSON content
|
|
// Read the JSON content
|
|
|
json_object *root = json_object_from_file(file);
|
|
json_object *root = json_object_from_file(file);
|
|
@@ -101,7 +107,7 @@ extern int update_json(
|
|
|
fflush(stdout); // To refresh GUI output.
|
|
fflush(stdout); // To refresh GUI output.
|
|
|
|
|
|
|
|
// Recreate the database tables
|
|
// Recreate the database tables
|
|
|
- int status = update_db_tables(clear_teams);
|
|
|
|
|
|
|
+ int status = update_db_tables(options->clear);
|
|
|
if (SUCCESS != status) return(status);
|
|
if (SUCCESS != status) return(status);
|
|
|
|
|
|
|
|
// Parse runes
|
|
// Parse runes
|
|
@@ -122,7 +128,7 @@ extern int update_json(
|
|
|
idx = json_object_array_get_idx(unit_list, i);
|
|
idx = json_object_array_get_idx(unit_list, i);
|
|
|
|
|
|
|
|
status = update_json_unit(
|
|
status = update_json_unit(
|
|
|
- idx, six_stars, with_runes, &total_runes, &total_stats
|
|
|
|
|
|
|
+ idx, options, &total_runes, &total_stats
|
|
|
);
|
|
);
|
|
|
if (status == 1) total_units ++;
|
|
if (status == 1) total_units ++;
|
|
|
}
|
|
}
|
|
@@ -130,11 +136,19 @@ extern int update_json(
|
|
|
status = update_current_stats();
|
|
status = update_current_stats();
|
|
|
if (SUCCESS != status) return(status);
|
|
if (SUCCESS != status) return(status);
|
|
|
|
|
|
|
|
|
|
+ // If rta mode, update rta runes
|
|
|
|
|
+ if (options->rta){
|
|
|
|
|
+ json_object *rta_runes =
|
|
|
|
|
+ json_object_object_get(root, "world_arena_rune_equip_list");
|
|
|
|
|
+ save_rta_runes(rta_runes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Insert into table info
|
|
// Insert into table info
|
|
|
status = update_info(
|
|
status = update_info(
|
|
|
json_object_get_string(wizard_id),
|
|
json_object_get_string(wizard_id),
|
|
|
json_object_get_string(wizard_name),
|
|
json_object_get_string(wizard_name),
|
|
|
- json_object_get_string(wizard_level)
|
|
|
|
|
|
|
+ json_object_get_string(wizard_level),
|
|
|
|
|
+ options->rta
|
|
|
);
|
|
);
|
|
|
if (SUCCESS != status) return(status);
|
|
if (SUCCESS != status) return(status);
|
|
|
|
|
|
|
@@ -390,11 +404,11 @@ static int update_json_rune(json_object *rune_json, unsigned char *unit_id){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int update_json_unit(
|
|
static int update_json_unit(
|
|
|
- json_object *unit_json, unsigned char six_stars,
|
|
|
|
|
- unsigned char with_runes, unsigned int *total_runes, unsigned int *total_stats
|
|
|
|
|
|
|
+ json_object *unit_json, Update_Options *options,
|
|
|
|
|
+ unsigned int *total_runes, unsigned int *total_stats
|
|
|
){
|
|
){
|
|
|
int ret_val = 0;
|
|
int ret_val = 0;
|
|
|
- unsigned char unit_has_runes = FALSE;
|
|
|
|
|
|
|
+ bool unit_has_runes = false;
|
|
|
struct DB_Unit unit;
|
|
struct DB_Unit unit;
|
|
|
char *query_parameters[23];
|
|
char *query_parameters[23];
|
|
|
for (int i = 1; i < 23; i ++) query_parameters[i] = malloc(5);
|
|
for (int i = 1; i < 23; i ++) query_parameters[i] = malloc(5);
|
|
@@ -449,7 +463,7 @@ static int update_json_unit(
|
|
|
json_object *unit_runes = json_object_object_get(unit_json, "runes");
|
|
json_object *unit_runes = json_object_object_get(unit_json, "runes");
|
|
|
int rune_count = json_object_array_length(unit_runes);
|
|
int rune_count = json_object_array_length(unit_runes);
|
|
|
for (int i = 0; i < rune_count; i++){
|
|
for (int i = 0; i < rune_count; i++){
|
|
|
- unit_has_runes = TRUE;
|
|
|
|
|
|
|
+ unit_has_runes = true;
|
|
|
// TODO: Test this: reference or value?
|
|
// TODO: Test this: reference or value?
|
|
|
total_runes ++;
|
|
total_runes ++;
|
|
|
json_object *idx = json_object_array_get_idx(unit_runes, i);
|
|
json_object *idx = json_object_array_get_idx(unit_runes, i);
|
|
@@ -459,9 +473,14 @@ static int update_json_unit(
|
|
|
|
|
|
|
|
// Insert unit, depending on flags and status
|
|
// Insert unit, depending on flags and status
|
|
|
if (
|
|
if (
|
|
|
- unit_has_runes == TRUE ||
|
|
|
|
|
- (six_stars == FALSE && with_runes == FALSE) ||
|
|
|
|
|
- (six_stars == TRUE && unit.stars == TRUE)
|
|
|
|
|
|
|
+ unit_has_runes
|
|
|
|
|
+ || (
|
|
|
|
|
+ !options->runes // If no runes, and only runes flag, don't
|
|
|
|
|
+ && (
|
|
|
|
|
+ (unit.level < 40 && options->lower) // lv<40 only with lower flag
|
|
|
|
|
+ || (unit.level == 40)
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
){
|
|
){
|
|
|
ret_val = 1;
|
|
ret_val = 1;
|
|
|
query_parameters[0] = (char *) unit.id;
|
|
query_parameters[0] = (char *) unit.id;
|
|
@@ -498,16 +517,49 @@ static int update_json_unit(
|
|
|
" base_crr, base_crd, base_res, base_acc,"
|
|
" base_crr, base_crd, base_res, base_acc,"
|
|
|
" current_hp, current_atk, current_def, current_spd,"
|
|
" current_hp, current_atk, current_def, current_spd,"
|
|
|
" current_crr, current_crd, current_res, current_acc,"
|
|
" current_crr, current_crd, current_res, current_acc,"
|
|
|
- " storage, monster"
|
|
|
|
|
|
|
+ " storage, monster, modified"
|
|
|
") VALUES ("
|
|
") VALUES ("
|
|
|
- " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
|
|
|
|
|
|
|
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
|
|
|
|
|
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0"
|
|
|
")",
|
|
")",
|
|
|
query_parameters
|
|
query_parameters
|
|
|
)
|
|
)
|
|
|
){
|
|
){
|
|
|
fprintf(stderr, "Unable to insert unit: %s\n", sqlite3_errmsg(db));
|
|
fprintf(stderr, "Unable to insert unit: %s\n", sqlite3_errmsg(db));
|
|
|
- return(-1);
|
|
|
|
|
|
|
+ return ERROR_DB_INSERT_UNITS;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ret_val;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int save_rta_runes(json_object *runes){
|
|
|
|
|
+ // Unassigne every rune
|
|
|
|
|
+ if (SUCCESS != db_execute("UPDATE runes SET unit = '' ", NULL)){
|
|
|
|
|
+ fprintf(
|
|
|
|
|
+ stderr, "Unable to clear runes for RTA: %s\n", sqlite3_errmsg(db)
|
|
|
|
|
+ );
|
|
|
|
|
+ return ERROR_DB_UPDATE_RUNES;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Loop the json object and save the runes
|
|
|
|
|
+ int count = json_object_array_length(runes);
|
|
|
|
|
+ char *parameters[2]; // RUNE_ID_LEN > UNIT_ID_LEN
|
|
|
|
|
+ parameters[0] = malloc(sizeof(char) * (RUNE_ID_LEN + 1));
|
|
|
|
|
+ parameters[1] = malloc(sizeof(char) * (RUNE_ID_LEN + 1));
|
|
|
|
|
+
|
|
|
|
|
+ json_object *idx;
|
|
|
|
|
+ int i;
|
|
|
|
|
+ for (i = 0; i < count; i++){
|
|
|
|
|
+ idx = json_object_array_get_idx(runes, i);
|
|
|
|
|
+ json_object *rune_id = json_object_object_get(idx, "rune_id");
|
|
|
|
|
+ json_object *unit_id = json_object_object_get(idx, "occupied_id");
|
|
|
|
|
+ strcpy(parameters[0], json_object_get_string(unit_id));
|
|
|
|
|
+ strcpy(parameters[1], json_object_get_string(rune_id));
|
|
|
|
|
+ if (SUCCESS != db_execute(
|
|
|
|
|
+ "UPDATE runes SET unit = ? WHERE id = ?", parameters)
|
|
|
|
|
+ ){
|
|
|
|
|
+ fprintf(stderr, "Error saving RTA rune: %s\n", sqlite3_errmsg(db));
|
|
|
|
|
+ return ERROR_DB_UPDATE_RUNES;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return(ret_val);
|
|
|
|
|
|
|
+ return i;
|
|
|
}
|
|
}
|