Skip to content

Commit

Permalink
Fix bodyguard getting two messages for jailed target
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Papel committed Jan 6, 2024
1 parent 87ceefa commit 04223f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/src/game/role/bodyguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl RoleStateImpl for Bodyguard {
let Some(visit) = actor_ref.night_visits(game).first() else {return};
let target_ref = visit.target;

if target_ref.night_jailed(game){
actor_ref.push_night_message(game, ChatMessage::TargetJailed);
return
}

if actor_ref == target_ref {
if target_ref.night_jailed(game){
actor_ref.push_night_message(game, ChatMessage::TargetJailed);
return
}

let self_shields_remaining = self.self_shields_remaining - 1;
target_ref.increase_defense_to(game, 2);
actor_ref.set_role_state(game, RoleState::Bodyguard(Bodyguard{ self_shields_remaining, target_protected_ref: self.target_protected_ref, redirected_player_refs: self.redirected_player_refs }));
Expand Down
33 changes: 33 additions & 0 deletions server/tests/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,37 @@ fn vampire_convert_bodyguard() {

assert!(vamp.role_state().role() == Role::Vampire);
assert!(bg.role_state().role() == Role::Vampire);
}

#[test]
fn bodyguard_gets_single_target_jailed_message() {
kit::scenario!(game where
bg: Bodyguard,
jailor: Jailor,
_maf: Mafioso,
townie: Sheriff
);

jailor.day_target(townie);

game.next_phase();

bg.set_night_target(townie);

game.next_phase();

assert_eq!(
bg.get_messages_after_last_message(
ChatMessage::PhaseChange {
phase_type: PhaseType::Night, day_number: 1
}
),
vec![
ChatMessage::TargetJailed,
/* They should not get a second TargetJailed message */
ChatMessage::PhaseChange {
phase_type: PhaseType::Morning, day_number: 2
}
]
);
}

1 comment on commit 04223f8

@vercel
Copy link

@vercel vercel bot commented on 04223f8 Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mafia-game – ./

mafia-game.vercel.app
mafia-game-itssammym.vercel.app
mafia-game-git-00x-main-itssammym.vercel.app

Please sign in to comment.