Skip to content

Commit

Permalink
fixing cheats
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiSev committed Jun 24, 2024
1 parent b5120e2 commit 46a5095
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions server/game_logic/characters/enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void Enemy::revive(Vector2D new_position) {
revive_counter = revive_cooldown;
health = MAX_HEALTH;
position = new_position;
velocity = Vector2D(x_speed, DEFAULT_SPEED_Y);
spawn_position = new_position;
set_active_status(true);
}
Expand Down
4 changes: 3 additions & 1 deletion server/game_logic/characters/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool Player::is_shooting() {
void Player::update_body() {

if (is_dead()) { // if the player is dead, then it shouldnt move

velocity = Vector2D(NONE, NONE);
return;
}

Expand Down Expand Up @@ -259,6 +259,7 @@ void Player::revive(Vector2D new_position) {
this->health = MAX_HEALTH;
this->state = STATE_IDLE_RIGHT;
position = new_position;
velocity = Vector2D(NONE, DEFAULT_SPEED_Y);

for (auto& weapon: weapons) {
weapon->reset_ammo();
Expand All @@ -275,6 +276,7 @@ void Player::take_damage(int damage) {
health = NONE;
state = STATE_DEAD;
set_active_status(false);
velocity = Vector2D(NONE, NONE);
} else {
state = STATE_DAMAGED;
}
Expand Down
26 changes: 19 additions & 7 deletions server/game_logic/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void Match::run_command(const CommandDTO& dto) {
void Match::respawn_players() {
for (auto& pair: players) {
auto& player = pair.second;
if (player->try_revive() || cheat_revive_enabled) {
if (player->try_revive()) {

bool can_be_placed = false;
Vector2D new_position = get_random_spawn_point(player_spawn_points);
Expand All @@ -147,7 +147,7 @@ void Match::respawn_players() {
}
void Match::respawn_enemies() {
for (auto& enemy: enemies) {
if (enemy->try_revive() || cheat_revive_enabled) {
if (enemy->try_revive()) {
std::cout << "| ENEMY respawned with ID:" << enemy->get_id() << " |" << std::endl;
enemy->revive(enemy.get()->spawn_position);
collision_manager->track_dynamic_body(enemy);
Expand Down Expand Up @@ -181,8 +181,9 @@ void Match::run_cheat_command(const CheatCommandDTO& dto) {
revive_all_cheat();
} else if (dto.command == CHEAT_REVIVE) {
std::shared_ptr<Player> player = get_player(dto.id_player);
if (player) {
if (player && player->is_dead()) {
player->revive(get_random_spawn_point(player_spawn_points));
collision_manager->track_dynamic_body(player);
}
} else {
std::shared_ptr<Player> player = get_player(dto.id_player);
Expand All @@ -202,10 +203,21 @@ void Match::kill_all_cheat() {
}

void Match::revive_all_cheat() {
cheat_revive_enabled = true;
respawn_enemies();
respawn_players();
cheat_revive_enabled = false;

for (auto& enemy: enemies) {
if (enemy->is_dead()) {
enemy->revive(enemy.get()->spawn_position);
collision_manager->track_dynamic_body(enemy);
}
}

for (auto& pair: players) {
auto& player = pair.second;
if (player->is_dead()) {
player->revive(player.get()->position); // revive at the same position
collision_manager->track_dynamic_body(player);
}
}
}

//-------------------- Conection Methods -----------------
Expand Down
2 changes: 0 additions & 2 deletions server/game_logic/match.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Match: public Thread {
std::vector<Vector2D> item_spawn_points;
std::mutex match_mutex;

std::atomic<bool> cheat_revive_enabled = false;

const std::shared_ptr<engine::ResourcePool>& resource_pool;

//-------------------- Gameloop Methods ----------------------
Expand Down

0 comments on commit 46a5095

Please sign in to comment.