Пример #1
0
def members_train(context):
    """获取社团成员数据
    """
    ki_user = context.user

    uid = context.get_parameter("uid")

    group_id = ki_user.group.group_id
    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id, uid)
    # 检测目标是否在公会
    if not member_data:
        context.result['mc'] = MsgCode['GroupMemberNotExist']
        return

    user = User.get(uid)
    if not isinstance(user, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        data = {}
        data["state"] = user.group.train_list
        ids = [i for i in user.group.train_list if i not in [0,-1]]
        heros = {}
        group_data = GroupService.find(ki_user.sid, group_id)
        for hid in ids:
            heros[hid] = count_group_train_hero(hid, user, group_data["level"])

        data["heros"] = heros

        context.result["data"] = data
Пример #2
0
def members_train(context):
    """获取社团成员数据
    """
    ki_user = context.user

    uid = context.get_parameter("uid")

    group_id = ki_user.group.group_id
    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id,
                                                      uid)
    # 检测目标是否在公会
    if not member_data:
        context.result['mc'] = MsgCode['GroupMemberNotExist']
        return

    user = User.get(uid)
    if not isinstance(user, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        data = {}
        data["state"] = user.group.train_list
        ids = [i for i in user.group.train_list if i not in [0, -1]]
        heros = {}
        group_data = GroupService.find(ki_user.sid, group_id)
        for hid in ids:
            heros[hid] = count_group_train_hero(hid, user, group_data["level"])

        data["heros"] = heros

        context.result["data"] = data
Пример #3
0
def group_train_info(context):
    """获取社团训练所面板数据
        1.当前已使用加速次数
        2.被动加速次数
        3.被加速日志
        4.成员列表
    """
    ki_user = context.user

    group_id = ki_user.group.group_id

    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    data = {}
    data["times"] = ki_user.daily_info.group_train_express_times
    data["times1"] = GroupService.get_train_pos_times(ki_user.sid, group_id,
                                                      ki_user.uid)
    data["logs"] = GroupService.get_train_logs(ki_user.sid, group_id,
                                               ki_user.uid)
    data["members"] = GroupService.train_members(ki_user.sid, group_id,
                                                 ki_user.uid)

    context.result["data"] = data
Пример #4
0
def _build_group_data_s2c(data, sid):
    """未上榜的公会只传基础数据
    """
    temp = {}
    temp["name"] = data["name"]
    temp["master"] = GroupService.get_master_name_by_uid(data["master"])
    temp["icon"] = data["icon"]
    temp["level"] = data["level"]
    temp["rank"] = 0
    temp["fight"] = sum([member["fight"] for member in GroupService.members(sid, int(data["id"])) if isinstance(member, dict)])

    return temp
Пример #5
0
def help(context):
    """帮助其它社员加速
    """
    ki_user = context.user

    uid = context.get_parameter("uid")
    hero_id = context.get_parameter("hero_id")

    if not judge_open_train(ki_user.sid, ki_user.group.group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    # 不能给自己加速啊!!!
    if ki_user.uid == uid:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if ki_user.daily_info.group_train_express_times >= GROUP_TRAIN_HELP_TIMES:
        context.result['mc'] = MsgCode['GroupTrainTimesMax']
        return

    group_id = ki_user.group.group_id
    member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id,
                                                      uid)
    # 检测目标是否在公会
    if not member_data:
        context.result['mc'] = MsgCode['GroupMemberNotExist']
        return

    user = User.get(uid)
    if not isinstance(user, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        helped_times = int(
            GroupService.get_train_pos_times(ki_user.sid, group_id, uid))
        if helped_times >= GROUP_TRAIN_HELP_TIMES1:
            context.result['mc'] = MsgCode['GroupTrainHisTimesMax']
            return

        if hero_id not in user.group.train_list:
            context.result['mc'] = MsgCode['GroupTrainHeroNotOn']
            return

        GroupService.update_train_express_times(ki_user.sid, group_id, uid,
                                                hero_id, ki_user.name)

        user_logic.add_game_values(ki_user, {1: GROUP_TRAIN_HELP_GOLD})

        ki_user.daily_info.group_train_express_times += 1
        ki_user.daily_info.put()

    context.result['mc'] = MsgCode['GroupTrainHelpOtherSucc']
Пример #6
0
def help(context):
    """帮助其它社员加速
    """
    ki_user = context.user

    uid = context.get_parameter("uid")
    hero_id = context.get_parameter("hero_id")

    if not judge_open_train(ki_user.sid, ki_user.group.group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    # 不能给自己加速啊!!!
    if ki_user.uid == uid:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if ki_user.daily_info.group_train_express_times >= GROUP_TRAIN_HELP_TIMES:
        context.result['mc'] = MsgCode['GroupTrainTimesMax']
        return

    group_id = ki_user.group.group_id
    member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id, uid)
    # 检测目标是否在公会
    if not member_data:
        context.result['mc'] = MsgCode['GroupMemberNotExist']
        return

    user = User.get(uid)
    if not isinstance(user, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        helped_times = int(GroupService.get_train_pos_times(ki_user.sid, group_id, uid))
        if helped_times >= GROUP_TRAIN_HELP_TIMES1:
            context.result['mc'] = MsgCode['GroupTrainHisTimesMax']
            return

        if hero_id not in user.group.train_list:
            context.result['mc'] = MsgCode['GroupTrainHeroNotOn']
            return

        GroupService.update_train_express_times(ki_user.sid, group_id, uid, hero_id, ki_user.name)

        user_logic.add_game_values(ki_user, {1: GROUP_TRAIN_HELP_GOLD})

        ki_user.daily_info.group_train_express_times += 1
        ki_user.daily_info.put()

    context.result['mc'] = MsgCode['GroupTrainHelpOtherSucc']
Пример #7
0
def count_group_train_hero(hero_id, user, group_level):
    """计算训练所姬甲当前经验
    """
    hero = user.hero.heros[hero_id]
    tmp_exp = hero["exp"]
    max_exp = game_config.hero_level_exp_cfg.get(hero["level"] + 1, None)
    if not max_exp:
        return tmp_exp

    # 经验已经最大,更新时间改为当前
    if hero["level"] >= user.game_info.role_level and tmp_exp >= max_exp:
        return tmp_exp
    else:
        now = int(time.time())
        gcfg = game_config.group_cfg.get(group_level, {})
        if not gcfg:
            return tmp_exp

        interval_minutes = int(now - user.group.train_dict[hero_id]) / 60
        # 读取别人帮我加速的次数
        express_times = GroupService.get_train_hero_times(
            user.sid, user.group.group_id, user.uid, hero_id)
        add_exp = (interval_minutes +
                   int(express_times) * 30) * gcfg["train_exp"]

        if tmp_exp + add_exp > max_exp:
            tmp_exp = max_exp
        else:
            tmp_exp += add_exp

        return tmp_exp
Пример #8
0
def fighter_data(context):
    """获取对手的竞技场数据

    Args:
        fighter_id  # 对手的uid

    """
    fighter_id = context.get_parameter("fighter_id")

    if fighter_id.startswith("robot_"):
        context.result['mc'] = MsgCode['UserNotExist']
        return

    player = User.get(fighter_id)
    if not isinstance(player, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        fighter = {}
        fighter['level'] = player.game_info.role_level
        fighter['array'] = user_helper.build_arena_hero_euqip_skill(player)
        fighter['talents'] = player.talent.talents
        fighter['warship'] = user_helper.build_warship_data(
            player.warship.ships, player.warship.team)
        fighter['group_name'] = GroupService.get_name_by_id(
            player.sid, player.group.group_id)

        context.result["data"] = fighter
Пример #9
0
def get_user_info(context):
    """获取其他玩家的基本数据

    Args:
        uid = "110000001"

    Returns:
        user_data
    """
    uid = context.get_parameter("uid")

    from apps.models.user import User
    user = User.get(uid)
    if not isinstance(user, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        user_data = {}
        user_data['name'] = user.name
        user_data['level'] = user.game_info.role_level
        user_data['avatar'] = user.avatar
        user_data['vip'] = user.game_info.vip_level
        user_data['group_name'] = GroupService.get_name_by_id(
            user.sid, user.group.group_id)
        user_data['heros'] = user_helper.build_array_hero_data(
            user.array.mission, user.hero.heros)

        context.result["data"] = {}
        context.result["data"]["user_data"] = user_data
Пример #10
0
def fighter_data(context):
    """获取对手的竞技场数据

    Args:
        fighter_id  # 对手的uid

    """
    fighter_id = context.get_parameter("fighter_id")

    if fighter_id.startswith("robot_"):
        context.result['mc'] = MsgCode['UserNotExist']
        return

    player = User.get(fighter_id)
    if not isinstance(player, User):
        context.result['mc'] = MsgCode['UserNotExist']
        return
    else:
        fighter = {}
        fighter['level'] = player.game_info.role_level
        fighter['array'] = user_helper.build_arena_hero_euqip_skill(player)
        fighter['talents'] = player.talent.talents
        fighter['warship'] = user_helper.build_warship_data(player.warship.ships, player.warship.team)
        fighter['group_name'] = GroupService.get_name_by_id(player.sid, player.group.group_id)

        context.result["data"] = fighter
Пример #11
0
def count_group_train_hero(hero_id, user, group_level):
    """计算训练所姬甲当前经验
    """
    hero = user.hero.heros[hero_id]
    tmp_exp = hero["exp"]
    max_exp = game_config.hero_level_exp_cfg.get(hero["level"]+1, None)
    if not max_exp:
        return tmp_exp

    # 经验已经最大,更新时间改为当前
    if hero["level"] >= user.game_info.role_level and tmp_exp >= max_exp:
        return tmp_exp
    else:
        now = int(time.time())
        gcfg = game_config.group_cfg.get(group_level, {})
        if not gcfg:
            return tmp_exp

        interval_minutes = int(now - user.group.train_dict[hero_id]) / 60
        # 读取别人帮我加速的次数
        express_times = GroupService.get_train_hero_times(user.sid, user.group.group_id, user.uid, hero_id)
        add_exp = (interval_minutes + int(express_times) * 30) * gcfg["train_exp"]

        if tmp_exp + add_exp > max_exp:
            tmp_exp = max_exp
        else:
            tmp_exp += add_exp

        return tmp_exp
Пример #12
0
def judge_open_train(sid, group_id):
    """判断训练所是否开启
    """
    group_data = GroupService.find(sid, group_id)
    if group_data:
        gcfg = game_config.group_cfg.get(group_data["level"], {})

        # return gcfg["open_train"] == 1
        return True
    else:
        return False
Пример #13
0
def judge_open_train(sid, group_id):
    """判断训练所是否开启
    """
    group_data = GroupService.find(sid, group_id)
    if group_data:
        gcfg = game_config.group_cfg.get(group_data["level"], {})

        # return gcfg["open_train"] == 1
        return True
    else:
        return False
Пример #14
0
def group_train_info(context):
    """获取社团训练所面板数据
        1.当前已使用加速次数
        2.被动加速次数
        3.被加速日志
        4.成员列表
    """
    ki_user = context.user

    group_id = ki_user.group.group_id

    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    data = {}
    data["times"] = ki_user.daily_info.group_train_express_times
    data["times1"] = GroupService.get_train_pos_times(ki_user.sid, group_id, ki_user.uid)
    data["logs"] = GroupService.get_train_logs(ki_user.sid, group_id, ki_user.uid)
    data["members"] = GroupService.train_members(ki_user.sid, group_id, ki_user.uid)

    context.result["data"] = data
Пример #15
0
    def settle_after_boss_fight(cls, sid):
        """9:20检查并结算boss数据
        """
        key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid
        if not redis_client.exists(key):
            cls.initial(sid)
        else:
            cls.award_today_rank_players(sid)       # 发今日伤害榜奖励

            old_data = cls.get(sid)
            # 英雄圣殿对应数据更新
            if old_data["uid"]:
                redis_client.zincrby(rediskey_config.WORLD_BOSS_HEROS_KEY % sid, old_data["uid"], 1)

            # boss被打死,版本增加,boss名称改变,清除总榜,今日榜-》昨日榜,boss血量更新
            if old_data["left_hp"] <= 0 or old_data["days"] >= WORLD_BOSS_CYCLE:
                total_rank_key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, old_data["version"]) # 获取这个boss总榜的第一名玩家
                uids = redis_client.zrange(total_rank_key,0,1)
                new_boss = {"name": pickle.dumps(""), "uid": "", "level": WORLD_BOSS_DEFAULT_LEVEL}
                if uids:
                    user = User.get(uids[0])
                    if isinstance(user, User):
                        group_name = GroupService.get_name_by_id(user.sid, user.group.group_id)
                        new_boss["name"], new_boss["uid"], new_boss["level"] = pickle.dumps("%s(%s)" % (user.name, group_name)), uids[0], user.game_info.role_level

                boss_new_hp = max(min(old_data["lose_hp"] * 1.15 * (1 + 0.2 * (3 - (old_data["days"] + 1))), WORLD_BOSS_HP_MAX), WORLD_BOSS_HP_MIN)
                main_data = {
                    "id": WORLD_BOSS_MONSTER_ID,
                    "type": WORLD_BOSS_TYPE_NPC if not old_data["version"] else WORLD_BOSS_TYPE_PLAYER,
                    "hp": int(boss_new_hp),
                    "days": 1,
                    "update": time.strftime('%Y%m%d%H'),
                    "version": old_data["version"] + 1,
                    "ender": "",
                    "lose_hp": 0,
                }

                main_data.update(new_boss)
                redis_client.hmset(key, main_data)          # 更新boss数据
                cls.award_total_rank_players(sid, old_data["version"])          # 发总榜奖励
                cls.award_boss_ender(sid, old_data["ender"])        # 发boss终结者
            else:
                redis_client.hincrby(key, "days", 1)

            # 生成旧榜单
            cls.build_yesterday_rank(sid)

            print "BOSS STATUS:"
            print cls.get(sid)
Пример #16
0
def handle_group_train_heros(train_heros, user, exp_every_minutes):
    """每个心跳中结算公会训练所的姬甲数据
    """
    now = int(time.time())
    train_hero_exps = {}
    for hero_id in train_heros:
        hero = user.hero.heros[hero_id]
        tmp_exp = hero["exp"]
        max_exp = game_config.hero_level_exp_cfg.get(hero["level"] + 1, None)
        if not max_exp:
            continue

        # 经验已经最大,更新时间改为当前
        if hero["level"] >= user.game_info.role_level and tmp_exp >= max_exp:
            user.group.train_dict[hero_id] = now
        else:
            interval_minutes = int(now - user.group.train_dict[hero_id]) / 60
            # 读取别人帮我加速的次数
            express_times = GroupService.get_train_hero_times(
                user.sid, user.group.group_id, user.uid, hero_id)
            add_exp = (interval_minutes +
                       int(express_times) * 30) * exp_every_minutes
            user.group.train_dict[hero_id] += interval_minutes * 60  # 更新时间

            if tmp_exp + add_exp > max_exp:
                tmp_exp = max_exp
                user.group.train_dict[hero_id] = now
            else:
                tmp_exp += add_exp

            after_level = common_helper.get_level_by_exp(
                game_config.hero_exp_level_cfg, tmp_exp)
            user.hero.update_exp_level(
                hero_id, tmp_exp, min(user.game_info.role_level, after_level),
                False)

        train_hero_exps[hero_id] = add_exp

    user.hero.put()
    user.group.put()

    return train_hero_exps
Пример #17
0
    def rank(cls, rtype, sid, start, end):
        """读取排行榜数据

        rtype:
            1 - 今日排名
            2 - 总排名
            3 - 英雄圣殿
            4 - 昨日榜单
        """
        if rtype == WORLD_BOSS_RANK_YES:
            cache_rank_name = rediskey_config.WORLD_BOSS_DMG_YES_RANK_KEY % sid
            return redis_client.lrange(cache_rank_name, start - 1, end - 1)

        if rtype == WORLD_BOSS_RANK_TODAY:
            key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        elif rtype == WORLD_BOSS_RANK_TOTAL:
            key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid
            version = redis_client.hget(key, "version")
            key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid,
                                                                   version)
        else:
            key = rediskey_config.WORLD_BOSS_HEROS_KEY % sid

        ranking_list = redis_client.zrevrange(key,
                                              start - 1,
                                              end - 1,
                                              withscores=True)
        ranks = []
        for index, i in enumerate(ranking_list):
            rank_data = {}
            rank_data['rank'] = start + index + 1
            rank_data['data'] = int(i[1])
            user = User.get(i[0])
            if isinstance(user, User):
                rank_data['name'] = user.name
                rank_data['level'] = user.game_info.role_level
                rank_data['group_name'] = GroupService.find(
                    user.sid, user.group.group_id)

            ranks.append(rank_data)

        return ranks
Пример #18
0
def info(context):
    """训练所信息
    """
    ki_user = context.user
    group_id = ki_user.group.group_id

    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    group_data = GroupService.find(ki_user.sid, group_id)
    gcfg = game_config.group_cfg.get(group_data["level"])
    ids = [i for i in ki_user.group.train_list if i not in [0,-1]]

    data = {}
    data["hero_add_exps"] = sys_logic.handle_group_train_heros(ids, ki_user, gcfg["train_exp"])
    data["state"] = ki_user.group.train_list
    data["info"] = ki_user.group.train_dict

    context.result["data"] = data
Пример #19
0
def info(context):
    """训练所信息
    """
    ki_user = context.user
    group_id = ki_user.group.group_id

    if not judge_open_train(ki_user.sid, group_id):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    group_data = GroupService.find(ki_user.sid, group_id)
    gcfg = game_config.group_cfg.get(group_data["level"])
    ids = [i for i in ki_user.group.train_list if i not in [0, -1]]

    data = {}
    data["hero_add_exps"] = sys_logic.handle_group_train_heros(
        ids, ki_user, gcfg["train_exp"])
    data["state"] = ki_user.group.train_list
    data["info"] = ki_user.group.train_dict

    context.result["data"] = data
Пример #20
0
def fetch_user_info(uid):
    """根据玩家uid获取基础信息

    使用场景:
    1. 聊天信息,私聊对象的名字

    Args:
        uid 玩家UID

    """
    user_data = {}
    from apps.models.user import User
    user = User.get(uid)
    if isinstance(user, User):
        user_data['name'] = user.name
        user_data['level'] = user.game_info.role_level
        user_data['avatar'] = user.avatar
        user_data['vip'] = user.game_info.vip_level
        user_data['group_name'] = GroupService.get_name_by_id(
            user.sid, user.group.group_id)

    return user_data
Пример #21
0
def get(context):
    """获取排行榜数据

    Args:
        rtype 排行榜类型
        start 排行榜起始位置
        end 排行榜结束位置

    Returns:
        my_rank 我的名次
        rank_datas 对应条件的排行榜数据
    """
    rtype = context.get_parameter("rtype")
    start = context.get_parameter("start")
    stop = context.get_parameter("stop")

    if rtype not in rank_service.RANK_KEY_MAPPING:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    ki_user = context.user
    if rtype == 3:
        my_rank = rank_service.rank(ki_user.sid, rtype, "%s_%s" % (ki_user.uid, ki_user.hero.get_max_fight_hero()))
    elif rtype == 2:
        my_rank = rank_service.rank(ki_user.sid, rtype, ki_user.group.group_id)
        if not my_rank and ki_user.group.group_id:
            group_data = GroupService.find(ki_user.sid, ki_user.group.group_id)
            my_rank = _build_group_data_s2c(group_data, ki_user.sid)
    else:
        my_rank = rank_service.rank(ki_user.sid, rtype, ki_user.uid)

    rank_datas = rank_service.top(ki_user.sid, rtype, start, stop)

    data = {}
    data["my_rank"] = my_rank
    data["rank_datas"] = rank_datas

    context.result["data"] = data
Пример #22
0
def handle_group_train_heros(train_heros, user, exp_every_minutes):
    """每个心跳中结算公会训练所的姬甲数据
    """
    now = int(time.time())
    train_hero_exps = {}
    for hero_id in train_heros:
        hero = user.hero.heros[hero_id]
        tmp_exp = hero["exp"]
        max_exp = game_config.hero_level_exp_cfg.get(hero["level"]+1, None)
        if not max_exp:
            continue

        # 经验已经最大,更新时间改为当前
        if hero["level"] >= user.game_info.role_level and tmp_exp >= max_exp:
            user.group.train_dict[hero_id] = now
        else:
            interval_minutes = int(now - user.group.train_dict[hero_id]) / 60
            # 读取别人帮我加速的次数
            express_times = GroupService.get_train_hero_times(user.sid, user.group.group_id, user.uid, hero_id)
            add_exp = (interval_minutes + int(express_times) * 30) * exp_every_minutes
            user.group.train_dict[hero_id] += interval_minutes * 60     # 更新时间

            if tmp_exp + add_exp > max_exp:
                tmp_exp = max_exp
                user.group.train_dict[hero_id] = now
            else:
                tmp_exp += add_exp

            after_level = common_helper.get_level_by_exp(game_config.hero_exp_level_cfg, tmp_exp)
            user.hero.update_exp_level(hero_id, tmp_exp, min(user.game_info.role_level, after_level), False)

        train_hero_exps[hero_id] = add_exp

    user.hero.put()
    user.group.put()

    return train_hero_exps
Пример #23
0
    def rank(cls, rtype, sid, start, end):
        """读取排行榜数据

        rtype:
            1 - 今日排名
            2 - 总排名
            3 - 英雄圣殿
            4 - 昨日榜单
        """
        if rtype == WORLD_BOSS_RANK_YES:
            cache_rank_name = rediskey_config.WORLD_BOSS_DMG_YES_RANK_KEY % sid
            return redis_client.lrange(cache_rank_name, start-1, end-1)

        if rtype == WORLD_BOSS_RANK_TODAY:
            key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        elif rtype == WORLD_BOSS_RANK_TOTAL:
            key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid
            version = redis_client.hget(key, "version")
            key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, version)
        else:
            key = rediskey_config.WORLD_BOSS_HEROS_KEY % sid

        ranking_list = redis_client.zrevrange(key, start-1, end-1, withscores=True)
        ranks = []
        for index,i in enumerate(ranking_list):
            rank_data = {}
            rank_data['rank'] = start + index + 1
            rank_data['data'] = int(i[1])
            user = User.get(i[0])
            if isinstance(user, User):
                rank_data['name'] = user.name
                rank_data['level'] = user.game_info.role_level
                rank_data['group_name'] = GroupService.find(user.sid, user.group.group_id)

            ranks.append(rank_data)

        return ranks
def _run_update_cached_group_rank(sid, tag):
    """更新公会排行榜

    抓取所有公会数据 - 按等级排 - 按总战力排 - 存放进cache里

    """
    ranking_name = rediskey_config.RANK_KEY_PREFIX % (sid, tag)
    ranking_list = redis_client.zrevrange(ranking_name, 0, -1, withscores=True)

    group_rank = []

    if ranking_list:
        for key, value in enumerate(ranking_list):
            rank_data = {}
            rank_data['rank'] = 0
            rank_data['group_id'] = int(value[0])
            rank_data['exp'] = int(value[1])

            group_data = GroupService.find(sid, value[0])
            if group_data:
                rank_data['name'] = group_data["name"]
                rank_data['icon'] = group_data["icon"]
                rank_data['level'] = group_data["level"]
                master = User.get(group_data["master"])
                rank_data['master'] = master.name if isinstance(master, User) else "会长"
                rank_data['member_number'] = group_data["member_number"]
                rank_data['join_level_limit'] = group_data["join_level_limit"]
                rank_data['join_state'] = group_data["join_state"]
                rank_data['notice'] = group_data["notice"]

                fight = 0
                for uid in [member["uid"] for member in GroupService.members(sid, int(value[0])) if isinstance(member, dict)]:
                    try:
                        user = User.get(uid)
                        fight += user.game_info.fight
                    except:
                        fight += 0

                rank_data['fight'] = fight

            group_rank.append(rank_data)

    def gsorted(x,y):
        if x["level"] == y["level"]:
           return y["fight"] - x["fight"]
        else:
           return y["level"] - x["level"]

    group_rank = sorted(group_rank, cmp=gsorted)

    a = 1
    for x in group_rank:
        x['rank'] = a
        a += 1
    # 放入排行缓存列表中
    group_rank.reverse()

    cache_rank_name = rediskey_config.RANK_CACHE_KEY_PREFIX % (sid, tag)
    while redis_client.llen(cache_rank_name) != 0:
        redis_client.delete(cache_rank_name)
        time.sleep(1)

    # 放入排行缓存列表中
    for rank in group_rank:
        redis_client.lpush(cache_rank_name, rank)

    print 'ranking_name:', cache_rank_name
    print 'ranking_list:', group_rank
    print '=' * 60
Пример #25
0
    def admin_query_player_info(cls, params):
        sid = params.get("sid")
        uid = params.get("uid", "")
        uname = params.get("uname", "")
        dtype = params.get("type", "user")

        from apps.models.user import User
        # uid为空 则根据uname查询玩家数据
        if uid:
            target_user = User.get(uid)
        elif uname:
            target_uid = name_service.get_uid_by_name(uname)
            target_user = User.get(target_uid)
        else:
            target_user = None

        if not target_user:
            return {"mc": 900007}

        data = {}
        if str(dtype) == "user":
            user_attrs = ["uid","name","update_name_times","avatar",
                           "user_sign","account_id","platform","sid",
                           "state","type","create_time","last_request",
                           "last_sign_time","total_login_days","login_history_dates",
                           "used_cdkey_tags", "game_info", "ext_info"]

        elif str(dtype) == "hero":
            user_attrs = ["hero", "equip", "skill", "spirit"]

        elif str(dtype) == "group":
            attr_obj = eval("target_user.group")
            data["group"] = {}
            for attr1 in attr_obj.all_def_attrs:
                if attr1 not in ["uid"]:
                    data["group"][attr1] = getattr(attr_obj, attr1)

            if not target_user.group.group_id:
                group = {}
            else:
                group = GroupService.find(target_user.sid, target_user.group.group_id)

            data["group_data"] = {}
            data["group_data"]["base"] = group

            data["uid"] = target_user.uid
            data["name"] = target_user.name

            data["mc"] = 900002
            data["info"] = pickle.dumps(data)

            return data

        else:
            user_attrs = [dtype]

        for attr in user_attrs:
            if type(eval("target_user.%s" % attr)) in [unicode, str, int, dict, list, set, tuple]:
                data[attr] = eval("target_user.%s" % attr)
            else:
                attr_obj = eval("target_user.%s" % attr)
                data[attr] = {}
                for attr1 in attr_obj.all_def_attrs:
                    if attr1 not in ["uid"]:
                        data[attr][attr1] = getattr(attr_obj, attr1)

            data["uid"] = target_user.uid
            data["name"] = target_user.name

        data["mc"] = 900002
        data["info"] = pickle.dumps(data)

        return data
def _fetch_group_name_by_id(sid, group_id):
    """
    """
    group_data = GroupService.find(sid, group_id)

    return group_data["name"] if group_data else ''
Пример #27
0
def _run_update_cached_group_rank(sid, tag):
    """更新公会排行榜

    抓取所有公会数据 - 按等级排 - 按总战力排 - 存放进cache里

    """
    ranking_name = rediskey_config.RANK_KEY_PREFIX % (sid, tag)
    ranking_list = redis_client.zrevrange(ranking_name, 0, -1, withscores=True)

    group_rank = []

    if ranking_list:
        for key, value in enumerate(ranking_list):
            rank_data = {}
            rank_data['rank'] = 0
            rank_data['group_id'] = int(value[0])
            rank_data['exp'] = int(value[1])

            group_data = GroupService.find(sid, value[0])
            if group_data:
                rank_data['name'] = group_data["name"]
                rank_data['icon'] = group_data["icon"]
                rank_data['level'] = group_data["level"]
                master = User.get(group_data["master"])
                rank_data['master'] = master.name if isinstance(master,
                                                                User) else "会长"
                rank_data['member_number'] = group_data["member_number"]
                rank_data['join_level_limit'] = group_data["join_level_limit"]
                rank_data['join_state'] = group_data["join_state"]
                rank_data['notice'] = group_data["notice"]

                fight = 0
                for uid in [
                        member["uid"]
                        for member in GroupService.members(sid, int(value[0]))
                        if isinstance(member, dict)
                ]:
                    try:
                        user = User.get(uid)
                        fight += user.game_info.fight
                    except:
                        fight += 0

                rank_data['fight'] = fight

            group_rank.append(rank_data)

    def gsorted(x, y):
        if x["level"] == y["level"]:
            return y["fight"] - x["fight"]
        else:
            return y["level"] - x["level"]

    group_rank = sorted(group_rank, cmp=gsorted)

    a = 1
    for x in group_rank:
        x['rank'] = a
        a += 1
    # 放入排行缓存列表中
    group_rank.reverse()

    cache_rank_name = rediskey_config.RANK_CACHE_KEY_PREFIX % (sid, tag)
    while redis_client.llen(cache_rank_name) != 0:
        redis_client.delete(cache_rank_name)
        time.sleep(1)

    # 放入排行缓存列表中
    for rank in group_rank:
        redis_client.lpush(cache_rank_name, rank)

    print 'ranking_name:', cache_rank_name
    print 'ranking_list:', group_rank
    print '=' * 60
Пример #28
0
def _fetch_group_name_by_id(sid, group_id):
    """
    """
    group_data = GroupService.find(sid, group_id)

    return group_data["name"] if group_data else ''
Пример #29
0
def fetch_user_data(ki_user):
    """
    """
    user_data = {}
    user_data["user"] = ki_user.get_user_game_info()
    user_data["package"] = ki_user.package.items
    user_data["array"] = ki_user.array.mission

    user_data["hero"] = {}
    user_data["hero"]["heros"] = user_helper.build_hero_euqip_skill(ki_user)  # 把技能和装备 装配到机甲上。
    user_data["hero"]["gold_cd"] = ki_user.hero.pick_info["gold_cd"]
    user_data["hero"]["diamond_pick_times"] = ki_user.hero.pick_info["diamond_pick_times"]
    user_data["hero"]["diamond_ten_times"] = ki_user.hero.pick_info["diamond_ten_times"]

    user_data["daily"] = {}
    user_data["daily"]["mission_info"] = ki_user.daily_info.mission_info
    user_data["daily"]["hero_pick_info"] = ki_user.daily_info.hero_pick_info
    user_data["daily"]["buy_energy_times"] = ki_user.daily_info.buy_energy_times
    user_data["daily"]["buy_gold_times"] = ki_user.daily_info.buy_gold_times
    user_data["daily"]["mall_pick_cd"] = ki_user.daily_info.mall_pick_cd
    user_data["daily"]["mall_refresh_times"] = ki_user.daily_info.mall_refresh_times
    user_data["daily"]["world_chat_times"] = ki_user.daily_info.world_chat_times
    user_data["daily"]["resign_tag"] = ki_user.daily_info.resign_tag
    user_data["daily"]["group_donate_times"] = ki_user.daily_info.group_info["donate_times"]
    user_data["daily"]["online_awards"] = ki_user.daily_info.online_awards
    user_data["daily"]["trial_proccess"] = ki_user.trial.daily_current_process  # 冗余数据,临时增加。
    user_data["daily"]["arena_fight_times"] = ki_user.arena.daily_challenge_times  # 冗余数据,临时增加。

    act_mission_times = dict.fromkeys(range(1,6), 0)
    for k,v in ki_user.daily_info.act_missions.items():
        act_mission_times[int(k)] = v["past_times"]
    user_data["daily"]["act_mission_times"] = act_mission_times

    user_data["mission"] = {}
    user_data["mission"]["chapters"] = ki_user.mission.chapters
    user_data["mission"]["missions"] = ki_user.mission.missions

    user_data["group"] = {}
    user_data["group"]["group_id"] = ki_user.group.group_id
    user_data["group"]["group_name"] = GroupService.get_name_by_id(ki_user.sid, ki_user.group.group_id)
    user_data["group"]["cd"] = ki_user.group.cd

    user_data["vip"] = {}
    user_data["vip"]["card_data"] = ki_user.vip.card_data
    user_data["vip"]["bought_gifts"] = ki_user.vip.bought_gifts

    user_data["extra"] = {}
    user_data["extra"]["update_name_times"] = ki_user.update_name_times

    #  ======================== update =======================
    user_data["arena"] = {}
    user_data["arena"]["challenge_times"] = ki_user.arena.daily_challenge_times
    user_data["arena"]["add_times"] = ki_user.arena.daily_add_times
    user_data["arena"]["last_fight"] = ki_user.arena.last_fight
    user_data["arena"]["refresh_times"] = ki_user.arena.daily_refresh_times
    user_data["arena"]["admire_list"] = ki_user.arena.daily_admire_list
    user_data["arena"]["awarded_index"] = ki_user.arena.awarded_index
    user_data["arena"]["daily_awarded_index"] = ki_user.arena.daily_awarded_index
    user_data["arena"]["daily_scores"] = ki_user.arena.daily_scores
    user_data["arena"]["max_rank"] = ki_user.arena.max_rank
    #  ======================== update =======================

    fetch_user_module_data(ki_user, user_data)

    return user_data
Пример #30
0
    def settle_after_boss_fight(cls, sid):
        """9:20检查并结算boss数据
        """
        key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid
        if not redis_client.exists(key):
            cls.initial(sid)
        else:
            cls.award_today_rank_players(sid)  # 发今日伤害榜奖励

            old_data = cls.get(sid)
            # 英雄圣殿对应数据更新
            if old_data["uid"]:
                redis_client.zincrby(
                    rediskey_config.WORLD_BOSS_HEROS_KEY % sid,
                    old_data["uid"], 1)

            # boss被打死,版本增加,boss名称改变,清除总榜,今日榜-》昨日榜,boss血量更新
            if old_data["left_hp"] <= 0 or old_data["days"] >= WORLD_BOSS_CYCLE:
                total_rank_key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (
                    sid, old_data["version"])  # 获取这个boss总榜的第一名玩家
                uids = redis_client.zrange(total_rank_key, 0, 1)
                new_boss = {
                    "name": pickle.dumps(""),
                    "uid": "",
                    "level": WORLD_BOSS_DEFAULT_LEVEL
                }
                if uids:
                    user = User.get(uids[0])
                    if isinstance(user, User):
                        group_name = GroupService.get_name_by_id(
                            user.sid, user.group.group_id)
                        new_boss["name"], new_boss["uid"], new_boss[
                            "level"] = pickle.dumps(
                                "%s(%s)" % (user.name, group_name)
                            ), uids[0], user.game_info.role_level

                boss_new_hp = max(
                    min(
                        old_data["lose_hp"] * 1.15 *
                        (1 + 0.2 * (3 - (old_data["days"] + 1))),
                        WORLD_BOSS_HP_MAX), WORLD_BOSS_HP_MIN)
                main_data = {
                    "id": WORLD_BOSS_MONSTER_ID,
                    "type": WORLD_BOSS_TYPE_NPC
                    if not old_data["version"] else WORLD_BOSS_TYPE_PLAYER,
                    "hp": int(boss_new_hp),
                    "days": 1,
                    "update": time.strftime('%Y%m%d%H'),
                    "version": old_data["version"] + 1,
                    "ender": "",
                    "lose_hp": 0,
                }

                main_data.update(new_boss)
                redis_client.hmset(key, main_data)  # 更新boss数据
                cls.award_total_rank_players(sid, old_data["version"])  # 发总榜奖励
                cls.award_boss_ender(sid, old_data["ender"])  # 发boss终结者
            else:
                redis_client.hincrby(key, "days", 1)

            # 生成旧榜单
            cls.build_yesterday_rank(sid)

            print "BOSS STATUS:"
            print cls.get(sid)