示例#1
0
def recover_copy():
    """
    * 重置副本次数
    """
    rk_user = UserBase.get(uid)
    recover_copy_coin = game_config.system_config['recover_copy_coin']
    #检查vip可以回复的次数到了没
    if not vip.check_limit_recover(rk_user,'recover_copy'):
        return 11,{'msg':utils.get_msg('user','max_recover_copy_times')}
    else:
        try:
            #检测参数是否合法
            dungeon_type = 'normal' 
            floor_id = '1' 
            room_id  = '1' 
        except:
            return 11,{'msg':utils.get_msg('dungeon','invalid_dungeon_info')}
        #检查用户coin是否足够
        if not rk_user.user_property.minus_coin(recover_copy_coin, 'recover_copy'):
            return 11,{'msg':utils.get_msg('user','not_enough_coin')}
        #添加回复次数
        rk_user.user_property.add_recover_times('recover_copy',dungeon_type)
        user_dungeon_obj = UserDungeon.get(rk_user.uid)
        user_dungeon_obj.recover_copy(dungeon_type,floor_id,room_id)

        rk_user.user_property.do_put()
        user_dungeon_obj.do_put()
        return 0,{}
示例#2
0
def get_box_gift(rk_user,params):
    '''
    * 领取宝箱奖励
    '''
    data = {}
    get_step = params.get('step','0')
    floor_id = params.get('floor_id')
    box_type = params.get('box_type')
    dungeon_config = game_config.dungeon_world_config.get('box_info',{})
    floor_conf = dungeon_config.get(floor_id,{})
    if not box_type in floor_conf:
        return 11,{'msg':utils.get_msg('dungeon', 'no_box_config')}
    box_info = floor_conf[box_type]
    if get_step == '0':
        #处理前端要显示的宝箱的内容
        data['box_info'] = utils.format_award(box_info)
        data['box_star'] = int(floor_conf[box_type+'_star'])
        return 0,data
    elif get_step == '1':
        #处理前端要领取的宝箱信息
        user_dungeon_obj = UserDungeon.get(rk_user.uid)
        has_played_info_copy = copy.deepcopy(user_dungeon_obj.has_played_info)
        if floor_id in has_played_info_copy.get('normal',{}):
            floor_info = has_played_info_copy['normal'][floor_id]
            #查看领取条件是否合适
            floor_get_star = floor_info['cur_star']
            if floor_get_star < int(floor_conf[box_type+'_star']):
                return 11,{'msg':utils.get_msg('dungeon', 'box_can_not_open')}
            if floor_info[box_type]:
                #宝箱已领取情况
                return 11,{'msg':utils.get_msg('dungeon', 'has_got_box_award')}
            else:
                #领取宝箱逻辑 格式化内容
                award = utils.format_award(box_info)
                user_property_obj = UserProperty.get(rk_user.uid)
                #将宝箱里面的内容添加到用户信息里面
                award_info = user_property_obj.test_give_award(award,where='get_'+box_type)
                #格式化要返回的内容
                data['award_info'] = award_info
                data['floor_info'] = {}
                data['floor_info']['floor_id'] = floor_id
                data['floor_info']['box_type'] = box_type
                data['floor_info']['box_flag'] = True
                #重置标志位
                user_dungeon_obj.has_played_info['normal'][floor_id][box_type] = True
                user_dungeon_obj.put()
                #判断新手引导
                newbie_step = int(params.get('newbie_step', 0))
                if newbie_step:
                    rk_user.user_property.set_newbie_steps(newbie_step, "get_box_gift")
                #结果返回
                return 0,data
        else:
            return 11,{'msg':utils.get_msg('dungeon', 'invalid_dungeon_info')}
    else:
        #未识别的内容
        return 11,{'msg':utils.get_msg('dungeon', 'invalid_dungeon_info')}
示例#3
0
def revive(rk_user,params):
    """复活
    """
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    last_info = user_dungeon_obj.dungeon_info['last']
    revive_coin = game_config.system_config['revive_coin']
    #检查是否有重试请求,重试时,直接返回结果
    #检查用户coin是否足够
    last_revive_coin = last_info.get('revive_coin',0)
    if rk_user.user_property.coin < revive_coin+last_revive_coin:
        return 11,{'msg':utils.get_msg('user','not_enough_coin')}
    last_info['revive_coin'] = last_revive_coin + revive_coin
    user_dungeon_obj.put()
    return 0,{}
示例#4
0
def revive(rk_user, params):
    """复活
    """
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    last_info = user_dungeon_obj.dungeon_info['last']
    revive_coin = game_config.system_config['revive_coin']
    #检查是否有重试请求,重试时,直接返回结果
    #检查用户coin是否足够
    last_revive_coin = last_info.get('revive_coin', 0)
    if rk_user.user_property.coin < revive_coin + last_revive_coin:
        return 11, {'msg': utils.get_msg('user', 'not_enough_coin')}
    last_info['revive_coin'] = last_revive_coin + revive_coin
    user_dungeon_obj.put()
    return 0, {}
示例#5
0
def recover_copy(rk_user, params):
    """重置副本可挑战次数
    
    Args:
        dungeon_type: 战场类型 (normal 普通战场/ daily试炼)  
        floor_id
        room_id   (试炼可无)
    """
    #检测参数是否合法
    dungeon_type = params['dungeon_type']
    floor_id = params['floor_id']
    room_id = params.get('room_id', '')
    if room_id:
        where = 'recover_copy_' + "_".join([dungeon_type, floor_id, room_id])
    else:
        where = 'recover_copy_' + "_".join([dungeon_type, floor_id])

    # 检查vip可以回复的次数到了没
    has_recover_times = vip.check_limit_recover(rk_user, 'recover_copy',
                                                dungeon_type, floor_id)
    next_recover_times = has_recover_times + 1
    if dungeon_type == 'normal':
        recover_conf = game_config.system_config['recover_normal_copy_need']
    elif dungeon_type == 'daily':
        recover_conf = game_config.system_config['recover_daily_copy_need']
    # 检查重置次数是否达到上限
    if next_recover_times not in recover_conf:
        raise GameLogicError('dungeon', 'reach_max_recover_%s' % dungeon_type)

    #检查用户coin是否足够
    recover_need_coin = recover_conf[next_recover_times]
    if not rk_user.user_property.minus_coin(recover_need_coin, where):
        return 11, {'msg': utils.get_msg('user', 'not_enough_coin')}
    #添加回复次数
    rk_user.user_property.add_recover_times('recover_copy', dungeon_type,
                                            floor_id)
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    user_dungeon_obj.recover_copy(dungeon_type, floor_id, room_id)

    return {}
示例#6
0
def recover_copy(rk_user, params):
    """重置副本可挑战次数
    
    Args:
        dungeon_type: 战场类型 (normal 普通战场/ daily试炼)  
        floor_id
        room_id   (试炼可无)
    """
    #检测参数是否合法
    dungeon_type = params['dungeon_type']
    floor_id = params['floor_id']
    room_id  = params.get('room_id', '')
    if room_id:
        where = 'recover_copy_' + "_".join([dungeon_type, floor_id, room_id])
    else:
        where = 'recover_copy_' + "_".join([dungeon_type, floor_id])

    # 检查vip可以回复的次数到了没
    has_recover_times = vip.check_limit_recover(rk_user,'recover_copy', dungeon_type, floor_id)
    next_recover_times = has_recover_times + 1
    if dungeon_type == 'normal':
        recover_conf = game_config.system_config['recover_normal_copy_need']
    elif dungeon_type == 'daily':
        recover_conf = game_config.system_config['recover_daily_copy_need']
    # 检查重置次数是否达到上限
    if next_recover_times not in recover_conf:
        raise GameLogicError('dungeon', 'reach_max_recover_%s' % dungeon_type)

    #检查用户coin是否足够
    recover_need_coin = recover_conf[next_recover_times]
    if not rk_user.user_property.minus_coin(recover_need_coin, where):
        return 11,{'msg':utils.get_msg('user', 'not_enough_coin')}
    #添加回复次数
    rk_user.user_property.add_recover_times('recover_copy', dungeon_type, floor_id)
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    user_dungeon_obj.recover_copy(dungeon_type,floor_id,room_id)

    return {}
示例#7
0
def wipe_out():
    '''
    扫荡
    目前只有普通战场有扫荡
    '''
    d_type = 'normal' 
    floor_id = '1'
    room_id  = '1'
    do_times = 1   # 扫荡次数
    data = {}
    if d_type not in ['normal'] or not floor_id or not room_id or do_times not in [1, 10]:
        return 11,{'msg':utils.get_msg('dungeon', 'invalid_params')} # 
    user_dungeon = UserDungeon.get(uid)
    has_played_info = user_dungeon.has_played_info
    '''
    has_played_floor = has_played_info[d_type].get(floor_id)
    # 未达到此战场
    if not has_played_floor:
        return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # 
    has_played_room = has_played_floor['rooms'].get(room_id)
    if not has_played_room:
        return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # 
    # 没达到3星
    if not has_played_room['perfect']:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')} # 
    '''
    try:
        has_played_info[d_type][floor_id]['rooms'][room_id]
    except:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')}
    # 没达到3星(完美过关)
    if not has_played_info[d_type][floor_id]['rooms'][room_id]['perfect']:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')}
    # 扫荡券不够
    user_pack = UserPack.get_instance(uid)
    if not user_pack.is_props_enough('24_props', do_times):
        return 11,{'msg':utils.get_msg('dungeon', 'wipe_out_not_enough')} # 
    # 目前只有普通战场 
    dungeon_config = game_config.normal_dungeon_config
    room_config = dungeon_config[floor_id]['rooms'][room_id]

    # 计算能够扫荡次数
    can_make_copy_cnt = room_config['can_make_copy_cn']
    if d_type == 'normal':
        try:  #  判断dungeon_repeat_info中有无此关卡记录
            user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] += 0
        except :
            # 无此关卡记录时,把此关卡今日完成次数置零
            if d_type not in user_dungeon.dungeon_repeat_info:
                user_dungeon.dungeon_repeat_info[d_type]={}
            if floor_id not in user_dungeon.dungeon_repeat_info[d_type]:
                user_dungeon.dungeon_repeat_info[d_type][floor_id] = {}
            if room_id not in user_dungeon.dungeon_repeat_info[d_type][floor_id]:
                user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] = 0
            user_dungeon.do_put()
    has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id]
    can_wipe_out_cnt = can_make_copy_cnt - has_played_cnt
    print can_make_copy_cnt, has_played_cnt 
    # 进入战场次数用完,不能扫荡
    if can_wipe_out_cnt <= 0:
        return 11,{'msg':utils.get_msg('dungeon', 'invalid_limit_dungeon')}
    # 剩余战场次数不够扫荡十次
    if can_wipe_out_cnt < do_times:
        return 11,{'msg':utils.get_msg('dungeon', 'can_not_do_ten_times')}
    # 扫荡战利品
    get_goods = {
        'exp': 0,
        'exp_point': 0,
        'gold': 0,
        'card': {},
        'equip': {},
        'soul':{
            'card': {},
            'equip': {},
        },
        'mat': {},
        'props': {},
    }

    # 扫荡一次能够得到的经验,卡经验点,和钱币
    get_goods['exp'] += room_config.get('exp', 0) * do_times
    get_goods['exp_point'] += room_config.get('exp_point', 0) * do_times
    get_goods['gold'] += room_config.get('gold', 0) * do_times

    # 扫荡能够得到的物品
    drop_info = _pack_drop_info(room_config.get('drop_info', {}))
    invisible_drop = _pack_drop_info(room_config.get('invisible_drop', {}))
    drop_info.extend(invisible_drop)
    # 有掉落物品(包括可见和不可见)时计算掉落, 不用战斗所以不区分可见不可见
    if drop_info: # sample  ['12002_equip', '5_card_soul', '53001_equip_1_soul', '6_card', '23_props', '8_props']
        drop_info = list(set(drop_info))  # list去重
        drop_info_config = game_config.drop_info_config['normal_dungeon']
        # 检查战场掉落配置中是否有此物品
        for goods_id in drop_info:
            print 'goods_id------*--*-*-*-*-*--*-*-*-*-------', goods_id
            if 'soul' in goods_id:
                if goods_id[:-5] not in drop_info_config['soul']:
                    return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')}
            else:
                if goods_id not in drop_info_config:
                    return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')}
        # 计算掉落数量
        for n in range(do_times):
            for goods_id in drop_info:
                if 'soul' in goods_id:
                    goods_id = goods_id[:-5]  # 去掉'_soul'后缀
                    value_config = drop_info_config['soul'][goods_id]['visible']
                    # 根据配置概率判断是否得到
                    if utils.is_happen(value_config[1]):
                        num = random.randint(value_config[0][0], value_config[0][1])
                        soul_type = 'card' if 'card' in goods_id else 'equip'
                        if goods_id not in get_goods['soul'][soul_type]:
                            get_goods['soul'][soul_type][goods_id] = num
                        else:
                            get_goods['soul'][soul_type][goods_id] += num
                    else:
                        continue

                else:
                    value_config = drop_info_config[goods_id]['visible']
                    # 根据配置概率判断是否得到
                    if utils.is_happen(value_config[1]):
                        num = random.randint(value_config[0][0], value_config[0][1])
                        for t in ['card', 'equip', 'props', 'mat']:
                            if t in goods_id:
                                get_type = t
                        if goods_id not in get_goods[get_type]:
                            get_goods[get_type][goods_id] = num
                        else:
                            get_goods[get_type][goods_id] += num
                    else:
                        continue
    # 减扫荡券
    user_pack = UserPack.get_instance(uid)
    user_pack.minus_props('24_props', do_times, 'wipe_out')
    # 添加扫荡奖励
    user_property = UserProperty.get_instance(uid)
    tmpdata = user_property.test_give_award(get_goods, where='wipe out')
    user_property.do_put()
    uc = UserCards.get_instance(uid)
    uc.do_put()
    ue = UserEquips.get_instance(uid)
    ue.do_put()
    up = UserPack.get_instance(uid)
    up.do_put()
    us = UserSouls.get_instance(uid)
    us.do_put()
    # 记录repeat info
    user_dungeon.add_repeat_cnt(d_type, floor_id, room_id, do_times)
    user_dungeon.do_put()

    # 给前端
    data['get_exp'] = tmpdata['exp']
    data['get_exp_point'] = tmpdata['exp_point']
    data['get_gold'] = tmpdata['gold']
    data['get_card'] = tmpdata['card']
    data['get_equip'] = tmpdata['equip']
    data['get_souls'] = tmpdata['soul']
    data['get_material'] = tmpdata['mat']
    data['get_props'] = tmpdata['props']

    print data
示例#8
0
def end(rk_user,params):
    """
    离开战场请求
    """
    data = {}
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    #记录中如果没有未完成的战场,则返回
    if not user_dungeon_obj.dungeon_info['last'].get('floor_id'):
        return 11,{'msg':utils.get_msg('dungeon','already_end')}
    #给用户奖励
    last_info = user_dungeon_obj.dungeon_info['last']
    floor_id = last_info['floor_id']
    room_id = last_info['room_id']
    dungeon_type = last_info['dungeon_type']
    #检查场和局
    para_floor_id = params['floor_id']
    para_room_id = params['room_id']
    para_dungeon_type = params['dungeon_type']

    where = 'dungeon_%s_%s_%s' % (para_dungeon_type, para_floor_id, para_room_id)

    if floor_id != para_floor_id or room_id != para_room_id or dungeon_type != para_dungeon_type:
        return 11,{'msg':utils.get_msg('dungeon','unsame_dungeon')}

    #检查战场唯一标识
    para_dungeon_uid = params.get('dungeon_uid','')
    if para_dungeon_uid and para_dungeon_uid != last_info['dungeon_uid']:
        return 11,{'msg':utils.get_msg('dungeon','unsame_dungeon')}
    #判断战场是否是完成的
    if params.get('result','1') == '0':
        data = {'dungeon_fail': True}#__resolve_fail(rk_user,user_dungeon_obj,ver=float(params['version']))
        return 0,data
    #获取获得的金币
    user_gold = int(params['user_gold'])

    #胜利扣除复活的元宝
    if 'revive_coin' in last_info:
        if not rk_user.user_property.minus_coin(last_info['revive_coin'],
                'revive_%s_%s_%s'%(last_info.get("floor_id"),last_info.get("room_id"),last_info.get("dungeon_type"))):
            return 11,{'msg':utils.get_msg('dungeon','revive_err')}
    #金币 打怪掉的
    get_gold = min(user_gold,last_info['total_gold'])
    #获取打怪掉的和通关奖励的金币之和
    get_gold = int((get_gold + last_info['dungeon_gold']))
    if get_gold:
        rk_user.user_property.add_gold(get_gold,where)
    data['get_gold'] = get_gold
    ####异常记录####
    if user_gold > last_info['total_gold']:
        dungeon_except = ExceptUsers.get_instance('normal_dungeon')
        dungeon_except.set_users('%s_%s'%(floor_id,room_id),rk_user.uid)
    # all_drop_info mat item props   添加背包里面的掉落信息
    all_drop_info = last_info['all_drop_info']
    user_pack_obj = UserPack.get(rk_user.uid)
    data['get_material'] = {}
    # data['get_item'] = {}
    data['get_props'] = {}
    pack_list = ['mat','item','props']
    for drop_type in pack_list:
        drop_info = all_drop_info.get(drop_type,{})
        for drop_id in drop_info:
            num = int(drop_info[drop_id])
            if drop_type == 'mat':
                #添加素材
                user_pack_obj.add_material(drop_id, num, where=where)
                data['get_material'][drop_id] = num
            elif drop_type == 'props':
                #添加道具
                user_pack_obj.add_props(drop_id, num, where=where)
                data['get_props'][drop_id] = num
            else:
                pass

    #  成功打完战场才扣体力
    need_stamina = last_info['dungeon_stamina']
    #新手用户可以几天不用体力
    # if datetime.datetime.now() < \
    # utils.timestamp_toDatetime(rk_user.add_time) + datetime.timedelta(days=game_config.system_config.get('newbie_days',0)):
    #     last_info['need_stamina'] = need_stamina
    # elif rk_user.user_property.charged_user and user_dungeon_obj.can_free_stamina():
    #     #付费用户每天可以有多少次可以不扣体力
    #     last_info['need_stamina'] = need_stamina
    #     user_dungeon_obj.add_free_stamina_cnt()
    # else:
    # 需要扣除体力  进战场时已经扣一点  这里只扣剩下的
    rk_user.user_property.minus_stamina(max(need_stamina - 1, 0))

    #加碎片
    data['get_souls'] = {}
    if last_info['all_drop_info'].get('soul'):
        user_souls_obj = UserSouls.get_instance(rk_user.uid)
        soul = last_info['all_drop_info']['soul']
        for soul_type in soul:
            data['get_souls'][soul_type] = {}
            if soul_type == 'equip':
                #如果碎片是普通装备的话的处理逻辑
                drop_soul_info = soul[soul_type]
                for drop_id in drop_soul_info:
                    num = int(drop_soul_info[drop_id])
                    #装备的添加
                    user_souls_obj.add_equip_soul(drop_id,num,where=where)
                    data['get_souls'][soul_type][drop_id] = num
            elif soul_type == 'card':
                #如果碎片类型是武将的话
                drop_card_soul_info = soul[soul_type]
                for drop_id in drop_card_soul_info:
                    num = int(drop_card_soul_info[drop_id])
                    user_souls_obj.add_normal_soul(drop_id,num,where=where)
                    data['get_souls'][soul_type][drop_id] = num
            else:
                pass

    #处理装备掉落返回值
    user_equip_obj = UserEquips.get(rk_user.uid)
    get_equips = []
    for eid in last_info['all_drop_info'].get('equip',{}):
        num = int(last_info['all_drop_info']['equip'][eid])
        for i in xrange(num):
            fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip(eid, where=where)
            temp = {
                    'ueid':ueid,
            }
            temp.update(user_equip_obj.equips[ueid])
            get_equips.append(temp)
    data['get_equip'] = get_equips
    user_card_obj = UserCards.get(rk_user.uid)
    #图鉴更新列表
    get_cards = []
    for cid in last_info['all_drop_info'].get('card',{}):
        num = int(last_info['all_drop_info']['card'][cid])
        for i in xrange(num):
            card_lv = 1
            success_fg,all_cards_num,ucid,is_first = user_card_obj.add_card(cid,card_lv,where=where)
            temp = {
                    'ucid':ucid,
            }
            temp.update(user_card_obj.cards[ucid])
            get_cards.append(temp)
    #加经验
    lv_up,get_upg_data = rk_user.user_property.add_exp(last_info['exp'],where)
    data['get_exp'] = last_info['exp']
    get_cards.extend(get_upg_data.get('get_card',[]))
    #添加经验点
    get_exp_point = last_info['exp_point']
    if get_exp_point:
        rk_user.user_property.add_card_exp_point(get_exp_point, where)
    data['get_exp_point'] = get_exp_point
    data['get_card'] = get_cards
    #用户升级的用于引导奖励 
    if 'get_material' in get_upg_data:
        for mat_id in get_upg_data['get_material']:
            if mat_id in data['get_material']:
                data['get_material'][mat_id] += get_upg_data['get_material'][mat_id]
            else:
                data['get_material'][mat_id] = get_upg_data['get_material'][mat_id]
    #判断新手引导
    newbie_step = int(params.get('newbie_step',0))
    if newbie_step:
        rk_user.user_property.set_newbie_steps(newbie_step, where)
    #更新用户的迷宫状态
    data['dungeon_info'] = user_dungeon_obj.update_dungeon_info(dungeon_type,floor_id,room_id,once_daily = last_info.get('once_daily',False))
    if 'clear_floor_coin' in data['dungeon_info']:
        data['clear_floor_coin'] = data['dungeon_info'].pop('clear_floor_coin')
    log_data = {
        'statament': 'end',
        'dungeon_id': '%s_%s' % (para_floor_id,para_room_id),
        'dungeon_type': para_dungeon_type,
        'card_deck': user_card_obj.deck,
        'exp_point': get_exp_point,
        'lv': rk_user.user_property.lv,
    }

    #记录该次战场的星级
    if dungeon_type in ['normal', 'daily']:
        #获取难度系数
        hard_ratio = params.get('hard_ratio', 'normal')         # 中等难度
        #获取星级系数
        star_ratio = int(params['star_ratio'])
        data['star_ratio'] = star_ratio
        user_dungeon_obj.update_has_played_info(dungeon_type,floor_id,room_id,hard_ratio,star_ratio)

        has_played_floor_info = user_dungeon_obj.has_played_info[dungeon_type].get(floor_id)
        
        if has_played_floor_info:
            #格式化要返回的部分数据
            tmpdata = {}
            tmpdata['floor_id'] = floor_id
            tmpdata['rooms_id'] = room_id
            tmpdata['floor_get_star'] = has_played_floor_info['cur_star']
            tmpdata['hard'] = hard_ratio
            tmpdata['room_get_star'] = has_played_floor_info['rooms'][room_id][hard_ratio]['get_star']
            tmpdata['room_perfect'] = has_played_floor_info['rooms'][room_id]['perfect']
            data['floor_info'] = tmpdata
    else:
        pass

    # 战场次数处理 因为每日战场和普通战场的每日可打次数的计算是不同的 
    # 普通战场要精确到每一个 room 但是每日活动战场则是精确到 floor 
    dungeon_repeat_info = user_dungeon_obj.dungeon_repeat_info
    dungeon_repeat_info.setdefault(dungeon_type, {})
    if dungeon_type == 'normal':
        #进入普通战场就减少当天进入的次数
        dungeon_repeat_info[dungeon_type].setdefault(floor_id, {})
        dungeon_repeat_info[dungeon_type][floor_id].setdefault(room_id, 0)
        dungeon_repeat_info[dungeon_type][floor_id][room_id] +=1
    elif dungeon_type == 'daily':
        #进入每日战场就减少当天进入的次数  
        dungeon_repeat_info[dungeon_type].setdefault(floor_id, 0)
        dungeon_repeat_info[dungeon_type][floor_id] +=1

    # #统计当日可以打多少次
    # if dungeon_type == 'normal':
    #     #获取该战场的今日次数
    #     data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id)
    #     data['copy_times']['floor_id'] = floor_id
    #     data['copy_times']['room_id'] = room_id
    # elif dungeon_type == 'daily':
    #     data['daily_info'] = user_dungeon_obj.get_daily_info()
    #     #获取该战场的今日次数
    #     data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id)
    #     data['copy_times']['floor_id'] = floor_id

    user_dungeon_obj.put()
    if lv_up:
        rk_user.user_character.check_open_talent()
    data_log_mod.set_log('DungeonRecord', rk_user, **log_data)

    return 0,data
示例#9
0
def get_box_gift(rk_user, params):
    '''
    * 领取宝箱奖励
    '''
    data = {}
    get_step = params.get('step', '0')
    floor_id = params.get('floor_id')
    box_type = params.get('box_type')
    dungeon_config = game_config.dungeon_world_config.get('box_info', {})
    floor_conf = dungeon_config.get(floor_id, {})
    if not box_type in floor_conf:
        return 11, {'msg': utils.get_msg('dungeon', 'no_box_config')}
    box_info = floor_conf[box_type]
    if get_step == '0':
        #处理前端要显示的宝箱的内容
        data['box_info'] = utils.format_award(box_info)
        data['box_star'] = int(floor_conf[box_type + '_star'])
        return 0, data
    elif get_step == '1':
        #处理前端要领取的宝箱信息
        user_dungeon_obj = UserDungeon.get(rk_user.uid)
        has_played_info_copy = copy.deepcopy(user_dungeon_obj.has_played_info)
        if floor_id in has_played_info_copy.get('normal', {}):
            floor_info = has_played_info_copy['normal'][floor_id]
            #查看领取条件是否合适
            floor_get_star = floor_info['cur_star']
            if floor_get_star < int(floor_conf[box_type + '_star']):
                return 11, {
                    'msg': utils.get_msg('dungeon', 'box_can_not_open')
                }
            if floor_info[box_type]:
                #宝箱已领取情况
                return 11, {
                    'msg': utils.get_msg('dungeon', 'has_got_box_award')
                }
            else:
                #领取宝箱逻辑 格式化内容
                award = utils.format_award(box_info)
                user_property_obj = UserProperty.get(rk_user.uid)
                #将宝箱里面的内容添加到用户信息里面
                award_info = user_property_obj.test_give_award(award,
                                                               where='get_' +
                                                               box_type)
                #格式化要返回的内容
                data['award_info'] = award_info
                data['floor_info'] = {}
                data['floor_info']['floor_id'] = floor_id
                data['floor_info']['box_type'] = box_type
                data['floor_info']['box_flag'] = True
                #重置标志位
                user_dungeon_obj.has_played_info['normal'][floor_id][
                    box_type] = True
                user_dungeon_obj.put()
                #判断新手引导
                newbie_step = int(params.get('newbie_step', 0))
                if newbie_step:
                    rk_user.user_property.set_newbie_steps(
                        newbie_step, "get_box_gift")
                #结果返回
                return 0, data
        else:
            return 11, {
                'msg': utils.get_msg('dungeon', 'invalid_dungeon_info')
            }
    else:
        #未识别的内容
        return 11, {'msg': utils.get_msg('dungeon', 'invalid_dungeon_info')}
示例#10
0
def end(rk_user, params):
    """
    离开战场请求
    """
    data = {}
    user_dungeon_obj = UserDungeon.get(rk_user.uid)
    #记录中如果没有未完成的战场,则返回
    if not user_dungeon_obj.dungeon_info['last'].get('floor_id'):
        return 11, {'msg': utils.get_msg('dungeon', 'already_end')}
    #给用户奖励
    last_info = user_dungeon_obj.dungeon_info['last']
    floor_id = last_info['floor_id']
    room_id = last_info['room_id']
    dungeon_type = last_info['dungeon_type']
    #检查场和局
    para_floor_id = params['floor_id']
    para_room_id = params['room_id']
    para_dungeon_type = params['dungeon_type']

    where = 'dungeon_%s_%s_%s' % (para_dungeon_type, para_floor_id,
                                  para_room_id)

    if floor_id != para_floor_id or room_id != para_room_id or dungeon_type != para_dungeon_type:
        return 11, {'msg': utils.get_msg('dungeon', 'unsame_dungeon')}

    #检查战场唯一标识
    para_dungeon_uid = params.get('dungeon_uid', '')
    if para_dungeon_uid and para_dungeon_uid != last_info['dungeon_uid']:
        return 11, {'msg': utils.get_msg('dungeon', 'unsame_dungeon')}
    #判断战场是否是完成的
    if params.get('result', '1') == '0':
        data = {
            'dungeon_fail': True
        }  #__resolve_fail(rk_user,user_dungeon_obj,ver=float(params['version']))
        return 0, data
    #获取获得的金币
    user_gold = int(params['user_gold'])

    #胜利扣除复活的元宝
    if 'revive_coin' in last_info:
        if not rk_user.user_property.minus_coin(
                last_info['revive_coin'], 'revive_%s_%s_%s' %
            (last_info.get("floor_id"), last_info.get("room_id"),
             last_info.get("dungeon_type"))):
            return 11, {'msg': utils.get_msg('dungeon', 'revive_err')}
    #金币 打怪掉的
    get_gold = min(user_gold, last_info['total_gold'])
    #获取打怪掉的和通关奖励的金币之和
    get_gold = int((get_gold + last_info['dungeon_gold']))
    if get_gold:
        rk_user.user_property.add_gold(get_gold, where)
    data['get_gold'] = get_gold
    ####异常记录####
    if user_gold > last_info['total_gold']:
        dungeon_except = ExceptUsers.get_instance('normal_dungeon')
        dungeon_except.set_users('%s_%s' % (floor_id, room_id), rk_user.uid)
    # all_drop_info mat item props   添加背包里面的掉落信息
    all_drop_info = last_info['all_drop_info']
    user_pack_obj = UserPack.get(rk_user.uid)
    data['get_material'] = {}
    # data['get_item'] = {}
    data['get_props'] = {}
    pack_list = ['mat', 'item', 'props']
    for drop_type in pack_list:
        drop_info = all_drop_info.get(drop_type, {})
        for drop_id in drop_info:
            num = int(drop_info[drop_id])
            if drop_type == 'mat':
                #添加素材
                user_pack_obj.add_material(drop_id, num, where=where)
                data['get_material'][drop_id] = num
            elif drop_type == 'props':
                #添加道具
                user_pack_obj.add_props(drop_id, num, where=where)
                data['get_props'][drop_id] = num
            else:
                pass

    #  成功打完战场才扣体力
    need_stamina = last_info['dungeon_stamina']
    #新手用户可以几天不用体力
    # if datetime.datetime.now() < \
    # utils.timestamp_toDatetime(rk_user.add_time) + datetime.timedelta(days=game_config.system_config.get('newbie_days',0)):
    #     last_info['need_stamina'] = need_stamina
    # elif rk_user.user_property.charged_user and user_dungeon_obj.can_free_stamina():
    #     #付费用户每天可以有多少次可以不扣体力
    #     last_info['need_stamina'] = need_stamina
    #     user_dungeon_obj.add_free_stamina_cnt()
    # else:
    # 需要扣除体力  进战场时已经扣一点  这里只扣剩下的
    rk_user.user_property.minus_stamina(max(need_stamina - 1, 0))

    #加碎片
    data['get_souls'] = {}
    if last_info['all_drop_info'].get('soul'):
        user_souls_obj = UserSouls.get_instance(rk_user.uid)
        soul = last_info['all_drop_info']['soul']
        for soul_type in soul:
            data['get_souls'][soul_type] = {}
            if soul_type == 'equip':
                #如果碎片是普通装备的话的处理逻辑
                drop_soul_info = soul[soul_type]
                for drop_id in drop_soul_info:
                    num = int(drop_soul_info[drop_id])
                    #装备的添加
                    user_souls_obj.add_equip_soul(drop_id, num, where=where)
                    data['get_souls'][soul_type][drop_id] = num
            elif soul_type == 'card':
                #如果碎片类型是武将的话
                drop_card_soul_info = soul[soul_type]
                for drop_id in drop_card_soul_info:
                    num = int(drop_card_soul_info[drop_id])
                    user_souls_obj.add_normal_soul(drop_id, num, where=where)
                    data['get_souls'][soul_type][drop_id] = num
            else:
                pass

    #处理装备掉落返回值
    user_equip_obj = UserEquips.get(rk_user.uid)
    get_equips = []
    for eid in last_info['all_drop_info'].get('equip', {}):
        num = int(last_info['all_drop_info']['equip'][eid])
        for i in xrange(num):
            fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip(
                eid, where=where)
            temp = {
                'ueid': ueid,
            }
            temp.update(user_equip_obj.equips[ueid])
            get_equips.append(temp)
    data['get_equip'] = get_equips
    user_card_obj = UserCards.get(rk_user.uid)
    #图鉴更新列表
    get_cards = []
    for cid in last_info['all_drop_info'].get('card', {}):
        num = int(last_info['all_drop_info']['card'][cid])
        for i in xrange(num):
            card_lv = 1
            success_fg, all_cards_num, ucid, is_first = user_card_obj.add_card(
                cid, card_lv, where=where)
            temp = {
                'ucid': ucid,
            }
            temp.update(user_card_obj.cards[ucid])
            get_cards.append(temp)
    #加经验
    lv_up, get_upg_data = rk_user.user_property.add_exp(
        last_info['exp'], where)
    data['get_exp'] = last_info['exp']
    get_cards.extend(get_upg_data.get('get_card', []))
    #添加经验点
    get_exp_point = last_info['exp_point']
    if get_exp_point:
        rk_user.user_property.add_card_exp_point(get_exp_point, where)
    data['get_exp_point'] = get_exp_point
    data['get_card'] = get_cards
    #用户升级的用于引导奖励
    if 'get_material' in get_upg_data:
        for mat_id in get_upg_data['get_material']:
            if mat_id in data['get_material']:
                data['get_material'][mat_id] += get_upg_data['get_material'][
                    mat_id]
            else:
                data['get_material'][mat_id] = get_upg_data['get_material'][
                    mat_id]
    #判断新手引导
    newbie_step = int(params.get('newbie_step', 0))
    if newbie_step:
        rk_user.user_property.set_newbie_steps(newbie_step, where)
    #更新用户的迷宫状态
    data['dungeon_info'] = user_dungeon_obj.update_dungeon_info(
        dungeon_type,
        floor_id,
        room_id,
        once_daily=last_info.get('once_daily', False))
    if 'clear_floor_coin' in data['dungeon_info']:
        data['clear_floor_coin'] = data['dungeon_info'].pop('clear_floor_coin')
    log_data = {
        'statament': 'end',
        'dungeon_id': '%s_%s' % (para_floor_id, para_room_id),
        'dungeon_type': para_dungeon_type,
        'card_deck': user_card_obj.deck,
        'exp_point': get_exp_point,
        'lv': rk_user.user_property.lv,
    }

    #记录该次战场的星级
    if dungeon_type in ['normal', 'daily']:
        #获取难度系数
        hard_ratio = params.get('hard_ratio', 'normal')  # 中等难度
        #获取星级系数
        star_ratio = int(params['star_ratio'])
        data['star_ratio'] = star_ratio
        user_dungeon_obj.update_has_played_info(dungeon_type, floor_id,
                                                room_id, hard_ratio,
                                                star_ratio)

        has_played_floor_info = user_dungeon_obj.has_played_info[
            dungeon_type].get(floor_id)

        if has_played_floor_info:
            #格式化要返回的部分数据
            tmpdata = {}
            tmpdata['floor_id'] = floor_id
            tmpdata['rooms_id'] = room_id
            tmpdata['floor_get_star'] = has_played_floor_info['cur_star']
            tmpdata['hard'] = hard_ratio
            tmpdata['room_get_star'] = has_played_floor_info['rooms'][room_id][
                hard_ratio]['get_star']
            tmpdata['room_perfect'] = has_played_floor_info['rooms'][room_id][
                'perfect']
            data['floor_info'] = tmpdata
    else:
        pass

    # 战场次数处理 因为每日战场和普通战场的每日可打次数的计算是不同的
    # 普通战场要精确到每一个 room 但是每日活动战场则是精确到 floor
    dungeon_repeat_info = user_dungeon_obj.dungeon_repeat_info
    dungeon_repeat_info.setdefault(dungeon_type, {})
    if dungeon_type == 'normal':
        #进入普通战场就减少当天进入的次数
        dungeon_repeat_info[dungeon_type].setdefault(floor_id, {})
        dungeon_repeat_info[dungeon_type][floor_id].setdefault(room_id, 0)
        dungeon_repeat_info[dungeon_type][floor_id][room_id] += 1
    elif dungeon_type == 'daily':
        #进入每日战场就减少当天进入的次数
        dungeon_repeat_info[dungeon_type].setdefault(floor_id, 0)
        dungeon_repeat_info[dungeon_type][floor_id] += 1

    # #统计当日可以打多少次
    # if dungeon_type == 'normal':
    #     #获取该战场的今日次数
    #     data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id)
    #     data['copy_times']['floor_id'] = floor_id
    #     data['copy_times']['room_id'] = room_id
    # elif dungeon_type == 'daily':
    #     data['daily_info'] = user_dungeon_obj.get_daily_info()
    #     #获取该战场的今日次数
    #     data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id)
    #     data['copy_times']['floor_id'] = floor_id

    user_dungeon_obj.put()
    if lv_up:
        rk_user.user_character.check_open_talent()
    data_log_mod.set_log('DungeonRecord', rk_user, **log_data)

    return 0, data