perks update

Perks are now working properly, but they, as training, do not yet impact the item's stats
This commit is contained in:
komiko44240BB
2024-10-12 00:49:44 +02:00
parent 75ba332b9f
commit d741554ca0
167 changed files with 240 additions and 214 deletions

View File

@@ -17,15 +17,15 @@ link_directories(${XLSXWRITER_LIBRARY_DIRS})
add_executable(BattleBay_tool
#main.c
#menu.c
#objects.c
#perks.c
#readobjects.c
#ships.c
#readtraining.c
#clear_input.c
scriptspy/perks_.c
main.c
menu.c
objects.c
perks.c
readobjects.c
ships.c
readtraining.c
clear_input.c
#scriptspy/perks_.c
)
include_directories("/usr/local/include/xlsxio")

61
perks.c
View File

@@ -6,7 +6,7 @@
#include "clear_input.h"
#define MAX_LINE_SIZE 1024
struct Perk* createPerk(char* first_boost_type,char* second_boost_type, int first_boost_value,int second_boost_value) {
struct Perk* createPerk(char* first_boost_type,char* second_boost_type, float first_boost_value,float second_boost_value) {
struct Perk* p = malloc(sizeof(struct Perk));
p->first_boost_type = strdup(first_boost_type);
p->second_boost_type = strdup(second_boost_type);
@@ -62,17 +62,17 @@ void addPerks(struct Object* o) {
return;
}
bool perk_choice = true;
bool is_event = false;
bool is_event = true;
int number_of_perks = numberOfPerks(o);
for(int i = 0; i<number_of_perks; i++){
while(perk_choice){
printf("Is the perk an event perk\n");
printf("\n");
printf("------------------------\n");
printf("1. Yes\n");
printf("2. No\n");
printf("0. Don't add more perks\n");
printf("\n");
printf("Your choice :\n");
printf("------------------------\n");
printf("Your choice : ");
int choice = 0;
scanf("%d",&choice);
clearInputBuffer();
@@ -108,11 +108,10 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
while (perk_rarity_choice) {
printf("What do you want to do\n");
printf("------------------------\n");
printf("1.Common\n");
printf("2.Uncommon\n");
printf("3.Rare\n");
printf("4.Epic\n");
printf("5.Legendary\n");
printf("1.Uncommon\n");
printf("2.Rare\n");
printf("3.Epic\n");
printf("4.Legendary\n");
printf("------------------------\n");
printf("Your choice: ");
int choice = 0;
@@ -120,22 +119,18 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
clearInputBuffer();
switch (choice) {
case 1:
perk_rarity = strdup("common");
perk_rarity_choice = false;
break;
case 2:
perk_rarity = strdup("uncommon");
perk_rarity_choice = false;
break;
case 3:
case 2:
perk_rarity = strdup("rare");
perk_rarity_choice = false;
break;
case 4:
case 3:
perk_rarity = strdup("epic");
perk_rarity_choice = false;
break;
case 5:
case 4:
perk_rarity = strdup("legendary");
perk_rarity_choice = false;
break;
@@ -193,12 +188,12 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
continue;
}
if (fgets(line, sizeof(line), file) == NULL) {
/*if (fgets(line, sizeof(line), file) == NULL) {
printf("Error reading first line from file \"%s\"\n", perks_full_path[i]);
fclose(file);
file = NULL;
continue;
}
}*/
while (!feof(file)) {
if (fgets(line, sizeof(line), file) == NULL) {
@@ -226,16 +221,19 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
}
printf("------------------------\n");
printf("Your choice: ");
int choice_perk = 0;
int choice_perk = 2;
scanf("%d", &choice_perk);
clearInputBuffer();
int file_number = -1;
if (choice_perk <= perk_choice[0]) {
file_number = 0;
} else if (choice_perk <= perk_choice[0] + perk_choice[1]) {
choice_perk = choice_perk - 1;
} else if (choice_perk <= (perk_choice[0] + perk_choice[1])) {
file_number = 1;
choice_perk = choice_perk - perk_choice[0] - 1;
} else {
file_number = 2;
choice_perk = choice_perk - (perk_choice[0] + perk_choice[1]) - 1;
}
FILE* file = fopen(perks_full_path[file_number], "r");
@@ -244,13 +242,13 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
return NULL;
}
if (fgets(line, sizeof(line), file) == NULL) {
/*if (fgets(line, sizeof(line), file) == NULL) {
printf("Error reading first line from file \"%s\"\n", perks_full_path[file_number]);
fclose(file);
return NULL;
}
}*/
perk_iter = 1;
perk_iter = 0;
while (choice_perk > perk_iter) {
if (fgets(line, sizeof(line), file) == NULL) {
printf("Error reading line from file \"%s\"\n", perks_full_path[file_number]);
@@ -259,12 +257,14 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
}
perk_iter++;
}
fgets(line, sizeof(line), file);
if (fgets(line, sizeof(line), file) == NULL) {
if (line == NULL) {
printf("Error reading chosen perk line from file \"%s\"\n", perks_full_path[file_number]);
fclose(file);
return NULL;
}
printf("\n %s \n",line);
char* copiedline = strdup(line);
char* token = strtok(copiedline, ",");
@@ -286,7 +286,7 @@ struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event) {
for (int i = 0; i < num_files; i++) {
free(perks_full_path[i]);
}
displayPerk(*p);
return p;
}
@@ -366,3 +366,12 @@ char** perkLists(struct Object* o) {
}
return files_names;
}
void displayPerk(struct Perk p ) {
printf("Is Event: %s\n", p.is_event ? "True" : "False");
printf("First Boost Value: %.2f\n", p.first_boost_value);
printf("First Boost Type: %s\n", p.first_boost_type);
printf("Second Boost Value: %.2f\n", p.second_boost_value);
printf("Second Boost Type: %s\n", p.second_boost_type);
}

View File

@@ -5,13 +5,13 @@
struct Perk {
bool is_event;
unsigned int first_boost_value;
float first_boost_value;
char* first_boost_type;
unsigned int second_boost_value;
float second_boost_value;
char* second_boost_type;
};
struct Perk* createPerk(char* first_boost_type,char* second_boost_type, int first_boost_value,int second_boost_value);
struct Perk* createPerk(char* first_boost_type,char* second_boost_type, float first_boost_value,float second_boost_value);
int numberOfPerks(struct Object* o);
void addPerks(struct Object* o);
@@ -19,5 +19,5 @@ char** perkLists(struct Object* o);
struct Perk* displayAndChooseAvailablePerks(char** perk_list, bool is_event);
void updateEvent(struct Perk* p,bool is_event);
void displayPerk(struct Perk p );
#endif

View File

@@ -27,7 +27,7 @@ struct Object* readObjectFile(unsigned int object_type, char* object_name, char*
return NULL;
}
// Loop to prompt user for object level until a valid input is provided
/*while (true){
while (true){
printf("What level is the object ?\n");
printf("(Between 1 and 50)\n");
printf("------------------------\n");
@@ -38,8 +38,7 @@ struct Object* readObjectFile(unsigned int object_type, char* object_name, char*
// Validate the level input
if(object_lvl < 0 || object_lvl > 50){
printf("Invalid choice, please try again\n");
}else{*/
int object_lvl = 10;
}else{
// Allocate memory for the filename using object name and rarity
char* object_file_name = malloc(sizeof(char)*(strlen(object_name) + strlen(rarity) + 16 + 1 + 5 + 1));
if(object_file_name == NULL){
@@ -115,5 +114,5 @@ struct Object* readObjectFile(unsigned int object_type, char* object_name, char*
// Return the newly created object
return o;
}
/*}
}*/
}
}

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <xlsxio_read.h>
#include <dirent.h>
@@ -149,20 +150,37 @@ void parse_bonus(const char *bonus, char *value, char *name) {
void write_to_csv(const char *output_path, ItemNode* head) {
ItemNode* current = head;
while (current != NULL) {
char filename[MAX_PATH];
char current_filename[MAX_PATH] = "";
FILE *fp = NULL;
while (current != NULL) {
snprintf(filename, sizeof(filename), "%sevent_%s_%s.csv", output_path, current->item.rarity, current->item.object_name);
FILE *fp = fopen(filename, "a");
if (strcmp(filename, current_filename) != 0) {
if (fp != NULL) {
fclose(fp);
}
strcpy(current_filename, filename);
fp = fopen(filename, "a");
if (fp == NULL) {
perror("fopen");
return;
}
}
fprintf(fp, "%s,%s,%s,%s\n", current->item.first_bonus_value, current->item.first_bonus_name, current->item.second_bonus_value, current->item.second_bonus_name);
fclose(fp);
if (ftell(fp) == 0) {
// File is empty, don't write newline
fprintf(fp, "%s,%s,%s,%s", current->item.first_bonus_value, current->item.first_bonus_name, current->item.second_bonus_value, current->item.second_bonus_name);
} else {
// File is not empty, write newline
fprintf(fp, "\n%s,%s,%s,%s", current->item.first_bonus_value, current->item.first_bonus_name, current->item.second_bonus_value, current->item.second_bonus_name);
}
current = current->next;
}
if (fp != NULL) {
fclose(fp);
}
}