def _run_finalist_tribe_council(self, finalists: List[Player], gamedb: Database, engine: Engine) -> Player: gamedb.clear_votes() engine.add_event( events.NotifyFinalTribalCouncilEvent( game_id=self._game_id, game_options=self._options, finalists=finalists)) tribal_council_start_timestamp = _unixtime() # wait for votes while (((_unixtime() - tribal_council_start_timestamp) < self._options.final_tribal_council_time_sec) and not self._stop.is_set()): log_message("Waiting for tribal council to end.") time.sleep(self._options.game_wait_sleep_interval_sec) # count votes player_votes = gamedb.count_votes(is_for_win=True) max_votes = 0 winner = None for player_id, votes in player_votes.items(): if votes > max_votes: max_votes = votes winner = gamedb.player_from_id(id=player_id) # announce winner engine.add_event(events.NotifyWinnerAnnouncementEvent( game_id=self._game_id, game_options=self._options, winner=winner)) return winner
def _run_finalist_tribe_council(self, finalists: List[Player], gamedb: Database, engine: Engine) -> Player: gamedb.clear_votes() self._wait_for_tribal_council_start_time() engine.add_event( events.NotifyFinalTribalCouncilEvent(game_id=self._game_id, game_options=self._options, finalists=finalists)) self._wait_for_tribal_council_end_time() # count votes player_votes = gamedb.count_votes(is_for_win=True) max_votes = 0 winner = None for player_id, votes in player_votes.items(): if votes > max_votes: max_votes = votes winner = gamedb.player_from_id(id=player_id) for player in gamedb.stream_players( active_player_predicate_value=True): if player.id != winner.id: gamedb.deactivate_player(player=player) # announce winner engine.add_event( events.NotifyWinnerAnnouncementEvent(game_id=self._game_id, game_options=self._options, winner=winner)) return winner
def test_notify_final_tribal_council_event_msg(self): event = events.NotifyFinalTribalCouncilEvent( game_id=_TEST_GAME_ID, game_options=self.game_options, finalists=[ _gamedb.player_from_id( id="5700835a-9e93-467d-b4c6-8d4d2f4e5158"), _gamedb.player_from_id( id="5d3deb3a-eced-4cfb-b1b4-cb3aeb718119"), ] ) self.assertEqual( _event_messages_as_json(event.messages(gamedb=_gamedb)), json.dumps( [ { "class": "SMSEventMessage", "content": ("\nhttps://vir_us.io Only 2 players remain and it's your chance to vote for " "a WINNER of #VIRUSALPHA!\nReply by 9PM EDT with the letter of the player you vote to WIN!" "\n\nA: www.tiktok.com/@juanita\n\nB: www.tiktok.com/@bruce\n\n\n\n"), "recipient_phone_numbers": [ "751-005-3935", "962-582-3407", "388-685-3212", "331-046-5651", "802-722-8425", "704-425-0095", "555-259-3255", "877-102-2965", "835-161-1468", "436-038-5365", "994-138-5472", "514-721-1531", "191-221-0517", "142-175-7280", "312-441-3246", "114-458-3014", "245-228-6657", "917-511-9963", "461-328-0686", "381-505-3014" ] } ] ) )
team=_TEST_TEAM1), events.NotifySingleTeamCouncilEvent( game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, winning_player=_TEST_PLAYER1, losing_players=[_TEST_PLAYER1, _TEST_PLAYER2]), events.NotifySingleTribeCouncilEvent(game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, winning_teams=[_TEST_TEAM1], losing_teams=[_TEST_TEAM2]), events.NotifyMultiTribeCouncilEvent(game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, winning_tribe=_TEST_TRIBE1, losing_tribe=_TEST_TRIBE2), events.NotifyFinalTribalCouncilEvent( game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, finalists=[_TEST_PLAYER1, _TEST_PLAYER2]), events.NotifyPlayerVotedOutEvent(game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, player=_TEST_PLAYER1), events.NotifyTribalCouncilCompletionEvent( game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, ), events.NotifyWinnerAnnouncementEvent(game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, winner=_TEST_PLAYER2), events.NotifyImmunityAwardedEvent(game_id=_TEST_GAME_ID, game_options=_TEST_GAME_OPTIONS, team=_TEST_TEAM2) ]