Skip to content

Commit

Permalink
Hard exit on failed decode & Balanced stats added
Browse files Browse the repository at this point in the history
  • Loading branch information
datcord committed Jun 17, 2020
1 parent 91c33aa commit 3884847
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
14 changes: 4 additions & 10 deletions src/game_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,6 @@ void level_up(player_t *player, monster_t monsters[], map_t *map)
{

return;
/*TODO:
Place the save function here which will save the player stats
and reload them at the next level. Ex. player hp=20 at=70 ar=65 ac=55
These values should be saved at the .rpg file so we can keep the player`s
stats for the next level. Each monster should be saved + players stats
*/
}
}
map->level++;
Expand Down Expand Up @@ -665,10 +659,10 @@ int check_game_over_multi(player_t players[],game_t *game)
game->mons_arr[i].health = 100;
if(game->mons_arr[i].monster_id == game->boss_arr[game->map.level - 1][1]){
game->mons_arr[i].is_boss = TRUE;
game->mons_arr[i].health = 40;
game->mons_arr[i].armor = 15;
game->mons_arr[i].attack = 30;
game->mons_arr[i].accuracy = 40;
game->mons_arr[i].health = 20 + 4 * game->map.level;
game->mons_arr[i].armor = 20 + 4 * game->map.level;
game->mons_arr[i].attack = 10 + 4 * game->map.level;
game->mons_arr[i].accuracy = 10 + 4 * game->map.level;
}
map_set(&game->map,MSYMBOL,game->mons_arr[i].y,game->mons_arr[i].x);
}
Expand Down
8 changes: 4 additions & 4 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ void set_boss(map_t *map, monster_t mons_arr[], int boss_array[TOTAL_LVLS][2])
if (mons_arr[i].monster_id == boss_array[map->level - 1][1])
{
mons_arr[i].is_boss = TRUE;
mons_arr[i].attack = 1;
mons_arr[i].health = 1;
mons_arr[i].armor = 15;
mons_arr[i].accuracy = 40;
mons_arr[i].attack = 10 + 4 * map->level;
mons_arr[i].health = 20 + 4 * map->level;
mons_arr[i].armor = 20 + 4 * map->level;
mons_arr[i].accuracy = 10 + 4 * map->level;
break;
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/mode_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,6 @@ void *multi_game_handler(void *args)
//break;
}

if (save_flag == TRUE && lock_flag == FALSE)
{
}

if (hard_exit_flag == TRUE && lock_flag == FALSE)
{

Expand Down Expand Up @@ -485,7 +481,7 @@ void *multi_recv_handler(void *args)
{
if (decode_on_player_death(&game->map, game->players, net_buffer) != 0)
{
// send message to server for message loss
hard_exit_flag = TRUE;
}
lock_flag = FALSE;
}
Expand All @@ -495,7 +491,7 @@ void *multi_recv_handler(void *args)
{
if (decode_on_player_move(game->players, net_buffer) != 0)
{
// send message to server for message loss
hard_exit_flag = TRUE;
}
lock_flag = FALSE;
}
Expand All @@ -505,7 +501,7 @@ void *multi_recv_handler(void *args)
{
if (decode_on_player_update_stats(game->players, net_buffer, &game->map) != 0)
{
// send message to server for message loss
hard_exit_flag = TRUE;
}
lock_flag = FALSE;
}
Expand All @@ -519,7 +515,12 @@ void *multi_recv_handler(void *args)
{
if (decode_on_monster_death(game->mons_arr, net_buffer, &game->map) != 0)
{
// send message to server for message loss
free(net_buffer_cp);
net_buffer_cp = NULL;
net_buffer_cp = on_player_hard_exit();
send(game->client->sockfd, net_buffer_cp, SOCK_BUFF_SZ, 0);
system("clear");
redprint_slow("Your game stopped violently\nC0ntr0l 1s 4n 1llus10n!\n");
}
lock_flag = FALSE;
}
Expand All @@ -529,7 +530,7 @@ void *multi_recv_handler(void *args)
{
if (decode_on_monster_update_stats(game->mons_arr, net_buffer, &game->map) != 0)
{
// send message to server for message loss
hard_exit_flag = TRUE;
}
lock_flag = FALSE;
}
Expand All @@ -540,9 +541,9 @@ void *multi_recv_handler(void *args)
itoa(CHEST_OPEN_ID_C, comp, 10);
if (!strcmp(response_id, comp))
{
if (decode_on_chest_open(game->chest_arr, net_buffer, &game->map) != 0)
if (decode_on_chest_open(game->chest_arr, net_buffer, &game->map) == 0)
{
// send message to server for message loss
hard_exit_flag = TRUE;
}
lock_flag = FALSE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/monster.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
void init_monster(monster_t *monster, int id, int x1, int y1)
{
monster->is_boss = 0;
monster->attack = 1;
monster->health = 1;
monster->armor = 10;
monster->accuracy = 40;
monster->attack = 10;
monster->health = 20;
monster->armor = 20;
monster->accuracy = 10;
monster->x = x1;
monster->y = y1;
monster->isDead = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ int attack(float accuracy, float damage, float armor)
* */
void open_chest(chest_t chest, player_t *player)
{
player->health += (chest.level) * 5;
player->armor += (chest.level) * 2;
player->attack += (chest.level) * 2;
player->accuracy += (chest.level) * 2;
player->health += 5 + player->level;
player->armor += 2 + player->level;
player->attack += 2 + player->level;
player->accuracy += 2 + player->level;
}

/**
Expand Down

0 comments on commit 3884847

Please sign in to comment.