def more_dungeon_drop(dungeon_type, floor_id, room_id, times=1): """ 运营活动 特定时间 指定战场 额外掉落物品 Args: dungeon_type 战场类型 floor_id room_id times 需要随机掉落几次 Retruns: { 'card':{ '1_card': 4, '2_card': 5, }, 'soul':{ '1_card': 10, '2_equip_1': 1, }, 'gold':{ 'gold': 50, } ..... } """ more_drop_conf = game_config.operat_config.get('more_drop_conf') if not more_drop_conf: return {} drop_info = {} for each_conf in more_drop_conf.values(): now_str = datetime_toString(datetime.datetime.now()) start_time = each_conf.get("start_time", 0) end_time = each_conf.get("end_time", 0) # 开发时间 if now_str > end_time or now_str < start_time: continue # 指定战场类型开放 if not dungeon_type in each_conf.get('dungeon', {}): continue # 指定战场开放 if each_conf['dungeon'][dungeon_type] != 'all' and '-'.join( [floor_id, room_id]) not in each_conf['dungeon'][dungeon_type]: continue for thing_id, thing_drop_conf in each_conf.get('drop_things', {}).items(): num = 0 for cnt in range(times): if not utils.is_happen(thing_drop_conf.get('drop_rate', 0)): continue num += utils.get_item_by_random_simple(thing_drop_conf['num']) if num > 0: thing_type = thing_drop_conf['type'] drop_info.setdefault(thing_type, {}) thing_id = thing_id.replace('Soul', '') drop_info[thing_type][thing_id] = drop_info[thing_type].get( thing_id, 0) + num return drop_info
def more_dungeon_drop(dungeon_type, floor_id, room_id, times=1): """ 运营活动 特定时间 指定战场 额外掉落物品 Args: dungeon_type 战场类型 floor_id room_id times 需要随机掉落几次 Retruns: { 'card':{ '1_card': 4, '2_card': 5, }, 'soul':{ '1_card': 10, '2_equip_1': 1, }, 'gold':{ 'gold': 50, } ..... } """ more_drop_conf = game_config.operat_config.get('more_drop_conf') if not more_drop_conf: return {} drop_info = {} for each_conf in more_drop_conf.values(): now_str = datetime_toString(datetime.datetime.now()) start_time = each_conf.get("start_time", 0) end_time = each_conf.get("end_time", 0) # 开发时间 if now_str > end_time or now_str < start_time: continue # 指定战场类型开放 if not dungeon_type in each_conf.get('dungeon', {}): continue # 指定战场开放 if each_conf['dungeon'][dungeon_type] != 'all' and '-'.join([floor_id, room_id]) not in each_conf['dungeon'][dungeon_type]: continue for thing_id, thing_drop_conf in each_conf.get('drop_things', {}).items(): num = 0 for cnt in range(times): if not utils.is_happen(thing_drop_conf.get('drop_rate', 0)): continue num += utils.get_item_by_random_simple(thing_drop_conf['num']) if num > 0: thing_type = thing_drop_conf['type'] drop_info.setdefault(thing_type, {}) thing_id = thing_id.replace('Soul', '') drop_info[thing_type][thing_id] = drop_info[thing_type].get(thing_id, 0) + num return drop_info
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
def wipe_out(rk_user, params): ''' 扫荡 玩家能够在已经完美过关的关卡上使用扫荡功能,扫荡不用进入战斗画面,直接返回关卡奖励 与普通战斗不同的是扫荡并不需要更新战场的关卡信息, params: dungeon_type:'normal' 战场类型,有普通战场 normal , 试炼 daily floor_id:'1' room_id:'1' do_times: '1' 扫荡次数 ''' d_type = params.get('dungeon_type') floor_id = params.get('floor_id') room_id = params.get('room_id') do_times = params.get('do_times') # 扫荡次数 # ------------------------------参数check start------------------------- if d_type not in ['normal', 'daily'] or not floor_id or not room_id: return 6, {'msg':utils.get_msg('dungeon', 'invalid_params')} try: do_times = int(do_times) except ValueError: return 6, {'msg':utils.get_msg('dungeon', 'invalid_params')} if do_times <= 0: return 6, {'msg':utils.get_msg('dungeon', 'invalid_params')} user_dungeon = rk_user.user_dungeon has_played_info = user_dungeon.has_played_info user_property = rk_user.user_property # 读配置 conf_dict = { 'normal': game_config.normal_dungeon_config, 'daily': game_config.daily_dungeon_config } dungeon_config = conf_dict[d_type] # 战场不存在 try: dungeon_config[floor_id]['rooms'][room_id] except KeyError: return 6,{'msg':utils.get_msg('dungeon', 'invalid_dungeon')} # ------------------------------参数check end---------------------------- # ------------------------------扫荡逻辑check start---------------- # 玩家未达到15级,不开启扫荡 open_lv = game_config.user_init_config['open_lv'].get('wipe_out', 0) if user_property.lv < open_lv: return 11,{'msg':utils.get_msg('dungeon', 'wipe_out_open_lv') % open_lv} # vip未达到4级,不开启多次扫荡 open_lv = game_config.user_init_config['open_lv'].get('vip_multi_wipe_out', 0) if do_times > 1 and user_property.vip_cur_level < open_lv: return 11,{'msg':utils.get_msg('dungeon', 'vip_wipe_out') % open_lv} floor_config = dungeon_config[floor_id] room_config = dungeon_config[floor_id]['rooms'][room_id] # 未达到此战场 try: has_played_info[d_type][floor_id]['rooms'][room_id] except KeyError: return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # 没达到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 = rk_user.user_pack if not user_pack.is_props_enough('24_props', do_times): return 11,{'msg':utils.get_msg('dungeon', 'wipe_out_not_enough')} # 检查用户体力是否足够 #need_stamina = int(room_config['stamina']) * do_times #if user_property.stamina < need_stamina: # raise GameLogicError('user','not_enough_stamina') # 进入战场次数用完,不能扫荡, 或者更新repeat_info的当天日期 if user_dungeon.check_limit_dungeon(rk_user,params) is False: raise GameLogicError('dungeon', 'invalid_limit_dungeon') # 计算能够扫荡次数 if d_type == 'normal': try: # 判断dungeon_repeat_info中有无此关卡记录 user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] except KeyError: # 无此关卡记录时,把此关卡今日完成次数置零 user_dungeon.dungeon_repeat_info \ .setdefault(d_type, {}) \ .setdefault(floor_id, {}) \ .setdefault(room_id, 0) user_dungeon.put() can_make_copy_cnt = room_config['can_make_copy_cn'] has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] elif d_type == 'daily': try: # 判断dungeon_repeat_info中有无此关卡记录 user_dungeon.dungeon_repeat_info[d_type][floor_id] except KeyError: # 无此关卡记录时,把此关卡今日完成次数置零 user_dungeon.dungeon_repeat_info \ .setdefault(d_type, {}) \ .setdefault(floor_id, 0) user_dungeon.put() can_make_copy_cnt = floor_config['can_make_copy_cn'] has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id] can_wipe_out_cnt = can_make_copy_cnt - has_played_cnt data = {} # 剩余战场次数不够扫荡n次 if can_wipe_out_cnt < do_times: return 11,{'msg':utils.get_msg('dungeon', 'cant_do_multi_times') % do_times} data['can_wipe_out_cnt'] = can_wipe_out_cnt # ------------------------------扫荡逻辑check end---------------- # 能扫荡次数和vip等级有关 #if utils.get_today_str() == user_property.property_info['recover_times']['today_str']: # wipe_out_times = user_property.property_info.get('wipe_out_times', 0) # vip_lv = user_property.vip_cur_level # can_wipe_out_cnt = game_config.user_vip_config[str(vip_lv)]['can_wipe_out_cnt'] # if can_wipe_out_cnt - wipe_out_times < do_times: # return 11,{'msg':utils.get_msg('dungeon', 'vip_wipe_out')} # user_property.property_info['wipe_out_times'] += do_times #else: # user_property.property_info['wipe_out_times'] = do_times # vip.check_limit_recover(rk_user, 'wipe_out') # 更新一下,防止出错 #user_property.put() # ------------------------------添加扫荡物品 start---------------- # 扫荡战利品 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: 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]) if 'card' in goods_id: soul_type = 'card' else: soul_type = '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 # 添加must_drop必掉物品 md = room_config.get('must_drop', {}) for goods_type in md: if goods_type == 'soul': for key in md[goods_type]: if 'card' in key: soul_type = 'card' elif 'equip' in key: soul_type = 'equip' if key in get_goods[goods_type][soul_type]: get_goods[goods_type][soul_type][key] += md[goods_type][key] else: get_goods[goods_type][soul_type][key] = md[goods_type][key] else: for key in md[goods_type]: if key in get_goods[goods_type]: get_goods[goods_type][key] += md[goods_type][key] else: get_goods[goods_type][key] = md[goods_type][key] # ------------------------------添加扫荡物品 end---------------- # 添加扫荡获得奖励 tmpdata = user_property.test_give_award(get_goods, where='wipe_out') user_property.do_put() # 减扫荡券 user_pack.minus_props('24_props', do_times, 'wipe_out') user_pack.do_put() # 扣体力 #user_property.minus_stamina(need_stamina) # 记录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'] return 0, data
def calculate_steps(params, conf, rk_user, multiply=1): """ 计算本次进入战场的每步数据 Arges: multiply 活动收益翻倍翻得倍数 """ data = {} #获取每一小节的敌将信息 steps_info = copy.deepcopy(conf['steps_info']) #获取到每一小节 并排序 step_key = sorted(steps_info.keys()) return_step = [] max_gold = 0 for step in step_key: #遍历每一小节 cur_step_info = [] for monster_info in steps_info[step]: # monster_list = {} # #获取金币配置区间 # gold_config = monster_info[1] # #设置id # monster_list['monster_id'] = monster_info[0] # monster_list['gold'] = random.randint(gold_config[0],gold_config[1]) # #统计总的金币掉落 # max_gold += monster_list['gold'] * multiply # 修改配置格式于 2015-06-29 # 旧格式: '1':[['1_1_0_1_monster', [20, 30]], ['1_1_0_2_monster', [20, 30]] # 新格式: '1':['1_1_0_1_monster', '1_1_0_2_monster'] monster_list = {'monster_id': monster_info, 'gold': 0} #将敌将信息给当前小节 cur_step_info.append(monster_list) #将每一步的信息赋值到要返回的信息中 return_step.append(cur_step_info) all_drop_info = {} #计算掉落的信息 dungeon_type = params['dungeon_type'] if dungeon_type == 'normal': dungeon_drop_config = game_config.drop_info_config.get('normal_dungeon',{}) elif dungeon_type == 'daily': dungeon_drop_config = game_config.drop_info_config.get('daily_dungeon',{}) room_drop_config = conf.get('drop_info',{}) invisible_drop = conf.get('invisible_drop',{}) all_drop = {'visible_drop':room_drop_config,'invisible_drop':invisible_drop} # 添加必掉的物品 if 'must_drop' in conf: all_drop_info.update(conf['must_drop']) #获取掉落的你内容 for visible in all_drop: if visible == 'visible_drop': visible_type = 'visible' elif visible == 'invisible_drop': visible_type = 'invisible' cur_drop_conf = all_drop[visible] for drop_type in cur_drop_conf: if drop_type != 'soul': #不是碎片的处理 cur_drop_type_info = cur_drop_conf[drop_type] #遍历内容 获取可能掉落的内容 for drop_info in cur_drop_type_info: #获取掉落的配置信息 drop_config = dungeon_drop_config[drop_info] #获取掉落的概率 drop_rate = drop_config.get(visible_type,[[0,0],0])[1] #判断掉落是否发生 if utils.is_happen(drop_rate): num = random.randint(drop_config[visible_type][0][0],drop_config[visible_type][0][1]) * multiply #判断掉落的类型是否在返回的内容中 ''' 在这里面赋值而不在for外面赋值的原因是不确定是否掉落 ''' if drop_type not in all_drop_info: all_drop_info[drop_type] = {} #判断掉落的内容是否在类型中 if drop_info not in all_drop_info[drop_type]: all_drop_info[drop_type][drop_info] = 0 #赋值掉落的数目 all_drop_info[drop_type][drop_info] += num else: cur_soul_info = cur_drop_conf[drop_type] for drop_info in cur_soul_info: if 'card' in drop_info: soul_type = 'card' elif 'equip' in drop_info: soul_type = 'equip' else: break drop_config = dungeon_drop_config[drop_type][drop_info] #获取掉落的概率 drop_rate = drop_config[visible_type][1] #判断掉落是否发生 if utils.is_happen(drop_rate): num = random.randint(drop_config[visible_type][0][0],drop_config[visible_type][0][1]) * multiply ''' 在这里面赋值而不在for外面赋值的原因是不确定是否掉落 ''' #判断掉落的类型是否在返回的内容中 if drop_type not in all_drop_info: all_drop_info[drop_type] = {} #判断掉落的类型是否在返回的内容中 if soul_type not in all_drop_info[drop_type]: all_drop_info[drop_type][soul_type] = {} #判断掉落的内容是否在类型中 if drop_info not in all_drop_info[drop_type][soul_type]: all_drop_info[drop_type][soul_type][drop_info] = 0 #赋值掉落的数目 all_drop_info[drop_type][soul_type][drop_info] += num #将素材道具随机分配到敌将身上 steps_info = random_monster_info(conf['boss'],return_step,all_drop_info) #结果返回 data['dungeon_gold'] = conf.get('gold',0) * multiply data['exp'] = int(conf.get('exp',0)) data['steps_info'] = steps_info data['all_drop_info'] = all_drop_info data['total_gold'] = max_gold * multiply data['exp_point'] = conf.get('exp_point',0) * multiply return data
def wipe_out(rk_user, params): ''' 扫荡 玩家能够在已经完美过关的关卡上使用扫荡功能,扫荡不用进入战斗画面,直接返回关卡奖励 与普通战斗不同的是扫荡并不需要更新战场的关卡信息, params: dungeon_type:'normal' 战场类型,有普通战场 normal , 试炼 daily floor_id:'1' room_id:'1' do_times: '1' 扫荡次数 ''' # ------------------------------参数check start------------------------- d_type = params.get('dungeon_type') floor_id = params.get('floor_id') room_id = params.get('room_id') do_times = params.get('do_times') if d_type not in ['normal', 'daily'] or not floor_id or not room_id: return 6, {'msg': utils.get_msg('dungeon', 'invalid_params')} try: do_times = int(do_times) except ValueError: return 6, {'msg': utils.get_msg('dungeon', 'invalid_params')} if do_times < 1 or do_times > 10: return 6, {'msg': utils.get_msg('dungeon', 'invalid_params')} # 读配置 conf_dict = { 'normal': game_config.normal_dungeon_config, 'daily': game_config.daily_dungeon_config } dungeon_config = conf_dict[d_type] # 战场不存在 try: dungeon_config[floor_id]['rooms'][room_id] except KeyError: return 6, {'msg': utils.get_msg('dungeon', 'invalid_dungeon')} # ------------------------------参数check end---------------------------- # ------------------------------扫荡逻辑check start---------------- user_dungeon = rk_user.user_dungeon has_played_info = user_dungeon.has_played_info user_property = rk_user.user_property # 玩家未达到15级,不开启扫荡 open_lv = game_config.user_init_config['open_lv'].get('wipe_out', 0) if user_property.lv < open_lv: return 11, { 'msg': utils.get_msg('dungeon', 'wipe_out_open_lv') % open_lv } # vip未达到4级,不开启多次扫荡 open_lv = game_config.user_init_config['open_lv'].get( 'vip_multi_wipe_out', 0) if do_times > 1 and user_property.vip_cur_level < open_lv: return 11, {'msg': utils.get_msg('dungeon', 'vip_wipe_out') % open_lv} # 未达到此战场 try: has_played_info[d_type][floor_id]['rooms'][room_id] except KeyError: return 11, {'msg': utils.get_msg('dungeon', 'not_arrived')} # 没达到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 = rk_user.user_pack if not user_pack.is_props_enough('24_props', do_times): return 11, {'msg': utils.get_msg('dungeon', 'wipe_out_not_enough')} floor_config = dungeon_config[floor_id] room_config = dungeon_config[floor_id]['rooms'][room_id] # 检查用户体力是否足够 need_stamina = int(room_config['stamina']) * do_times if user_property.stamina < need_stamina: raise GameLogicError('user', 'not_enough_stamina') # 进入战场次数用完,不能扫荡, 或者更新repeat_info的当天日期 if user_dungeon.check_limit_dungeon(rk_user, params) is False: raise GameLogicError('dungeon', 'invalid_limit_dungeon') # 计算能够扫荡次数 if d_type == 'normal': try: # 判断dungeon_repeat_info中有无此关卡记录 user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] except KeyError: # 无此关卡记录时,把此关卡今日完成次数置零 user_dungeon.dungeon_repeat_info \ .setdefault(d_type, {}) \ .setdefault(floor_id, {}) \ .setdefault(room_id, 0) user_dungeon.put() can_make_copy_cnt = room_config['can_make_copy_cn'] has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id][ room_id] elif d_type == 'daily': try: # 判断dungeon_repeat_info中有无此关卡记录 user_dungeon.dungeon_repeat_info[d_type][floor_id] except KeyError: # 无此关卡记录时,把此关卡今日完成次数置零 user_dungeon.dungeon_repeat_info \ .setdefault(d_type, {}) \ .setdefault(floor_id, 0) user_dungeon.put() can_make_copy_cnt = floor_config['can_make_copy_cn'] has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id] can_wipe_out_cnt = can_make_copy_cnt - has_played_cnt data = {} # 剩余战场次数不够扫荡n次 if can_wipe_out_cnt < do_times: return 11, { 'msg': utils.get_msg('dungeon', 'cant_do_multi_times') % do_times } data['can_wipe_out_cnt'] = can_wipe_out_cnt # ------------------------------扫荡逻辑check end---------------- # 能扫荡次数和vip等级有关 #if utils.get_today_str() == user_property.property_info['recover_times']['today_str']: # wipe_out_times = user_property.property_info.get('wipe_out_times', 0) # vip_lv = user_property.vip_cur_level # can_wipe_out_cnt = game_config.user_vip_config[str(vip_lv)]['can_wipe_out_cnt'] # if can_wipe_out_cnt - wipe_out_times < do_times: # return 11,{'msg':utils.get_msg('dungeon', 'vip_wipe_out')} # user_property.property_info['wipe_out_times'] += do_times #else: # user_property.property_info['wipe_out_times'] = do_times # vip.check_limit_recover(rk_user, 'wipe_out') # 更新一下,防止出错 #user_property.put() # ------------------------------添加扫荡物品 start---------------- # 扫荡战利品 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 ######## 运营活动 特定时间额外掉落物品 万恶的代码 more_drop = activity.more_dungeon_drop(d_type, floor_id, room_id, times=do_times) if more_drop: for thing_type, things_id_num in more_drop.items(): if thing_type == 'gold': get_goods['gold'] += more_drop['gold']['num'] continue for thing_id, num in things_id_num.items(): if thing_type == 'soul': if 'card' in thing_id: soul_type = 'card' elif 'equip' in thing_id: soul_type = 'equip' get_goods[thing_type][soul_type][ thing_id] = get_goods[thing_type][soul_type].get( thing_id, 0) + num else: get_goods[ thing_type][thing_id] = get_goods[thing_type].get( thing_id, 0) + num ################### ############ # 扫荡能够得到的物品 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: 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].get( 'visible', drop_info_config['soul'][goods_id].get('invisible', 0)) # 根据配置概率判断是否得到 if utils.is_happen(value_config[1]): num = random.randint(value_config[0][0], value_config[0][1]) if 'card' in goods_id: soul_type = 'card' elif 'equip' in goods_id: soul_type = 'equip' else: continue 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].get( 'visible', drop_info_config[goods_id].get('invisible', 0)) # 根据配置概率判断是否得到 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 # 添加must_drop必掉物品 md = room_config.get('must_drop', {}) for goods_type in md: if goods_type == 'soul': for key in md[goods_type]: if 'card' in key: soul_type = 'card' elif 'equip' in key: soul_type = 'equip' else: continue if key in get_goods[goods_type][soul_type]: get_goods[goods_type][soul_type][key] += md[goods_type][ key] else: get_goods[goods_type][soul_type][key] = md[goods_type][key] else: for key in md[goods_type]: if key in get_goods[goods_type]: get_goods[goods_type][key] += md[goods_type][key] else: get_goods[goods_type][key] = md[goods_type][key] # ------------------------------添加扫荡物品 end---------------- # 添加扫荡获得物品 tmpdata = user_property.test_give_award(get_goods, where='wipe_out') # 减扫荡券 user_pack.minus_props('24_props', do_times, 'wipe_out') # 扣体力 user_property.minus_stamina(need_stamina) # 记录repeat info user_dungeon.add_repeat_cnt(d_type, floor_id, room_id, do_times) # 给前端 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'] return 0, data
def calculate_steps(params, conf, rk_user, multiply=1): """ 计算本次进入战场的每步数据 Arges: multiply 活动收益翻倍翻得倍数 """ data = {} #获取每一小节的敌将信息 steps_info = copy.deepcopy(conf['steps_info']) #获取到每一小节 并排序 step_key = sorted(steps_info.keys()) return_step = [] max_gold = 0 for step in step_key: #遍历每一小节 cur_step_info = [] for monster_info in steps_info[step]: # monster_list = {} # #获取金币配置区间 # gold_config = monster_info[1] # #设置id # monster_list['monster_id'] = monster_info[0] # monster_list['gold'] = random.randint(gold_config[0],gold_config[1]) # #统计总的金币掉落 # max_gold += monster_list['gold'] * multiply # 修改配置格式于 2015-06-29 # 旧格式: '1':[['1_1_0_1_monster', [20, 30]], ['1_1_0_2_monster', [20, 30]] # 新格式: '1':['1_1_0_1_monster', '1_1_0_2_monster'] monster_list = {'monster_id': monster_info, 'gold': 0} #将敌将信息给当前小节 cur_step_info.append(monster_list) #将每一步的信息赋值到要返回的信息中 return_step.append(cur_step_info) all_drop_info = {} #计算掉落的信息 dungeon_type = params['dungeon_type'] if dungeon_type == 'normal': dungeon_drop_config = game_config.drop_info_config.get( 'normal_dungeon', {}) elif dungeon_type == 'daily': dungeon_drop_config = game_config.drop_info_config.get( 'daily_dungeon', {}) room_drop_config = conf.get('drop_info', {}) invisible_drop = conf.get('invisible_drop', {}) all_drop = { 'visible_drop': room_drop_config, 'invisible_drop': invisible_drop } # 添加必掉的物品 if 'must_drop' in conf: all_drop_info.update(conf['must_drop']) #获取掉落的你内容 for visible in all_drop: if visible == 'visible_drop': visible_type = 'visible' elif visible == 'invisible_drop': visible_type = 'invisible' cur_drop_conf = all_drop[visible] for drop_type in cur_drop_conf: if drop_type != 'soul': #不是碎片的处理 cur_drop_type_info = cur_drop_conf[drop_type] #遍历内容 获取可能掉落的内容 for drop_info in cur_drop_type_info: #获取掉落的配置信息 drop_config = dungeon_drop_config[drop_info] #获取掉落的概率 drop_rate = drop_config.get(visible_type, [[0, 0], 0])[1] #判断掉落是否发生 if utils.is_happen(drop_rate): num = random.randint( drop_config[visible_type][0][0], drop_config[visible_type][0][1]) * multiply #判断掉落的类型是否在返回的内容中 ''' 在这里面赋值而不在for外面赋值的原因是不确定是否掉落 ''' if drop_type not in all_drop_info: all_drop_info[drop_type] = {} #判断掉落的内容是否在类型中 if drop_info not in all_drop_info[drop_type]: all_drop_info[drop_type][drop_info] = 0 #赋值掉落的数目 all_drop_info[drop_type][drop_info] += num else: cur_soul_info = cur_drop_conf[drop_type] for drop_info in cur_soul_info: if 'card' in drop_info: soul_type = 'card' elif 'equip' in drop_info: soul_type = 'equip' else: break drop_config = dungeon_drop_config[drop_type][drop_info] #获取掉落的概率 drop_rate = drop_config[visible_type][1] #判断掉落是否发生 if utils.is_happen(drop_rate): num = random.randint( drop_config[visible_type][0][0], drop_config[visible_type][0][1]) * multiply ''' 在这里面赋值而不在for外面赋值的原因是不确定是否掉落 ''' #判断掉落的类型是否在返回的内容中 if drop_type not in all_drop_info: all_drop_info[drop_type] = {} #判断掉落的类型是否在返回的内容中 if soul_type not in all_drop_info[drop_type]: all_drop_info[drop_type][soul_type] = {} #判断掉落的内容是否在类型中 if drop_info not in all_drop_info[drop_type][ soul_type]: all_drop_info[drop_type][soul_type][drop_info] = 0 #赋值掉落的数目 all_drop_info[drop_type][soul_type][drop_info] += num #将素材道具随机分配到敌将身上 steps_info = random_monster_info(conf['boss'], return_step, all_drop_info) #结果返回 data['dungeon_gold'] = conf.get('gold', 0) * multiply data['exp'] = int(conf.get('exp', 0)) data['steps_info'] = steps_info data['all_drop_info'] = all_drop_info data['total_gold'] = max_gold * multiply data['exp_point'] = conf.get('exp_point', 0) * multiply return data