Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2018
- ** PSU_zappy_2017
- ** File description:
- ** incantation_command.c
- */
- #include "server_reply.h"
- #include "incantation_command.h"
- static const elevation_t elevation_g[9];
- bool cell_ctn(unsigned int level, cell_t cell)
- {
- if (cell.items[LINEMATE] >= elevation_g[level].item_required[LINEMATE]
- && cell.items[DERAUMERE] >= elevation_g[level].item_required[DERAUMERE]
- && cell.items[SIBUR] >= elevation_g[level].item_required[SIBUR]
- && cell.items[MENDIANE] >= elevation_g[level].item_required[MENDIANE]
- && cell.items[PHIRAS] >= elevation_g[level].item_required[PHIRAS]
- && cell.items[THYSTAME] >= elevation_g[level].item_required[THYSTAME]) {
- return (true);
- }
- return (false);
- }
- unsigned int count_client_on_cell(position_t pos, zappy_server_t *srv)
- {
- unsigned int i = 0;
- unsigned int count = 0;
- while (i < srv->db_size) {
- if (srv->client[i]->used
- && srv->client[i]->logged
- && srv->client[i]->infos->pos.y == pos.y
- && srv->client[i]->infos->pos.x == pos.x) {
- ++count;
- }
- ++i;
- }
- return (count);
- }
- int incant_all_cli(zappy_server_t *srv, client_t *cli, const char *info)
- {
- for (unsigned int i = 1; i < srv->db_size; ++i) {
- if (srv->client[i]->used && srv->client[i]->logged
- && srv->client[i]->infos->pos.x == cli->infos->pos.x
- && srv->client[i]->infos->pos.y == cli->infos->pos.y
- && cli->infos->level == srv->client[i]->infos->level) {
- srv->client[i]->wait_time = cli->wait_time;
- c_queue_push_reply(srv->reply_queue,
- create_reply(srv->client[i]->socket,
- "Elevation underway\n", 0, no_arg_g));
- c_queue_push_reply(srv->reply_queue,
- create_reply(srv->client[i]->socket, info,
- srv->client[i]->wait_time, (reply_options_t){0, 1, 0}));
- }
- }
- return (0);
- }
- int incantation_command(__attribute__((unused))
- char *cmd, zappy_server_t *srv, client_t *cli)
- {
- char *info = malloc(512);
- if (!info)
- return (-1);
- snprintf(info, 512, "Current level: %d\n", cli->infos->level + 1);
- if (count_client_on_cell(cli->infos->pos, srv)
- >= elevation_g[cli->infos->level].player_count &&
- cell_ctn(cli->infos->level,
- srv->game->map->map[cli->infos->pos.y][cli->infos->pos.x])) {
- incant_all_cli(srv, cli, info);
- }
- else
- c_queue_push_reply(srv->reply_queue, create_reply(cli->socket,
- "ko\n", 0, no_arg_g));
- free(info);
- return (0);
- }
- static const elevation_t elevation_g[9] = {
- {0, {0, 0, 0, 0, 0, 0, 0}},
- {1, {0, 1, 0, 0, 0, 0, 0}},
- {2, {0, 1, 1, 1, 0, 0, 0}},
- {2, {0, 2, 0, 1, 0, 2, 0}},
- {4, {0, 1, 1, 2, 0, 1, 0}},
- {4, {0, 1, 2, 1, 3, 0, 0}},
- {6, {0, 1, 2, 3, 0, 1, 0}},
- {6, {0, 2, 2, 2, 2, 2, 1}},
- {99999, {0, 0, 0, 0, 0, 0, 0}}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement