示例#1
0
    def test_game_info_data_hidding(self):
        '''
        player hero always must show actual data
        enemy hero always must show data on statrt of the turn
        '''
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        hero_1.pvp.set_energy(1)
        heroes_logic.save_hero(hero_1)

        hero_2.pvp.set_energy(2)
        heroes_logic.save_hero(hero_2)

        data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['account']['hero']['pvp']['energy'], 1)
        self.assertEqual(data['enemy']['hero']['pvp']['energy'], 0)

        hero_2.pvp.store_turn_data()
        heroes_logic.save_hero(hero_2)

        data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['enemy']['hero']['pvp']['energy'], 2)
    def test_register_accounts_on_initialization__multiple_accounts_bandles(self):
        account_3 = self.accounts_factory.create_account()
        account_4 = self.accounts_factory.create_account()
        account_5 = self.accounts_factory.create_account()
        account_6 = self.accounts_factory.create_account()

        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)
        hero_3 = heroes_logic.load_hero(account_id=account_3.id)
        hero_4 = heroes_logic.load_hero(account_id=account_4.id)
        hero_6 = heroes_logic.load_hero(account_id=account_6.id)

        hero_3.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_3.actions.updated = True
        heroes_logic.save_hero(hero_3)

        hero_4.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_4.actions.updated = True
        heroes_logic.save_hero(hero_4)

        hero_6.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id
        hero_6.actions.updated = True
        heroes_logic.save_hero(hero_6)

        self.worker.process_initialize()

        self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1',
                                                       self.account_2.id: 'game_logic_2',
                                                       account_3.id: 'game_logic_2',
                                                       account_4.id: 'game_logic_2',
                                                       account_5.id: 'game_logic_1',
                                                       account_6.id: 'game_logic_2'})
        self.assertEqual(self.worker.logic_accounts_number, {'game_logic_1': 2, 'game_logic_2': 4})
示例#3
0
    def test_game_info_caching(self):
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        def get_ui_info(hero, **kwargs):
            if hero.id == hero_1.id:
                return {'actual_on_turn': hero_1.saved_at_turn,
                        'pvp__actual':'actual',
                        'pvp__last_turn':'last_turn',
                        'changed_fields': [],
                        'ui_caching_started_at': 0}
            else:
                return self.create_not_own_ui_info(hero_2)

        with mock.patch('the_tale.game.heroes.objects.Hero.ui_info', get_ui_info):
            data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['account']['hero']['pvp'], 'actual')
        self.assertEqual(data['enemy']['hero']['pvp'], 'last_turn')

        self.assertFalse('pvp__actual' in data['account']['hero']['pvp'])
        self.assertFalse('pvp__last_turn' in data['account']['hero']['pvp'])
        self.assertFalse('pvp__actual' in data['enemy']['hero']['pvp'])
        self.assertFalse('pvp__last_turn' in data['enemy']['hero']['pvp'])

        self.assertNotEqual(data['enemy']['hero']['cards'], 'fake')
        self.assertEqual(data['enemy']['hero']['energy']['max'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['value'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['bonus'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['discount'], 0)
示例#4
0
    def test_save_hero_data_with_meta_action(self):
        bundle_id = 666

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

        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_1,
            _bundle_id=bundle_id,
            meta_action=meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(
            hero=self.hero_2,
            _bundle_id=bundle_id,
            meta_action=meta_action_battle)

        self.storage._save_hero_data(self.hero_1.id)
        self.storage._save_hero_data(self.hero_2.id)

        self.hero_1 = heroes_logic.load_hero(hero_id=self.hero_1.id)
        self.hero_2 = heroes_logic.load_hero(hero_id=self.hero_2.id)

        self.assertEqual(
            meta_action_battle.serialize(),
            self.hero_1.actions.current_action.saved_meta_action.serialize())
        self.assertEqual(
            meta_action_battle.serialize(),
            self.hero_2.actions.current_action.saved_meta_action.serialize())
示例#5
0
    def test_game_info_caching(self):
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        def get_ui_info(hero, **kwargs):
            if hero.id == hero_1.id:
                return {'actual_on_turn': hero_1.saved_at_turn,
                        'action': {'data': {'pvp__actual':'actual',
                                            'pvp__last_turn':'last_turn'}},
                        'changed_fields': [],
                        'ui_caching_started_at': 0}
            else:
                return self.create_not_own_ui_info(hero_2)

        with mock.patch('the_tale.game.heroes.objects.Hero.ui_info', get_ui_info):
            data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['account']['hero']['action']['data']['pvp'], 'actual')
        self.assertEqual(data['enemy']['hero']['action']['data']['pvp'], 'last_turn')

        self.assertFalse('pvp__actual' in data['account']['hero']['action']['data']['pvp'])
        self.assertFalse('pvp__last_turn' in data['account']['hero']['action']['data']['pvp'])
        self.assertFalse('pvp__actual' in data['enemy']['hero']['action']['data']['pvp'])
        self.assertFalse('pvp__last_turn' in data['enemy']['hero']['action']['data']['pvp'])

        self.assertNotEqual(data['enemy']['hero']['cards'], 'fake')
        self.assertEqual(data['enemy']['hero']['energy']['max'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['value'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['bonus'], 0)
        self.assertEqual(data['enemy']['hero']['energy']['discount'], 0)
示例#6
0
    def test_save_all(self):

        self.hero_1.health = 1
        self.hero_2.health = 1

        self.storage.save_all()

        self.assertEqual(self.hero_1.health, heroes_logic.load_hero(hero_id=self.hero_1.id).health)
        self.assertEqual(self.hero_2.health, heroes_logic.load_hero(hero_id=self.hero_2.id).health)
示例#7
0
    def setUp(self):
        super(AbilitiesTests, self).setUp()

        create_test_map()

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

        self.hero = heroes_logic.load_hero(account_id=account_1_id)
        self.enemy = heroes_logic.load_hero(account_id=account_1_id)
    def test_process_arena_pvp_1x1(self):
        task = SupervisorTaskPrototype.create_arena_pvp_1x1(
            self.account_1, self.account_2)

        task.capture_member(self.account_1.id)
        task.capture_member(self.account_2.id)

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

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

        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PREPAIRING).count(), 2)
        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PROCESSING).count(), 0)

        old_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        old_hero.health = 1
        heroes_logic.save_hero(old_hero)

        task.process(bundle_id=666)

        new_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        new_hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertEqual(new_hero.actions.current_action.bundle_id,
                         new_hero_2.actions.current_action.bundle_id)
        self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id,
                            new_hero.actions.actions_list[1].bundle_id)
        self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id,
                            new_hero_2.actions.actions_list[1].bundle_id)

        self.assertNotEqual(old_hero, new_hero)
        self.assertTrue(old_hero.actions.number < new_hero.actions.number)
        self.assertEqual(new_hero.health, new_hero.max_health)

        self.assertEqual(new_hero.actions.number, 2)
        self.assertEqual(new_hero_2.actions.number, 2)

        self.assertEqual(
            new_hero.actions.current_action.meta_action.serialize(),
            new_hero_2.actions.current_action.meta_action.serialize())

        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PREPAIRING).count(), 0)
        self.assertEqual(
            Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
示例#9
0
    def setUp(self):
        super(AbilitiesTests, self).setUp()

        create_test_map()

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

        self.hero = heroes_logic.load_hero(account_id=account_1_id)
        self.enemy = heroes_logic.load_hero(account_id=account_1_id)
示例#10
0
    def test_save_all(self):

        self.hero_1.health = 1
        self.hero_2.health = 1

        self.hero_1.actions.updated = True

        self.storage.save_all()

        self.assertEqual(self.hero_1.health, heroes_logic.load_hero(hero_id=self.hero_1.id).health)
        self.assertEqual(self.hero_2.health, heroes_logic.load_hero(hero_id=self.hero_2.id).health)

        self.assertFalse(self.hero_1.actions.updated)
示例#11
0
    def setUp(self):
        super(TestRequestsBase, self).setUp()

        create_test_map()

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

        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.client = client.Client()

        self.request_login(self.account_1.email)
示例#12
0
    def setUp(self):
        super(BaseEffectsTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.account_3 = self.accounts_factory.create_account()
        self.hero_3 = heroes_logic.load_hero(account_id=self.account_3.id)

        self.effect = effects.EFFECT.PLACE_SAFETY
示例#13
0
    def setUp(self):
        super(BaseEffectsTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.account_3 = self.accounts_factory.create_account()
        self.hero_3 = heroes_logic.load_hero(account_id=self.account_3.id)

        self.effect = effects.EFFECT.PLACE_SAFETY
示例#14
0
def show(context):
    accounts_short_infos = game_short_info.get_accounts_accounts_info(
        list(context.place.politic_power.inner_accounts_ids()))

    return dext_views.Page(
        'places/show.html',
        content={
            'place':
            context.place,
            'place_bills':
            info.place_info_bills(context.place),
            'place_chronicle':
            chronicle_prototypes.chronicle_info(
                context.place, conf.settings.CHRONICLE_RECORDS_NUMBER),
            'accounts_short_infos':
            accounts_short_infos,
            'HABIT_TYPE':
            game_relations.HABIT_TYPE,
            'place_meta_object':
            meta_relations.Place.create_from_object(context.place),
            'hero':
            heroes_logic.load_hero(
                account_id=context.account.id) if context.account else None,
            'resource':
            context.resource
        })
示例#15
0
    def accept_battle(cls, pvp_balancer, battle_id, hero_id):

        accepted_battle = Battle1x1Prototype.get_by_id(battle_id)

        if accepted_battle is None:
            return ACCEPT_BATTLE_RESULT.BATTLE_NOT_FOUND

        if not accepted_battle.state.is_WAITING:
            return ACCEPT_BATTLE_RESULT.WRONG_ACCEPTED_BATTLE_STATE

        if not accepted_battle.account_id in pvp_balancer.arena_queue:
            return ACCEPT_BATTLE_RESULT.NOT_IN_QUEUE

        initiator_id = heroes_logic.load_hero(hero_id=hero_id).account_id

        initiator_battle = Battle1x1Prototype.get_by_account_id(initiator_id)

        if initiator_battle is not None and not initiator_battle.state.is_WAITING:
            return ACCEPT_BATTLE_RESULT.WRONG_INITIATOR_BATTLE_STATE

        if initiator_id not in pvp_balancer.arena_queue:
            pvp_balancer.add_to_arena_queue(hero_id)

        pvp_balancer.force_battle(accepted_battle.account_id, initiator_id)

        return ACCEPT_BATTLE_RESULT.PROCESSED
示例#16
0
    def accept_battle(cls, pvp_balancer, battle_id, hero_id):

        accepted_battle = Battle1x1Prototype.get_by_id(battle_id)

        if accepted_battle is None:
            return ACCEPT_BATTLE_RESULT.BATTLE_NOT_FOUND

        if not accepted_battle.state.is_WAITING:
            return ACCEPT_BATTLE_RESULT.WRONG_ACCEPTED_BATTLE_STATE

        if not accepted_battle.account_id in pvp_balancer.arena_queue:
            return ACCEPT_BATTLE_RESULT.NOT_IN_QUEUE

        initiator_id = heroes_logic.load_hero(hero_id=hero_id).account_id

        initiator_battle = Battle1x1Prototype.get_by_account_id(initiator_id)

        if initiator_battle is not None and not initiator_battle.state.is_WAITING:
            return ACCEPT_BATTLE_RESULT.WRONG_INITIATOR_BATTLE_STATE

        if initiator_id not in pvp_balancer.arena_queue:
            pvp_balancer.add_to_arena_queue(hero_id)

        pvp_balancer.force_battle(accepted_battle.account_id, initiator_id)

        return ACCEPT_BATTLE_RESULT.PROCESSED
示例#17
0
    def add_to_arena_queue(self, hero_id):

        hero = heroes_logic.load_hero(hero_id=hero_id)

        if hero.account_id in self.arena_queue:
            return None

        battle = Battle1x1Prototype.create(
            AccountPrototype.get_by_id(hero.account_id))

        if not battle.state.is_WAITING:
            raise PvPBalancerException(
                'account %d already has battle not in waiting state' %
                hero.account_id)

        record = QueueRecord(account_id=battle.account_id,
                             created_at=battle.created_at,
                             battle_id=battle.id,
                             hero_level=hero.level)

        if record.account_id in self.arena_queue:
            raise PvPBalancerException(
                'account %d already added in balancer queue' %
                record.account_id)

        self.arena_queue[record.account_id] = record

        return battle
示例#18
0
    def test_dispatch_command_for_unregistered_account(self):
        self.worker.process_initialize()

        result, account_3_id, bundle_id = register_user(
            'test_user_3', '*****@*****.**', '111111')

        account_3 = AccountPrototype.get_by_id(account_3_id)
        hero_3 = heroes_logic.load_hero(account_id=account_3_id)

        with mock.patch('the_tale.game.workers.logic.Worker.cmd_logic_task'
                        ) as logic_task_counter:
            with mock.patch.object(self.worker.logger,
                                   'warn') as logger_warn_counter:
                self.worker.process_update_hero_with_account_data(
                    account_3_id,
                    is_fast=account_3.is_fast,
                    premium_end_at=account_3.premium_end_at,
                    active_end_at=account_3.active_end_at,
                    ban_end_at=account_3.ban_game_end_at,
                    might=666,
                    actual_bills=7)

        self.assertEqual(logic_task_counter.call_count, 0)
        self.assertEqual(logger_warn_counter.call_count, 1)
        self.assertFalse(account_3_id in self.worker.accounts_owners)
        self.assertTrue(account_3_id in self.worker.accounts_queues)
示例#19
0
    def _initiate_battle_with_bot(self, record):

        # search free bot
        # since now bots needed only for PvP, we can do simplified search
        battled_accounts_ids = Battle1x1Prototype._model_class.objects.all().values_list('account_id', flat=True)

        try:
            bot_account = AccountPrototype(model=AccountPrototype._model_class.objects.filter(is_bot=True).exclude(id__in=battled_accounts_ids)[0])
        except IndexError:
            bot_account = None

        if bot_account is None:
            return [record], []

        bot_hero = heroes_logic.load_hero(account_id=bot_account.id)

        self.logger.info('start battle between account %d and bot %d' % (record.account_id, bot_account.id))

        # create battle for bot
        self.add_to_arena_queue(bot_hero.id)
        bot_record = self.arena_queue[bot_account.id]

        self._initiate_battle(record, bot_record, calculate_ratings=False)

        return [], [record, bot_record]
示例#20
0
    def test_not_own_hero_get_cached_data(self):
        hero = heroes_logic.load_hero(account_id=self.account_1.id)

        with mock.patch(
                'the_tale.game.heroes.objects.Hero.ui_info',
                mock.Mock(return_value=self.create_not_own_ui_info(
                    hero))) as ui_info:
            data = form_game_info(self.account_1, is_own=False)

        self.assertEqual(data['account']['hero']['action']['data']['pvp'],
                         'last_turn')
        self.assertEqual(data['enemy'], None)

        self.assertFalse(
            'pvp__actual' in data['account']['hero']['action']['data']['pvp'])
        self.assertFalse('pvp__last_turn' in data['account']['hero']['action']
                         ['data']['pvp'])

        self.assertNotEqual(data['account']['hero']['cards'], 'fake')
        self.assertEqual(data['account']['hero']['energy']['max'], 0)
        self.assertEqual(data['account']['hero']['energy']['value'], 0)
        self.assertEqual(data['account']['hero']['energy']['bonus'], 0)
        self.assertEqual(data['account']['hero']['energy']['discount'], 0)

        self.assertEqual(ui_info.call_count, 1)
        self.assertEqual(ui_info.call_args, mock.call(actual_guaranteed=False))
示例#21
0
    def _initiate_battle_with_bot(self, record):

        # search free bot
        # since now bots needed only for PvP, we can do simplified search
        battled_accounts_ids = Battle1x1Prototype._model_class.objects.all().values_list("account_id", flat=True)

        try:
            bot_account = AccountPrototype(
                model=AccountPrototype._model_class.objects.filter(is_bot=True).exclude(id__in=battled_accounts_ids)[0]
            )
        except IndexError:
            bot_account = None

        if bot_account is None:
            return [record], []

        bot_hero = heroes_logic.load_hero(account_id=bot_account.id)

        self.logger.info("start battle between account %d and bot %d" % (record.account_id, bot_account.id))

        # create battle for bot
        self.add_to_arena_queue(bot_hero.id)
        bot_record = self.arena_queue[bot_account.id]

        self._initiate_battle(record, bot_record, calculate_ratings=False)

        return [], [record, bot_record]
示例#22
0
    def test_add_achievements__all_accounts(self):

        GiveAchievementTaskPrototype.create(
            account_id=None, achievement_id=self.achievement_3.id)

        account_achievements_2 = AccountAchievementsPrototype.get_by_account_id(
            self.account_2.id)

        self.assertFalse(
            self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(
            account_achievements_2.has_achievement(self.achievement_3))
        hero = heroes_logic.load_hero(account_id=self.account_1.id)
        hero.statistics.change_pve_deaths(self.achievement_3.barrier)
        heroes_logic.save_hero(hero)

        with self.check_not_changed(MessagePrototype._db_count):
            self.worker.add_achievements()

        self.account_achievements_1.reload()
        account_achievements_2.reload()

        self.assertTrue(
            self.account_achievements_1.has_achievement(self.achievement_3))
        self.assertFalse(
            account_achievements_2.has_achievement(self.achievement_3))

        self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
示例#23
0
    def setUp(self):
        super(TestVoteRequests, self).setUp()

        self.account2.prolong_premium(30)
        self.account2.save()

        self.hero = heroes_logic.load_hero(account_id=self.account2.id)
        self.hero.places_history.add_place(self.place1.id)
        self.hero.places_history.add_place(self.place2.id)
        self.hero.places_history.add_place(self.place3.id)

        heroes_logic.save_hero(self.hero)

        new_name = names.generator().get_test_name('new-name')

        data = linguistics_helpers.get_word_post_data(new_name, prefix='name')
        data.update({'caption': 'bill-caption',
                     'rationale': 'bill-rationale',
                     'chronicle_on_accepted': 'chronicle-on-accepted',
                     'place': self.place1.id})

        self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data)
        self.bill = BillPrototype(Bill.objects.all()[0])

        self.request_logout()
        self.request_login(self.account2.email)
示例#24
0
    def test_own_hero_get_cached_data(self):
        hero = heroes_logic.load_hero(account_id=self.account_1.id)

        with mock.patch(
                'the_tale.game.heroes.objects.Hero.cached_ui_info_for_hero',
                mock.Mock(
                    return_value={
                        'actual_on_turn': hero.saved_at_turn,
                        'pvp': 'actual',
                        'ui_caching_started_at': 0
                    })) as cached_ui_info_for_hero:
            with mock.patch(
                    'the_tale.game.heroes.objects.Hero.ui_info') as ui_info:
                data = form_game_info(self.account_1, is_own=True)

        self.assertEqual(data['account']['hero']['pvp'], 'actual')
        self.assertEqual(data['enemy'], None)

        self.assertEqual(cached_ui_info_for_hero.call_count, 1)
        self.assertEqual(
            cached_ui_info_for_hero.call_args,
            mock.call(account_id=self.account_1.id,
                      recache_if_required=True,
                      patch_turns=None,
                      for_last_turn=False))
        self.assertEqual(ui_info.call_count, 0)
示例#25
0
def shop(context):
    hero = heroes_logic.load_hero(account_id=context.account.id)

    if context.account.is_premium:
        featured_group = relations.GOODS_GROUP.CHEST
    else:
        featured_group = relations.GOODS_GROUP.PREMIUM

    price_types = [group.type for group in price_list.PRICE_GROUPS]

    def _cmp(x, y):
        choices = { (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, False): -1,
                    (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, True): 1,
                    (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, False): 1,
                    (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, True): -1,

                    (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, False): -1,
                    (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, True): 1,
                    (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, False): 1,
                    (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, True): -1 }

        return choices.get((x.type, y.type, context.account.is_premium), cmp(price_types.index(x.type), price_types.index(y.type)))

    price_groups = sorted(price_list.PRICE_GROUPS, cmp=_cmp)

    return dext_views.Page('shop/shop.html',
                           content={'PRICE_GROUPS': price_groups,
                                    'hero': hero,
                                    'payments_settings': payments_settings,
                                    'account': context.account,
                                    'featured_group': featured_group,
                                    'page_type': 'shop',
                                    'resource': context.resource})
示例#26
0
    def use(self, api_version, building=None, battle=None):
        '''
Использование одной из способностей игрока (список способностей см. в разделе типов)

- **адрес:** /game/abilities/<идентификатор способности>/api/use
- **http-метод:** POST
- **версии:** 1.0
- **параметры:**
    * GET: building — идентификатор здания, если способность касается здания
    * GET: battle — идентификатор pvp сражения, если способность касается операций с pvp сражением
- **возможные ошибки**: нет

Метод является «неблокирующей операцией» (см. документацию), формат ответа соответствует ответу для всех «неблокирующих операций».

Цена использования способностей возвращается при запросе базовой информации.
        '''

        task = self.ability.activate(
            heroes_logic.load_hero(account_id=self.account.id),
            data={
                'building_id': building,
                'battle_id': battle
            })

        return self.processing(task.status_url)
示例#27
0
def show(context):
    from the_tale.game.ratings import relations as ratings_relations
    from the_tale.game.ratings import conf as ratings_conf

    friendship = FriendshipPrototype.get_for_bidirectional(
        context.account, context.master_account)

    master_hero = heroes_logic.load_hero(account_id=context.master_account.id)

    return dext_views.Page(
        'accounts/show.html',
        content={
            'master_hero':
            master_hero,
            'account_meta_object':
            meta_relations.Account.create_from_object(context.master_account),
            'account_info':
            logic.get_account_info(context.master_account, master_hero),
            'master_account':
            context.master_account,
            'accounts_settings':
            conf.accounts_settings,
            'RATING_TYPE':
            ratings_relations.RATING_TYPE,
            'resource':
            context.resource,
            'ratings_on_page':
            ratings_conf.ratings_settings.ACCOUNTS_ON_PAGE,
            'informer_link':
            conf.accounts_settings.INFORMER_LINK % {
                'account_id': context.master_account.id
            },
            'friendship':
            friendship
        })
示例#28
0
def show(context):

    accounts_short_infos = game_short_info.get_accounts_accounts_info(
        list(context.person.politic_power.inner_accounts_ids()))

    return dext_views.Page(
        'persons/show.html',
        content={
            'person':
            context.person,
            'person_meta_object':
            meta_relations.Person.create_from_object(context.person),
            'accounts_short_infos':
            accounts_short_infos,
            'hero':
            heroes_logic.load_hero(
                account_id=context.account.id) if context.account else None,
            'social_connections':
            storage.social_connections.get_connected_persons(context.person),
            'master_chronicle':
            chronicle_prototypes.chronicle_info(
                context.person, conf.settings.CHRONICLE_RECORDS_NUMBER),
            'resource':
            context.resource
        })
示例#29
0
    def test_save_hero_data_with_meta_action(self):
        bundle_id = 666

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

        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=bundle_id, meta_action=meta_action_battle)
        actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=bundle_id, meta_action=meta_action_battle)

        self.storage._save_hero_data(self.hero_1.id)
        self.storage._save_hero_data(self.hero_2.id)

        self.hero_1 = heroes_logic.load_hero(hero_id=self.hero_1.id)
        self.hero_2 = heroes_logic.load_hero(hero_id=self.hero_2.id)


        self.assertEqual(meta_action_battle.serialize(), self.hero_1.actions.current_action.saved_meta_action.serialize())
        self.assertEqual(meta_action_battle.serialize(), self.hero_2.actions.current_action.saved_meta_action.serialize())
示例#30
0
    def test_is_old__not_own_hero(self):
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])
示例#31
0
    def test_is_old(self):
        self.assertFalse(form_game_info(self.account_1, is_own=True)['account']['is_old'])

        turn.set(666)
        self.assertTrue(form_game_info(self.account_1, is_own=True)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=True)['account']['is_old'])
示例#32
0
    def setUp(self):
        super(SupervisorWorkerTests, self).setUp()

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

        self.account_1 = self.accounts_factory.create_account()
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        environment.deinitialize()
        environment.initialize()

        self.worker = environment.workers.supervisor

        self.worker.logger = mock.Mock()
示例#33
0
    def setUp(self):
        super(MobsPrototypeTests, self).setUp()
        create_test_map()

        account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=account.id)

        storage.mobs.sync(force=True)
示例#34
0
 def test_show(self):
     hero = heroes_logic.load_hero(account_id=self.account_1.id)
     self.check_ajax_ok(self.request_ajax_json(
         url('accounts:api-show',
             self.account_1.id,
             api_version='1.0',
             api_client=project_settings.API_CLIENT)),
                        data=logic.get_account_info(self.account_1, hero))
示例#35
0
    def setUp(self):
        super(TestShowRequests, self).setUp()

        self.hero = heroes_logic.load_hero(account_id=self.account2.id)

        places_logic.add_fame(hero_id=self.hero.id, fames=[(self.place1.id, 1000),
                                                           (self.place2.id, 1000),
                                                           (self.place3.id, 1000)])
示例#36
0
    def setUp(self):
        super(MobsPrototypeTests, self).setUp()
        create_test_map()

        account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=account.id)

        mobs_storage.sync(force=True)
示例#37
0
    def setUp(self):
        super(TestShowRequests, self).setUp()

        self.hero = heroes_logic.load_hero(account_id=self.account2.id)
        self.hero.places_history.add_place(self.place1.id)
        self.hero.places_history.add_place(self.place2.id)
        self.hero.places_history.add_place(self.place3.id)
        heroes_logic.save_hero(self.hero)
示例#38
0
    def get_achievements_source_iterator(self, achievement):
        from the_tale.accounts.prototypes import AccountPrototype

        if achievement.type.source.is_ACCOUNT:
            return (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_all())

        if achievement.type.source.is_GAME_OBJECT:
            return (heroes_logic.load_hero(hero_model=hero_model) for hero_model in heroes_models.Hero.objects.all().iterator())
示例#39
0
    def setUp(self):
        super(SupervisorWorkerTests, self).setUp()

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

        self.account_1 = self.accounts_factory.create_account()
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        environment.deinitialize()
        environment.initialize()

        self.worker = environment.workers.supervisor

        self.worker.logger = mock.Mock()
示例#40
0
    def test_is_old__not_own_hero(self):
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1, is_own=False)['account']['is_old'])

        heroes_logic.save_hero(heroes_logic.load_hero(account_id=self.account_1.id))
        self.assertFalse(form_game_info(self.account_1, is_own=False)['account']['is_old'])
示例#41
0
    def __init__(self, choosen_person_id, owner_id, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)

        hero_id = heroes_logic.load_hero(account_id=owner_id).id

        self.fields['new_place'].choices = places_storage.places.get_choices()
        self.fields['person'].choices = persons_objects.Person.form_choices(choosen_person=persons_storage.persons.get(choosen_person_id),
                                                                            predicate=lambda place, person: person.politic_power.is_in_inner_circle(hero_id))
示例#42
0
    def setUp(self):
        super(TestRequestsBase, self).setUp()
        create_test_map()

        result, account_id, bundle_id = register_user("test_user", "*****@*****.**", "111111")
        self.account_1_id = account_id
        self.account_1 = AccountPrototype.get_by_id(account_id)
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        result, account_id, bundle_id = register_user("test_user_2", "*****@*****.**", "111111")
        self.account_2_id = account_id
        self.account_2 = AccountPrototype.get_by_id(account_id)
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.client = client.Client()

        self.request_login("*****@*****.**")
示例#43
0
    def test_can_not_voted(self):
        self.assertEqual(heroes_logic.load_hero(account_id=self.account1.id).places_history.history, collections.deque([], maxlen=200))

        # one vote automaticaly created for bill author
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account1, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 0),))
示例#44
0
    def setUp(self):
        super(BalancerTestsBase, 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.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        environment.deinitialize()
        environment.initialize()

        Battle1x1Prototype.create(self.account_1)

        self.worker = environment.workers.pvp_balancer
        self.worker.process_initialize('pvp_balancer')
示例#45
0
    def _test_save(self):
        for hero_id in self.heroes:
            self._save_hero_data(hero_id)

        test_storage = LogicStorage()
        for hero_id in self.heroes:
            test_storage._add_hero(heroes_logic.load_hero(hero_id=hero_id))

        return self == test_storage
示例#46
0
    def test_get_random_mob__action_type(self):
        account = self.accounts_factory.create_account()
        hero = heroes_logic.load_hero(account_id=account.id)

        action_type = actions_relations.ACTION_TYPE.random()

        with mock.patch("the_tale.game.actions.prototypes.ActionBase.ui_type", action_type):
            mob = mobs_storage.get_random_mob(hero)

        self.assertEqual(mob.action_type, action_type)
示例#47
0
    def test_is_old__pvp(self):
        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)
        hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertFalse(form_game_info(self.account_1)['account']['is_old'])
        self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])

        TimePrototype(turn_number=666).save()
        self.assertTrue(form_game_info(self.account_1)['account']['is_old'])
        self.assertTrue(form_game_info(self.account_1)['enemy']['is_old'])

        heroes_logic.save_hero(hero_1)
        heroes_logic.save_hero(hero_2)

        self.assertFalse(form_game_info(self.account_1)['account']['is_old'])
        self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])
示例#48
0
def show(context):

    accounts_short_infos = game_short_info.get_accounts_accounts_info(list(context.person.politic_power.inner_accounts_ids()))

    return dext_views.Page('persons/show.html',
                           content={'person': context.person,
                                    'person_meta_object': meta_relations.Person.create_from_object(context.person),
                                    'accounts_short_infos': accounts_short_infos,
                                    'hero': heroes_logic.load_hero(account_id=context.account.id) if context.account else None,
                                    'resource': context.resource})
示例#49
0
    def test_get_random_mob__terrain(self):
        account = self.accounts_factory.create_account()
        hero = heroes_logic.load_hero(account_id=account.id)

        terrain = map_relations.TERRAIN.random()

        with mock.patch("the_tale.game.heroes.position.Position.get_terrain", lambda h: terrain):
            mob = mobs_storage.get_random_mob(hero)

        self.assertEqual(mob.terrain, terrain)
示例#50
0
    def setUp(self):
        super(EffectsTestsBase, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.hero_1 = heroes_logic.load_hero(account_id=self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.account_3 = self.accounts_factory.create_account()
        self.hero_3 = heroes_logic.load_hero(account_id=self.account_3.id)

        self.place = self.place_1
        self.person = self.place.persons[0]

        self.actor_name = 'actor name'
        self.job_power = 666
示例#51
0
    def setUp(self):
        super(PrototypeTests, self).setUp()
        create_test_map()

        account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=account.id)

        artifacts_storage.sync(force=True)

        self.artifact_record = artifacts_storage.all()[0]
示例#52
0
    def test_process_arena_pvp_1x1(self):
        task = SupervisorTaskPrototype.create_arena_pvp_1x1(self.account_1, self.account_2)

        task.capture_member(self.account_1.id)
        task.capture_member(self.account_2.id)

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

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

        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 2)
        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 0)

        old_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        old_hero.health = 1
        heroes_logic.save_hero(old_hero)

        task.process(bundle_id=666)

        new_hero = heroes_logic.load_hero(account_id=self.account_1.id)
        new_hero_2 = heroes_logic.load_hero(account_id=self.account_2.id)

        self.assertEqual(new_hero.actions.current_action.bundle_id, new_hero_2.actions.current_action.bundle_id)
        self.assertNotEqual(new_hero.actions.actions_list[0].bundle_id, new_hero.actions.actions_list[1].bundle_id)
        self.assertNotEqual(new_hero_2.actions.actions_list[0].bundle_id, new_hero_2.actions.actions_list[1].bundle_id)

        self.assertNotEqual(old_hero, new_hero)
        self.assertTrue(old_hero.actions.number < new_hero.actions.number)
        self.assertEqual(new_hero.health, new_hero.max_health)

        self.assertEqual(new_hero.actions.number, 2)
        self.assertEqual(new_hero_2.actions.number, 2)

        self.assertEqual(new_hero.actions.current_action.meta_action.serialize(),
                         new_hero_2.actions.current_action.meta_action.serialize())

        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PREPAIRING).count(), 0)
        self.assertEqual(Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING).count(), 2)
示例#53
0
    def load_account_data(self, account):
        hero = heroes_logic.load_hero(account_id=account.id)
        hero.update_with_account_data(is_fast=account.is_fast,
                                      premium_end_at=account.premium_end_at,
                                      active_end_at=account.active_end_at,
                                      ban_end_at=account.ban_game_end_at,
                                      might=account.might,
                                      actual_bills=account.actual_bills)
        self._add_hero(hero)

        return hero