コード例 #1
0
    def setUp(self):
        self.channel = MagicMock()

        self.player1 = 'Player1'
        self.player2 = 'Player2'
        self.player3 = 'Player3'
        self.player4 = 'Player4'

        self.quest_manager = QuestManager(self.channel)
コード例 #2
0
    def setUp(self):
        self.channel = MagicMock()

        self.player1 = 'Player1'
        self.player2 = 'Player2'
        self.player3 = 'Player3'
        self.player4 = 'Player4'

        self.quest_manager = QuestManager(self.channel)
コード例 #3
0
    def __init__(self, owner, channel_manager):
        super().__init__(owner, channel_manager)

        self.quest_manager = QuestManager(self)

        self.mod_commands.add_commands(
            exact_match_commands={
                '!queston':
                lambda _: self.channel_manager.enable_quest(self.owner),
                '!questoff':
                lambda _: self.channel_manager.disable_quest(self.owner)
            },
            starts_with_commands={'!questcooldown': self.set_quest_cooldown})
コード例 #4
0
    def setUp(self):
        player_save_patcher = patch(
            'twitch.player_manager.PlayerManager.save_player_data')
        player_load_patcher = patch(
            'twitch.player_manager.PlayerManager.load_player_data')
        randint_0_patcher = patch('quest.quests.{}.randint'.format(
            self.quest_constructor.__name__.lower()),
                                  return_value=0)
        for patcher in [
                player_save_patcher, player_load_patcher, randint_0_patcher
        ]:
            patcher.start()
            self.addCleanup(patcher.stop)

        self.bot = MagicMock()
        with patch('twitch.player_manager.PlayerManager.load_player_data'):
            self.player_manager = QuestPlayerManager(self.bot)
        self.channel = MagicMock()
        self.channel.channel_manager.bot = self.bot
        self.channel.channel_manager.bot.player_manager = self.player_manager

        self.player1 = 'Player1'
        self.player2 = 'Player2'
        self.player3 = 'Player3'
        self.player4 = 'Player4'
        self.player5 = 'Player5'
        self.player6 = 'Player6'
        self.player7 = 'Player7'
        self.player8 = 'Player8'
        self.player9 = 'Player9'
        self.player10 = 'Player10'
        self.all_players = [
            self.player1, self.player2, self.player3, self.player4,
            self.player5, self.player6, self.player7, self.player8,
            self.player9, self.player10
        ]

        self.party = self.all_players[:self.num_start_players]

        with patch('twitch.player_manager.PlayerManager.save_player_data'):
            self.player_manager.reward(self.all_players,
                                       gold=self.starting_gold,
                                       exp=self.starting_exp)

        self.quest_manager = QuestManager(self.channel)
        self.quest_manager.party = self.party
        if self.quest_constructor:
            self.quest = self.quest_constructor(self.quest_manager)
コード例 #5
0
class TestQuestManager(unittest.TestCase):
    def setUp(self):
        self.channel = MagicMock()

        self.player1 = 'Player1'
        self.player2 = 'Player2'
        self.player3 = 'Player3'
        self.player4 = 'Player4'

        self.quest_manager = QuestManager(self.channel)

    def test_disabled(self):
        self.quest_manager.disable_questing()
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertEqual(self.channel.send_msg.call_count, 1)
        self.assertIsNone(self.quest_manager.quest_timer)
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)

    def test_quest_disable_enable(self):
        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        # Only the first player "starts" the quest, second player shouldn't increase the reply count
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.forming_party)
        self.assertEqual(self.channel.send_msg.call_count, 1)
        self.assertIsNotNone(self.quest_manager.quest_timer)

        self.quest_manager.disable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)
        # Every request should say that we're disabled
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)
        self.assertEqual(self.channel.send_msg.call_count, 4)
        self.assertIsNone(self.quest_manager.quest_timer)

        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.forming_party)
        self.assertEqual(self.channel.send_msg.call_count, 5)
        self.assertIsNotNone(self.quest_manager.quest_timer)

    def test_party_form(self):
        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player3, '!quest')
        self.quest_manager.commands.execute_command(self.player3, '!quest')
        self.quest_manager.commands.execute_command(self.player2, '!quest')

        # Simulate timing out and the callback for quest_advance getting called
        self.quest_manager.kill_quest_advance_timer()
        self.quest_manager.quest_advance()

        self.assertIs(self.quest_manager.quest_state, QuestState.active)
        self.assertIsNotNone(self.quest_manager.quest_timer)
        quest = self.quest_manager.quest
        self.assertIsNotNone(quest)
        # Party should be ordered the same
        self.assertSequenceEqual(quest.party, [self.player1, self.player2, self.player3])
        self.assertIn(type(quest), QUEST_LIST[3])
コード例 #6
0
class TestQuestManager(unittest.TestCase):
    def setUp(self):
        self.channel = MagicMock()

        self.player1 = 'Player1'
        self.player2 = 'Player2'
        self.player3 = 'Player3'
        self.player4 = 'Player4'

        self.quest_manager = QuestManager(self.channel)

    def test_disabled(self):
        self.quest_manager.disable_questing()
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertEqual(self.channel.send_msg.call_count, 1)
        self.assertIsNone(self.quest_manager.quest_timer)
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)

    def test_quest_disable_enable(self):
        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        # Only the first player "starts" the quest, second player shouldn't increase the reply count
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.forming_party)
        self.assertEqual(self.channel.send_msg.call_count, 1)
        self.assertIsNotNone(self.quest_manager.quest_timer)

        self.quest_manager.disable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)
        # Every request should say that we're disabled
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.disabled)
        self.assertEqual(self.channel.send_msg.call_count, 4)
        self.assertIsNone(self.quest_manager.quest_timer)

        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.assertIs(self.quest_manager.quest_state, QuestState.forming_party)
        self.assertEqual(self.channel.send_msg.call_count, 5)
        self.assertIsNotNone(self.quest_manager.quest_timer)

    def test_party_form(self):
        self.quest_manager.enable_questing()
        self.assertIs(self.quest_manager.quest_state, QuestState.ready)
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player2, '!quest')
        self.quest_manager.commands.execute_command(self.player1, '!quest')
        self.quest_manager.commands.execute_command(self.player3, '!quest')
        self.quest_manager.commands.execute_command(self.player3, '!quest')
        self.quest_manager.commands.execute_command(self.player2, '!quest')

        # Simulate timing out and the callback for quest_advance getting called
        self.quest_manager.kill_quest_advance_timer()
        self.quest_manager.quest_advance()

        self.assertIs(self.quest_manager.quest_state, QuestState.active)
        self.assertIsNotNone(self.quest_manager.quest_timer)
        quest = self.quest_manager.quest
        self.assertIsNotNone(quest)
        # Party should be ordered the same
        self.assertSequenceEqual(quest.party,
                                 [self.player1, self.player2, self.player3])
        self.assertIn(type(quest), QUEST_LIST[3])