def reset(context): """重置所有天赋 Args: Returns: """ ki_user = context.user if not user_logic.check_game_values1(ki_user, diamond=TALENT_RESET_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return all_talents = ki_user.talent.talents total_talent_point = 0 for talent_id, level in all_talents.items(): cfg = game_config.talent_detail_cfg.get(talent_id) for l in range(level): consume = cfg["intensify_consume"][l + 1] total_talent_point += consume[10] # 返回技能点 user_logic.add_game_values(ki_user, {10: total_talent_point}) ki_user.talent.reset_talent() context.result['mc'] = MsgCode['TalentResetSucc']
def reset(context): """重置所有天赋 Args: Returns: """ ki_user = context.user if not user_logic.check_game_values1(ki_user, diamond=TALENT_RESET_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return all_talents = ki_user.talent.talents total_talent_point = 0 for talent_id, level in all_talents.items(): cfg = game_config.talent_detail_cfg.get(talent_id) for l in range(level): consume = cfg["intensify_consume"][l+1] total_talent_point += consume[10] # 返回技能点 user_logic.add_game_values(ki_user, {10: total_talent_point}) ki_user.talent.reset_talent() context.result['mc'] = MsgCode['TalentResetSucc']
def enter(context): """进入副本 Args: mission_id 副本ID """ ki_user = context.user mission_id = context.get_parameter("mission_id") fight = context.get_parameter("fight") extra = ki_user.mission.extra_data if extra["last_mission"] != 0: now = int(time.time()) if now - extra["last_mission"] <= MISSION_CD: context.result['mc'] = MsgCode['MissionTooMany'] return cfg = game_config.mission_base_cfg.get(mission_id, {}) if not cfg: context.result['mc'] = MsgCode['MissionNotExist'] return if not _check_module_open(mission_id, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return if not user_logic.check_game_values1(ki_user, energy=cfg["energy"]): context.result['mc'] = MsgCode['PowerNotEnough'] return if cfg["need_level"] > ki_user.game_info.role_level: context.result['mc'] = MsgCode['UserLevelTooLow'] return if cfg["need_mission"] and _check_need_mission(cfg["need_mission"], ki_user.mission.missions): context.result['mc'] = MsgCode['MissionCondsNotEnough'] return if cfg["type"] in [MISSION_TYPE_JY, MISSION_TYPE_EM]: mission_daily_data = ki_user.daily_info.mission_info daily = mission_daily_data.get(mission_id, {}) if daily and daily["past_times"] >= cfg["daily_limit"]: context.result['mc'] = MsgCode['MissionTimesError'] return # 战力校验 if (mission_id not in ki_user.mission.missions) and (not user_helper.check_user_fight(ki_user, fight)): context.result['mc'] = MsgCode['UserFightCheckFailed'] return # 进入副本成功。更新数据 ki_user.mission.enter(mission_id) # 失败或没打完同样扣体力,加经验。进入副本时预扣体力,防止玩家中途退出游戏 energy_role_exp = cfg["energy"] / 3 user_logic.consume_game_values1(ki_user, energy=energy_role_exp) user_logic.add_game_values(ki_user, {4: energy_role_exp}) context.result['mc'] = MsgCode['MissionEnterSucc']
def past(context): """副本结算 Args: mission_id 副本ID star 获得星星数量 """ ki_user = context.user mission_id = context.get_parameter("mission_id") star = context.get_parameter("star") if not _check_module_open(mission_id, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return if star < 0 or star > 3: context.result['mc'] = MsgCode['ParamIllegal'] return extra = ki_user.mission.extra_data if extra["last_mission"] != mission_id: context.result['mc'] = MsgCode['MissionNotIn'] return # ========= 检测完毕 ============ # 获得物品 cfg = game_config.mission_base_cfg.get(mission_id) # 随机获得物品数量 awards_num = common_helper.weight_random(cfg["awards_num"]) awards_pack_list = mission_helper.random_mission_award(cfg["awards_lib"], awards_num) awards = [game_config.item_pack_cfg.get(pack_id) for pack_id in awards_pack_list] # 扣除其余体力 energy_role_exp = cfg["energy"] / 3 * 2 # 增加玩家经验 user_logic.consume_game_values1(ki_user, energy=energy_role_exp) user_logic.add_game_values(ki_user, {4: energy_role_exp, 1: cfg["gold"]}) heros = [hero_id for hero_id in ki_user.array.mission if hero_id] hero_logic.hero_add_exp(ki_user, heros, cfg["hero_exp"]) is_first_pass = mission_id not in ki_user.mission.missions # 第一次通关送机甲碎片和钻石 if is_first_pass: awards.append(cfg["chips"]) awards.append(cfg["diamonds"]) pack_logic.add_items(ki_user, common_helper.handle_pack_items(awards)) # 【日志统计】玩家副本通关进度 try: if is_first_pass: stat_service.mission(ki_user, mission_id, cfg["type"]) except Exception,e: logging.error(e)
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']
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']
def add_items(user, items): """新增道具 Args: user 用户对象 items 道具字典, eg: {71001:2, 71003:3} """ # 类似金币,钻石,经验,vip经验,荣誉等特殊道具类型,特殊添加处理 special_items = {} normal_items = {} heros = [] for item_id, num in items.iteritems(): if item_id in static_const.SPECIAL_ITEMS_LIST: special_items[item_id] = num elif item_id in game_config.hero_base_cfg: heros.append({item_id: num}) else: normal_items[item_id] = num if heros: import apps.logics.hero as hero_logic hero_logic.add_heros(user, heros) if special_items: user_logic.add_game_values(user, special_items) if normal_items: broadcast_list = [] for k, v in normal_items.iteritems(): if int(k) in game_config.item_cfg: user.package.add(k, v) if game_config.item_cfg[k]["broadcast"]: broadcast_list.append(k) # 炫耀觉醒碎片 try: for item_id in broadcast_list: trigger = {'uid': user.uid, 'name': user.name} NoticeService.broadcast(user.sid, 19, trigger, item_id) except: logging.error("【武器觉醒碎片】炫耀广播发生错误。") user.package.put()
def add_items(user, items): """新增道具 Args: user 用户对象 items 道具字典, eg: {71001:2, 71003:3} """ # 类似金币,钻石,经验,vip经验,荣誉等特殊道具类型,特殊添加处理 special_items = {} normal_items = {} heros = [] for item_id, num in items.iteritems(): if item_id in static_const.SPECIAL_ITEMS_LIST: special_items[item_id] = num elif item_id in game_config.hero_base_cfg: heros.append({item_id: num}) else: normal_items[item_id] = num if heros: import apps.logics.hero as hero_logic hero_logic.add_heros(user, heros) if special_items: user_logic.add_game_values(user, special_items) if normal_items: broadcast_list = [] for k,v in normal_items.iteritems(): if int(k) in game_config.item_cfg: user.package.add(k, v) if game_config.item_cfg[k]["broadcast"]: broadcast_list.append(k) # 炫耀觉醒碎片 try: for item_id in broadcast_list: trigger = {'uid': user.uid, 'name': user.name} NoticeService.broadcast(user.sid, 19, trigger, item_id) except: logging.error("【武器觉醒碎片】炫耀广播发生错误。") user.package.put()
def post(self): request_context = self.request.request_context method = request_context.get_parameter("method", "") result = {"mc": 100} if method == "add_game_value": items = request_context.get_parameter("items").strip() user_logic.add_game_values(request_context.user, eval(items)) elif method == "reset_user_data": module = request_context.get_parameter("module").strip() debug_handle_reset_user_data(request_context.user, module) elif method == "add_items": items = request_context.get_parameter("items").strip() debug_handle_add_items(request_context.user, items) elif method == "send_mails": receiver = request_context.get_parameter("receiver").strip() title = request_context.get_parameter("title").strip() sender = request_context.get_parameter("sender").strip() msg = request_context.get_parameter("msg").strip() attachments = request_context.get_parameter("attachments").strip() attachments = eval(attachments) if not isinstance(attachments, dict): raise 1 from apps.services.mail import MailService MailService.send_system([receiver], title, sender, msg, attachments) else: result = {"mc": 404} self.write(json_encode(result))
def hangup(context): """挂机扫荡 Args: mission_id 扫荡目标副本ID htimes 扫荡次数 """ ki_user = context.user mission_id = context.get_parameter("mission_id") htimes = context.get_parameter("htimes") cfg = game_config.mission_base_cfg.get(mission_id) if (not cfg) or (cfg["type"] not in [MISSION_TYPE_PT, MISSION_TYPE_JY]) or \ (htimes > 10) or (htimes <= 0): context.result['mc'] = MsgCode['ParamIllegal'] return if not _check_module_open(mission_id, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if htimes > 1 and not vip_cfg["open_ten_hangup"]: context.result['mc'] = MsgCode['UserVipTooLow'] return need_energy = cfg["energy"] * htimes if not user_logic.check_game_values1(ki_user, energy=need_energy): context.result['mc'] = MsgCode['MissionEnergyNotEnough'] return mdata = ki_user.mission.get_mission_by_id(mission_id) if not mdata or mdata["star"] != 3: context.result['mc'] = MsgCode['MissionStarNotEnough'] return if cfg["type"] in [MISSION_TYPE_JY]: mission_daily_data = ki_user.daily_info.mission_info daily = mission_daily_data.get(mission_id, {}) used_times = 0 if not daily else daily["past_times"] if used_times + htimes > cfg["daily_limit"]: context.result['mc'] = MsgCode['MissionTimesError'] return # 计算收获 total_awards = {} _total_awards = [] show_mystery_shop = 0 for i in xrange(htimes): # 副本正常掉落 _awards_num = common_helper.weight_random(cfg["awards_num"]) _awards1 = mission_helper.random_mission_award(cfg["awards_lib"], _awards_num) # 副本扫荡额外掉落 _awards2 = [] for award in cfg["hangup_awards_lib"]: rate = cfg["hangup_awards_lib"][award] if random.random() <= rate: _awards2.append(award) for pack in _awards1 + _awards2: _total_awards.append(game_config.item_pack_cfg.get(pack)) if not show_mystery_shop: show_mystery_shop = random_mystery_shop(ki_user.mall.mystery) total_awards[i+1] = {} total_awards[i+1]["normal"] = _awards1 total_awards[i+1]["extra"] = _awards2 user_logic.consume_game_values1(ki_user, energy=need_energy) # 扣除体力 pack_logic.add_items(ki_user, common_helper.handle_pack_items(_total_awards)) # 增加物品 user_logic.add_game_values(ki_user, {4: need_energy, 1: htimes * cfg["gold"]}) # 加经验,金币 # 更新运维活动数据 act_helper.update_after_hangup_mission(ki_user, mission_id, htimes) # 精英和噩梦副本进入每日数据统计 if cfg["type"] in [MISSION_TYPE_JY]: handle_daily_data(ki_user, mission_id, htimes) # 刷新随机商店物品 if show_mystery_shop: show_mystery_time = mall_logic.refresh_mission_mystery_shop(ki_user) else: show_mystery_time = 0 context.result["data"] = {} context.result["data"]["mystery_shop"] = {"show": show_mystery_shop, "time": show_mystery_time} context.result["data"]["goods"] = total_awards