Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battle contract: Health fix for Event::RoundAction #495

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions contracts/battle/app/src/services/game/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub fn automatic_move(
};
pair.action = None;
let current_round = pair.round;
if let Some(battle_result) = round_result {
let (player_1_health, player_2_health) = if let Some(battle_result) = round_result {
match battle_result {
BattleResult::PlayerWin(winner) => {
let loser = pair.get_opponent(&winner);
Expand All @@ -493,6 +493,12 @@ pub fn automatic_move(
.participants
.get_mut(&winner)
.expect("The player must exist");

let healths = if player_1.owner == winner {
(player_winner.player_settings.health, 0)
} else {
(0, player_winner.player_settings.health)
};
player_winner.player_settings.health = storage.config.health;
player_winner.reflect_reload = 0;
player_winner.ultimate_reload = 0;
Expand All @@ -502,6 +508,7 @@ pub fn automatic_move(
battle.players_to_pairs.remove(&winner);
battle.players_to_pairs.remove(&loser);
battle.check_end_game();
healths
}
BattleResult::Draw(id_1, id_2) => {
let player_1 = battle
Expand All @@ -523,6 +530,7 @@ pub fn automatic_move(
battle.players_to_pairs.remove(&id_1);
battle.players_to_pairs.remove(&id_2);
battle.check_draw_end_game();
(0, 0)
}
}
} else {
Expand All @@ -534,16 +542,16 @@ pub fn automatic_move(
pair.round,
storage.config.time_for_move_in_blocks,
);
}
(
player_1.player_settings.health,
player_2.player_settings.health,
)
};

return Ok(Event::RoundAction {
round: current_round,
player_1: (
opponent_info.0,
opponent_info.1,
player_1.player_settings.health,
),
player_2: (player_id, Move::Attack, player_2.player_settings.health),
player_1: (opponent_info.0, opponent_info.1, player_1_health),
player_2: (player_id, Move::Attack, player_2_health),
});
} else {
pair.action = Some((player_id, Move::Attack));
Expand Down Expand Up @@ -638,7 +646,7 @@ pub fn make_move(storage: &mut Storage, warrior_move: Move) -> Result<Event, Bat
};
pair.action = None;
let current_round = pair.round;
if let Some(battle_result) = round_result {
let (player_1_health, player_2_health) = if let Some(battle_result) = round_result {
match battle_result {
BattleResult::PlayerWin(winner) => {
let loser = pair.get_opponent(&winner);
Expand All @@ -651,6 +659,11 @@ pub fn make_move(storage: &mut Storage, warrior_move: Move) -> Result<Event, Bat
.participants
.get_mut(&winner)
.expect("The player must exist");
let healths = if player_1.owner == winner {
(player_winner.player_settings.health, 0)
} else {
(0, player_winner.player_settings.health)
};
player_winner.player_settings.health = storage.config.health;
player_winner.reflect_reload = 0;
player_winner.ultimate_reload = 0;
Expand All @@ -659,6 +672,7 @@ pub fn make_move(storage: &mut Storage, warrior_move: Move) -> Result<Event, Bat
battle.players_to_pairs.remove(&winner);
battle.players_to_pairs.remove(&loser);
battle.check_end_game();
healths
}
BattleResult::Draw(id_1, id_2) => {
let player_1 = battle
Expand All @@ -680,20 +694,21 @@ pub fn make_move(storage: &mut Storage, warrior_move: Move) -> Result<Event, Bat
battle.players_to_pairs.remove(&id_1);
battle.players_to_pairs.remove(&id_2);
battle.check_draw_end_game();
(0, 0)
}
}
} else {
pair.round += 1;
pair.round_start_time = exec::block_timestamp();
}
(
player_1.player_settings.health,
player_2.player_settings.health,
)
};
Ok(Event::RoundAction {
round: current_round,
player_1: (
opponent_info.0,
opponent_info.1,
player_1.player_settings.health,
),
player_2: (player, warrior_move, player_2.player_settings.health),
player_1: (opponent_info.0, opponent_info.1, player_1_health),
player_2: (player, warrior_move, player_2_health),
})
} else {
pair.action = Some((player, warrior_move));
Expand Down