コード例 #1
0
    def add_items(self):
        for task in GiveItemTaskPrototype.from_query(GiveItemTaskPrototype._db_all()):
            item = items_storage[task.item_id]

            self.logger.info('process task %d for item %d' % (task.id, item.id))

            self.add_item(item, task.account_id, notify=True)

            task.remove()
コード例 #2
0
    def add_achievement__items(self):
        with self.check_delta(GiveItemTaskPrototype._db_count, 2):
            self.account_achievements_1.add_achievement(self.achievement_1, notify=True)

        item_task_1 = GiveItemTaskPrototype._db_get_object(0)
        self.assertEqual(item_task_1.account_id, self.account_1.id)
        self.assertEqual(item_task_1.item_id, self.item_1_1.id)

        item_task_2 = GiveItemTaskPrototype._db_get_object(0)
        self.assertEqual(item_task_2.account_id, self.account_1.id)
        self.assertEqual(item_task_2.item_id, self.item_1_2.id)
コード例 #3
0
    def test_add_items(self):
        GiveItemTaskPrototype.create(account_id=self.account_1.id, item_id=self.item_2_1.id)

        self.assertFalse(self.account_1_items.has_item(self.item_2_1))

        self.worker.add_items()

        self.account_1_items.reload()

        self.assertTrue(self.account_1_items.has_item(self.item_2_1))
        self.assertEqual(GiveItemTaskPrototype._db_count(), 0)
コード例 #4
0
    def handle(self, *args, **options):

        for achievements in models.AccountAchievements.objects.all().iterator():
            prototype = prototypes.AccountAchievementsPrototype(achievements)

            collection = AccountItemsPrototype.get_by_account_id(prototype.account_id)

            for achievement_id in prototype.achievements.achievements_ids():
                for item in storage.achievements_storage[achievement_id].rewards:
                    if not collection.has_item(item):
                        GiveItemTaskPrototype.create(prototype.account_id, item.id)
コード例 #5
0
ファイル: items_manager.py プロジェクト: serhii73/the-tale
    def add_items(self):
        for task in GiveItemTaskPrototype.from_query(
                GiveItemTaskPrototype._db_all()):
            item = items_storage[task.item_id]

            self.logger.info('process task %d for item %d' %
                             (task.id, item.id))

            self.add_item(item, task.account_id, notify=True)

            task.remove()
コード例 #6
0
ファイル: test_prototypes.py プロジェクト: lshestov/the-tale
    def add_achievement__items(self):
        with self.check_delta(GiveItemTaskPrototype._db_count, 2):
            self.account_achievements_1.add_achievement(self.achievement_1, notify=True)

        item_task_1 = GiveItemTaskPrototype._db_get_object(0)
        self.assertEqual(item_task_1.account_id, self.account_1.id)
        self.assertEqual(item_task_1.item_id, self.item_1_1.id)

        item_task_2 = GiveItemTaskPrototype._db_get_object(0)
        self.assertEqual(item_task_2.account_id, self.account_1.id)
        self.assertEqual(item_task_2.item_id, self.item_1_2.id)
コード例 #7
0
    def test_add_items(self):
        GiveItemTaskPrototype.create(account_id=self.account_1.id,
                                     item_id=self.item_2_1.id)

        self.assertFalse(self.account_1_items.has_item(self.item_2_1))

        self.worker.add_items()

        self.account_1_items.reload()

        self.assertTrue(self.account_1_items.has_item(self.item_2_1))
        self.assertEqual(GiveItemTaskPrototype._db_count(), 0)
コード例 #8
0
    def handle(self, *args, **options):

        for achievements in models.AccountAchievements.objects.all().iterator(
        ):
            prototype = prototypes.AccountAchievementsPrototype(achievements)

            collection = AccountItemsPrototype.get_by_account_id(
                prototype.account_id)

            for achievement_id in prototype.achievements.achievements_ids():
                for item in storage.achievements_storage[
                        achievement_id].rewards:
                    if not collection.has_item(item):
                        GiveItemTaskPrototype.create(prototype.account_id,
                                                     item.id)
コード例 #9
0
ファイル: prototypes.py プロジェクト: Redneck-prm/the-tale
    def add_achievement(self, achievement, notify):
        from the_tale.collections.prototypes import GiveItemTaskPrototype
        from the_tale.accounts.personal_messages import tt_api as pm_tt_api
        from the_tale.accounts.logic import get_system_user

        already_had_achievement = self.achievements.has_achievement(
            achievement)

        self.achievements.add_achievement(achievement)
        self._model.points = self.achievements.get_points()

        rewards = achievement.rewards
        approved_rewards = achievement.approved_rewards

        for item in rewards:
            GiveItemTaskPrototype.create(self.account_id, item.id)

        if not notify or already_had_achievement:
            return

        rewards_message = ''

        if approved_rewards:
            reward_texts = []
            for item in approved_rewards:
                reward_texts.append('[url=%s#k%d]%s[/url]' % (full_url(
                    'http', 'collections:collections:show',
                    item.kit.collection.id), item.kit.id, item.caption))
            rewards_message = 'Награды: %s' % ', '.join(reward_texts)

        message = (
            'Вы заработали достижение «%(achievement)s» — %(description)s. %(rewards_message)s'
            % {
                'achievement':
                '[url=%s#a%d]%s[/url]' %
                (full_url('http', 'accounts:achievements:group', achievement.
                          group.slug), achievement.id, achievement.caption),
                'description':
                achievement.description,
                'rewards_message':
                rewards_message
            })

        pm_tt_api.send_message(get_system_user().id, [self.account.id],
                               message,
                               async=True)
コード例 #10
0
    def add_achievement(self, achievement, notify):
        from the_tale.collections.prototypes import GiveItemTaskPrototype
        from the_tale.accounts.personal_messages.prototypes import MessagePrototype
        from the_tale.accounts.logic import get_system_user

        already_had_achievement = self.achievements.has_achievement(achievement)

        self.achievements.add_achievement(achievement)
        self._model.points = self.achievements.get_points()

        rewards = achievement.rewards
        approved_rewards = achievement.approved_rewards

        for item in rewards:
            GiveItemTaskPrototype.create(self.account_id, item.id)

        if not notify or already_had_achievement:
            return

        rewards_message = ''

        if approved_rewards:
            reward_texts = []
            for item in approved_rewards:
                reward_texts.append( '[url=%s#k%d]%s[/url]' % (full_url('http', 'collections:collections:show', item.kit.collection.id),
                                                                item.kit.id,
                                                                item.caption))
            rewards_message = 'Награды: %s' % ', '.join(reward_texts)


        message = ('Вы заработали достижение «%(achievement)s» — %(description)s. %(rewards_message)s' %
                   {'achievement': '[url=%s#a%d]%s[/url]' % (full_url('http', 'accounts:achievements:group', achievement.group.slug),
                                                              achievement.id,
                                                              achievement.caption),
                    'description': achievement.description,
                    'rewards_message': rewards_message})

        MessagePrototype.create(get_system_user(), self.account, message)