Skip to content

Commit

Permalink
Merge branch 'main' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Oct 12, 2024
2 parents 2cef3ed + ed27712 commit a6c59b6
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server/src/game/components/cult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Cult{
};

if player_ref.role(game) == role.role() {continue}
player_ref.set_role(game, role);
player_ref.set_role_and_wincon(game, role);
}

game.set_cult(cult);
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/components/mafia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Mafia{
let random_mafia = all_living_mafia.choose(&mut rand::thread_rng());

if let Some(random_mafia) = random_mafia {
random_mafia.set_role(game, role);
random_mafia.set_role_and_wincon(game, role);
}
}
}
4 changes: 2 additions & 2 deletions server/src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Game {
//on role creation needs to be called after all players roles are known
for player_ref in PlayerReference::all_players(&game){
let role_data_copy = player_ref.role_state(&game).clone();
player_ref.set_role(&mut game, role_data_copy);
player_ref.set_role_and_wincon(&mut game, role_data_copy);
}

for player_ref in PlayerReference::all_players(&game){
Expand Down Expand Up @@ -478,7 +478,7 @@ pub mod test {
//on role creation needs to be called after all players roles are known
for player_ref in PlayerReference::all_players(&game){
let role_data_copy = player_ref.role_state(&game).clone();
player_ref.set_role(&mut game, role_data_copy);
player_ref.set_role_and_wincon(&mut game, role_data_copy);
}

OnGameStart::invoke(&mut game);
Expand Down
4 changes: 3 additions & 1 deletion server/src/game/player/player_helper_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ impl PlayerReference{
OnAnyDeath::new(*self)
}
/// Swaps this persons role, sends them the role chat message, and makes associated changes
pub fn set_role(&self, game: &mut Game, new_role_data: impl Into<RoleState>){
pub fn set_role_and_wincon(&self, game: &mut Game, new_role_data: impl Into<RoleState>){
let new_role_data = new_role_data.into();

let old = self.role_state(game).clone();

self.set_win_condition(game, new_role_data.clone().default_win_condition());

BeforeRoleSwitch::new(*self, old.clone(), new_role_data.clone()).invoke(game);

self.set_role_state(game, new_role_data.clone());
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/apostle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl RoleStateImpl for Apostle {
return
}

target_ref.set_role(game, Zealot);
target_ref.set_role_and_wincon(game, Zealot);
target_ref.set_win_condition(game, WinCondition::new_single_resolution_state(ResolutionState::Cult));
Cult::set_ability_used_last_night(game, Some(CultAbility::Convert));
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/counterfeiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl RoleStateImpl for Counterfeiter {
if !backup.alive(game){return}

//convert backup to Counterfeiter
backup.set_role(game, RoleState::Counterfeiter(Counterfeiter{backup: None, ..self}));
backup.set_role_and_wincon(game, RoleState::Counterfeiter(Counterfeiter{backup: None, ..self}));
}
else if self.backup.is_some_and(|p|p == dead_player_ref) {
actor_ref.set_role_state(game, RoleState::Counterfeiter(Counterfeiter{backup: None, ..self}));
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/doomsayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Doomsayer{
player.alive(game) && DoomsayerGuess::convert_to_guess(player.role(game)).is_some() && *player != actor_ref
).count() < 3
{
actor_ref.set_role(game, RoleState::Jester(Jester::default()));
actor_ref.set_role_and_wincon(game, RoleState::Jester(Jester::default()));
}
}
pub fn won(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/fiends_wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl FiendsWildcard {
.collect::<Vec<Role>>()
)
{
actor_ref.set_role(game, self.role.default_state());
actor_ref.set_role_and_wincon(game, self.role.default_state());
}else{
actor_ref.add_private_chat_message(game, ChatMessageVariant::WildcardConvertFailed{role: self.role.clone()})
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/godfather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl RoleStateImpl for Godfather {
if !backup.alive(game){return}

//convert backup to godfather
backup.set_role(game, RoleState::Godfather(Godfather{backup: None}));
backup.set_role_and_wincon(game, RoleState::Godfather(Godfather{backup: None}));
}
else if self.backup.is_some_and(|p|p == dead_player_ref) {
actor_ref.set_role_state(game, RoleState::Godfather(Godfather{backup: None}));
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/imposter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl RoleStateImpl for Imposter {
if !backup.alive(game){return}

//convert backup to godfather
backup.set_role(game, RoleState::Imposter(Imposter{backup: None, ..self}));
backup.set_role_and_wincon(game, RoleState::Imposter(Imposter{backup: None, ..self}));
}
else if self.backup.is_some_and(|p|p == dead_player_ref) {
actor_ref.set_role_state(game, RoleState::Imposter(Imposter{backup: None, ..self}));
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/mafia_killing_wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl MafiaKillingWildcard {
.collect::<Vec<Role>>()
)
{
actor_ref.set_role(game, self.role.default_state());
actor_ref.set_role_and_wincon(game, self.role.default_state());
}else{
actor_ref.add_private_chat_message(game, ChatMessageVariant::WildcardConvertFailed{role: self.role.clone()})
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/mafia_support_wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl MafiaSupportWildcard {
.collect::<Vec<Role>>()
)
{
actor_ref.set_role(game, self.role.default_state());
actor_ref.set_role_and_wincon(game, self.role.default_state());
}else{
actor_ref.add_private_chat_message(game, ChatMessageVariant::WildcardConvertFailed{role: self.role.clone()})
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/politician.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RoleStateImpl for Politician {
}
fn on_role_creation(self, game: &mut Game, actor_ref: PlayerReference){
if self.should_suicide(game, actor_ref) {
actor_ref.set_role(game, RoleState::Jester(Jester::default()));
actor_ref.set_role_and_wincon(game, RoleState::Jester(Jester::default()));
}
}
fn on_any_death(self, game: &mut Game, actor_ref: PlayerReference, _dead_player_ref: PlayerReference){
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/recruiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl RoleStateImpl for Recruiter {
if !backup.alive(game){return}

//convert backup to godfather
backup.set_role(game, RoleState::Recruiter(Recruiter{backup: None, ..self}));
backup.set_role_and_wincon(game, RoleState::Recruiter(Recruiter{backup: None, ..self}));
}
else if self.backup.is_some_and(|p|p == dead_player_ref) {
actor_ref.set_role_state(game, RoleState::Recruiter(Recruiter{backup: None, ..self}));
Expand Down
4 changes: 2 additions & 2 deletions server/src/game/role/retrainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl RoleStateImpl for Retrainer {
if !backup.alive(game){return}

//convert backup to godfather
backup.set_role(game, RoleState::Retrainer(Retrainer{backup: None, ..self}));
backup.set_role_and_wincon(game, RoleState::Retrainer(Retrainer{backup: None, ..self}));
}
else if self.backup.is_some_and(|p|p == dead_player_ref) {
actor_ref.set_role_state(game, RoleState::Retrainer(Retrainer{backup: None, ..self}));
Expand All @@ -149,7 +149,7 @@ impl Retrainer {

if let Some(backup) = retrainer.backup {
if retrainer.retrains_remaining > 0 && backup.role(game) != role{
backup.set_role(game, role.default_state());
backup.set_role_and_wincon(game, role.default_state());
retrainer.retrains_remaining = retrainer.retrains_remaining.saturating_sub(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/game/role/revolutionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ impl RoleStateImpl for Revolutionary {
actor_ref.set_role_state(game, RoleState::Revolutionary(Revolutionary{target: RevolutionaryTarget::Target(*target)}));
actor_ref.insert_role_label(game, *target);
}else{
actor_ref.set_role(game, RoleState::Jester(Jester::default()))
actor_ref.set_role_and_wincon(game, RoleState::Jester(Jester::default()))
};
}
fn on_any_death(self, game: &mut Game, actor_ref: PlayerReference, dead_player_ref: PlayerReference){
if Some(dead_player_ref) == self.target.get_target() && self.target != RevolutionaryTarget::Won {
actor_ref.set_role(game, RoleState::Jester(Jester::default()))
actor_ref.set_role_and_wincon(game, RoleState::Jester(Jester::default()))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/true_wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TrueWildcard {
&[]
)
{
actor_ref.set_role(game, self.role.default_state());
actor_ref.set_role_and_wincon(game, self.role.default_state());
}else{
actor_ref.add_private_chat_message(game, ChatMessageVariant::WildcardConvertFailed{role: self.role.clone()})
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/wild_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Wildcard {
.collect::<Vec<Role>>()
)
{
actor_ref.set_role(game, self.role.default_state());
actor_ref.set_role_and_wincon(game, self.role.default_state());
}else{
actor_ref.add_private_chat_message(game, ChatMessageVariant::WildcardConvertFailed{role: self.role.clone()})
}
Expand Down

0 comments on commit a6c59b6

Please sign in to comment.