Esempio n. 1
0
    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
Esempio n. 2
0
    def test_notify_winner_announcement_event_winner_msg(self):
        event = events.NotifyWinnerAnnouncementEvent(
            game_id=_TEST_GAME_ID,
            game_options=self.game_options,
            winner=_gamedb.player_from_id(
                id="1a037b16-191c-4890-8c31-9122fe5d6dc1")
        )

        self.assertEqual(
            _event_messages_as_json(event.messages(gamedb=_gamedb)),
            json.dumps([
                {
                    "class": "SMSEventMessage",
                    "content": "\nVIR-US: You are the last survivor and WINNER of #VIRUSALPHA!\n",
                    "recipient_phone_numbers": [
                        "962-582-3407"
                    ]
                },
                {
                    "class": "SMSEventMessage",
                    "content": "\nVIR-US: sarah (www.tiktok.com/@sarah) is the last survivor and WINNER of #VIRUSALPHA!\n",
                    "recipient_phone_numbers": [

                    ]
                }
            ])
        )
Esempio n. 3
0
    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
Esempio n. 4
0
                                        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)
]


class EngineTest(unittest.TestCase):
    def setUp(self):
        self._game_options = GameOptions()
        self._game_options.game_schedule = STV_I18N_TABLE['US']

    @mock.patch('game_engine.twilio.TwilioSMSNotifier.send')
    def test_event_processing(self, send_fn):
        engine = Engine(options=self._game_options,