Example #1
0
    def process(self, main_task, storage):

        battle = Battle1x1Prototype.get_by_id(self.battle_id)

        if battle is None: # battle ended
            self.state = USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED
            main_task.comment = 'battle finished'
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        hero = storage.accounts_to_heroes.get(self.account_id)
        enemy_hero = storage.accounts_to_heroes.get(battle.enemy_id)

        if hero is None:
            self.state = USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND
            main_task.comment = 'hero for account %d not found' % self.account_id
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        pvp_ability_class = ABILITIES.get(self.ability_id)

        if pvp_ability_class is None:
            self.state = USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID
            main_task.comment = 'unknown ability id "%s"' % self.ability_id
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        pvp_ability = pvp_ability_class(hero=hero, enemy=enemy_hero)

        if not pvp_ability.has_resources:
            self.state = USE_PVP_ABILITY_TASK_STATE.NO_ENERGY
            main_task.comment = 'no resources for ability %s' % self.ability_id
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        pvp_ability.use()

        self.state = USE_PVP_ABILITY_TASK_STATE.PROCESSED
        return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        result, account_1_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        result, account_2_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')

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

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

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)
Example #3
0
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

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

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.hero_1.actions.current_action.bundle_id, meta_action=self.meta_action_battle)
Example #4
0
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        result, account_1_id, bundle_id = register_user(
            'test_user', '*****@*****.**', '111111')
        result, account_2_id, bundle_id = register_user(
            'test_user_2', '*****@*****.**', '111111')

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

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

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)
    def test_get_bot_pvp_properties(self):
        properties = self.meta_action_battle.bot_pvp_properties

        self.assertEqual(set(properties.keys()), set(('ability_chance', 'priorities')))
        self.assertTrue(0 < properties['ability_chance'] <= 1)
        self.assertEqual(set(properties['priorities']), set(ABILITIES.keys()))

        for ability_priority in properties['priorities']:
            self.assertTrue(ability_priority > 0)
Example #6
0
    def test_get_bot_pvp_properties(self):
        properties = self.meta_action_battle.bot_pvp_properties

        self.assertEqual(set(properties.keys()),
                         set(('ability_chance', 'priorities')))
        self.assertTrue(0 < properties['ability_chance'] <= 1)
        self.assertEqual(set(properties['priorities']), set(ABILITIES.keys()))

        for ability_priority in properties['priorities'].values():
            self.assertTrue(ability_priority > 0)
Example #7
0
    def get_bot_pvp_properties(self):
        from the_tale.game.pvp.abilities import ABILITIES

        if 'bot_pvp_properties' in self.data:
            return self.data['bot_pvp_properties']

        priorities = {ability.TYPE: random.uniform(0.1, 1.0) for ability in ABILITIES.values()}
        priorities_sum = sum(priorities.values())
        priorities = {ability_type: ability_priority/priorities_sum
                      for ability_type, ability_priority in priorities.items()}

        self.data['bot_pvp_properties'] = {'priorities': priorities,
                                           'ability_chance': random.uniform(0.1, 0.33)}
        return self.data['bot_pvp_properties']
Example #8
0
 def get_bot_pvp_properties(cls):
     bot_priorities = {
         ability.TYPE: random.uniform(0.1, 1.0)
         for ability in PVP_ABILITIES.values()
     }
     bot_priorities_sum = sum(bot_priorities.values())
     bot_priorities = {
         ability_type: ability_priority / bot_priorities_sum
         for ability_type, ability_priority in bot_priorities.items()
     }
     return {
         'priorities': bot_priorities,
         'ability_chance': random.uniform(0.1, 0.33)
     }
    def test_get_bot_pvp_properties(self):
        properties = self.meta_action_battle.get_bot_pvp_properties()

        self.meta_action_battle.save()
        self.meta_action_battle.reload()

        self.assertEqual(set(properties.keys()), set(("ability_chance", "priorities")))
        self.assertTrue("bot_pvp_properties" in self.meta_action_battle.data)
        self.assertEqual(set(properties.keys()), set(self.meta_action_battle.data["bot_pvp_properties"]))
        self.assertTrue(0 < properties["ability_chance"] <= 1)
        self.assertEqual(set(properties["priorities"]), set(ABILITIES.keys()))

        self.assertEqual(properties, self.meta_action_battle.get_bot_pvp_properties())

        for ability_priority in properties["priorities"]:
            self.assertTrue(ability_priority > 0)
    def test_get_bot_pvp_properties(self):
        properties = self.meta_action_battle.get_bot_pvp_properties()

        self.meta_action_battle.save()
        self.meta_action_battle.reload()

        self.assertEqual(set(properties.keys()),
                         set(('ability_chance', 'priorities')))
        self.assertTrue('bot_pvp_properties' in self.meta_action_battle.data)
        self.assertEqual(
            set(properties.keys()),
            set(self.meta_action_battle.data['bot_pvp_properties']))
        self.assertTrue(0 < properties['ability_chance'] <= 1)
        self.assertEqual(set(properties['priorities']), set(ABILITIES.keys()))

        self.assertEqual(properties,
                         self.meta_action_battle.get_bot_pvp_properties())

        for ability_priority in properties['priorities']:
            self.assertTrue(ability_priority > 0)
Example #11
0
    def setUp(self):
        super(UsePvPAbilityTests, self).setUp()

        self.p1, self.p2, self.p3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

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

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(list(ABILITIES.values()))

        self.task = UsePvPAbilityTask(battle_id=self.battle.id,
                                      account_id=self.account_1.id,
                                      ability_id=self.ability.TYPE)

        self.meta_action_battle = meta_actions.ArenaPvP1x1.create(
            self.storage, self.hero_1, self.hero_2)
        self.meta_action_battle.set_storage(self.storage)

        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_1,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_2,
            _bundle_id=self.hero_1.actions.current_action.bundle_id,
            meta_action=self.meta_action_battle)
Example #12
0
 def get_bot_pvp_properties(cls):
     bot_priorities = {ability.TYPE: random.uniform(0.1, 1.0) for ability in PVP_ABILITIES.values()}
     bot_priorities_sum = sum(bot_priorities.values())
     bot_priorities = {ability_type: ability_priority/bot_priorities_sum
                       for ability_type, ability_priority in bot_priorities.items()}
     return {'priorities': bot_priorities, 'ability_chance': random.uniform(0.1, 0.33)}
Example #13
0
 def setUp(self):
     super(UsePvPAbilityRequestsTests, self).setUp()
     self.ability = random.choice(ABILITIES.values())
     self.change_style_url = url('game:pvp:use-ability', ability=self.ability.TYPE)