def award_today_rank_players(sid):
        """给今日伤害榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(game_config.boss_daily_award_cfg, index+1)
            if award_cfg:
                MailService.send_game(value[0], 3009, [index+1], award_cfg["awards"])
                print "[boss] award_today_rank_players: receiver: %s, dmg: %s, awards: %s" % (value[0], index+1, award_cfg["awards"])

        # 支持了今日第一名的玩家额外获得金币
        support_key = rediskey_config.WORLD_BOSS_SUPPORT_KEY % sid
        try:
            number_one = ranking_list[0][0]
        except:
            number_one = None

        if isinstance(number_one, str):
            supports = redis_client.hget(support_key, number_one)
            l = [] if not supports else pickle.loads(supports)
            for uid in l:
                MailService.send_game(uid, 3010, [number_one], WORLD_BOSS_SUPPORT_EXTRA_AWARD)
                print "[boss] award_today_support_awards: receiver: %s, number_one: %s, awards: %s" % (uid, number_one, WORLD_BOSS_SUPPORT_EXTRA_AWARD)
Exemple #2
0
def _act_add_awards_mail(sid, actid):
    """
    """
    receivers = rank_service.get_all_players(sid)
    for uid in receivers:
        user = User.get(uid)
        if not isinstance(user, User):
            print "uid: [ %s ] not exist." % uid
        else:
            if actid not in user.activity.acts:
                continue

            act_data = user.activity.acts[actid]
            index_list = game_config.act_sample_detail_cfg.get(actid)
            awards_indexes = [
                index for index in index_list
                if utils.bit_test(act_data["canget"], index)
            ]
            if not awards_indexes:
                print "[act:%s] act add mail awards: receiver: %s, count: %s, award_level: 0, awards: {}" % (
                    actid, uid, act_data["data"])
                continue

            award_index = max(awards_indexes)
            award_cfg = game_config.act_detail_cfg.get("%s-%s" %
                                                       (actid, award_index))
            MailService.send_game(uid, 3008, [act_data["data"]],
                                  award_cfg["awards"])

            print "[act:%s] act add mail awards: receiver: %s, count: %s, award_level: %s, awards: %s" % (
                actid, uid, act_data["data"], award_index, award_cfg["awards"])
Exemple #3
0
def fight_rank_send_mail_awards(sid, act_id):
    """到活动结束时间点发送排行奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_FIGHT])
    top = redis_client.zrevrange(rank_name, 0, max_cfg["cond_a"]-1, withscores=True)

    for index, player in enumerate(top):
        fight_rank = index + 1
        try:
            award_index = min([rank for rank in indexes if rank >= fight_rank])
        except:
            award_index = 0

        if not award_index:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
        # 排名前10 且 战力达到指定值才有奖励
        if player[1] >= cfg["cond_b"]:
            MailService.send_game(player[0], 1001, [fight_rank], cfg["awards"])
            print "[act:%s] fight_rank_send_mail_awards: receiver: %s, rank: %s, fight: %s, awards: %s" % (act_id, player[0], fight_rank, player[1], cfg["awards"])
Exemple #4
0
def fight_send_mail_awards(sid, act_id):
    """到活动结束时间点发送战力达标奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    min_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_FIGHT])
    max_score = 9999999
    targets = redis_client.zrangebyscore(rank_name, min_cfg["cond_a"], max_score, withscores=True)

    for index, player in enumerate(targets):
        try:
            def is_reached(level):
                cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, level), {})
                if not cfg:
                    return False
                else:
                    return player[1] >= cfg["cond_a"]

            fight_level = min(filter(is_reached, indexes))
        except:
            fight_level = 0

        if not fight_level:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, fight_level))
        MailService.send_game(player[0], 1002, [player[1]], cfg["awards"])
        print "[act:%s] fight_send_mail_awards: receiver: %s, fight_level: %s, fight: %s, awards: %s" % (act_id, player[0], fight_level, player[1], cfg["awards"])
Exemple #5
0
    def award_today_rank_players(sid):
        """给今日伤害榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(
                game_config.boss_daily_award_cfg, index + 1)
            if award_cfg:
                MailService.send_game(value[0], 3009, [index + 1],
                                      award_cfg["awards"])
                print "[boss] award_today_rank_players: receiver: %s, dmg: %s, awards: %s" % (
                    value[0], index + 1, award_cfg["awards"])

        # 支持了今日第一名的玩家额外获得金币
        support_key = rediskey_config.WORLD_BOSS_SUPPORT_KEY % sid
        try:
            number_one = ranking_list[0][0]
        except:
            number_one = None

        if isinstance(number_one, str):
            supports = redis_client.hget(support_key, number_one)
            l = [] if not supports else pickle.loads(supports)
            for uid in l:
                MailService.send_game(uid, 3010, [number_one],
                                      WORLD_BOSS_SUPPORT_EXTRA_AWARD)
                print "[boss] award_today_support_awards: receiver: %s, number_one: %s, awards: %s" % (
                    uid, number_one, WORLD_BOSS_SUPPORT_EXTRA_AWARD)
Exemple #6
0
def divorce(context):
    """与机甲解除誓言

    Args:
        hero_id 姬甲ID
    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_id")
    hero = ki_user.hero.get_by_hero_id(hero_id)
    if not hero:
        context.result['mc'] = MsgCode['HeroNotExist']
        return

    # 是否已经许誓
    if not hero["marry_id"]:
        context.result['mc'] = MsgCode['HeroFavorNoMarried']
        return

    marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"])
    if not user_logic.check_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"]):
        context.result['mc'] = MsgCode['DiamondNotEnough']
        return

    user_logic.consume_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"])
    # 解除契约,戒指通过邮箱返还玩家
    from apps.services.mail import MailService
    marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"])
    MailService.send_game(ki_user.uid, 2000, [], marry_cfg["items"])

    ki_user.hero.divorce(hero_id) # 解除契约

    context.result['mc'] = MsgCode['HeroFavorDivorceSucc']
Exemple #7
0
def payback_diamonds(sid, plat, account_id, uid, login_days):
    """4.13 ios越狱删档测试 充值返现

        走邮件形式发送
    """
    if int(sid) not in (1, 2) or login_days > 60:
        return

    payback_amount = redis_client.hget(rediskey_config.ACT_PAYBACK_KEY % sid,
                                       "%s_%s" % (plat, account_id))
    if not payback_amount:
        return
    else:
        payback_amount = int(payback_amount)
        if 0 < login_days <= 7:
            get = int(math.ceil(payback_amount * 15.0 / 7))
            left = payback_amount * 50 - get * login_days
        else:
            get = int(math.ceil(payback_amount * 35.0 / 53))
            left = payback_amount * 35 - get * (login_days - 7)

        left = left if left >= 0 else 0

        # 第一次返还的时候 所有的vip经验都返还
        awards = {static_const.DIAMOND: get}
        if login_days == 1:
            awards = {
                static_const.DIAMOND: get,
                static_const.VIP_EXP: payback_amount * 10
            }

        MailService.send_game(uid, 3006, [get, left, 60 - login_days], awards)
Exemple #8
0
def fight_rank_send_mail_awards(sid, act_id):
    """到活动结束时间点发送排行奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_FIGHT])
    top = redis_client.zrevrange(rank_name,
                                 0,
                                 max_cfg["cond_a"] - 1,
                                 withscores=True)

    for index, player in enumerate(top):
        fight_rank = index + 1
        try:
            award_index = min([rank for rank in indexes if rank >= fight_rank])
        except:
            award_index = 0

        if not award_index:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
        # 排名前10 且 战力达到指定值才有奖励
        if player[1] >= cfg["cond_b"]:
            MailService.send_game(player[0], 1001, [fight_rank], cfg["awards"])
            print "[act:%s] fight_rank_send_mail_awards: receiver: %s, rank: %s, fight: %s, awards: %s" % (
                act_id, player[0], fight_rank, player[1], cfg["awards"])
Exemple #9
0
def payback_diamonds(sid, plat, account_id, uid, login_days):
    """4.13 ios越狱删档测试 充值返现

        走邮件形式发送
    """
    if int(sid) not in (1,2) or login_days > 60:
        return

    payback_amount = redis_client.hget(rediskey_config.ACT_PAYBACK_KEY % sid, "%s_%s" % (plat, account_id))
    if not payback_amount:
        return
    else:
        payback_amount = int(payback_amount)
        if 0 < login_days <= 7:
            get = int(math.ceil(payback_amount * 15.0 / 7))
            left = payback_amount * 50 - get * login_days
        else:
            get = int(math.ceil(payback_amount * 35.0 / 53))
            left = payback_amount * 35 - get * (login_days - 7)

        left = left if left >= 0 else 0

        # 第一次返还的时候 所有的vip经验都返还
        awards = {static_const.DIAMOND: get}
        if login_days == 1:
            awards = {static_const.DIAMOND: get, static_const.VIP_EXP: payback_amount * 10}

        MailService.send_game(uid, 3006, [get, left, 60 - login_days], awards)
Exemple #10
0
    def award_boss_ender(sid, uid):
        """给该版本BOSS最后一击的玩家发奖
        """
        if not uid:
            return

        award_cfg = common_helper.get_award_by_data(game_config.boss_total_award_cfg, 1)
        MailService.send_game(uid, 3011, [], award_cfg["awards"])
        print "[boss] award_boss_ender: receiver: %s, awards: %s" % (uid, award_cfg["awards"])
Exemple #11
0
    def award_boss_ender(sid, uid):
        """给该版本BOSS最后一击的玩家发奖
        """
        if not uid:
            return

        award_cfg = common_helper.get_award_by_data(
            game_config.boss_total_award_cfg, 1)
        MailService.send_game(uid, 3011, [], award_cfg["awards"])
        print "[boss] award_boss_ender: receiver: %s, awards: %s" % (
            uid, award_cfg["awards"])
Exemple #12
0
    def install_default_datas(self):
        """默认获得姬甲,排布阵容等
        """
        from apps.logics import hero as hero_logic
        hero_logic.add_heros(self, [{100050: 1}])
        self.array.update(1, [0, 100050, 0, 0, 0, 0])
        self.arena.init_when_install(self.sid)

        # 创建角色时,检测是否需要发[ 应用宝的预约礼包 | uc封测测试奖励 | 360封测测试奖励 ]
        if self.platform in ["YSDK", "UC", "QIHOO"]:
            account = Account.get_account("%s_%s" % (self.platform, self.account_id))
            if not isinstance(account, Account):
                return

            if self.platform == "YSDK" and redis_client.sismember(rediskey_config.YYB_ORDERED_SET % self.sid, account.open_id):
                order_awards_cfg = game_config.gift_key_config.get("YY02", {})
                if order_awards_cfg:
                    MailService.send_game(self.uid, 5003, [], order_awards_cfg["award"])

            if self.platform in ["UC", "QIHOO"]:
                # 1.最终等级达到x级 2.累计登陆x天 3.竞技场最终排名x
                awards,logins = pregift_service.uc_qihoo_test_award_4003(self.sid, self.platform, account.open_id)
                if awards:
                    MailService.send_game(self.uid, 5000, [logins], awards)

                awards1,days = pregift_service.uc_qihoo_test_award_4004(self.sid, self.platform, account.open_id)
                if awards1:
                    MailService.send_game(self.uid, 5001, [days], awards1)

                awards2,rank = pregift_service.uc_qihoo_test_award_4005(self.sid, self.platform, account.open_id)
                if awards2:
                    MailService.send_game(self.uid, 5002, [rank], awards2)
Exemple #13
0
    def award_total_rank_players(sid, version):
        """给击杀该版本BOSS伤害总榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid,version)
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(game_config.boss_total_award_cfg, index+1)
            if award_cfg:
                awards = copy.deepcopy(award_cfg["awards"])
                for k,v in awards.items():
                    awards[k] = v * 2

                MailService.send_game(value[0], 3010, [index+1], awards)

                print "[boss] award_total_rank_players: receiver: %s, dmg: %s, awards: %s" % (value[0], index+1, awards)
Exemple #14
0
    def award_total_rank_players(sid, version):
        """给击杀该版本BOSS伤害总榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, version)
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(
                game_config.boss_total_award_cfg, index + 1)
            if award_cfg:
                awards = copy.deepcopy(award_cfg["awards"])
                for k, v in awards.items():
                    awards[k] = v * 2

                MailService.send_game(value[0], 3010, [index + 1], awards)

                print "[boss] award_total_rank_players: receiver: %s, dmg: %s, awards: %s" % (
                    value[0], index + 1, awards)
Exemple #15
0
    def crontab_act_send_award_mail(sid, act_id):
        """每日晚上九点,运维活动中有给玩家发送奖励的活动
        """
        # 检查活动是否还在有效时间内
        from apps.services import act as act_service
        act_info = act_service.get_act_info(sid, act_id)

        now = int(time.time())

        if not act_info:
            return

        # 计算是否在有效范围内
        if now >= act_info["end"] or now < act_info["start"]:
            return

        indexes = game_config.act_sample_detail_cfg.get(act_id, [])
        max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

        # 最低名次,即取N多名竞技场玩家
        key = rediskey_config.RANK_KEY_PREFIX % (sid, "arena")
        top = redis_client.zrangebyscore(key, 0, max_cfg["cond_a"])

        for index, fighter in enumerate(top):
            # 机器人不发奖励
            if fighter.startswith("robot_"):
                continue

            fighter_rank = index + 1
            try:
                award_index = min([rank for rank in indexes if game_config.act_detail_cfg.get("%s-%s" % (act_id, rank))["cond_a"] >= fighter_rank])
            except:
                award_index = 0

            if not award_index:
                continue

            cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
            MailService.send_game(fighter, 3000, [fighter_rank], cfg["awards"])

            print "[act:%s] crontab_send_award_mail: receiver: %s, rank: %s, awards: %s" % (act_id, fighter, fighter_rank, cfg["awards"])
Exemple #16
0
def fight_send_mail_awards(sid, act_id):
    """到活动结束时间点发送战力达标奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    min_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_FIGHT])
    max_score = 9999999
    targets = redis_client.zrangebyscore(rank_name,
                                         min_cfg["cond_a"],
                                         max_score,
                                         withscores=True)

    for index, player in enumerate(targets):
        try:

            def is_reached(level):
                cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, level),
                                                     {})
                if not cfg:
                    return False
                else:
                    return player[1] >= cfg["cond_a"]

            fight_level = min(filter(is_reached, indexes))
        except:
            fight_level = 0

        if not fight_level:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, fight_level))
        MailService.send_game(player[0], 1002, [player[1]], cfg["awards"])
        print "[act:%s] fight_send_mail_awards: receiver: %s, fight_level: %s, fight: %s, awards: %s" % (
            act_id, player[0], fight_level, player[1], cfg["awards"])
Exemple #17
0
    def crontab_send_award_mail(sid):
        """每日晚九点,结算竞技场排行榜,发奖励
        """
        key = rediskey_config.RANK_KEY_PREFIX % (sid, "arena")
        top = redis_client.zrangebyscore(key, 0, ARENA_ROBOTS_NUM)

        for index, fighter in enumerate(top):
            # 机器人不发奖励
            if fighter.startswith("robot_"):
                continue

            fighter_rank = index + 1
            try:
                award_index = min([rank for rank in game_config.arena_mail_award_cfg if rank >= fighter_rank])
            except:
                award_index = 0

            if not award_index:
                continue

            cfg = game_config.arena_mail_award_cfg.get(award_index)
            MailService.send_game(fighter, 1000, [fighter_rank], cfg["awards"])

            print "crontab_send_award_mail: receiver: %s, rank: %s, awards: %s" % (fighter, fighter_rank, cfg["awards"])
Exemple #18
0
    def install_default_datas(self):
        """默认获得姬甲,排布阵容等
        """
        from apps.logics import hero as hero_logic
        hero_logic.add_heros(self, [{100050: 1}])
        self.array.update(1, [0, 100050, 0, 0, 0, 0])
        self.arena.init_when_install(self.sid)

        # 创建角色时,检测是否需要发[ 应用宝的预约礼包 | uc封测测试奖励 | 360封测测试奖励 ]
        if self.platform in ["YSDK", "UC", "QIHOO"]:
            account = Account.get_account("%s_%s" %
                                          (self.platform, self.account_id))
            if not isinstance(account, Account):
                return

            if self.platform == "YSDK" and redis_client.sismember(
                    rediskey_config.YYB_ORDERED_SET % self.sid,
                    account.open_id):
                order_awards_cfg = game_config.gift_key_config.get("YY02", {})
                if order_awards_cfg:
                    MailService.send_game(self.uid, 5003, [],
                                          order_awards_cfg["award"])

            if self.platform in ["UC", "QIHOO"]:
                # 1.最终等级达到x级 2.累计登陆x天 3.竞技场最终排名x
                awards, logins = pregift_service.uc_qihoo_test_award_4003(
                    self.sid, self.platform, account.open_id)
                if awards:
                    MailService.send_game(self.uid, 5000, [logins], awards)

                awards1, days = pregift_service.uc_qihoo_test_award_4004(
                    self.sid, self.platform, account.open_id)
                if awards1:
                    MailService.send_game(self.uid, 5001, [days], awards1)

                awards2, rank = pregift_service.uc_qihoo_test_award_4005(
                    self.sid, self.platform, account.open_id)
                if awards2:
                    MailService.send_game(self.uid, 5002, [rank], awards2)
Exemple #19
0
def trial_rank_send_mail_awards(sid):
    """每日凌晨五点结算终极试炼排行榜,给玩家发送排行奖励
    """
    all_players = get_all_players(sid)

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_TRIAL])
    ranking_list = redis_client.zrevrange(rank_name, 0, -1, withscores=True)

    if not ranking_list:
        return

    user_ranking = []
    from apps.models.user import User
    for key, value in enumerate(ranking_list):
        rank_data = {'uid': value[0], 'score': int(value[1])}
        user = User.get(rank_data['uid'])
        if user:
            rank_data['score1'] = user.trial.daily_scores
        else:
            rank_data['score1'] = 0

        user_ranking.append(rank_data)

    def tsorted(x, y):
        if x["score"] == y["score"]:
            return y["score1"] - x["score1"]
        else:
            return y["score"] - x["score"]

    user_ranking = sorted(user_ranking, cmp=tsorted)

    a = 1
    for x in user_ranking:
        x['rank'] = a
        a += 1

    user_ranking1 = {}
    for i in user_ranking:
        user_ranking1[str(i['uid'])] = i['rank']

    for uid in all_players:
        user = User.get(uid)
        if not user or user.game_info.role_level <= game_config.user_func_cfg.get(
                4020, 999):
            continue

        player_rank = user_ranking1.get(uid, 0)
        if player_rank < 0:
            continue

        try:
            award_index = min([
                rank for rank in game_config.trial_mail_award_cfg
                if rank >= player_rank
            ])
        except:
            award_index = -1

        if award_index < 0:
            continue

        cfg = game_config.trial_mail_award_cfg.get(award_index)
        MailService.send_game(uid, 1003, [player_rank], cfg["awards"])

        print "trial_rank_awards: receiver: %s, rank: %s, awards: %s" % (
            uid, player_rank, cfg["awards"])

    trial_delete_daily_rank(sid)
Exemple #20
0
def trial_rank_send_mail_awards(sid):
    """每日凌晨五点结算终极试炼排行榜,给玩家发送排行奖励
    """
    all_players = get_all_players(sid)

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_TRIAL])
    ranking_list = redis_client.zrevrange(rank_name, 0, -1, withscores=True)

    if not ranking_list:
        return

    user_ranking = []
    from apps.models.user import User
    for key, value in enumerate(ranking_list):
        rank_data = {'uid': value[0], 'score': int(value[1])}
        user = User.get(rank_data['uid'])
        if user:
            rank_data['score1'] = user.trial.daily_scores
        else:
            rank_data['score1'] = 0

        user_ranking.append(rank_data)

    def tsorted(x,y):
        if x["score"] == y["score"]:
           return y["score1"] - x["score1"]
        else:
           return y["score"] - x["score"]

    user_ranking = sorted(user_ranking, cmp=tsorted)

    a = 1
    for x in user_ranking:
        x['rank'] = a
        a += 1

    user_ranking1 = {}
    for i in user_ranking:
        user_ranking1[str(i['uid'])] = i['rank']

    for uid in all_players:
        user = User.get(uid)
        if not user or user.game_info.role_level <= game_config.user_func_cfg.get(4020, 999):
            continue

        player_rank = user_ranking1.get(uid, 0)
        if player_rank < 0:
            continue

        try:
            award_index = min([rank for rank in game_config.trial_mail_award_cfg if rank >= player_rank])
        except:
            award_index = -1

        if award_index < 0:
            continue

        cfg = game_config.trial_mail_award_cfg.get(award_index)
        MailService.send_game(uid, 1003, [player_rank], cfg["awards"])

        print "trial_rank_awards: receiver: %s, rank: %s, awards: %s" % (uid, player_rank, cfg["awards"])

    trial_delete_daily_rank(sid)