예제 #1
0
    def test_count_habit_values(self):
        hero_1 = self.hero
        hero_1.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy)
        hero_1.premium_state_end_at = datetime.datetime.now(
        ) + datetime.timedelta(seconds=60)
        hero_1.habit_honor.change(-1)
        hero_1.habit_peacefulness.change(1)
        logic.save_hero(hero_1)

        account_2 = self.accounts_factory.create_account()
        hero_2 = logic.load_hero(account_id=account_2.id)
        hero_2.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy)
        hero_2.premium_state_end_at = datetime.datetime.now(
        ) + datetime.timedelta(seconds=60)
        hero_2.habit_honor.change(2)
        hero_2.habit_peacefulness.change(-2)
        logic.save_hero(hero_2)

        account_3 = self.accounts_factory.create_account()
        hero_3 = logic.load_hero(account_id=account_3.id)
        hero_3.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy_2)
        hero_3.premium_state_end_at = datetime.datetime.now(
        ) + datetime.timedelta(seconds=30)
        hero_3.habit_honor.change(-4)
        hero_3.habit_peacefulness.change(4)
        logic.save_hero(hero_3)

        account_4 = self.accounts_factory.create_account()
        hero_4 = logic.load_hero(account_id=account_4.id)
        hero_4.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy)
        hero_4.premium_state_end_at = datetime.datetime.now(
        ) + datetime.timedelta(seconds=30)
        hero_4.habit_honor.change(8)
        hero_4.habit_peacefulness.change(-8)
        logic.save_hero(hero_4)

        self.assertEqual(
            HeroPreferences.count_habit_values(self.place_1, all=False),
            ((10, -1), (1, -10)))
        self.assertEqual(
            HeroPreferences.count_habit_values(self.place_2, all=False),
            ((0, -4), (4, 0)))

        self.assertEqual(
            HeroPreferences.count_habit_values(self.place_1, all=True),
            ((10, -1), (1, -10)))
        self.assertEqual(
            HeroPreferences.count_habit_values(self.place_2, all=True),
            ((0, -4), (4, 0)))
예제 #2
0
    def update_heroes_habits(self):
        from the_tale.game.heroes.preferences import HeroPreferences

        habits_values = HeroPreferences.count_habit_values(self, all=self.depends_from_all_heroes)

        self.habit_honor_positive = habits_values[0][0]
        self.habit_honor_negative = habits_values[0][1]
        self.habit_peacefulness_positive = habits_values[1][0]
        self.habit_peacefulness_negative = habits_values[1][1]