mirror of
https://github.com/komiko44240BB/BattleBay_tool_v1.0.git
synced 2026-01-18 16:27:29 +01:00
update perks
This commit is contained in:
Binary file not shown.
Binary file not shown.
260
perks.c
260
perks.c
@@ -14,7 +14,40 @@ struct Perk* createPerk(char* first_boost_type,char* second_boost_type, int firs
|
||||
}
|
||||
|
||||
int numberOfPerks(struct Object* o) {
|
||||
|
||||
if(strcmp(o->rarity, "common") == 0){
|
||||
if(o->level>20){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if(strcmp(o->rarity, "uncommon") == 0){
|
||||
switch (o->level){
|
||||
case o->level > 30: return 2;
|
||||
case o->level > 10: return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
if(strcmp(o->rarity, "rare") == 0){
|
||||
switch (o->level){
|
||||
case o->level > 20: return 3;
|
||||
case o->level > 10: return 2;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
if(strcmp(o->rarity, "epic") == 0){
|
||||
switch (o->level){
|
||||
case o->level > 30: return 4;
|
||||
case o->level > 10: return 3;
|
||||
default: return 2;
|
||||
}
|
||||
}
|
||||
if(strcmp(o->rarity, "legendary") == 0){
|
||||
if(o->level>20){
|
||||
return 4;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void addPerks(struct Object* o) {
|
||||
@@ -37,28 +70,29 @@ void addPerks(struct Object* o) {
|
||||
scanf("%d",&choice);
|
||||
clearInputBuffer();
|
||||
switch (choice){
|
||||
case 1 :
|
||||
is_event = true;
|
||||
perk_choice = false;
|
||||
break;
|
||||
case 2:
|
||||
is_event = false;
|
||||
perk_choice = false;
|
||||
break;
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
printf("Wrong input\n");
|
||||
case 1 :
|
||||
is_event = true;
|
||||
perk_choice = false;
|
||||
break;
|
||||
case 2:
|
||||
is_event = false;
|
||||
perk_choice = false;
|
||||
break;
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
printf("Wrong input\n");
|
||||
}
|
||||
}
|
||||
char** perk_list = perkLists(o);
|
||||
displayAvailablePerks(perk_list, is_event);
|
||||
o->perk_list[i] = displayAndChoseAvailablePerks(perk_list, is_event);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void displayAvailablePerks(char** perk_list, bool is_event) {
|
||||
struct Perk* displayAndChoseAvailablePerks(char** perk_list, bool is_event) {
|
||||
if(perk_list == NULL){
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
char* perk_rarity = "" ;
|
||||
bool perk_rarity_choice = true;
|
||||
@@ -100,6 +134,7 @@ void displayAvailablePerks(char** perk_list, bool is_event) {
|
||||
printf("Invalid choice, please try again\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(is_event){
|
||||
char* event_perks_file_name_self = malloc(19 + strlen(perk_rarity) + 1 + strlen(perk_list[0]) + 4 + 1);
|
||||
char* event_perks_file_name_group = malloc(19 + strlen(perk_rarity) + 1 + strlen(perk_list[1]) + 4 + 1);
|
||||
@@ -107,33 +142,194 @@ void displayAvailablePerks(char** perk_list, bool is_event) {
|
||||
free(perk_rarity);
|
||||
free(event_perks_file_name_self);
|
||||
free(event_perks_file_name_group);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
sprintf(event_perks_file_name_self, "../Perk_data/event_%s_%s.csv", perk_rarity, perk_list[0]);
|
||||
sprintf(event_perks_file_name_group, "../Perk_data/event_%s_%s.csv", perk_rarity, perk_list[1]);
|
||||
|
||||
FILE* file = fopen(event_perks_file_name_self, "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening \"%s\", file does not exist\n", event_perks_file_name_self);
|
||||
return ;
|
||||
}
|
||||
char* perks_full_path[2] = {event_perks_file_name_self, event_perks_file_name_group};
|
||||
char line[MAX_LINE_SIZE];
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return;
|
||||
int perk_iter = 0;
|
||||
int perk_choice[2] = {0};
|
||||
printf("What do you want to do\n");
|
||||
printf("------------------------\n");
|
||||
for(int i =0; i < 2; i++){
|
||||
FILE* file = fopen(perks_full_path[i], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening \"%s\", file does not exist\n", perks_full_path[i]);
|
||||
}else{
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
while(!feof(file)){
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
char* copiedline = strdup(line);
|
||||
perk_iter++;
|
||||
printf("%d. %s\n", perk_iter,copiedline);
|
||||
}
|
||||
if(i>0){
|
||||
perk_choice[i] = perk_iter - perk_choice[i-1];
|
||||
}else{
|
||||
perk_choice[i] = perk_iter;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
printf("------------------------\n");
|
||||
printf("Your choice: ");
|
||||
int choice_perk = 0;
|
||||
scanf("%d",&choice_perk);
|
||||
clearInputBuffer();
|
||||
int file_number = -1;
|
||||
if(choice_perk <= perk_choice[0]){
|
||||
file_number = 0;
|
||||
} else{
|
||||
file_number = 1;
|
||||
}
|
||||
char* copiedline = strdup(line);
|
||||
|
||||
FILE* file = fopen(perks_full_path[file_number], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening \"%s\", file does not exist\n", perks_full_path[file_number]);
|
||||
}else{
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
perk_iter = 1;
|
||||
while(choice_perk<perk_iter){
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
perk_iter++;
|
||||
}
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
char* copiedline = strdup(line);
|
||||
char* token = strtok(copiedline, ",");
|
||||
float first_boost_value = atof(token);
|
||||
token = strtok(NULL, ",");
|
||||
char* first_boost_type = strdup(token);
|
||||
token = strtok(NULL, ",");
|
||||
float second_boost_value = atof(token);
|
||||
token = strtok(NULL, "\r");
|
||||
char* second_boost_type = strdup(token);
|
||||
struct Perk* p = createPerk(first_boost_type,second_boost_type,first_boost_value,second_boost_value);
|
||||
updateEvent(p,is_event);
|
||||
return p;
|
||||
}
|
||||
|
||||
}else{
|
||||
} else{
|
||||
|
||||
char* normal_perks_file_name_self = malloc(20 + strlen(perk_rarity) + 1 + strlen(perk_list[0]) + 4 + 1);
|
||||
char* normal_perks_file_name_group = malloc(20 + strlen(perk_rarity) + 1 + strlen(perk_list[1]) + 4 + 1);
|
||||
char* all_items_perk_file_name = malloc(20 + strlen(perk_rarity) + 14 + 1);
|
||||
if (normal_perks_file_name_self == NULL || normal_perks_file_name_group == NULL) {
|
||||
free(perk_rarity);
|
||||
free(normal_perks_file_name_self);
|
||||
free(normal_perks_file_name_group);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(normal_perks_file_name_self, "../Perk_data/normal_%s_%s.csv", perk_rarity, perk_list[0]);
|
||||
sprintf(normal_perks_file_name_group, "../Perk_data/normal_%s_%s.csv", perk_rarity, perk_list[1]);
|
||||
sprintf(all_items_perk_file_name, "../Perk_data/normal_%s_all_items.csv", perk_rarity);
|
||||
char* perks_full_path[3] = {normal_perks_file_name_self, normal_perks_file_name_group,all_items_perk_file_name};
|
||||
char line[MAX_LINE_SIZE];
|
||||
int perk_iter = 0;
|
||||
int perk_choice[3] = {0};
|
||||
printf("What do you want to do\n");
|
||||
printf("------------------------\n");
|
||||
for(int i = 0; i < 3; i++){
|
||||
FILE* file = fopen(perks_full_path[i], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening \"%s\", file does not exist\n", perks_full_path[i]);
|
||||
}else{
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
while(!feof(file)){
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
char* copiedline = strdup(line);
|
||||
perk_iter++;
|
||||
printf("%d. %s\n", perk_iter,copiedline);
|
||||
}
|
||||
if(i>0){
|
||||
perk_choice[i] = perk_iter - perk_choice[i-1];
|
||||
}else{
|
||||
perk_choice[i] = perk_iter;
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
printf("------------------------\n");
|
||||
printf("Your choice: ");
|
||||
int choice_perk = 0;
|
||||
scanf("%d",&choice_perk);
|
||||
clearInputBuffer();
|
||||
if(choice_perk <= perk_choice[0]){
|
||||
|
||||
}
|
||||
int file_number = -1;
|
||||
if(choice_perk <= perk_choice[0]){
|
||||
file_number = 0;
|
||||
} else{
|
||||
if((choice_perk - perk_choice[0])<= perk_choice[1]){
|
||||
file_number = 1;
|
||||
}else{
|
||||
file_number = 2;
|
||||
}
|
||||
}
|
||||
|
||||
FILE* file = fopen(perks_full_path[file_number], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening \"%s\", file does not exist\n", perks_full_path[file_number]);
|
||||
}else{
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
perk_iter = 1;
|
||||
while(choice_perk<perk_iter){
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
perk_iter++;
|
||||
}
|
||||
if (fgets(line, sizeof(line), file) == NULL) {
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
char* copiedline = strdup(line);
|
||||
char* token = strtok(copiedline, ",");
|
||||
float first_boost_value = atof(token);
|
||||
token = strtok(NULL, ",");
|
||||
char* first_boost_type = strdup(token);
|
||||
token = strtok(NULL, ",");
|
||||
float second_boost_value = atof(token);
|
||||
token = strtok(NULL, "\r");
|
||||
char* second_boost_type = strdup(token);
|
||||
struct Perk* p = createPerk(first_boost_type,second_boost_type,first_boost_value,second_boost_value);
|
||||
updateEvent(p,is_event);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateEvent(struct Perk* p,bool is_event) {
|
||||
p->is_event = is_event;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
4
perks.h
4
perks.h
@@ -19,6 +19,8 @@ struct Perk* createPerk(char* first_boost_type,char* second_boost_type, int firs
|
||||
int numberOfPerks(struct Object* o);
|
||||
void addPerks(struct Object* o);
|
||||
char** perkLists(struct Object* o);
|
||||
void displayAvailablePerks(char** perk_list, bool is_event);
|
||||
struct Perk* displayAndChoseAvailablePerks(char** perk_list, bool is_event);
|
||||
|
||||
void updateEvent(struct Perk* p,bool is_event);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user