From 78cb769cce7b3c8b80f5d220778e050219fbeecb Mon Sep 17 00:00:00 2001 From: firekann Date: Tue, 30 Apr 2024 18:07:36 +0900 Subject: [PATCH] feat: Prevent health increase when health is 0 or less before --- game/src/game/game_player/timing_judge.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/game/src/game/game_player/timing_judge.rs b/game/src/game/game_player/timing_judge.rs index 0ecacab..7a37f58 100644 --- a/game/src/game/game_player/timing_judge.rs +++ b/game/src/game/game_player/timing_judge.rs @@ -169,7 +169,9 @@ impl TimingJudge { let difference_abs = (hit_timing as i64 - precise_timing as i64).abs(); // calculte score by the accuracy - self.score += ((f64::abs(160.0 - difference_abs.clamp(10, 160) as f64) / 150.0) + self.score += ((f64::abs( + BAD_TIMING as f64 - difference_abs.clamp(OVERCHAOS_TIMING, BAD_TIMING) as f64, + ) / (BAD_TIMING - OVERCHAOS_TIMING) as f64) * 1000.0) as u64; let note_accuracy = note_accuracy_from_time_difference(difference_abs); @@ -184,6 +186,8 @@ impl TimingJudge { if let Some(processed_accuracy) = &result { let processed_note_id = self.notes.get(processed_index.unwrap()).unwrap().id; self.notes.remove(processed_index.unwrap()); + // check if the health is zero -> already died + let is_health_zero = self.health == 0; // increase or set combo and count match processed_accuracy { NoteAccuracy::Overchaos => { @@ -218,9 +222,13 @@ impl TimingJudge { } } - // clamp the health between 0 and max_health - self.health = self.health.clamp(0, self.max_health as i64); - + // check if the health is zero -> already died + if is_health_zero { + self.health = 0; + } else { + // clamp the health between 0 and max_health + self.health = self.health.clamp(0, self.max_health as i64); + } return Some(JudgeResult { accuracy: processed_accuracy.clone(), note_id: processed_note_id,