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 = HeroPrototype.get_by_account_id(self.account_2.id) hero_3 = HeroPrototype.get_by_account_id(account_3.id) hero_4 = HeroPrototype.get_by_account_id(account_4.id) hero_6 = HeroPrototype.get_by_account_id(account_6.id) hero_3.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_3.actions.updated = True hero_3.save() hero_4.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_4.actions.updated = True hero_4.save() hero_6.actions.current_action.bundle_id = hero_2.actions.current_action.bundle_id hero_6.actions.updated = True hero_6.save() 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})
def check_heroes(self): result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') hero_3 = HeroPrototype.get_by_account_id(account_id) hero_1.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_1.preferences.set_place(self.place_1) hero_1.preferences.set_friend(self.place_1.persons[0]) hero_1.preferences.set_enemy(self.place_1.persons[-1]) hero_1.save() hero_2.premium_state_end_at = datetime.datetime.now() + datetime.timedelta(seconds=60) hero_2.preferences.set_place(self.place_1) hero_2.preferences.set_friend(self.place_1.persons[-1]) hero_2.preferences.set_enemy(self.place_1.persons[0]) hero_2.save() hero_3.preferences.set_place(self.place_1) hero_3.preferences.set_friend(self.place_1.persons[-1]) hero_3.preferences.set_enemy(self.place_1.persons[0]) hero_3.save() texts = [(jinja2.escape(hero_1.name), 3), (jinja2.escape(hero_2.name), 3), (jinja2.escape(hero_3.name), 0)] self.check_html_ok(self.request_html(url('game:map:places:show', self.place_1.id)), texts=texts)
def setUp(self): super(PrototypeTests, self).setUp() current_time = TimePrototype.get_current_time() current_time.increment_turn() self.persons_changed_at_turn = TimePrototype.get_current_turn_number() self.p1, self.p2, self.p3 = create_test_map() self.person = create_person(self.p1, PERSON_STATE.IN_GAME) result, account_id, bundle_id = register_user('test_user1', '*****@*****.**', '111111') self.hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user2', '*****@*****.**', '111111') self.hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user3', '*****@*****.**', '111111') self.hero_3 = HeroPrototype.get_by_account_id(account_id) current_time = TimePrototype.get_current_time() current_time.increment_turn()
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 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_account_id(self.account_2.id) hero_1.pvp.set_energy(1) hero_1.save() hero_2.pvp.set_energy(2) hero_2.save() 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() hero_2.save() data = form_game_info(self.account_1, is_own=True) self.assertEqual(data['enemy']['hero']['pvp']['energy'], 2)
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 = HeroPrototype.get_by_account_id(account_1_id) self.enemy = HeroPrototype.get_by_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 = HeroPrototype.get_by_account_id(self.account_1.id) old_hero.health = 1 old_hero.save() task.process(bundle_id=666) new_hero = HeroPrototype.get_by_account_id(self.account_1.id) new_hero_2 = HeroPrototype.get_by_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)
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']) HeroPrototype.get_by_account_id(self.account_1.id).save() self.assertFalse( form_game_info(self.account_1, is_own=False)['account']['is_old'])
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 = HeroPrototype.get_by_account_id(account_1_id) self.enemy = HeroPrototype.get_by_account_id(account_1_id)
def setUp(self): super(TestVoteRequests, self).setUp() self.account2.prolong_premium(30) self.account2.save() self.hero = HeroPrototype.get_by_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) self.hero.save() 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('*****@*****.**')
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 = HeroPrototype.get_by_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]
def test_successfull_result(self): self.assertEqual(AccountAchievementsPrototype._db_count(), 0) self.assertEqual(AccountItemsPrototype._db_count(), 0) result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') # test result self.assertEqual(result, REGISTER_USER_RESULT.OK) self.assertTrue(bundle_id is not None) #test basic structure account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.nick, 'test_user') self.assertEqual(account.email, '*****@*****.**') self.assertTrue(not account.is_fast) hero = HeroPrototype.get_by_account_id(account.id) # test hero equipment self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves') self.assertEqual( hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id, 'default_weapon') self.assertTrue( hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None) self.assertEqual(HeroPreferencesPrototype._db_count(), 1) self.assertEqual( HeroPreferencesPrototype.get_by_hero_id( hero.id).energy_regeneration_type, hero.preferences.energy_regeneration_type) self.assertEqual(account.referer, None) self.assertEqual(account.referer_domain, None) self.assertEqual(account.referral_of_id, None) self.assertEqual(account.action_id, None) self.assertEqual(account.is_bot, False) self.assertEqual(AccountAchievementsPrototype._db_count(), 1) self.assertEqual(AccountItemsPrototype._db_count(), 1) self.assertEqual(market_models.Goods.objects.count(), 1)
def test_get_random_mob__no_mob(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) self.assertEqual(mobs_storage.get_random_mob(hero), None)
def show(context): place_info = logic.place_info(context.place) return dext_views.Page( 'places/show.html', content={ 'place_info': place_info, 'place_meta_object': meta_relations.Place.create_from_object(context.place), 'RACE': game_relations.RACE, 'GENDER': game_relations.GENDER, 'PERSON_TYPE': persons_relations.PERSON_TYPE, 'CONNECTION_TYPE': persons_relations.SOCIAL_CONNECTION_TYPE, 'hero': HeroPrototype.get_by_account_id(context.account.id) if context.account else None, 'persons_storage': persons_storage.persons_storage, 'resource': context.resource })
def test_own_hero_get_cached_data(self): hero = HeroPrototype.get_by_account_id(self.account_1.id) with mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.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.prototypes.HeroPrototype.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)
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 = HeroPrototype.get_by_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]
def use(self, api_version, building=None, battle=None): u''' Использование одной из способностей игрока (список способностей см. в разделе типов) - **адрес:** /game/abilities/<идентификатор способности>/api/use - **http-метод:** POST - **версии:** 1.0 - **параметры:** * GET: building — идентификатор здания, если способность касается здания * GET: battle — идентификатор pvp сражения, если способность касается операций с pvp сражением - **возможные ошибки**: нет Метод является «неблокирующей операцией» (см. документацию), формат ответа соответствует ответу для всех «неблокирующих операций». Цена использования способностей возвращается при запросе базовой информации. ''' task = self.ability.activate(HeroPrototype.get_by_account_id( self.account.id), data={ 'building_id': building, 'battle_id': battle }) return self.processing(task.status_url)
def shop(context): hero = HeroPrototype.get_by_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})
def setUp(self): super(MobsPrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) mobs_storage.sync(force=True)
def setUp(self): super(MobsPrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) mobs_storage.sync(force=True)
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 = HeroPrototype.get_by_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 = HeroPrototype.get_by_account_id(self.account_2.id) self.client = client.Client() self.request_login('*****@*****.**')
def setUp(self): super(TestShowRequests, self).setUp() self.hero = HeroPrototype.get_by_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) self.hero.save()
def test_can_not_voted(self): self.assertEqual(HeroPrototype.get_by_account_id(self.account1.id).places_history.history, []) # 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),))
def remove_game_data(account): from the_tale.game.heroes.prototypes import HeroPrototype hero = HeroPrototype.get_by_account_id(account.id) for action in reversed(hero.actions.actions_list): action.remove() hero.remove()
def remove_game_data(account): from the_tale.game.heroes.prototypes import HeroPrototype hero = HeroPrototype.get_by_account_id(account.id) for action in reversed(hero.actions.actions_list): action.remove() hero.remove()
def test_get_random_mob__action_type(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_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)
def setUp(self): super(PrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact_record = artifacts_storage.all()[0]
def setUp(self): super(PrototypeTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact_record = artifacts_storage.all()[0]
def test_get_random_mob__terrain(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) terrain = map_relations.TERRAIN.random() with mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.get_terrain', lambda h: terrain): mob = mobs_storage.get_random_mob(hero) self.assertEqual(mob.terrain, terrain)
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 = HeroPrototype.get_by_account_id(self.account_1.id) old_hero.health = 1 old_hero.save() task.process(bundle_id=666) new_hero = HeroPrototype.get_by_account_id(self.account_1.id) new_hero_2 = HeroPrototype.get_by_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)
def setUp(self): super(EffectsTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact = self.hero.equipment.values()[0]
def setUp(self): super(EffectsTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) artifacts_storage.sync(force=True) self.artifact = self.hero.equipment.values()[0]
def load_account_data(self, account): hero = HeroPrototype.get_by_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
def setUp(self): super(SupervisorWorkerTests, 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.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) self.account_1 = AccountPrototype.get_by_id(account_1_id) self.account_2 = AccountPrototype.get_by_id(account_2_id) environment.deinitialize() environment.initialize() self.worker = environment.workers.supervisor self.worker.logger = mock.Mock()
def load_account_data(self, account): hero = HeroPrototype.get_by_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
def test_choose_mob__when_actions__total_actions(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) MobRecordPrototype.create_random('action_1', global_action_probability=0.66) MobRecordPrototype.create_random('action_2', global_action_probability=0.66) counter = collections.Counter([mobs_storage.get_random_mob(hero).id for i in xrange(10000)]) self.assertEqual(sum([count for uuid, count in counter.iteritems() if uuid not in ('action_1', 'action_2')], 0), 0) self.assertTrue(abs(counter['action_2'] - counter['action_1']) < 0.2 * counter['action_2'])
def setUp(self): super(BalancerTestsBase, 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.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) environment.deinitialize() environment.initialize() Battle1x1Prototype.create(self.account_1) self.worker = environment.workers.pvp_balancer self.worker.process_initialize('pvp_balancer')
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 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_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']) hero_1.save() hero_2.save() self.assertFalse(form_game_info(self.account_1)['account']['is_old']) self.assertFalse(form_game_info(self.account_1)['enemy']['is_old'])
def show(context): place_info = logic.place_info(context.place) return dext_views.Page('places/show.html', content={'place_info': place_info, 'place_meta_object': meta_relations.Place.create_from_object(context.place), 'RACE': game_relations.RACE, 'GENDER': game_relations.GENDER, 'PERSON_TYPE': persons_relations.PERSON_TYPE, 'CONNECTION_TYPE': persons_relations.SOCIAL_CONNECTION_TYPE, 'hero': HeroPrototype.get_by_account_id(context.account.id) if context.account else None, 'persons_storage': persons_storage.persons_storage, 'resource': context.resource} )
def test_show__places_history(self): texts = [(self.place1.name, 1), (self.place2.name, 1), (self.place3.name, 0), ('pgf-no-common-places-message', 0)] hero = HeroPrototype.get_by_account_id(self.account_1.id) hero.places_history.add_place(self.place1.id) hero.places_history.add_place(self.place2.id) hero.places_history.add_place(self.place1.id) hero.save() self.check_html_ok(self.request_html(reverse('accounts:show', args=[self.account_1.id])), texts=texts)
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 = HeroPrototype.get_by_account_id(self.account_1.id) hero_2 = HeroPrototype.get_by_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.prototypes.HeroPrototype.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)
def test_get_random_mob__boss(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) boss = mobs_storage.get_random_mob(hero, is_boss=True) self.assertTrue(boss.is_boss) normal_mob = boss.record.create_mob(hero) self.assertFalse(normal_mob.is_boss) self.assertTrue(boss.max_health > normal_mob.max_health)
def test_get_random_mob__action_type(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_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)
def setUp(self): super(PrototypeTests, self).setUp() current_time = TimePrototype.get_current_time() current_time.increment_turn() self.persons_changed_at_turn = TimePrototype.get_current_turn_number() self.p1, self.p2, self.p3 = create_test_map() self.person = create_person(self.p1, PERSON_STATE.IN_GAME) result, account_id, bundle_id = register_user('test_user1', '*****@*****.**', '111111') self.hero_1 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user2', '*****@*****.**', '111111') self.hero_2 = HeroPrototype.get_by_account_id(account_id) result, account_id, bundle_id = register_user('test_user3', '*****@*****.**', '111111') self.hero_3 = HeroPrototype.get_by_account_id(account_id) current_time = TimePrototype.get_current_time() current_time.increment_turn()
def test_successfull_result(self): self.assertEqual(AccountAchievementsPrototype._db_count(), 0) self.assertEqual(AccountItemsPrototype._db_count(), 0) result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') # test result self.assertEqual(result, REGISTER_USER_RESULT.OK) self.assertTrue(bundle_id is not None) #test basic structure account = AccountPrototype.get_by_id(account_id) self.assertEqual(account.nick, 'test_user') self.assertEqual(account.email, '*****@*****.**') self.assertTrue(not account.is_fast) hero = HeroPrototype.get_by_account_id(account.id) # test hero equipment self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants') self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots') self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate') self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves') self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id, 'default_weapon') self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None) self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None) self.assertEqual(HeroPreferencesPrototype._db_count(), 1) self.assertEqual(HeroPreferencesPrototype.get_by_hero_id(hero.id).energy_regeneration_type, hero.preferences.energy_regeneration_type) self.assertEqual(account.referer, None) self.assertEqual(account.referer_domain, None) self.assertEqual(account.referral_of_id, None) self.assertEqual(account.action_id, None) self.assertEqual(account.is_bot, False) self.assertEqual(AccountAchievementsPrototype._db_count(), 1) self.assertEqual(AccountItemsPrototype._db_count(), 1) self.assertEqual(market_models.Goods.objects.count(), 1)
def test_get_random_mob__terrain(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) terrain = map_relations.TERRAIN.random() with mock.patch( 'the_tale.game.heroes.prototypes.HeroPositionPrototype.get_terrain', lambda h: terrain): mob = mobs_storage.get_random_mob(hero) self.assertEqual(mob.terrain, terrain)
def setUp(self): super(BalancerTestsBase, 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.hero_1 = HeroPrototype.get_by_account_id(account_1_id) self.hero_2 = HeroPrototype.get_by_account_id(account_2_id) environment.deinitialize() environment.initialize() Battle1x1Prototype.create(self.account_1) self.worker = environment.workers.pvp_balancer self.worker.process_initialize('pvp_balancer')
def index(self): if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit(self.request): return self.redirect(random.choice(portal_settings.FIRST_TIME_LANDING_URLS)) news = news_logic.load_news_from_query(news_models.News.objects.all().order_by('-created_at')[:portal_settings.NEWS_ON_INDEX]) bills = BillPrototype.get_recently_modified_bills(portal_settings.BILLS_ON_INDEX) account_of_the_day_id = settings.get(portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY) hero_of_the_day = None account_of_the_day = None clan_of_the_day = None if account_of_the_day_id is not None: hero_of_the_day = HeroPrototype.get_by_account_id(account_of_the_day_id) account_of_the_day = AccountPrototype.get_by_id(account_of_the_day_id) if account_of_the_day.clan_id is not None: clan_of_the_day = ClanPrototype.get_by_id(account_of_the_day.clan_id) forum_threads = ThreadPrototype.get_last_threads(account=self.account if self.account.is_authenticated() else None, limit=portal_settings.FORUM_THREADS_ON_INDEX) blog_posts = [ BlogPostPrototype(blog_post_model) for blog_post_model in BlogPost.objects.filter(state__in=[BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED], votes__gte=0).order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX] ] map_info = map_info_storage.item chronicle_records = ChronicleRecordPrototype.get_last_records(portal_settings.CHRONICLE_RECORDS_ON_INDEX) chronicle_actors = RecordToActorPrototype.get_actors_for_records(chronicle_records) return self.template('portal/index.html', {'news': news, 'forum_threads': forum_threads, 'bills': bills, 'hero_of_the_day': hero_of_the_day, 'account_of_the_day': account_of_the_day, 'clan_of_the_day': clan_of_the_day, 'map_info': map_info, 'blog_posts': blog_posts, 'TERRAIN': TERRAIN, 'MAP_STATISTICS': MAP_STATISTICS, 'chronicle_records': chronicle_records, 'chronicle_actors': chronicle_actors, 'RACE': RACE})
def test_get_random_mob__boss(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) boss = mobs_storage.get_random_mob(hero, is_boss=True) self.assertTrue(boss.is_boss) normal_mob = boss.record.create_mob(hero) self.assertFalse(normal_mob.is_boss) self.assertTrue(boss.max_health > normal_mob.max_health)
def setUp(self): super(LogicWorkerTests, self).setUp() self.p1, self.p2, self.p3 = create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) self.account = AccountPrototype.get_by_id(self.hero.account_id) environment.deinitialize() environment.initialize() self.worker = environment.workers.logic_1 self.worker.process_initialize(TimePrototype.get_current_turn_number(), 'logic')
def setUp(self): super(LogicWorkerTests, self).setUp() self.p1, self.p2, self.p3 = create_test_map() result, account_id, bundle_id = register_user('test_user') self.hero = HeroPrototype.get_by_account_id(account_id) self.account = AccountPrototype.get_by_id(self.hero.account_id) environment.deinitialize() environment.initialize() self.worker = environment.workers.logic_1 self.worker.process_initialize(TimePrototype.get_current_turn_number(), 'logic')
def leave_arena_queue(self, hero_id): hero = HeroPrototype.get_by_account_id(hero_id) battle = Battle1x1Prototype.get_by_account_id(hero.account_id) if not battle.state.is_WAITING: return if battle.account_id not in self.arena_queue: self.logger.error('can not leave queue: battle %d in waiting state but no in arena queue' % battle.id) return del self.arena_queue[battle.account_id] battle.remove()
def api_show(context): u''' Получить информацию об игроке - **адрес:** /accounts/<account>/api/show - **http-метод:** GET - **версии:** 1.0 - **параметры:** * URL account — идентификатор игрока - **возможные ошибки**: * account.wrong_value — аккаунт с таким идентификатором не найден формат данных в ответе: { "id": <целое число>, // идентификатор игрока "registered": true|false, // маркер завершения регистрации "name": "строка", // имя игрока "hero_id": <целое число>, // идентификатор героя "places_history": [ // список истории помощи городам "place": { // город "id": <целое число>, // идентификатор города "name": "строка" // название города }, "count": <целое число> // количество фактов помощи ], "might": <дробное число>, // могущество "achievements": <целое число>, // очки достижений "collections": <целое число>, // количество предметов в коллекции "referrals": <целое число>, // количество последователей (рефералов) "ratings": { // рейтинги "строка": { // идентификатор рейтинга: "name": "строка", // название рейтинга: иинформация о рейтинге "place": <целое число>, // место "value": <целое число>|<дробное число> // величина рейтингового значения } }, "permissions": { // права на выполнение различных операций "can_affect_game": true|false // оказывает ли влияние на игру }, "description": "строка" // описание игока, введённое им сами (в формате html) } ''' master_hero = HeroPrototype.get_by_account_id(context.master_account.id) return dext_views.AjaxOk(content=logic.get_account_info(context.master_account, master_hero))
def shop(context): hero = HeroPrototype.get_by_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 })
def leave_arena_queue(self, hero_id): hero = HeroPrototype.get_by_account_id(hero_id) battle = Battle1x1Prototype.get_by_account_id(hero.account_id) if not battle.state.is_WAITING: return if battle.account_id not in self.arena_queue: self.logger.error( 'can not leave queue: battle %d in waiting state but no in arena queue' % battle.id) return del self.arena_queue[battle.account_id] battle.remove()
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 = HeroPrototype.get_by_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} )