Ejemplo n.º 1
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False,
                  gender=game_relations.GENDER.MASCULINE,
                  full_create=True):
    from the_tale.game import tt_api as game_tt_api
    from the_tale.game.heroes import logic as heroes_logic
    from the_tale.game.balance import constants as c

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id,
                                      gender=gender)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    hero = heroes_logic.create_hero(account=account, full_create=full_create)

    if full_create:
        game_tt_api.change_energy_balance(account_id=account.id,
                                          type='initial_contribution',
                                          energy=c.INITIAL_ENERGY_AMOUNT,
                                          async=False,
                                          autocommit=True)

        tt_api.create_cards_timer(account_id=account.id)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Ejemplo n.º 2
0
    def verify_achievements(self, account_id, type, old_value, new_value):
        if old_value == new_value:
            return

        for achievement in self.by_type(type, only_approved=True):
            if achievement.check(old_value, new_value):
                AccountAchievementsPrototype.give_achievement(account_id=account_id, achievement=achievement)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def verify_achievements(self, account_id, type, old_value, new_value):
        if old_value == new_value:
            return

        for achievement in self.by_type(type, only_approved=True):
            if achievement.check(old_value, new_value):
                AccountAchievementsPrototype.give_achievement(
                    account_id=account_id, achievement=achievement)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False):
    from the_tale.game.heroes import logic as heroes_logic

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = heroes_logic.create_hero(account=account)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Ejemplo n.º 7
0
    def test_block_expired_accounts(self):
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)

        task.account._model.created_at = datetime.datetime.fromtimestamp(0)
        task.account._model.save()

        self.assertEqual(AccountAchievementsPrototype._db_count(), 1)

        logic.block_expired_accounts()

        self.assertEqual(Hero.objects.all().count(), 0)

        self.assertEqual(Account.objects.all().count(), 0)

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
Ejemplo n.º 8
0
def get_account_info(account, hero):
    from the_tale.game.ratings import prototypes as ratings_prototypes
    from the_tale.game.ratings import relations as ratings_relations

    ratings = {}

    rating_places = ratings_prototypes.RatingPlacesPrototype.get_by_account_id(account.id)

    rating_values = ratings_prototypes.RatingValuesPrototype.get_by_account_id(account.id)

    if rating_values and rating_places:
        for rating in ratings_relations.RATING_TYPE.records:
            ratings[rating.value] = {'name': rating.text,
                                     'place': getattr(rating_places, '%s_place' % rating.field, None),
                                     'value': getattr(rating_values, rating.field, None)}

    places_history = [{'place': {'id': place.id, 'name': place.name}, 'count': help_count} for place, help_count in hero.places_history.get_most_common_places()]

    return {'id': account.id,
            'registered': not account.is_fast,
            'name': account.nick_verbose,
            'hero_id': hero.id,
            'places_history': places_history,
            'might': account.might,
            'achievements': AccountAchievementsPrototype.get_by_account_id(account.id).points,
            'collections': AccountItemsPrototype.get_by_account_id(account.id).get_items_count(),
            'referrals': account.referrals_number,
            'ratings': ratings,
            'permissions': {
                'can_affect_game': account.can_affect_game
                },
            'description': account.description_html}
Ejemplo n.º 9
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1',
            description=u'description_1',
            approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_3',
                                             text=u'text_1_3',
                                             approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption=u'achievement_1',
            description=u'description_1',
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption=u'achievement_2',
            description=u'description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption=u'achievement_3',
            description=u'description_3',
            approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
Ejemplo n.º 10
0
    def setUp(self):
        super(_BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        group_edit = sync_group('edit achievement', ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=0, points=10,
                                                         caption=u'achievement_1', description=u'description_1', approved=True)
        self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=2, points=10,
                                                         caption=u'achievement_2', description=u'description_2', approved=False)
        self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.TIME, barrier=3, points=10,
                                                         caption=u'achievement_3', description=u'description_3', approved=True)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=True)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(self.achievement_1)
        self.account_achievements_1.save()
Ejemplo n.º 11
0
    def test_add_achievements__all_accounts__not_remove_already_received_achievements(
            self):
        self.account_achievements_1.achievements.add_achievement(
            self.achievement_3)
        self.account_achievements_1.save()

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

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

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

        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)
Ejemplo n.º 12
0
    def show_group(self, account=None):
        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('accounts:achievements:group',
                    self.group.slug,
                    account=self.account.id))

        self.master_account = account

        account_achievements = None
        if account:
            account_achievements = AccountAchievementsPrototype.get_by_account_id(
                account.id)
            achievements = sorted(achievements_storage.by_group(
                self.group, only_approved=not self.can_edit_achievements),
                                  key=account_achievements.sort_key_for)
        else:
            achievements = sorted(achievements_storage.by_group(
                self.group, only_approved=not self.can_edit_achievements),
                                  key=lambda achievement: achievement.order)

        return self.template(
            'achievements/group.html', {
                'account_achievements':
                account_achievements,
                'groups_statistics':
                achievements_storage.get_groups_statistics(
                    account_achievements),
                'achievements':
                achievements
            })
Ejemplo n.º 13
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('accounts:achievements:', account=self.account.id))

        self.master_account = account

        account_achievements = None
        last_achievements = []
        if account:
            account_achievements = AccountAchievementsPrototype.get_by_account_id(
                account.id)
            last_achievements = account_achievements.last_achievements(
                number=achievements_settings.LAST_ACHIEVEMENTS_NUMBER)

        groups_table = split_into_table(self.groups, 3)

        return self.template(
            'achievements/index.html', {
                'account_achievements':
                account_achievements,
                'groups_table':
                groups_table,
                'groups_statistics':
                achievements_storage.get_groups_statistics(
                    account_achievements),
                'last_achievements':
                last_achievements
            })
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
    def test_legendary_achievements(self):
        achievement_4 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.LEGENDS,
            type=ACHIEVEMENT_TYPE.LEGENDS,
            barrier=0,
            points=0,
            caption=u'achievement_4',
            description=u'description_4',
            approved=True)

        self.account_achievements_1.achievements.add_achievement(achievement_4)
        self.account_achievements_1.save()

        GiveAchievementTaskPrototype.create(account_id=None,
                                            achievement_id=achievement_4.id)

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

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

        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(achievement_4))
        self.assertFalse(account_achievements_2.has_achievement(achievement_4))

        self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
Ejemplo n.º 16
0
    def setUp(self):
        super(AchievementsManagerTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        group_edit = sync_group('edit achievement', ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=0, points=10,
                                                         caption=u'achievement_1', description=u'description_1', approved=True)
        self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=5, points=10,
                                                         caption=u'achievement_2', description=u'description_2', approved=False)
        self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.DEATHS, barrier=4, points=10,
                                                         caption=u'achievement_3', description=u'description_3', approved=True)


        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(self.achievement_1)
        self.account_achievements_1.save()

        self.worker = environment.workers.achievements_manager
        self.worker.initialize()
Ejemplo n.º 17
0
    def setUp(self):
        super(_BaseRequestTests, self).setUp()

        create_test_map()

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

        group_edit = sync_group('edit achievement',
                                ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=0,
            points=10,
            caption='achievement_1',
            description='description_1',
            approved=True)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption='achievement_2',
            description='description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption='achievement_3',
            description='description_3',
            approved=True)

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=True)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(
            self.achievement_1)
        self.account_achievements_1.save()
Ejemplo n.º 18
0
def register_user(nick, email=None, password=None, referer=None, referral_of_id=None, action_id=None, is_bot=False):

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = HeroPrototype.create(account=account)
    dress_new_hero(hero)
    messages_for_new_hero(hero)
    hero.save()

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Ejemplo n.º 19
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_3',
                                             text='text_1_3',
                                             approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption='achievement_1',
            description='description_1',
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption='achievement_2',
            description='description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption='achievement_3',
            description='description_3',
            approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
Ejemplo n.º 20
0
    def test_block_expired_accounts(self):
        task = RegistrationTask(account_id=None,
                                referer=None,
                                referral_of_id=None,
                                action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()),
                         POSTPONED_TASK_LOGIC_RESULT.SUCCESS)

        task.account._model.created_at = datetime.datetime.fromtimestamp(0)
        task.account._model.save()

        self.assertEqual(AccountAchievementsPrototype._db_count(), 1)

        logic.block_expired_accounts()

        self.assertEqual(Hero.objects.all().count(), 0)

        self.assertEqual(Account.objects.all().count(), 0)

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
Ejemplo n.º 21
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user("test_user_1", "*****@*****.**", "111111")
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.collection_1 = CollectionPrototype.create(
            caption=u"collection_1", description=u"description_1", approved=True
        )
        self.kit_1 = KitPrototype.create(
            collection=self.collection_1, caption=u"kit_1", description=u"description_1", approved=True
        )
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_1", text=u"text_1_1", approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_2", text=u"text_1_2", approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_3", text=u"text_1_3", approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption=u"achievement_1",
            description=u"description_1",
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2,
        )
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption=u"achievement_2",
            description=u"description_2",
            approved=False,
        )
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption=u"achievement_3",
            description=u"description_3",
            approved=True,
        )

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
Ejemplo n.º 22
0
    def setUp(self):
        super(AchievementsManagerTests, self).setUp()

        create_test_map()

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

        group_edit = sync_group('edit achievement',
                                ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=0,
            points=10,
            caption='achievement_1',
            description='description_1',
            approved=True)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=5,
            points=10,
            caption='achievement_2',
            description='description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.DEATHS,
            barrier=4,
            points=10,
            caption='achievement_3',
            description='description_3',
            approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(
            self.achievement_1)
        self.account_achievements_1.save()

        self.worker = environment.workers.achievements_manager
        self.worker.initialize()

        pm_logic.debug_clear_service()
Ejemplo n.º 23
0
    def show_group(self, account=None):
        if account is None and self.account.is_authenticated:
            return self.redirect(url('accounts:achievements:group', self.group.slug, account=self.account.id))

        self.master_account = account

        account_achievements = None
        if account:
            account_achievements = AccountAchievementsPrototype.get_by_account_id(account.id)
            achievements = sorted(achievements_storage.by_group(self.group, only_approved=not self.can_edit_achievements),
                                  key=account_achievements.sort_key_for)
        else:
            achievements = sorted(achievements_storage.by_group(self.group, only_approved=not self.can_edit_achievements),
                                  key=lambda achievement: achievement.order)


        return self.template('achievements/group.html',
                             {'account_achievements': account_achievements,
                              'groups_statistics': achievements_storage.get_groups_statistics(account_achievements),
                              'achievements': achievements})
Ejemplo n.º 24
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated():
            return self.redirect(url('accounts:achievements:', account=self.account.id))

        self.master_account = account

        account_achievements = None
        last_achievements = []
        if account:
            account_achievements = AccountAchievementsPrototype.get_by_account_id(account.id)
            last_achievements = account_achievements.last_achievements(number=achievements_settings.LAST_ACHIEVEMENTS_NUMBER)

        groups_table = split_into_table(self.groups, 3)

        return self.template('achievements/index.html',
                             {'account_achievements': account_achievements,
                              'groups_table': groups_table,
                              'groups_statistics': achievements_storage.get_groups_statistics(account_achievements),
                              'last_achievements': last_achievements})
Ejemplo n.º 25
0
    def test_add_achievements__all_accounts__not_remove_already_received_achievements(self):
        self.account_achievements_1.achievements.add_achievement(self.achievement_3)
        self.account_achievements_1.save()

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

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

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

        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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1', approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1, caption='item_1_3', text='text_1_3', approved=True)


        self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=1, points=10,
                                                         caption='achievement_1', description='description_1', approved=True,
                                                         item_1=self.item_1_1, item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=2, points=10,
                                                         caption='achievement_2', description='description_2', approved=False)
        self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.TIME, barrier=3, points=10,
                                                         caption='achievement_3', description='description_3', approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
Ejemplo n.º 28
0
    def test_legendary_achievements(self):
        achievement_4 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.LEGENDS, type=ACHIEVEMENT_TYPE.LEGENDS, barrier=0, points=0,
                                                    caption=u'achievement_4', description=u'description_4', approved=True)

        self.account_achievements_1.achievements.add_achievement(achievement_4)
        self.account_achievements_1.save()

        GiveAchievementTaskPrototype.create(account_id=None, achievement_id=achievement_4.id)

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

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

        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(achievement_4))
        self.assertFalse(account_achievements_2.has_achievement(achievement_4))

        self.assertEqual(GiveAchievementTaskPrototype._db_count(), 0)
Ejemplo n.º 29
0
def get_account_info(account, hero):
    from the_tale.game.ratings import prototypes as ratings_prototypes
    from the_tale.game.ratings import relations as ratings_relations
    from the_tale.game.places import storage as places_storage
    from the_tale.game.places import logic as places_logic

    ratings = {}

    rating_places = ratings_prototypes.RatingPlacesPrototype.get_by_account_id(
        account.id)

    rating_values = ratings_prototypes.RatingValuesPrototype.get_by_account_id(
        account.id)

    if rating_values and rating_places:
        for rating in ratings_relations.RATING_TYPE.records:
            ratings[rating.value] = {
                'name': rating.text,
                'place': getattr(rating_places, '%s_place' % rating.field,
                                 None),
                'value': getattr(rating_values, rating.field, None)
            }

    popularity = places_logic.get_hero_popularity(hero.id)

    places_history = [{
        'place': {
            'id': place_id,
            'name': places_storage.places[place_id].name
        },
        'count': help_count
    } for place_id, help_count in popularity.places_rating()]

    clan_info = None

    if account.clan_id:
        clan = account.clan
        clan_info = {'id': clan.id, 'abbr': clan.abbr, 'name': clan.name}

    return {
        'id':
        account.id,
        'registered':
        not account.is_fast,
        'name':
        account.nick_verbose,
        'hero_id':
        hero.id,
        'places_history':
        places_history,
        'might':
        account.might,
        'achievements':
        AccountAchievementsPrototype.get_by_account_id(account.id).points,
        'collections':
        AccountItemsPrototype.get_by_account_id(account.id).get_items_count(),
        'referrals':
        account.referrals_number,
        'ratings':
        ratings,
        'permissions': {
            'can_affect_game': account.can_affect_game
        },
        'description':
        account.description_html,
        'clan':
        clan_info
    }
Ejemplo n.º 30
0
    def test_successfull_result(self):
        game_tt_api.debug_clear_service()

        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 = heroes_logic.load_hero(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(heroes_models.HeroPreferences.objects.all().count(),
                         1)
        self.assertEqual(
            heroes_models.HeroPreferences.objects.get(
                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(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        self.assertEqual(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        timers = tt_api.get_owner_timers(account_id=account.id)

        self.assertEqual(len(timers), 1)
Ejemplo n.º 31
0
 def remove_achievement(self, achievement, account_id):
     achievements = AccountAchievementsPrototype.get_by_account_id(
         account_id)
     achievements.remove_achievement(achievement)
     achievements.save()
Ejemplo n.º 32
0
 def add_achievement(self, achievement, account_id, notify):
     achievements = AccountAchievementsPrototype.get_by_account_id(
         account_id)
     achievements.add_achievement(achievement, notify=notify)
     achievements.save()
Ejemplo n.º 33
0
 def add_achievement(self, achievement, account_id, notify):
     achievements = AccountAchievementsPrototype.get_by_account_id(account_id)
     achievements.add_achievement(achievement, notify=notify)
     achievements.save()
Ejemplo n.º 34
0
 def remove_achievement(self, achievement, account_id):
     achievements = AccountAchievementsPrototype.get_by_account_id(account_id)
     achievements.remove_achievement(achievement)
     achievements.save()