Exemple #1
0
def pk_top(request):
    ''' PK, 即实时 PvP (Real Time Peer-vs-Peer)
    '''
    data = []
#       data.append(tmp)

    top_model = pvp_redis.get_pvp_redis('1', top_name='real_pvp')
    top_30_uid_score = top_model.get(30, desc=False)
    top_30_uid_score.reverse()

    for uid, score in top_30_uid_score:
        pk_obj = UserRealPvp.get(uid)
        ub_obj = UserBase.get(uid)

        if pk_obj and ub_obj:
            user_prop_obj = UserProperty.get(uid)
            tmp = {}
            #base_info = pvp_obj.pvp_info['base_info']
            tmp['uid'] = uid
            tmp['pt'] = int(score)
            tmp['pvp_title'] = pk_obj.pvp_title
            tmp['username'] = ub_obj.username
            tmp['lv'] = user_prop_obj.lv
            data.append(tmp)

    return "admin/pk_top.html", {'data':data}
Exemple #2
0
def pk_top(request):
    ''' PK, 即实时 PvP (Real Time Peer-vs-Peer)
    '''
    data = []
    #       data.append(tmp)

    top_model = pvp_redis.get_pvp_redis('1', top_name='real_pvp')
    top_30_uid_score = top_model.get(30, desc=False)
    top_30_uid_score.reverse()

    for uid, score in top_30_uid_score:
        pk_obj = UserRealPvp.get(uid)
        ub_obj = UserBase.get(uid)

        if pk_obj and ub_obj:
            user_prop_obj = UserProperty.get(uid)
            tmp = {}
            #base_info = pvp_obj.pvp_info['base_info']
            tmp['uid'] = uid
            tmp['pt'] = int(score)
            tmp['pvp_title'] = pk_obj.pvp_title
            tmp['username'] = ub_obj.username
            tmp['lv'] = user_prop_obj.lv
            data.append(tmp)

    return "admin/pk_top.html", {'data': data}
 def pvp_rank(self):
     """返回自己pvp的排行,如果没有则添加最后一名到排行"""
     top_model = pvp_redis.get_pvp_redis(self.user_base.subarea, top_name='real_pvp')
     srank = top_model.rank(self.uid)
     # 不在排行榜内 返回 0
     if srank == None:
         return 0
     # top 的rank 第一名是 0
     return srank + 1
Exemple #4
0
def result_fight(win_uid, lose_uid):
    win_real_pvp_obj = UserRealPvp.get(win_uid)
    lose_real_pvp_obj = UserRealPvp.get(lose_uid)
    print "winner  {}, loser   {}".format(win_uid, lose_uid)
    top_model = pvp_redis.get_pvp_redis(win_real_pvp_obj.user_base.subarea,
                                        top_name='real_pvp')

    pt_gap = lose_real_pvp_obj.pt - win_real_pvp_obj.pt

    win_add_pt = _calculate_win_or_lose_pt(win_real_pvp_obj.pt,
                                           pt_gap,
                                           victory=True)
    lose_deduct_pt = _calculate_win_or_lose_pt(lose_real_pvp_obj.pt,
                                               pt_gap,
                                               victory=False)

    win_pt = win_real_pvp_obj.add_pt(win_add_pt)
    #  运营活动  特定时间内收益翻倍
    game_config = win_real_pvp_obj.game_config
    game_config.reload_config()
    multiply_income_conf = game_config.operat_config.get(
        "multiply_income", {}).get("pk", {})
    win_pt = win_pt * multiply_income(multiply_income_conf)
    win_real_pvp_obj.pvp_info['total_win'] += 1
    win_real_pvp_obj.pvp_info['total_join'] += 1

    lose_pt = lose_real_pvp_obj.add_pt(lose_deduct_pt)
    lose_real_pvp_obj.pvp_info['total_lose'] += 1
    lose_real_pvp_obj.pvp_info['total_join'] += 1

    top_model.set(win_uid, win_real_pvp_obj.pt)
    top_model.set(lose_uid, lose_real_pvp_obj.pt)

    win_info = {
        'pvp_title': win_real_pvp_obj.pvp_title,
        'pt': win_real_pvp_obj.pt,
        'pvp_rank': top_model.rank(win_uid),
        'change_pt': win_pt,
        'total_win': win_real_pvp_obj.pvp_info['total_win'],
        'total_lose': win_real_pvp_obj.pvp_info['total_lose'],
    }

    lose_info = {
        'pvp_title': lose_real_pvp_obj.pvp_title,
        'pt': lose_real_pvp_obj.pt,
        'pvp_rank': top_model.rank(lose_uid),
        'change_pt': lose_pt,
        'total_win': lose_real_pvp_obj.pvp_info['total_win'],
        'total_lose': lose_real_pvp_obj.pvp_info['total_lose'],
    }

    win_real_pvp_obj.do_put()
    lose_real_pvp_obj.do_put()
    return {'win_info': win_info, 'lose_info': lose_info}
def save_yesterday_pvp_top():
    # 每天于22:00 将此刻排行榜信息存入 昨日排行榜
    for subarea_num in all_subareas:
        now_top = pvp_redis.get_pvp_redis(subarea_num, top_name)
        yesterday_top = pvp_redis.get_yesterday_pvp_redis(subarea_num, top_name)

        # 清空老的昨日排名
        yesterday_top.zremrangeallrank()

        now_member_scores = app.top_redis.zrange(now_top.top_name, 0, -1, withscores=True)
        for uid, score in now_member_scores:
            yesterday_top.set(uid, score)
Exemple #6
0
def result_fight(win_uid, lose_uid):
    win_real_pvp_obj = UserRealPvp.get(win_uid)
    lose_real_pvp_obj = UserRealPvp.get(lose_uid)
    print "winner  {}, loser   {}".format(win_uid, lose_uid)
    top_model = pvp_redis.get_pvp_redis(win_real_pvp_obj.user_base.subarea, top_name='real_pvp')

    pt_gap = lose_real_pvp_obj.pt - win_real_pvp_obj.pt

    win_add_pt = _calculate_win_or_lose_pt(win_real_pvp_obj.pt, pt_gap, victory=True)
    lose_deduct_pt = _calculate_win_or_lose_pt(lose_real_pvp_obj.pt, pt_gap, victory=False)

    win_pt = win_real_pvp_obj.add_pt(win_add_pt)
    #  运营活动  特定时间内收益翻倍
    game_config = win_real_pvp_obj.game_config
    game_config.reload_config()
    multiply_income_conf = game_config.operat_config.get("multiply_income", {}).get("pk", {})
    win_pt = win_pt * multiply_income(multiply_income_conf)
    win_real_pvp_obj.pvp_info['total_win'] += 1
    win_real_pvp_obj.pvp_info['total_join'] += 1

    lose_pt = lose_real_pvp_obj.add_pt(lose_deduct_pt)
    lose_real_pvp_obj.pvp_info['total_lose'] += 1
    lose_real_pvp_obj.pvp_info['total_join'] += 1

    top_model.set(win_uid, win_real_pvp_obj.pt)
    top_model.set(lose_uid, lose_real_pvp_obj.pt)

    win_info = {
        'pvp_title': win_real_pvp_obj.pvp_title,
        'pt': win_real_pvp_obj.pt,
        'pvp_rank': top_model.rank(win_uid),
        'change_pt': win_pt,
        'total_win': win_real_pvp_obj.pvp_info['total_win'],
        'total_lose': win_real_pvp_obj.pvp_info['total_lose'],
    }

    lose_info = {
        'pvp_title': lose_real_pvp_obj.pvp_title,
        'pt': lose_real_pvp_obj.pt,
        'pvp_rank': top_model.rank(lose_uid),
        'change_pt': lose_pt,
        'total_win': lose_real_pvp_obj.pvp_info['total_win'],
        'total_lose': lose_real_pvp_obj.pvp_info['total_lose'],
    }

    win_real_pvp_obj.do_put()
    lose_real_pvp_obj.do_put()
    return {
        'win_info': win_info,
        'lose_info': lose_info
    }
def save_yesterday_pvp_top():
    # 每天于22:00 将此刻排行榜信息存入 昨日排行榜
    for subarea_num in all_subareas:
        now_top = pvp_redis.get_pvp_redis(subarea_num, top_name)
        yesterday_top = pvp_redis.get_yesterday_pvp_redis(
            subarea_num, top_name)

        # 清空老的昨日排名
        yesterday_top.zremrangeallrank()

        now_member_scores = app.top_redis.zrange(now_top.top_name,
                                                 0,
                                                 -1,
                                                 withscores=True)
        for uid, score in now_member_scores:
            yesterday_top.set(uid, score)
Exemple #8
0
def top_pvp(rk_user, params):
    data = {'friend': [], 'all_player': []}

    #前十的排行情况
    top_model = pvp_redis.get_pvp_redis(rk_user.subarea, top_name='real_pvp')
    top_30_uid_score = top_model.get(10)

    for uid, score in top_30_uid_score:
        pvp_obj = UserRealPvp.get(uid)
        data['all_player'].append(pvp_obj.get_pvp_need_info())

    urp = rk_user.user_real_pvp
    self_info = urp.get_pvp_need_info()
    self_info['self'] = True
    data['all_player'].append(self_info)

    return 0, data
Exemple #9
0
def top_pvp(rk_user, params):
    data = {'friend':[],'all_player':[]}
    

    #前十的排行情况
    top_model = pvp_redis.get_pvp_redis(rk_user.subarea, top_name='real_pvp')
    top_30_uid_score = top_model.get(10)


    for uid, score in top_30_uid_score:
        pvp_obj = UserRealPvp.get(uid)
        data['all_player'].append(pvp_obj.get_pvp_need_info())

    urp = rk_user.user_real_pvp
    self_info = urp.get_pvp_need_info()
    self_info['self'] = True
    data['all_player'].append(self_info)

    return 0, data
def clean_top():
    # 如果是周日 则 重置 排行榜
    if datetime.datetime.today().weekday() == 7:
        for subarea_num in all_subareas:
            now_top = pvp_redis.get_pvp_redis(subarea_num, top_name)
            now_top.zremrangeallrank()
def clean_top():
    # 如果是周日 则 重置 排行榜
    if datetime.datetime.today().weekday() == 7:
        for subarea_num in all_subareas:
            now_top = pvp_redis.get_pvp_redis(subarea_num, top_name)
            now_top.zremrangeallrank()
Exemple #12
0
def view_user(request):
    """
     更新用户信息
    """

    uid = request.GET.get('uid', '').strip()
    if not uid:
        pid = request.GET.get('pid', '').strip()
        if not pid:
            username = request.GET.get('username', '')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid = ocapp.mongo_store.mongo.db['username'].find(
                    {'name': username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid

    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')

    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data', '').strip()
    db_data_name = request.GET.get('db_data_name', '').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse(
            'Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data = {'user': {}}
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(
        ), locals()

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid +
                               '").' + db_data)
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data)

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data,
                                  RequestContext(request))
    ###### end view raw db

    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj': user_property_obj,
        'user': user,
        'deck_cards': [],
        'other_cards': [],
        'add_time': timestamp_toString(user.add_time),
        'last_login_time': timestamp_toString(user.user_property.login_time),
        'login_record': UserLogin.get(uid).login_info['login_record'],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k, v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key=lambda x: (all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(
        map(lambda x: int(x), game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]
                              ['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id, room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'], data['current_dungeon']
                  ['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index(
            '%s-%s' % (data['current_dungeon']['floor_id'],
                       data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader', 0)
            eid = ''
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)

    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips]
    data['user_equips'] = [
        game_config.equip_config[eid_dict['eid']] for eid_dict in eqids_dict
    ]
    all_equips_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i, game_config.equip_config[str(i) + '_equip'])
                          for i in all_equips_tag]

    #mat
    data['user_materials'] = {
        mid: {
            'name': game_config.material_config[mid]['name'],
            'num': user_pack_obj.materials[mid]
        }
        for mid in user_pack_obj.materials
    }
    all_materials_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.material_config.keys()])
    data['all_materials'] = [(i, game_config.material_config[str(i) + '_mat'])
                             for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find(
        {'uid': uid})[-1] if ChargeRecord.find({'uid': uid}) else {}

    ######将魂系统##############

    data.update(soul.get_all(user, None)[1])
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get(
            'star', '') + u'星 ' + game_config.card_config[sid].get('name',
                                                                   '') + u' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html', data, RequestContext(request))
Exemple #13
0
def view_user(request):
    """
     更新用户信息
    """

    uid = request.GET.get('uid','').strip()
    if not uid:
        pid = request.GET.get('pid','').strip()
        if not pid:
            username = request.GET.get('username','')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid=ocapp.mongo_store.mongo.db['username'].find({'name':username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid

    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')




    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data','').strip()
    db_data_name = request.GET.get('db_data_name','').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse('Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data={ 'user': {} }
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(), locals() 

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid + '").' + db_data )
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data )

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data, 
                    RequestContext(request))
    ###### end view raw db


    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj':user_property_obj,
        'user':user,
        'deck_cards':[],
        'other_cards':[],
        'add_time':timestamp_toString(user.add_time),
        'last_login_time':timestamp_toString(user.user_property.login_time),
        'login_record':UserLogin.get(uid).login_info['login_record'],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k,v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key = lambda x :(all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(map(lambda x:int(x),game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id,room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index('%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader',0)
            eid = ''
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)

    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips ]
    data['user_equips'] = [game_config.equip_config[eid_dict['eid']]  for eid_dict in eqids_dict]
    all_equips_tag = sorted([int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i,game_config.equip_config[str(i)+'_equip']) for i in all_equips_tag]

    #mat
    data['user_materials'] = {mid :{'name':game_config.material_config[mid]['name'],'num':user_pack_obj.materials[mid]} for mid in user_pack_obj.materials }
    all_materials_tag = sorted([int(i.split('_')[0]) for i in game_config.material_config.keys()])
    data['all_materials'] = [(i,game_config.material_config[str(i)+'_mat']) for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find({'uid':uid})[-1] if ChargeRecord.find({'uid':uid}) else {}


######将魂系统##############

    data.update(soul.get_all(user, None)[1])
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get('star','') + u'星 ' + game_config.card_config[sid].get('name','') + u' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html',data,RequestContext(request))