Exemple #1
0
    def send_yueka_reward(cls, server_id):
        config = ConfigPurchaseYueka.get(YUEKA_ID)

        condition = {'$and': [
            {'yueka_remained_days': {'$gt': 0}},
            {'yueka_new': False}
        ]}

        docs = MongoPurchase.db(server_id).find(condition)
        MongoPurchase.db(server_id).update_many(
            condition,
            {'$inc': {
                'yueka_remained_days': -1
            }}
        )

        # 把今天新购买的,设置为False,以便后面的定时任务好发送月卡
        MongoPurchase.db(server_id).update_many(
            {'yueka_new': True},
            {'$set': {'yueka_new': False}}
        )

        rc = ResourceClassification.classify(config.rewards)
        attachment = rc.to_json()

        amount = 0
        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(config.mail_title, config.mail_content, attachment=attachment)
            amount += 1

        return amount
Exemple #2
0
    def end(self, party_level, member_ids):
        ret = api_handle.API.Party.EndDone()
        ret.ret = 0

        config = ConfigPartyLevel.get(party_level)
        talent_id = random.choice(config.talent_skills)
        self.doc['talent_id'] = talent_id

        MongoParty.db(self.server_id).update_one(
            {'_id': self.char_id}, {'$set': {
                'talent_id': talent_id
            }})

        # apply talent_id to club
        Club(self.server_id, self.char_id).force_load_staffs(send_notify=True)

        reward = [
            (config.item_id, 1),
        ]
        rc = ResourceClassification.classify(reward)
        attachment = rc.to_json()

        char_ids = [self.char_id]
        char_ids.extend(member_ids)
        for c in char_ids:
            m = MailManager(self.server_id, c)
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)

        ret.talent_id = talent_id
        return ret
Exemple #3
0
    def send_reward(self, goods_id):
        if goods_id == YUEKA_ID:
            # 月卡买了就立即发送
            # 后面的再定时发送
            config = ConfigPurchaseYueka.get(YUEKA_ID)
            got = 0
            actual_got = 0

            MongoPurchase.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'yueka_remained_days': 29,
                    'yueka_new': True
                }}
            )

            self.doc['yueka_remained_days'] = 29
            self.doc['yueka_new'] = True

            rc = ResourceClassification.classify(config.rewards)
            attachment = rc.to_json()

            m = MailManager(self.server_id, self.char_id)
            m.add(config.mail_title, config.mail_content, attachment=attachment)
        else:
            config = ConfigPurchaseGoods.get(goods_id)

            got = config.diamond
            actual_got = config.diamond + config.diamond_extra
            if self.get_purchase_times() == 0:
                # 首充
                actual_got = config.diamond * 2 + config.diamond_extra

        doc = MongoPurchaseLog.document()
        doc['_id'] = make_string_id()
        doc['char_id'] = self.char_id
        doc['goods_id'] = goods_id
        doc['got'] = got
        doc['actual_got'] = actual_got
        doc['timestamp'] = arrow.utcnow().timestamp
        MongoPurchaseLog.db(self.server_id).insert_one(doc)

        reward = [
            (VIP_EXP_ITEM_ID, config.vip_exp),
            (money_text_to_item_id('diamond'), actual_got)
        ]

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="Purchase.send_reward:{0}".format(goods_id))

        purchase_done_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            goods_id=goods_id,
            got=got,
            actual_got=actual_got,
        )

        self.send_notify()
Exemple #4
0
    def send_rank_reward_and_reset_star(cls, server_id):
        char_ids = Club.get_recent_login_char_ids(server_id)
        char_ids = [i for i in char_ids]

        condition = {'$and': [
            {'_id': {'$in': char_ids}},
            {'today_max_star': {'$ne': 0}}
        ]}
        docs = MongoTower.db(server_id).find(condition, {'_id': 1}).sort('today_max_star', -1)

        rank = 1
        for doc in docs:
            cid = doc['_id']

            config = ConfigTowerRankReward.get(rank)

            rc = ResourceClassification.classify(config.reward)

            m = MailManager(server_id, cid)
            m.add(
                config.mail_title,
                config.mail_content,
                attachment=rc.to_json(),
            )

            rank += 1

        # reset today max star
        MongoTower.db(server_id).update_many(
            {},
            {'$set': {
                'today_max_star': 0,
            }}
        )
Exemple #5
0
    def end(self, party_level, member_ids):
        ret = api_handle.API.Party.EndDone()
        ret.ret = 0

        config = ConfigPartyLevel.get(party_level)
        talent_id = random.choice(config.talent_skills)
        self.doc['talent_id'] = talent_id

        MongoParty.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'talent_id': talent_id
            }}
        )

        # apply talent_id to club
        Club(self.server_id, self.char_id).force_load_staffs(send_notify=True)

        reward = [(config.item_id, 1), ]
        rc = ResourceClassification.classify(reward)
        attachment = rc.to_json()

        char_ids = [self.char_id]
        char_ids.extend(member_ids)
        for c in char_ids:
            m = MailManager(self.server_id, c)
            m.add(config.mail_title, config.mail_content, attachment=attachment)

        ret.talent_id = talent_id
        return ret
Exemple #6
0
    def create(cls, server_id, char_id, club_name, club_flag):
        from core.staff import StaffManger
        from core.formation import Formation
        from core.mail import MailManager
        from apps.config.models import Mail as ModelMail

        doc = MongoCharacter.document()
        doc['_id'] = char_id
        doc['create_at'] = arrow.utcnow().timestamp

        doc['name'] = club_name
        doc['flag'] = club_flag
        doc['gold'] = CHAR_INIT_GOLD
        doc['diamond'] = CHAR_INIT_DIAMOND
        doc['crystal'] = CHAR_INIT_CRYSTAL
        doc['gas'] = CHAR_INIT_GAS

        sm = StaffManger(server_id, char_id)

        formation_init_data = []
        for staff_id, unit_id in CHAR_INIT_STAFFS:
            uid = sm.add(staff_id, send_notify=False, trig_signal=False)
            formation_init_data.append((uid, unit_id))

        fm = Formation(server_id, char_id)
        fm.initialize(formation_init_data)

        MongoCharacter.db(server_id).insert_one(doc)

        # add welfare mail
        start_time = get_start_time_of_today()
        condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\
                    Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))
        mails = ModelMail.objects.filter(condition)

        m = MailManager(server_id, char_id)
        for m_obj in mails:
            if not m_obj.welfare:
                continue

            ok = False
            if m_obj.condition_type == 1:
                ok = True
            elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value():
                ok = True
            elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value():
                ok = True

            if not ok:
                continue

            if m_obj.items:
                rc = ResourceClassification.classify(m_obj.get_parsed_items())
                attachment = rc.to_json()
            else:
                attachment = ""

            m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
Exemple #7
0
    def gift(self, gift_code_record):
        """

        :type gift_code_record: GiftCodeRecord
        """

        gen_id = gift_code_record.gen_id
        category = GiftCodeGen.objects.get(id=gen_id).category.id
        gift = GiftCode.objects.get(id=category)
        """:type: GiftCode"""

        if not gift.active:
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NOT_ACTIVE"))

        if gift.time_range1:
            time1 = arrow.get(gift.time_range1).timestamp
            if arrow.utcnow().timestamp < time1:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NOT_STARTED"))

        if gift.time_range2:
            time2 = arrow.get(gift.time_range2).timestamp
            if arrow.utcnow().timestamp > time2:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_EXPIRED"))

        if gift.times_limit:
            using_times = GiftCodeUsingLog.objects.filter(gift_code=gift_code_record.id).count()
            if using_times >= gift.times_limit:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NO_TIMES"))

        # 每个礼品码默认每个玩家每个服只能用一次
        condition = Q(server_id=self.server_id) & Q(char_id=self.char_id) & Q(gift_code=gift_code_record.id)
        if GiftCodeUsingLog.objects.filter(condition).exists():
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_ALREADY_USED"))

        # 同类同服不可以多次使用
        condition = Q(server_id=self.server_id) & Q(char_id=self.char_id) & Q(category=gift.id)
        if GiftCodeUsingLog.objects.filter(condition).exists():
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_CATEGORY_ALREADY_USED"))

        # ALL OK
        items = gift.get_parsed_items()
        rc = ResourceClassification.classify(items)

        m = MailManager(self.server_id, self.char_id)
        m.add(title=gift.mail_title, content=gift.mail_content, attachment=rc.to_json())

        GiftCodeUsingLog.objects.create(
            server_id=self.server_id,
            char_id=self.char_id,
            gift_code=gift_code_record.id,
            category=category,
        )

        GiftCodeGen.objects.filter(id=gen_id).update(used_amount=F('used_amount') + 1)
Exemple #8
0
    def send_score_reward_mail(self, club_id, score):
        if is_npc(club_id):
            return

        config = ConfigChampionScoreReward.get(score)
        if not config:
            return

        rc = ResourceClassification.classify(config.reward)
        attachment = rc.to_json()

        m = MailManager(self.server_id, int(club_id))
        m.add(config.mail_title, config.mail_content, attachment=attachment)
Exemple #9
0
    def send_rank_reward_mail(self, level):
        config = ConfigChampionRankReward.get(level)

        member_ids = self.doc['levels'][str(level)]['member_ids']

        rc = ResourceClassification.classify(config.reward)
        attachment = rc.to_json()

        for m in member_ids:
            if is_npc(m):
                continue

            m = MailManager(self.server_id, int(m))
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
Exemple #10
0
    def send_rank_reward(cls, server_id):
        char_ids = Club.get_recent_login_char_ids(server_id)

        # 加上一分钟,确保已经到了第二天
        # 定时任务要是 23:59:59 启动,那天数判断就错了
        weekday = arrow.utcnow().to(
            settings.TIME_ZONE).replace(minutes=1).weekday()

        for cid in char_ids:
            arena = Arena(server_id, cid)
            rank = arena.get_current_rank()

            # 每日奖励
            config = ConfigArenaRankReward.get(rank)
            rc = ResourceClassification.classify(config.reward)

            m = MailManager(server_id, cid)
            m.add(
                config.mail_title,
                config.mail_content,
                attachment=rc.to_json(),
            )

            if weekday == 0:
                # 周一发周奖励
                config_weekly = ConfigArenaRankRewardWeekly.get(rank)
                rc = ResourceClassification.classify(config_weekly.reward)

                m = MailManager(server_id, cid)
                m.add(config_weekly.mail_title,
                      config_weekly.mail_content,
                      attachment=rc.to_json())

        if weekday == 0:
            docs = MongoArena.db(server_id).find({'_id': {
                '$regex': '^\d+$'
            }}, {'_id': 1})

            default_score_doc = MongoArenaScore.db(server_id).find_one(
                {'_id': ARENA_DEFAULT_SCORE})
            for doc in docs:
                if doc['_id'] in default_score_doc['char_ids']:
                    continue

                ArenaScore(server_id,
                           int(doc['_id'])).set_score(ARENA_DEFAULT_SCORE)
Exemple #11
0
    def send_rank_reward(cls, server_id):
        char_ids = Club.get_recent_login_char_ids(server_id)

        # 加上一分钟,确保已经到了第二天
        # 定时任务要是 23:59:59 启动,那天数判断就错了
        weekday = arrow.utcnow().to(settings.TIME_ZONE).replace(minutes=1).weekday()

        for cid in char_ids:
            arena = Arena(server_id, cid)
            rank = arena.get_current_rank()

            # 每日奖励
            config = ConfigArenaRankReward.get(rank)
            rc = ResourceClassification.classify(config.reward)

            m = MailManager(server_id, cid)
            m.add(
                config.mail_title,
                config.mail_content,
                attachment=rc.to_json(),
            )

            if weekday == 0:
                # 周一发周奖励
                config_weekly = ConfigArenaRankRewardWeekly.get(rank)
                rc = ResourceClassification.classify(config_weekly.reward)

                m = MailManager(server_id, cid)
                m.add(
                    config_weekly.mail_title,
                    config_weekly.mail_content,
                    attachment=rc.to_json()
                )

        if weekday == 0:
            docs = MongoArena.db(server_id).find(
                {'_id': {'$regex': '^\d+$'}},
                {'_id': 1}
            )

            default_score_doc = MongoArenaScore.db(server_id).find_one({'_id': ARENA_DEFAULT_SCORE})
            for doc in docs:
                if doc['_id'] in default_score_doc['char_ids']:
                    continue

                ArenaScore(server_id, int(doc['_id'])).set_score(ARENA_DEFAULT_SCORE)
Exemple #12
0
def cronjob_of_union_explore(server_id):
    members, _ = get_members_ordered_by_explore_point(server_id, 0, names=False)
    unions, _ = get_unions_ordered_by_explore_point(server_id, 0)

    MongoUnionMember.db(server_id).update_many(
        {},
        {'$set': {
            'explore_point': 0,
        }}
    )

    MongoUnion.db(server_id).update_many(
        {},
        {'$set': {
            'explore_point': 0,
        }}
    )

    for m in members:
        reward = ConfigUnionMemberExploreRankReward.get_by_rank(m.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        m = MailManager(server_id, m.id)
        m.add(reward.mail_title, reward.mail_content, attachment=attachment)

    for u in unions:
        reward = ConfigUnionExploreRankReward.get_by_rank(u.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        docs = MongoUnionMember.db(server_id).find(
            {'joined': u.id},
            {'_id': 1}
        )

        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(reward.mail_title, reward.mail_content, attachment=attachment)
Exemple #13
0
    def send_bet_reward_mail(self, level, win_ids):
        # 找到所有bet的玩家,然后遍历
        docs = MongoChampionship.db(self.server_id).find({'has_bet': True})
        for doc in docs:
            bet_info = doc['bet'].get(str(level), {})
            if not bet_info:
                continue

            config = ConfigChampionBet.get(bet_info['bet_id'])
            if bet_info['club_id'] in win_ids:
                m_title = config.win_mail_title
                m_content = config.win_mail_content
                m_reward = config.win_reward
            else:
                m_title = config.lose_mail_title
                m_content = config.lose_mail_content
                m_reward = config.lose_reward

            rc = ResourceClassification.classify(m_reward)
            attachment = rc.to_json()
            m = MailManager(self.server_id, doc['_id'])
            m.add(m_title, m_content, attachment=attachment)
Exemple #14
0
def cronjob_of_union_explore(server_id):
    members, _ = get_members_ordered_by_explore_point(server_id,
                                                      0,
                                                      names=False)
    unions, _ = get_unions_ordered_by_explore_point(server_id, 0)

    MongoUnionMember.db(server_id).update_many(
        {}, {'$set': {
            'explore_point': 0,
        }})

    MongoUnion.db(server_id).update_many({}, {'$set': {
        'explore_point': 0,
    }})

    for m in members:
        reward = ConfigUnionMemberExploreRankReward.get_by_rank(m.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        m = MailManager(server_id, m.id)
        m.add(reward.mail_title, reward.mail_content, attachment=attachment)

    for u in unions:
        reward = ConfigUnionExploreRankReward.get_by_rank(u.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        docs = MongoUnionMember.db(server_id).find({'joined': u.id},
                                                   {'_id': 1})

        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(reward.mail_title,
                  reward.mail_content,
                  attachment=attachment)
Exemple #15
0
    def send_yueka_reward(cls, server_id):
        config = ConfigPurchaseYueka.get(YUEKA_ID)

        condition = {
            '$and': [{
                'yueka_remained_days': {
                    '$gt': 0
                }
            }, {
                'yueka_new': False
            }]
        }

        docs = MongoPurchase.db(server_id).find(condition)
        MongoPurchase.db(server_id).update_many(
            condition, {'$inc': {
                'yueka_remained_days': -1
            }})

        # 把今天新购买的,设置为False,以便后面的定时任务好发送月卡
        MongoPurchase.db(server_id).update_many({'yueka_new': True},
                                                {'$set': {
                                                    'yueka_new': False
                                                }})

        rc = ResourceClassification.classify(config.rewards)
        attachment = rc.to_json()

        amount = 0
        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
            amount += 1

        return amount
Exemple #16
0
    def send_reward(self, goods_id):
        if goods_id == YUEKA_ID:
            # 月卡买了就立即发送
            # 后面的再定时发送
            config = ConfigPurchaseYueka.get(YUEKA_ID)
            got = 0
            actual_got = 0

            MongoPurchase.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'yueka_remained_days': 29,
                    'yueka_new': True
                }})

            self.doc['yueka_remained_days'] = 29
            self.doc['yueka_new'] = True

            rc = ResourceClassification.classify(config.rewards)
            attachment = rc.to_json()

            m = MailManager(self.server_id, self.char_id)
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
        else:
            config = ConfigPurchaseGoods.get(goods_id)

            got = config.diamond
            actual_got = config.diamond + config.diamond_extra
            if self.get_purchase_times() == 0:
                # 首充
                actual_got = config.diamond * 2 + config.diamond_extra

        doc = MongoPurchaseLog.document()
        doc['_id'] = make_string_id()
        doc['char_id'] = self.char_id
        doc['goods_id'] = goods_id
        doc['got'] = got
        doc['actual_got'] = actual_got
        doc['timestamp'] = arrow.utcnow().timestamp
        MongoPurchaseLog.db(self.server_id).insert_one(doc)

        reward = [(VIP_EXP_ITEM_ID, config.vip_exp),
                  (money_text_to_item_id('diamond'), actual_got)]

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id,
               self.char_id,
               message="Purchase.send_reward:{0}".format(goods_id))

        purchase_done_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            goods_id=goods_id,
            got=got,
            actual_got=actual_got,
        )

        self.send_notify()