示例#1
0
    def test_choose_ability__additional_companion_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        from the_tale.game.companions.abilities import effects as companions_effects
        from the_tale.game.companions.abilities import container as abilities_container
        from the_tale.game.companions import logic as companions_logic
        from the_tale.game.companions import relations as companions_relations

        abilities = [
            ability for ability in companions_effects.ABILITIES.records
            if (isinstance(ability.effect, companions_effects.BaseBattleAbility
                           ) and ability.effect.ABILITY.get_id() != 'hit')
        ]
        companion_ability = random.choice(abilities)

        all_abilities = [
            ability(level=ability.MAX_LEVEL)
            for ability in list(ABILITIES.values())
            if ability.get_id() != companion_ability.effect.ABILITY.get_id()
        ]

        active_abilities = set(ability.get_id()
                               for ability in list(ABILITIES.values())
                               if ability.ACTIVATION_TYPE.is_ACTIVE)

        companion_record = companions_logic.create_random_companion_record(
            'battle',
            abilities=abilities_container.Container(
                start=(companion_ability, )),
            state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(
            companions_logic.create_companion(companion_record))
        self.hero.health = 1  # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        # mock abilities modify_attribute instead of hereos, since we test correct work of it
        def modify_attribute(self, modifier, value):
            if modifier.is_ADDITIONAL_ABILITIES:
                return all_abilities
            return value

        with mock.patch(
                'the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute',
                modify_attribute):
            for i in range(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(len(active_abilities), len(chosen_abilities) + 1)
        self.assertEqual(
            active_abilities -
            set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
示例#2
0
文件: views.py 项目: Alkalit/the-tale
    def hero_abilities(self, ability_type=None, activation_type=None, availability=ABILITY_AVAILABILITY.FOR_ALL):

        abilities = ABILITIES.values()

        is_filtering = False

        if ability_type is not None:
            is_filtering = True
            abilities = [ability for ability in abilities if ability.TYPE == ability_type]

        if activation_type is not None:
            is_filtering = True
            abilities = [ability for ability in abilities if ability.ACTIVATION_TYPE == activation_type]

        if availability is not ABILITY_AVAILABILITY.FOR_ALL:
            if availability is not ABILITY_AVAILABILITY.FOR_ALL:
                is_filtering = True
            abilities = [ability for ability in abilities if ability.AVAILABILITY == availability]

        abilities = [ability(level=ability.MAX_LEVEL) for ability in sorted(abilities, key=lambda x: x.NAME)]

        url_builder = UrlBuilder(reverse('guide:hero-abilities'), arguments={'ability_type': ability_type.value if ability_type is not None else None,
                                                                             'activation_type': activation_type.value if activation_type is not None else None,
                                                                             'availability': availability.value})

        return self.template('guide/hero-abilities.html', {'section': 'hero-abilities',
                                                           'url_builder': url_builder,
                                                           'abilities': abilities,
                                                           'is_filtering': is_filtering,
                                                           'ability_type': ability_type,
                                                           'activation_type': activation_type,
                                                           'availability': availability,
                                                           'ABILITY_ACTIVATION_TYPE': ABILITY_ACTIVATION_TYPE,
                                                           'ABILITY_TYPE': ABILITY_TYPE,
                                                           'ABILITY_AVAILABILITY': ABILITY_AVAILABILITY})
示例#3
0
    def hero_abilities(self,
                       ability_type=None,
                       activation_type=None,
                       availability=ABILITY_AVAILABILITY.FOR_ALL):

        abilities = list(ABILITIES.values())

        is_filtering = False

        if ability_type is not None:
            is_filtering = True
            abilities = [
                ability for ability in abilities
                if ability.TYPE == ability_type
            ]

        if activation_type is not None:
            is_filtering = True
            abilities = [
                ability for ability in abilities
                if ability.ACTIVATION_TYPE == activation_type
            ]

        if availability is not ABILITY_AVAILABILITY.FOR_ALL:
            if availability is not ABILITY_AVAILABILITY.FOR_ALL:
                is_filtering = True
            abilities = [
                ability for ability in abilities
                if ability.AVAILABILITY == availability
            ]

        abilities = [
            ability(level=ability.MAX_LEVEL)
            for ability in sorted(abilities, key=lambda x: x.NAME)
        ]

        url_builder = UrlBuilder(
            reverse('guide:hero-abilities'),
            arguments={
                'ability_type':
                ability_type.value if ability_type is not None else None,
                'activation_type':
                activation_type.value if activation_type is not None else None,
                'availability':
                availability.value
            })

        return self.template(
            'guide/hero-abilities.html', {
                'section': 'hero-abilities',
                'url_builder': url_builder,
                'abilities': abilities,
                'is_filtering': is_filtering,
                'ability_type': ability_type,
                'activation_type': activation_type,
                'availability': availability,
                'ABILITY_ACTIVATION_TYPE': ABILITY_ACTIVATION_TYPE,
                'ABILITY_TYPE': ABILITY_TYPE,
                'ABILITY_AVAILABILITY': ABILITY_AVAILABILITY
            })
    def handle(self, *args, **options): # pylint: disable=R0914

        # account = AccountPrototype.get_by_nick('compare_abilities_user')
        # if account:
        #     account.remove()

        # account = AccountPrototype.get_by_nick('compare_abilities_user_2')
        # if account:
        #     account.remove()

        result, account_1_id, bundle_id = register_user('compare_abilities_user') # pylint: disable=W0612
        result, account_2_id, bundle_id = register_user('compare_abilities_user_2') # pylint: disable=W0612

        account_1 = AccountPrototype.get_by_id(account_1_id)
        account_2 = AccountPrototype.get_by_id(account_2_id)

        storage = LogicStorage()
        storage.load_account_data(account_1)
        storage.load_account_data(account_2)

        hero_1 = storage.accounts_to_heroes[account_1_id]
        hero_2 = storage.accounts_to_heroes[account_2_id]

        set_heroes_companion(hero_1, hero_2)

        try:

            abilities = [ability_class
                         for ability_class in ABILITIES.values()
                         if (ability_class.AVAILABILITY.value & ABILITY_AVAILABILITY.FOR_PLAYERS.value and
                             ability_class.get_id() != 'hit' and
                             ability_class.TYPE == ABILITY_TYPE.BATTLE) ]

            ability_matches = compare_abilities(hero_1, hero_2, abilities, level=LEVEL)

            ability_statistics = dict( (ability.get_id(), 0) for ability in abilities)
            ability_wins = dict( (ability.get_id(), []) for ability in abilities)

            for (ability_1_id, ability_2_id), (ability_1_wins, ability_2_wins) in ability_matches.items():
                ability_statistics[ability_1_id] = ability_statistics.get(ability_1_id, 0) + ability_1_wins
                ability_statistics[ability_2_id] = ability_statistics.get(ability_2_id, 0) + ability_2_wins

                ability_wins[ability_1_id].append(ability_1_wins)
                ability_wins[ability_2_id].append(ability_2_wins)

            statistics = sorted(ability_statistics.items(), key=lambda stat: -stat[1])

            battles_per_ability = TEST_BATTLES_NUMBER * (len(abilities)-1)

            for ability_id, wins in statistics:
                print '%d\t%.0f%%\t%s' % (wins, 100*float(wins)/(battles_per_ability*len(HERO_LEVELS)), ability_id)

            save_ability_power_statistics(statistics)
            save_ability_mathces_statistics(statistics, ability_matches)
            save_ability_wins_distribution(statistics, ability_wins)

        finally:
            remove_account(account_1)
            remove_account(account_2)
示例#5
0
    def test_choose_ability__additional_companion_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        from the_tale.game.companions.abilities import effects as companions_effects
        from the_tale.game.companions.abilities import container as abilities_container
        from the_tale.game.companions import logic as companions_logic
        from the_tale.game.companions import relations as companions_relations

        abilities = [ability for ability in companions_effects.ABILITIES.records
                     if ( isinstance(ability.effect, companions_effects.BaseBattleAbility) and
                          ability.effect.ABILITY.get_id() != 'hit' )]
        companion_ability = random.choice(abilities)

        all_abilities = [ability(level=ability.MAX_LEVEL)
                         for ability in ABILITIES.values()
                         if ability.get_id() != companion_ability.effect.ABILITY.get_id()]

        active_abilities = set(ability.get_id() for ability in ABILITIES.values() if ability.ACTIVATION_TYPE.is_ACTIVE)

        companion_record = companions_logic.create_random_companion_record(u'battle',
                                                                           abilities=abilities_container.Container(start=(companion_ability,)),
                                                                           state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(companion_record))
        self.hero.health = 1 # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        # mock abilities modify_attribute instead of hereos, since we test correct work of it
        def modify_attribute(self, modifier, value):
            if modifier.is_ADDITIONAL_ABILITIES:
                return all_abilities
            return value

        with mock.patch('the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute', modify_attribute):
            for i in xrange(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(len(active_abilities), len(chosen_abilities) + 1)
        self.assertEqual(active_abilities - set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
示例#6
0
    def test_choose_ability__additional_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        all_abilities = [ability(level=ability.MAX_LEVEL) for ability in ABILITIES.values()]

        active_abilities = set(ability.get_id() for ability in all_abilities if ability.activation_type.is_ACTIVE)

        self.hero.health = 1 # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        with mock.patch('the_tale.game.heroes.objects.Hero.additional_abilities', all_abilities):
            for i in xrange(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(active_abilities, chosen_abilities)
示例#7
0
 def get_available_abilities(cls):
     return [a for a in ABILITIES.values() if a.TYPE.is_BATTLE and a.AVAILABILITY.value & ABILITY_AVAILABILITY.FOR_MONSTERS.value]
示例#8
0
 def get_available_abilities(cls):
     return filter(lambda a: a.TYPE.is_BATTLE and a.AVAILABILITY.value & ABILITY_AVAILABILITY.FOR_MONSTERS.value, # pylint: disable=W0110
                   ABILITIES.values())
    def handle(self, *args, **options):  # pylint: disable=R0914

        # account = AccountPrototype.get_by_nick('compare_abilities_user')
        # if account:
        #     account.remove()

        # account = AccountPrototype.get_by_nick('compare_abilities_user_2')
        # if account:
        #     account.remove()

        result, account_1_id, bundle_id = register_user(
            'compare_abilities_user')  # pylint: disable=W0612
        result, account_2_id, bundle_id = register_user(
            'compare_abilities_user_2')  # pylint: disable=W0612

        account_1 = AccountPrototype.get_by_id(account_1_id)
        account_2 = AccountPrototype.get_by_id(account_2_id)

        storage = LogicStorage()
        storage.load_account_data(account_1)
        storage.load_account_data(account_2)

        hero_1 = storage.accounts_to_heroes[account_1_id]
        hero_2 = storage.accounts_to_heroes[account_2_id]

        set_heroes_companion(hero_1, hero_2)

        try:

            abilities = [
                ability_class for ability_class in list(ABILITIES.values())
                if (ability_class.AVAILABILITY.value
                    & ABILITY_AVAILABILITY.FOR_PLAYERS.value
                    and ability_class.get_id() != 'hit'
                    and ability_class.TYPE == ABILITY_TYPE.BATTLE)
            ]

            ability_matches = compare_abilities(hero_1,
                                                hero_2,
                                                abilities,
                                                level=LEVEL)

            ability_statistics = dict(
                (ability.get_id(), 0) for ability in abilities)
            ability_wins = dict(
                (ability.get_id(), []) for ability in abilities)

            for (ability_1_id, ability_2_id), (ability_1_wins,
                                               ability_2_wins) in list(
                                                   ability_matches.items()):
                ability_statistics[ability_1_id] = ability_statistics.get(
                    ability_1_id, 0) + ability_1_wins
                ability_statistics[ability_2_id] = ability_statistics.get(
                    ability_2_id, 0) + ability_2_wins

                ability_wins[ability_1_id].append(ability_1_wins)
                ability_wins[ability_2_id].append(ability_2_wins)

            statistics = sorted(list(ability_statistics.items()),
                                key=lambda stat: -stat[1])

            battles_per_ability = TEST_BATTLES_NUMBER * (len(abilities) - 1)

            for ability_id, wins in statistics:
                print('%d\t%.0f%%\t%s' %
                      (wins, 100 * float(wins) /
                       (battles_per_ability * len(HERO_LEVELS)), ability_id))

            save_ability_power_statistics(statistics)
            save_ability_mathces_statistics(statistics, ability_matches)
            save_ability_wins_distribution(statistics, ability_wins)

        finally:
            remove_account(account_1)
            remove_account(account_2)
示例#10
0
 def get_available_abilities(cls):
     return [
         a for a in ABILITIES.values()
         if a.TYPE.is_BATTLE and a.AVAILABILITY.value
         & ABILITY_AVAILABILITY.FOR_MONSTERS.value
     ]
示例#11
0
 def test_on_miss_method_exists(self):
     for ability_class in list(ABILITIES.values()):
         if ability_class.LOGIC_TYPE is not None and ability_class.LOGIC_TYPE.is_WITH_CONTACT:
             self.assertTrue('on_miss' in ability_class.__dict__)
示例#12
0
 def get_only_for_mobs_ability_id(self):
     for ability_key, ability in list(ABILITIES.items()):
         if (not ability().availability.value
                 & ABILITY_AVAILABILITY.FOR_PLAYERS.value):
             return ability_key
示例#13
0
 def test_serrialization(self):
     for ability_class in list(ABILITIES.values()):
         ability = ability_class(
             level=random.randint(1, ability_class.MAX_LEVEL))
         self.assertEqual(ability,
                          ability_class.deserialize(ability.serialize()))
示例#14
0
 def test_serrialization(self):
     for ability_class in ABILITIES.values():
         ability = ability_class(level=random.randint(1, ability_class.MAX_LEVEL))
         self.assertEqual(ability, ability_class.deserialize(ability.serialize()))
示例#15
0
 def get_available_abilities(cls):
     return filter(
         lambda a: a.TYPE.is_BATTLE and a.AVAILABILITY.value &
         ABILITY_AVAILABILITY.FOR_MONSTERS.value,  # pylint: disable=W0110
         ABILITIES.values())
示例#16
0
 def get_only_for_mobs_ability_id(self):
     for ability_key, ability in ABILITIES.items():
         if not ability().availability.value & ABILITY_AVAILABILITY.FOR_PLAYERS.value:
             return ability_key
示例#17
0
 def test_on_miss_method_exists(self):
     for ability_class in ABILITIES.values():
         if ability_class.LOGIC_TYPE is not None and ability_class.LOGIC_TYPE.is_WITH_CONTACT:
             self.assertTrue("on_miss" in ability_class.__dict__)