def express_buy(context): """快捷购买通道 Args: item_id item_num Returns: """ ki_user = context.user item_id = context.get_parameter("item_id") item_num = context.get_parameter("item_num") if item_num < 0 or item_num > 100: context.result['mc'] = MsgCode['ParamIllegal'] return cfg = game_config.item_cfg.get(item_id) if ki_user.game_info.role_level < cfg["need_level"]: context.result['mc'] = MsgCode['UserLevelTooLow'] return need_diamond = cfg["buy_price"] * item_num if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=need_diamond) add_items(ki_user, {item_id: item_num}) context.result["mc"] = MsgCode['PackageExpressBuySucc']
def buy_level_fund(context): """等级基金 基金达到指定等级返利 """ ki_user = context.user act_id = context.get_parameter("act_id") server_acts = act_helper.get_active_acts(ki_user.sid, ki_user.game_info.role_level) if act_id not in server_acts: context.result['mc'] = MsgCode['ActAlreadyFinish'] return act_data = ki_user.activity.get_act_data(act_id) if not act_data: context.result['mc'] = MsgCode['ActNotExist'] return if act_data["data"] == LEVEL_FUND_STATE_ACTIVE: context.result['mc'] = MsgCode['ActLevelFundAlreadyActive'] return if not user_logic.check_game_values1(ki_user, diamond=LEVEL_FUND_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=LEVEL_FUND_DIAMOND) act_helper.update_after_buy_level_fund(ki_user, LEVEL_FUND_STATE_ACTIVE) context.result["mc"] = MsgCode['ActBuyLevelFundSucc']
def cleancd(context): """清除CD """ ki_user = context.user alive = BossService.alive(ki_user.sid) if not alive: context.result['mc'] = MsgCode['BossEnd'] return if int(time.time()) > ki_user.daily_info.boss_last_fight + WORLD_BOSS_CD: context.result['mc'] = MsgCode['BossCleanCDFailed'] return if not user_logic.check_game_values1(ki_user, diamond=WORLD_BOSS_CLEAN_CD_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=WORLD_BOSS_CLEAN_CD_DIAMOND) # 扣款 ki_user.daily_info.boss_last_fight = 0 ki_user.daily_info.put() context.result['mc'] = MsgCode['BossCleanCDSucc']
def buy(context): """购买特权礼包 Args: index 与vip相对应 Returns: mc """ ki_user = context.user index = context.get_parameter("index") if index > ki_user.game_info.vip_level: context.result['mc'] = MsgCode['UserVipTooLow'] return # 只能买一次 if utils.bit_test(ki_user.vip.bought_gifts, index): context.result['mc'] = MsgCode['VipGiftAlreadyBought'] return cfg = game_config.vip_priv_cfg.get(index, {}) if not cfg: context.result['mc'] = MsgCode['VipGiftNotExist'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["priv_gift_price"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return ki_user.vip.buy(index) pack_logic.add_items(ki_user, cfg["priv_gift"]) user_logic.consume_game_values1(ki_user, diamond=cfg["priv_gift_price"]) context.result['mc'] = MsgCode['VipGiftBuySuccess']
def support(context): """支持昨日排行榜的玩家 """ ki_user = context.user now = int(time.strftime('%H%M')) if now >= WORLD_BOSS_START_TIME: context.result['mc'] = MsgCode['BossSupportEnd'] return if ki_user.daily_info.boss_supported: context.result['mc'] = MsgCode['BossSupportRepeated'] return if not user_logic.check_game_values1(ki_user, gold=WORLD_BOSS_SUPPORT_GOLD): context.result['mc'] = MsgCode['GoldNotEnough'] return uid = context.get_parameter("uid") result = BossService.support(ki_user.sid, uid, ki_user.uid) if not result: context.result['mc'] = MsgCode['BossSupportFailed'] return user_logic.consume_game_values1(ki_user, gold=WORLD_BOSS_SUPPORT_GOLD) # 扣款 ki_user.daily_info.boss_supported = uid ki_user.daily_info.put() context.result['mc'] = MsgCode['BossSupportSucc']
def encourage(context): """鼓舞 """ ki_user = context.user alive = BossService.alive(ki_user.sid) if not alive: context.result['mc'] = MsgCode['BossEnd'] return times = ki_user.daily_info.boss_encourage_times cfg = game_config.boss_encourage_cfg.get(times + 1, {}) if not cfg: context.result['mc'] = MsgCode['BossEncourageFailed'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=cfg["diamond"]) # 扣款 ki_user.daily_info.boss_encourage_times += 1 ki_user.daily_info.put() context.result['mc'] = MsgCode['BossEncourageSucc']
def divorce(context): """与机甲解除誓言 Args: hero_id 姬甲ID """ ki_user = context.user hero_id = context.get_parameter("hero_id") hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return # 是否已经许誓 if not hero["marry_id"]: context.result['mc'] = MsgCode['HeroFavorNoMarried'] return marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"]) if not user_logic.check_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"]) # 解除契约,戒指通过邮箱返还玩家 from apps.services.mail import MailService marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"]) MailService.send_game(ki_user.uid, 2000, [], marry_cfg["items"]) ki_user.hero.divorce(hero_id) # 解除契约 context.result['mc'] = MsgCode['HeroFavorDivorceSucc']
def support(context): """支持昨日排行榜的玩家 """ ki_user = context.user now = int(time.strftime('%H%M')) if now >= WORLD_BOSS_START_TIME: context.result['mc'] = MsgCode['BossSupportEnd'] return if ki_user.daily_info.boss_supported: context.result['mc'] = MsgCode['BossSupportRepeated'] return if not user_logic.check_game_values1(ki_user, gold=WORLD_BOSS_SUPPORT_GOLD): context.result['mc'] = MsgCode['GoldNotEnough'] return uid = context.get_parameter("uid") result = BossService.support(ki_user.sid, uid, ki_user.uid) if not result: context.result['mc'] = MsgCode['BossSupportFailed'] return user_logic.consume_game_values1(ki_user, gold=WORLD_BOSS_SUPPORT_GOLD) # 扣款 ki_user.daily_info.boss_supported = uid ki_user.daily_info.put() context.result['mc'] = MsgCode['BossSupportSucc']
def express_buy(context): """快捷购买通道 Args: item_id item_num Returns: """ ki_user = context.user item_id = context.get_parameter("item_id") item_num = context.get_parameter("item_num") if item_num < 0 or item_num > 100: context.result['mc'] = MsgCode['ParamIllegal'] return cfg = game_config.item_cfg.get(item_id) if ki_user.game_info.role_level < cfg["need_level"]: context.result['mc'] = MsgCode['UserLevelTooLow'] return need_diamond = cfg["buy_price"] * item_num if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=need_diamond) add_items(ki_user, {item_id: item_num}) context.result["mc"] = MsgCode['PackageExpressBuySucc']
def encourage(context): """鼓舞 """ ki_user = context.user alive = BossService.alive(ki_user.sid) if not alive: context.result['mc'] = MsgCode['BossEnd'] return times = ki_user.daily_info.boss_encourage_times cfg = game_config.boss_encourage_cfg.get(times+1, {}) if not cfg: context.result['mc'] = MsgCode['BossEncourageFailed'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=cfg["diamond"]) # 扣款 ki_user.daily_info.boss_encourage_times += 1 ki_user.daily_info.put() context.result['mc'] = MsgCode['BossEncourageSucc']
def intensify(context): """强化,升级 升级强化分为一键升级和普通升级 最后两个装备的强化的升级流程特殊 Args: hero_id position 装备部位 to_level 到达的等级 Raises: """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") to_level = context.get_parameter("to_level") if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return if position >= 5: context.result['mc'] = MsgCode['ParamIllegal'] return if equip_data[ "level"] >= to_level or to_level > game_config.equip_max_level: context.result['mc'] = MsgCode['ParamIllegal'] return equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"]) equip_quality_cfg = game_config.equip_upgrade_cfg.get( equip_quality_cfg_key) if to_level > equip_quality_cfg["equip_max_level"]: context.result['mc'] = MsgCode['EquipLvOverLimit'] return # 检查材料是否足够 gold = 0 for level in range(equip_data["level"] + 1, to_level + 1): cfg = game_config.equip_intensify_cfg["%s-%s" % (position, level)] gold += cfg["gold"] if not user_logic.check_game_values1(ki_user, gold=gold): context.result['mc'] = MsgCode['GoldNotEnough'] return ki_user.equip.intensify(hero_id, position, to_level) user_logic.consume_game_values1(ki_user, gold=gold) context.result['mc'] = MsgCode['EquipIntensifySucc']
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 intensify(context): """强化,升级 升级强化分为一键升级和普通升级 最后两个装备的强化的升级流程特殊 Args: hero_id position 装备部位 to_level 到达的等级 Raises: """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") to_level = context.get_parameter("to_level") if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return if position >= 5: context.result['mc'] = MsgCode['ParamIllegal'] return if equip_data["level"] >= to_level or to_level > game_config.equip_max_level: context.result['mc'] = MsgCode['ParamIllegal'] return equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"]) equip_quality_cfg = game_config.equip_upgrade_cfg.get(equip_quality_cfg_key) if to_level > equip_quality_cfg["equip_max_level"]: context.result['mc'] = MsgCode['EquipLvOverLimit'] return # 检查材料是否足够 gold = 0 for level in range(equip_data["level"]+1, to_level + 1): cfg = game_config.equip_intensify_cfg["%s-%s" % (position, level)] gold += cfg["gold"] if not user_logic.check_game_values1(ki_user, gold=gold): context.result['mc'] = MsgCode['GoldNotEnough'] return ki_user.equip.intensify(hero_id, position, to_level) user_logic.consume_game_values1(ki_user, gold=gold) context.result['mc'] = MsgCode['EquipIntensifySucc']
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 anti_weak(context): """降星 - 升星的逆操作 Args: hero_id position 装备部位 """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") if not _check_module_open(position, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return # 0星你降个鸡毛啊 if equip_data["star"] == 0: context.result['mc'] = MsgCode['ParamIllegal'] return cfg_key = "%s-%s" % (equip_data["equip_id"], equip_data["star"]) cfg = game_config.equip_weak_cfg.get(cfg_key) if not cfg: context.result['mc'] = MsgCode['GameConfigNotExist'] return # 检查消耗是否足够 need_diamond = 30 if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 返还材料 pack_logic.add_items(ki_user, cfg["material"]) ki_user.equip.anti_weak(hero_id, position) user_logic.consume_game_values1(ki_user, diamond=need_diamond) # 武器第一次觉醒时,更新该机甲的必杀技能, 如果1星降到0星,必杀技能被替换掉 if position == EQUIP_POSITION_WEAPON and equip_data["star"] == 0: from apps.logics import skill as skill_logic skill_logic.replace_bs_skill(ki_user, hero_id, False) context.result['mc'] = MsgCode['EquipAntiWeakSucc']
def anti_weak(context): """降星 - 升星的逆操作 Args: hero_id position 装备部位 """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") if not _check_module_open(position, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return # 0星你降个鸡毛啊 if equip_data["star"] == 0: context.result['mc'] = MsgCode['ParamIllegal'] return cfg_key = "%s-%s" % (equip_data["equip_id"], equip_data["star"]) cfg = game_config.equip_weak_cfg.get(cfg_key) if not cfg: context.result['mc'] = MsgCode['GameConfigNotExist'] return # 检查消耗是否足够 need_diamond = 30 if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 返还材料 pack_logic.add_items(ki_user, cfg["material"]) ki_user.equip.anti_weak(hero_id, position) user_logic.consume_game_values1(ki_user, diamond=need_diamond) # 武器第一次觉醒时,更新该机甲的必杀技能, 如果1星降到0星,必杀技能被替换掉 if position == EQUIP_POSITION_WEAPON and equip_data["star"] == 0: from apps.logics import skill as skill_logic skill_logic.replace_bs_skill(ki_user, hero_id, False) context.result['mc'] = MsgCode['EquipAntiWeakSucc']
def create(context): """创建公会 Args: name 社团名称 icon 社团徽章 Returns: """ ki_user = context.user name = context.get_parameter("name") icon = context.get_parameter("icon") if ki_user.group.group_id: context.result['mc'] = MsgCode['GroupAlreadyInGroup'] return # 检测等级 need_level = game_config.user_func_cfg.get(GROUP_CREATE_FUNC_ID) if need_level > ki_user.game_info.role_level: context.result['mc'] = MsgCode['UserLevelTooLow'] return # 检测花费 if not user_logic.check_game_values1(ki_user, diamond=GROUP_CREATE_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 检测名字重复 if name_service.check_name_repeated(name, 2): context.result['mc'] = MsgCode['GroupNameRepeated'] return # 扣除消耗 user_logic.consume_game_values1(ki_user, diamond=GROUP_CREATE_DIAMOND) # 创建公会 creater = {"uid": ki_user.uid, "name": ki_user.name} group_id = GroupService.create(ki_user.sid, name, icon, creater) # 更改自己的公会数据 ki_user.group.group_id = group_id ki_user.group.put() data = {} data["group_id"] = group_id context.result['data'] = data
def refresh(context): """刷新某个商店的物品 Args: mtype 商品类别 1-杂货 2-荣誉 3-试炼 4-社团 Returns: Raises: """ ki_user = context.user mtype = context.get_parameter("mtype") if mtype not in range(1, 5): context.result['mc'] = MsgCode['ParamIllegal'] return refresh_times = ki_user.daily_info.mall_refresh_times.get(mtype, 0) consume = refresh_times * REFRESH_CONSUME_DIAMOND_STEP + REFRESH_CONSUME_DIAMOND if not user_logic.check_game_values1(ki_user, diamond=consume): context.result['mc'] = MsgCode['DiamondNotEnough'] return info = None if mtype == MALL_MISC: info = ki_user.mall.misc elif mtype == MALL_HONOR: info = ki_user.mall.honor elif mtype == MALL_TRIAL: info = ki_user.mall.trial else: info = ki_user.mall.group cfg = game_config.mall_cfg[mtype] new_random_list = _handle_refresh_action(cfg, ki_user.game_info.role_level) user_logic.consume_game_values1(ki_user, diamond=consume) info["items"] = new_random_list info["bought"] = [] ki_user.mall.put() ki_user.daily_info.update_mall_refresh_times(mtype) context.result["data"] = {} context.result["data"]["items"] = new_random_list
def refresh(context): """刷新某个商店的物品 Args: mtype 商品类别 1-杂货 2-荣誉 3-试炼 4-社团 Returns: Raises: """ ki_user = context.user mtype = context.get_parameter("mtype") if mtype not in range(1,5): context.result['mc'] = MsgCode['ParamIllegal'] return refresh_times = ki_user.daily_info.mall_refresh_times.get(mtype, 0) consume = refresh_times * REFRESH_CONSUME_DIAMOND_STEP + REFRESH_CONSUME_DIAMOND if not user_logic.check_game_values1(ki_user, diamond=consume): context.result['mc'] = MsgCode['DiamondNotEnough'] return info = None if mtype == MALL_MISC: info = ki_user.mall.misc elif mtype == MALL_HONOR: info = ki_user.mall.honor elif mtype == MALL_TRIAL: info = ki_user.mall.trial else: info = ki_user.mall.group cfg = game_config.mall_cfg[mtype] new_random_list = _handle_refresh_action(cfg, ki_user.game_info.role_level) user_logic.consume_game_values1(ki_user, diamond=consume) info["items"] = new_random_list info["bought"] = [] ki_user.mall.put() ki_user.daily_info.update_mall_refresh_times(mtype) context.result["data"] = {} context.result["data"]["items"] = new_random_list
def create(context): """创建公会 Args: name 社团名称 icon 社团徽章 Returns: """ ki_user = context.user name = context.get_parameter("name") icon = context.get_parameter("icon") if ki_user.group.group_id: context.result['mc'] = MsgCode['GroupAlreadyInGroup'] return # 检测等级 need_level = game_config.user_func_cfg.get(GROUP_CREATE_FUNC_ID) if need_level > ki_user.game_info.role_level: context.result['mc'] = MsgCode['UserLevelTooLow'] return # 检测花费 if not user_logic.check_game_values1(ki_user, diamond=GROUP_CREATE_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 检测名字重复 if name_service.check_name_repeated(name, 2): context.result['mc'] = MsgCode['GroupNameRepeated'] return # 扣除消耗 user_logic.consume_game_values1(ki_user, diamond=GROUP_CREATE_DIAMOND) # 创建公会 creater = {"uid": ki_user.uid, "name": ki_user.name} group_id = GroupService.create(ki_user.sid, name, icon, creater) # 更改自己的公会数据 ki_user.group.group_id = group_id ki_user.group.put() data = {} data["group_id"] = group_id context.result['data'] = data
def reset(context): """重置精英副本次数 Args: mission_id 副本ID """ ki_user = context.user mission_id = context.get_parameter("mission_id") cfg = game_config.mission_base_cfg.get(mission_id, {}) if not cfg or cfg["type"] not in [MISSION_TYPE_JY, MISSION_TYPE_EM]: context.result['mc'] = MsgCode['MissionIllegal'] return if not _check_module_open(mission_id, ki_user.game_info.role_level): context.result['mc'] = MsgCode['UserModuleNotOpen'] return mission_daily_data = ki_user.daily_info.mission_info daily = mission_daily_data.get(mission_id, {}) if not daily or daily["past_times"] != cfg["daily_limit"]: context.result['mc'] = MsgCode['MissionTimesExist'] return vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if daily["reset_times"] >= vip_cfg["reset_mission_times"]: context.result['mc'] = MsgCode['MissionResetTimesEmpty'] return consume_cfg = game_config.user_buy_refresh_cfg.get(daily["reset_times"]+1) if not consume_cfg: last = max(game_config.user_buy_refresh_cfg.keys()) consume_cfg = game_config.user_buy_refresh_cfg.get(last) if not user_logic.check_game_values1(ki_user, diamond=consume_cfg["refresh_mission"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return # ========= 检测完毕 ============ user_logic.consume_game_values1(ki_user, diamond=consume_cfg["refresh_mission"]) ki_user.daily_info.reset_jy_mission(mission_id) context.result['mc'] = MsgCode['MissionResetSucc']
def intensify_skill(context): """战舰技能升级 Args: ship_id 战舰ID skill_id 战舰技能ID Returns: code 成功 | 失败 """ ki_user = context.user ship_id = context.get_parameter("ship_id") skill_id = context.get_parameter("skill_id") ship = ki_user.warship.get_warship_by_id(ship_id) if not ship: context.result['mc'] = MsgCode['WarshipNotExist'] return if skill_id not in ship["skills"]: context.result['mc'] = MsgCode['WarshipSkillUnlock'] return current_level = ship["skills"][skill_id] if current_level >= game_config.skill_max_level: context.result['mc'] = MsgCode['WarshipSkillLevelMax'] return base_cfg = game_config.skill_cfg.get(skill_id) cfg_key = "%s-%s" % (base_cfg["type"], current_level + 1) intensify_cfg = game_config.skill_intensify_cfg.get(cfg_key) # 检查材料是否足够 if not user_logic.check_game_values1(ki_user, gold=intensify_cfg["gold"]): context.result['mc'] = MsgCode['GoldNotEnough'] return user_logic.consume_game_values1(ki_user, gold=intensify_cfg["gold"]) ki_user.warship.intensify_skill(ship_id, skill_id) context.result['mc'] = MsgCode['WarshipSkillIntensifySucc']
def gamble(context): """钻石赌博 """ ki_user = context.user act_id = context.get_parameter("act_id") server_acts = act_helper.get_active_acts(ki_user.sid, ki_user.game_info.role_level) if act_id not in server_acts: context.result['mc'] = MsgCode['ActAlreadyFinish'] return act_data = ki_user.activity.get_act_data(act_id) if not act_data: context.result['mc'] = MsgCode['ActNotExist'] return if act_data["data"] >= max(game_config.activity_gamble_cfg): context.result['mc'] = MsgCode['ActGambleTimesUseUp'] return cfg = game_config.activity_gamble_cfg.get(act_data["data"] + 1) if not user_logic.check_game_values1(ki_user, diamond=cfg["need_diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return A = float("%.5f" % random.random()) B = pow((A - 0.5), 3) * cfg["arg_a"] + cfg["arg_b"] diamond = int((cfg["max"] - cfg["need_diamond"]) * B + cfg["need_diamond"]) # 需要扣除的部分 cosume_diamond = cfg["need_diamond"] - diamond user_logic.consume_game_values1(ki_user, diamond=cosume_diamond) act_helper.update_after_diamond_gamble(ki_user) try: record = {"id": ki_user.uid, "name": ki_user.name, "diamond": diamond} act_service.add_diamond_gamble_records(ki_user.sid, act_id, record) except: pass context.result["data"] = {} context.result["data"]["diamond"] = diamond
def refresh(context): """刷新当前对手数据 Args: Returns: tops 当前竞技场前十名数据 fighters 匹配到的4个对手数据 """ ki_user = context.user used_times = ki_user.arena.daily_refresh_times consume_cfg = game_config.user_buy_refresh_cfg.get(used_times + 1, {}) if not consume_cfg: last = max(game_config.user_buy_refresh_cfg.keys()) consume_cfg = game_config.user_buy_refresh_cfg.get(last) vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if (not consume_cfg) or (used_times >= vip_cfg["arena_refresh_times"]): context.result['mc'] = MsgCode['ArenaRefreshTimesUseUp'] return if not user_logic.check_game_values1(ki_user, diamond=consume_cfg["arena_refresh"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=consume_cfg["arena_refresh"]) rank = ArenaService.get_user_rank(ki_user.sid, ki_user.uid) fighters = ArenaService.match_fighters(ki_user.sid, ki_user.uid, rank, ki_user.arena.win_times) ki_user.arena.refresh(fighters) datas = {} datas["myrank"] = rank datas["fighters"] = fighters datas["tops"] = ArenaService.top_ten(ki_user.sid) context.result["data"] = datas
def open_box(context): """宝箱层,免费领取箱子里的道具 Args: Returns: """ ki_user = context.user process = ki_user.trial.daily_current_process _cfg = game_config.trial_cfg.get(process) if _cfg["type"] != PROCESS_BOX: context.result['mc'] = MsgCode['TrialWrongType'] return # 首次开箱子免费,奖品取现成的 loop_index = ki_user.trial.tmp_box_counter + 1 cfg = game_config.user_buy_refresh_cfg.get(loop_index) if not cfg: last = max(game_config.user_buy_refresh_cfg.keys()) cfg = game_config.user_buy_refresh_cfg.get(last) if not user_logic.check_game_values1(ki_user, diamond=cfg["trial_openbox_diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return if loop_index == 1: awards = ki_user.trial.daily_awards.get(process) act_helper.update_after_trial_process(ki_user, process) # 更新活动【通关试炼指定层数】 else: awards = random_awards(process, loop_index, ki_user.game_info.role_level) user_logic.consume_game_values1(ki_user, diamond=cfg["trial_openbox_diamond"]) pack_logic.add_items(ki_user, awards) # 加物品 # 更新这一层领取物品计数器 ki_user.trial.incr_award_counter() context.result["data"] = {} context.result["data"]["awards"] = awards
def unlock(context): """解锁训练槽 """ ki_user = context.user slot = context.get_parameter("slot") if not judge_open_train(ki_user.sid, ki_user.group.group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return slot_id = slot - 1 slot_state = ki_user.group.train_list[slot_id] if slot_state != -1: context.result['mc'] = MsgCode['GroupTrainSlotUnlocked'] return cfg = game_config.group_tra_cfg.get(slot, {}) if not cfg: context.result['mc'] = MsgCode['ParamIllegal'] return if cfg["open_level"] > ki_user.game_info.role_level: context.result['mc'] = MsgCode['UserLevelTooLow'] return if cfg["vip_level"] > ki_user.game_info.vip_level: context.result['mc'] = MsgCode['UserVipTooLow'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=cfg["diamond"]) # 扣款 ki_user.group.open_train_slot(slot_id) context.result['mc'] = MsgCode['GroupTrainSlotUnlockSucc']
def unlock(context): """解锁训练槽 """ ki_user = context.user slot = context.get_parameter("slot") if not judge_open_train(ki_user.sid, ki_user.group.group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return slot_id = slot - 1 slot_state = ki_user.group.train_list[slot_id] if slot_state != -1: context.result['mc'] = MsgCode['GroupTrainSlotUnlocked'] return cfg = game_config.group_tra_cfg.get(slot, {}) if not cfg: context.result['mc'] = MsgCode['ParamIllegal'] return if cfg["open_level"] > ki_user.game_info.role_level: context.result['mc'] = MsgCode['UserLevelTooLow'] return if cfg["vip_level"] > ki_user.game_info.vip_level: context.result['mc'] = MsgCode['UserVipTooLow'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["diamond"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=cfg["diamond"]) # 扣款 ki_user.group.open_train_slot(slot_id) context.result['mc'] = MsgCode['GroupTrainSlotUnlockSucc']
def refresh(context): """刷新当前对手数据 Args: Returns: tops 当前竞技场前十名数据 fighters 匹配到的4个对手数据 """ ki_user = context.user used_times = ki_user.arena.daily_refresh_times consume_cfg = game_config.user_buy_refresh_cfg.get(used_times + 1, {}) if not consume_cfg: last = max(game_config.user_buy_refresh_cfg.keys()) consume_cfg = game_config.user_buy_refresh_cfg.get(last) vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if (not consume_cfg) or (used_times >= vip_cfg["arena_refresh_times"]): context.result['mc'] = MsgCode['ArenaRefreshTimesUseUp'] return if not user_logic.check_game_values1(ki_user, diamond=consume_cfg["arena_refresh"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=consume_cfg["arena_refresh"]) rank = ArenaService.get_user_rank(ki_user.sid, ki_user.uid) fighters = ArenaService.match_fighters(ki_user.sid, ki_user.uid, rank, ki_user.arena.win_times) ki_user.arena.refresh(fighters) datas = {} datas["myrank"] = rank datas["fighters"] = fighters datas["tops"] = ArenaService.top_ten(ki_user.sid) context.result["data"] = datas
def add_times(context): """购买竞技场挑战次数 Args: Returns: mc """ ki_user = context.user add_times = ki_user.arena.daily_add_times consume_cfg = game_config.user_buy_refresh_cfg.get(add_times + 1, {}) if not consume_cfg: last = max(game_config.user_buy_refresh_cfg.keys()) consume_cfg = game_config.user_buy_refresh_cfg.get(last) vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if (not consume_cfg) or (add_times >= vip_cfg["arena_add_times"]): context.result['mc'] = MsgCode['ArenaAddTimesUseUp'] return total_times = ARENA_FIGHTING_DEFAULT_TIMES + ki_user.arena.daily_add_times if total_times > ki_user.arena.daily_challenge_times: context.result['mc'] = MsgCode['ArenaChallengeTimesExist'] return if not user_logic.check_game_values1( ki_user, diamond=consume_cfg["arena_add_times"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=consume_cfg["arena_add_times"]) ki_user.arena.add_times() context.result["mc"] = MsgCode['ArenaAddTimesSucc']
def clean_cd(context): """清除挑战CD Args: Returns: """ ki_user = context.user if not ki_user.arena.last_fight: context.result['mc'] = MsgCode['ArenaNotInCD'] return if not user_logic.check_game_values1(ki_user, diamond=ARENA_CLEAN_CD_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=ARENA_CLEAN_CD_DIAMOND) ki_user.arena.clean_cd() context.result["mc"] = MsgCode['ArenaCleanCDSucc']
def intensify2(context): """钻石强化升级战魂 Args: hero_id 姬甲ID spirit_id 战魂ID """ ki_user = context.user hero_id = context.get_parameter("hero_id") spirit_id = context.get_parameter("spirit_id") hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return spirit = ki_user.spirit.get_spirit(hero_id, spirit_id) if not spirit: context.result['mc'] = MsgCode['SpiritNotWeaken'] return lack_exp = 0 for exp, level in game_config.spirit_exp_level_cfg.items(): if level == spirit["level"]+1: lack_exp = exp - spirit["exp"] need_diamond = lack_exp * 5 # 检查材料是否足够 if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return ki_user.spirit.add_exp(hero_id, spirit_id, lack_exp) user_logic.consume_game_values1(ki_user, diamond=need_diamond) context.result['mc'] = MsgCode['SpiritLevelUpSucc']
def intensify2(context): """钻石强化升级战魂 Args: hero_id 姬甲ID spirit_id 战魂ID """ ki_user = context.user hero_id = context.get_parameter("hero_id") spirit_id = context.get_parameter("spirit_id") hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return spirit = ki_user.spirit.get_spirit(hero_id, spirit_id) if not spirit: context.result['mc'] = MsgCode['SpiritNotWeaken'] return lack_exp = 0 for exp, level in game_config.spirit_exp_level_cfg.items(): if level == spirit["level"] + 1: lack_exp = exp - spirit["exp"] need_diamond = lack_exp * 5 # 检查材料是否足够 if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return ki_user.spirit.add_exp(hero_id, spirit_id, lack_exp) user_logic.consume_game_values1(ki_user, diamond=need_diamond) context.result['mc'] = MsgCode['SpiritLevelUpSucc']
def cleancd(context): """清除CD """ ki_user = context.user alive = BossService.alive(ki_user.sid) if not alive: context.result['mc'] = MsgCode['BossEnd'] return if int(time.time()) > ki_user.daily_info.boss_last_fight + WORLD_BOSS_CD: context.result['mc'] = MsgCode['BossCleanCDFailed'] return if not user_logic.check_game_values1(ki_user, diamond=WORLD_BOSS_CLEAN_CD_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return user_logic.consume_game_values1(ki_user, diamond=WORLD_BOSS_CLEAN_CD_DIAMOND) # 扣款 ki_user.daily_info.boss_last_fight = 0 ki_user.daily_info.put() context.result['mc'] = MsgCode['BossCleanCDSucc']
def buy(context): """购买特权礼包 Args: index 与vip相对应 Returns: mc """ ki_user = context.user index = context.get_parameter("index") if index > ki_user.game_info.vip_level: context.result['mc'] = MsgCode['UserVipTooLow'] return # 只能买一次 if utils.bit_test(ki_user.vip.bought_gifts, index): context.result['mc'] = MsgCode['VipGiftAlreadyBought'] return cfg = game_config.vip_priv_cfg.get(index, {}) if not cfg: context.result['mc'] = MsgCode['VipGiftNotExist'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["priv_gift_price"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return ki_user.vip.buy(index) pack_logic.add_items(ki_user, cfg["priv_gift"]) user_logic.consume_game_values1(ki_user, diamond=cfg["priv_gift_price"]) context.result['mc'] = MsgCode['VipGiftBuySuccess']
def add_times(context): """购买竞技场挑战次数 Args: Returns: mc """ ki_user = context.user add_times = ki_user.arena.daily_add_times consume_cfg = game_config.user_buy_refresh_cfg.get(add_times + 1, {}) if not consume_cfg: last = max(game_config.user_buy_refresh_cfg.keys()) consume_cfg = game_config.user_buy_refresh_cfg.get(last) vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level) if (not consume_cfg) or (add_times >= vip_cfg["arena_add_times"]): context.result['mc'] = MsgCode['ArenaAddTimesUseUp'] return total_times = ARENA_FIGHTING_DEFAULT_TIMES + ki_user.arena.daily_add_times if total_times > ki_user.arena.daily_challenge_times: context.result['mc'] = MsgCode['ArenaChallengeTimesExist'] return if not user_logic.check_game_values1(ki_user, diamond=consume_cfg["arena_add_times"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=consume_cfg["arena_add_times"]) ki_user.arena.add_times() context.result["mc"] = MsgCode['ArenaAddTimesSucc']
def clean_cd(context): """清除挑战CD Args: Returns: """ ki_user = context.user if not ki_user.arena.last_fight: context.result['mc'] = MsgCode['ArenaNotInCD'] return if not user_logic.check_game_values1(ki_user, diamond=ARENA_CLEAN_CD_DIAMOND): context.result['mc'] = MsgCode['DiamondNotEnough'] return # 扣除消耗钻石 user_logic.consume_game_values1(ki_user, diamond=ARENA_CLEAN_CD_DIAMOND) ki_user.arena.clean_cd() context.result["mc"] = MsgCode['ArenaCleanCDSucc']
def game_tiger(context): """【公会游戏之老虎机】 Args: type 操作类型 1-投掷 2-改投 3-领取 Returns: """ ki_user = context.user action_type = context.get_parameter("type") if action_type not in [1,2,3]: context.result['mc'] = MsgCode['ParamIllegal'] return group_id = ki_user.group.group_id if not group_id: context.result['mc'] = MsgCode['GroupHaveNoGroup'] return data = {} group_daily_data = ki_user.daily_info.group_info if action_type == 1: max_times = get_game_max_times(1, ki_user.group.donate["tiger_exp1"]) if group_daily_data["tiger_time1"] >= max_times: context.result['mc'] = MsgCode['GroupGameTigerTimesUseUp'] return # 如果之前的还没领取,不能直接参与 if ki_user.group.game_data["tiger_points"] != -1: context.result['mc'] = MsgCode['GroupGameTigerAlreayIn'] return point = random_tiger_point(0) ki_user.group.tiger_update(point, 0) data["point"] = point elif action_type == 2: # 都还没投掷,改个毛线 if ki_user.group.game_data["tiger_points"] == -1: context.result['mc'] = MsgCode['GroupGameTigerNotIn'] return # 都已经满了 改个毛线 if ki_user.group.game_data["tiger_points"] == 5: context.result['mc'] = MsgCode['GroupGameTigerFull'] return max_free_times = get_game_max_times(2, ki_user.group.donate["tiger_exp2"]) # 免费的已经用完,可以花钻石改投 need_diamond = 0 if group_daily_data["tiger_time2"] >= max_free_times: # 检测花费 not_free_times = ki_user.group.game_data["tiger_change_times"]+1 need_diamond = game_config.user_buy_refresh_cfg[not_free_times]["group_game_tiger_refresh"] if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return point = random_tiger_point(ki_user.group.game_data["tiger_points"]) if need_diamond: user_logic.consume_game_values1(ki_user, diamond=need_diamond) ki_user.group.tiger_update(point, ki_user.group.game_data["tiger_change_times"]+1) # 花了钱的 else: ki_user.group.tiger_update(point, ki_user.group.game_data["tiger_change_times"]) ki_user.daily_info.group_update("tiger_time2") data["point"] = point elif action_type == 3: point = ki_user.group.game_data["tiger_points"] if point == -1: context.result['mc'] = MsgCode['GroupGameTigerNotIn'] return awards = game_config.group_game_tiger_awards_cfg[point] pack_logic.add_items(ki_user, awards) ki_user.group.tiger_update(-1, 0) ki_user.daily_info.group_update("tiger_time1") # 进入排行榜 GroupService.update_game_tiger_rank(ki_user.sid, ki_user.uid, ki_user.group.group_id, point) if point == 5: GroupService.create_group_log(ki_user.sid, group_id, GROUP_LOG_TYPE_GAME_TIGER, ki_user.uid, ki_user.name, int(time.time()), point) else: pass context.result['mc'] = MsgCode['GroupGameTigerSucc'] context.result['data'] = data
def send(context): """发送聊天 Args: ctype: 聊天类型 1 - 世界 2 - 公会 3 - 公告 4 - 私聊 (公告不能发) msg: 聊天内容 receiver: 私聊时,传接收消息的玩家uid Returns: mc """ ki_user = context.user ctype = context.get_parameter("ctype") msg = context.get_parameter("msg") receiver = context.get_parameter("receiver") if ctype not in [ CHAT_CHANNEL_WORLD, CHAT_CHANNEL_GROUP, CHAT_CHANNEL_PRIVATE ]: context.result["mc"] = MsgCode["ParamIllegal"] return if ctype == CHAT_CHANNEL_WORLD: if ki_user.ext_info.ban_chat and ki_user.ext_info.ban_chat > int( time.time()): context.result["mc"] = MsgCode["InvalidOperation"] return used_times = ki_user.daily_info.world_chat_times vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level, {}) if used_times >= vip_cfg[ "daily_world_chat_times"] and not user_logic.check_game_values1( ki_user, diamond=WORLD_CHAT_EXTRA_DIAMOND): context.result["mc"] = MsgCode["DiamondNotEnough"] return elif ctype == CHAT_CHANNEL_GROUP and ki_user.group.group_id == 0: context.result["mc"] = MsgCode["UserHasNoGroup"] return elif ctype == CHAT_CHANNEL_PRIVATE and int(receiver) == 0: context.result["mc"] = MsgCode["ChatPrivateTargetEmpty"] return elif ctype == CHAT_CHANNEL_PRIVATE and str(receiver) == ki_user.uid: context.result["mc"] = MsgCode["ChatCantToSelf"] return else: pass sender = {} sender["uid"] = ki_user.uid sender["avatar"] = ki_user.avatar sender["name"] = ki_user.name sender["level"] = ki_user.game_info.role_level msg = gfw.replace(msg) if ctype != CHAT_CHANNEL_PRIVATE: ChatService.send(ki_user.sid, ctype, msg, sender, ki_user.group.group_id) else: ChatService.send(ki_user.sid, ctype, msg, sender, ki_user.group.group_id, receiver) if ctype == CHAT_CHANNEL_WORLD: ki_user.daily_info.world_chat_times += 1 ki_user.daily_info.put() if ki_user.daily_info.world_chat_times > vip_cfg[ "daily_world_chat_times"]: user_logic.consume_game_values1(ki_user, diamond=WORLD_CHAT_EXTRA_DIAMOND) context.result["mc"] = MsgCode["ChatSendMsgSucc"]
def game_tiger(context): """【公会游戏之老虎机】 Args: type 操作类型 1-投掷 2-改投 3-领取 Returns: """ ki_user = context.user action_type = context.get_parameter("type") if action_type not in [1, 2, 3]: context.result['mc'] = MsgCode['ParamIllegal'] return group_id = ki_user.group.group_id if not group_id: context.result['mc'] = MsgCode['GroupHaveNoGroup'] return data = {} group_daily_data = ki_user.daily_info.group_info if action_type == 1: max_times = get_game_max_times(1, ki_user.group.donate["tiger_exp1"]) if group_daily_data["tiger_time1"] >= max_times: context.result['mc'] = MsgCode['GroupGameTigerTimesUseUp'] return # 如果之前的还没领取,不能直接参与 if ki_user.group.game_data["tiger_points"] != -1: context.result['mc'] = MsgCode['GroupGameTigerAlreayIn'] return point = random_tiger_point(0) ki_user.group.tiger_update(point, 0) data["point"] = point elif action_type == 2: # 都还没投掷,改个毛线 if ki_user.group.game_data["tiger_points"] == -1: context.result['mc'] = MsgCode['GroupGameTigerNotIn'] return # 都已经满了 改个毛线 if ki_user.group.game_data["tiger_points"] == 5: context.result['mc'] = MsgCode['GroupGameTigerFull'] return max_free_times = get_game_max_times(2, ki_user.group.donate["tiger_exp2"]) # 免费的已经用完,可以花钻石改投 need_diamond = 0 if group_daily_data["tiger_time2"] >= max_free_times: # 检测花费 not_free_times = ki_user.group.game_data["tiger_change_times"] + 1 need_diamond = game_config.user_buy_refresh_cfg[not_free_times][ "group_game_tiger_refresh"] if not user_logic.check_game_values1(ki_user, diamond=need_diamond): context.result['mc'] = MsgCode['DiamondNotEnough'] return point = random_tiger_point(ki_user.group.game_data["tiger_points"]) if need_diamond: user_logic.consume_game_values1(ki_user, diamond=need_diamond) ki_user.group.tiger_update( point, ki_user.group.game_data["tiger_change_times"] + 1) # 花了钱的 else: ki_user.group.tiger_update( point, ki_user.group.game_data["tiger_change_times"]) ki_user.daily_info.group_update("tiger_time2") data["point"] = point elif action_type == 3: point = ki_user.group.game_data["tiger_points"] if point == -1: context.result['mc'] = MsgCode['GroupGameTigerNotIn'] return awards = game_config.group_game_tiger_awards_cfg[point] pack_logic.add_items(ki_user, awards) ki_user.group.tiger_update(-1, 0) ki_user.daily_info.group_update("tiger_time1") # 进入排行榜 GroupService.update_game_tiger_rank(ki_user.sid, ki_user.uid, ki_user.group.group_id, point) if point == 5: GroupService.create_group_log(ki_user.sid, group_id, GROUP_LOG_TYPE_GAME_TIGER, ki_user.uid, ki_user.name, int(time.time()), point) else: pass context.result['mc'] = MsgCode['GroupGameTigerSucc'] context.result['data'] = data
def award(context): """活动领奖 Args: act_id 活动ID index 奖项编号 Returns: mc """ ki_user = context.user act_id = context.get_parameter("act_id") index = context.get_parameter("index") if index <= 0: context.result['mc'] = MsgCode['ParamIllegal'] return act_data = ki_user.activity.get_act_data(act_id) if not act_data: context.result['mc'] = MsgCode['ActNotExist'] return server_acts = act_helper.get_active_acts(ki_user.sid, ki_user.game_info.role_level) if act_id not in server_acts: context.result['mc'] = MsgCode['ActAlreadyFinish'] return if act_helper.check_award_repeat(act_id, act_data, index): context.result['mc'] = MsgCode['ActAlreadyAwarded'] return cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, index)) main_cfg = game_config.activity_cfg.get(act_id) if (not main_cfg) or (not cfg): context.result['mc'] = MsgCode['ActAwardFail'] return if main_cfg["type"] in act_helper.SPECIAL_ACTS1: func = getattr(act_helper, 'act_checker_%s' % main_cfg["type"]) # 等级基金未激活 if main_cfg["type"] in act_helper.LEVEL_FUND_ACT and act_data["data"] != LEVEL_FUND_STATE_ACTIVE: context.result['mc'] = MsgCode['ActAwardNotSatisfied'] return if not func(ki_user, cfg): context.result['mc'] = MsgCode['ActAwardNotSatisfied'] return else: if not act_helper.check_award_can_get(act_id, act_data, index): context.result['mc'] = MsgCode['ActAwardNotSatisfied'] return if main_cfg["type"] in act_helper.PRIVATE_SALE_ACT: # 每周特卖活动,检测 物品存量是否足够 元宝是否足够 saled_num = act_service.get_private_sale_num(ki_user.sid, act_id, index) if saled_num >= cfg["cond_c"]: context.result['mc'] = MsgCode['ActAwardEmpty'] return if not user_logic.check_game_values1(ki_user, diamond=cfg["cond_e"]): context.result['mc'] = MsgCode['DiamondNotEnough'] return if ki_user.game_info.vip_level < cfg["cond_b"]: context.result['mc'] = MsgCode['UserVipTooLow'] return act_service.update_private_sale_num(ki_user.sid, act_id, index) user_logic.consume_game_values1(ki_user, diamond=cfg["cond_e"]) # 扣款 pack_logic.add_items(ki_user, cfg["awards"]) old_data = copy.deepcopy(act_data) new_data = act_helper.update_after_award(act_id, old_data, index) ki_user.activity.update_after_award(act_id, new_data) # 处理相关任务 if main_cfg["union"]: act_helper.update_union_acts(ki_user, main_cfg["union"], 1) context.result['mc'] = MsgCode['ActAwardSucc']
def intensify(context): """升级技能 技能等级受机甲等级限制 Args: hero_id 机甲ID skill_id 技能ID Returns: """ ki_user = context.user hero_id = context.get_parameter("hero_id") skill_id = context.get_parameter("skill_id") level = context.get_parameter("level") if level not in range(1, 101): context.result['mc'] = MsgCode['ParamIllegal'] return hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return skills = ki_user.skill.get_skills_by_hero_id(hero_id) if skill_id not in skills: context.result['mc'] = MsgCode['SkillNotWeaken'] return if skills[skill_id] + level > hero["level"]: context.result['mc'] = MsgCode['SkillLevelMax'] return consume = {1: 0, 9: 0} current_level = skills[skill_id] base_cfg = game_config.skill_cfg.get(skill_id) for i in range(current_level + 1, current_level + level + 1): level_cfg = game_config.skill_intensify_cfg.get("%s-%s" % (base_cfg["type"], i)) if not level_cfg: context.result['mc'] = MsgCode['SkillLevelFull'] return else: consume[1] += level_cfg["gold"] consume[9] += level_cfg["skill_point"] # 检查金币是否足够 if not user_logic.check_game_values1(ki_user, gold=consume[1]): context.result['mc'] = MsgCode['GoldNotEnough'] return # 检查技能点是否足够 if not user_logic.check_game_values1(ki_user, skill_point=consume[9]): context.result['mc'] = MsgCode['SkillPointNotEnough'] return user_logic.consume_game_values1(ki_user, gold=consume[1], current_skill_point=consume[9]) ki_user.skill.intensify(hero_id, skill_id, level) context.result['mc'] = MsgCode['SkillLevelUpSucc']
def intensify(context): """强化升级战魂 Args: hero_id 姬甲ID spirit_id 战魂ID items 物品列表 {item_id: item_num, } """ ki_user = context.user hero_id = context.get_parameter("hero_id") spirit_id = context.get_parameter("spirit_id") items = context.get_parameter("items", "{}") try: items = eval(items) if not isinstance(items, dict): raise 1 for v in items.values(): if v <= 0: raise e except: context.result['mc'] = MsgCode['ParamIllegal'] return hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return spirit = ki_user.spirit.get_spirit(hero_id, spirit_id) if not spirit: context.result['mc'] = MsgCode['SpiritNotWeaken'] return if spirit["level"] >= max(game_config.spirit_exp_level_cfg.values()): context.result['mc'] = MsgCode['SpiritLevelMax'] return total_exp = 0 for item_id, num in items.items(): item_cfg = game_config.item_cfg.get(item_id) if not item_cfg["spirit_exp"]: context.result['mc'] = MsgCode['ParamIllegal'] return else: total_exp += item_cfg["spirit_exp"] * num need_gold = total_exp * SPIRIT_EXP_PRICE # 检查金币是否足够 if not user_logic.check_game_values1(ki_user, gold=need_gold): context.result['mc'] = MsgCode['GoldNotEnough'] return if not total_exp: context.result['mc'] = MsgCode['InvalidOperation'] return pack_logic.remove_items(ki_user, items) # 扣除物品 user_logic.consume_game_values1(ki_user, gold=need_gold) # 扣除金币 ki_user.spirit.add_exp(hero_id, spirit_id, total_exp) # 添加经验 context.result['mc'] = MsgCode['SpiritLevelUpSucc']
def intensify(context): """强化升级战魂 Args: hero_id 姬甲ID spirit_id 战魂ID items 物品列表 {item_id: item_num, } """ ki_user = context.user hero_id = context.get_parameter("hero_id") spirit_id = context.get_parameter("spirit_id") items = context.get_parameter("items", "{}") try: items = eval(items) if not isinstance(items, dict): raise 1 for v in items.values(): if v <= 0: raise e except: context.result['mc'] = MsgCode['ParamIllegal'] return hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return spirit = ki_user.spirit.get_spirit(hero_id, spirit_id) if not spirit: context.result['mc'] = MsgCode['SpiritNotWeaken'] return if spirit["level"] >= max(game_config.spirit_exp_level_cfg.values()): context.result['mc'] = MsgCode['SpiritLevelMax'] return total_exp = 0 for item_id, num in items.items(): item_cfg = game_config.item_cfg.get(item_id) if not item_cfg["spirit_exp"]: context.result['mc'] = MsgCode['ParamIllegal'] return else: total_exp += item_cfg["spirit_exp"] * num need_gold = total_exp * SPIRIT_EXP_PRICE # 检查金币是否足够 if not user_logic.check_game_values1(ki_user, gold=need_gold): context.result['mc'] = MsgCode['GoldNotEnough'] return if not total_exp: context.result['mc'] = MsgCode['InvalidOperation'] return pack_logic.remove_items(ki_user, items) # 扣除物品 user_logic.consume_game_values1(ki_user, gold=need_gold) # 扣除金币 ki_user.spirit.add_exp(hero_id, spirit_id, total_exp) # 添加经验 context.result['mc'] = MsgCode['SpiritLevelUpSucc']
def intensify2(context): """两特殊装备加经验 Args: hero_id position 装备部位 items 经验道具 [] Raises: """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") items = context.get_parameter("items", []) try: items = eval(items) if not isinstance(items, list): raise 1 if position < 5: context.result['mc'] = MsgCode['ParamIllegal'] return except: context.result['mc'] = MsgCode['ParamIllegal'] return if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"]) equip_quality_cfg = game_config.equip_upgrade_cfg.get( equip_quality_cfg_key) if equip_data["level"] > equip_quality_cfg["equip_max_level"]: context.result['mc'] = MsgCode['EquipLvOverLimit'] return add_exp = 0 exp_item_type = SPECIAL_EQUIP_EXP_ITEM_1 if position == 5 else SPECIAL_EQUIP_EXP_ITEM_2 # 检查材料是否足够 items = pack_logic.amend_goods([{ item_id: 1 } for item_id in items if item_id]) if not pack_logic.check_items_enough(ki_user, items): context.result['mc'] = MsgCode['PackageItemNotEnough'] return for item_id, num in items.items(): item_cfg = game_config.item_cfg.get(item_id) if not item_cfg: context.result['mc'] = MsgCode['GameConfigNotExist'] return if item_cfg["type"] != exp_item_type: context.result['mc'] = MsgCode['ParamIllegal'] return add_exp += item_cfg["effect_value"] * num total_exp = equip_data["exp"] + add_exp if not user_logic.check_game_values1(ki_user, gold=add_exp * 50): context.result['mc'] = MsgCode['GoldNotEnough'] return level = level_checker(position, equip_data["quality"], total_exp) ki_user.equip.intensify(hero_id, position, level, total_exp) if items: pack_logic.remove_items(ki_user, items) user_logic.consume_game_values1(ki_user, gold=add_exp * 50) context.result['mc'] = MsgCode['EquipIntensifySucc']
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
def intensify(context): """升级技能 技能等级受机甲等级限制 Args: hero_id 机甲ID skill_id 技能ID Returns: """ ki_user = context.user hero_id = context.get_parameter("hero_id") skill_id = context.get_parameter("skill_id") level = context.get_parameter("level") if level not in range(1,101): context.result['mc'] = MsgCode['ParamIllegal'] return hero = ki_user.hero.get_by_hero_id(hero_id) if not hero: context.result['mc'] = MsgCode['HeroNotExist'] return skills = ki_user.skill.get_skills_by_hero_id(hero_id) if skill_id not in skills: context.result['mc'] = MsgCode['SkillNotWeaken'] return if skills[skill_id]+level > hero["level"]: context.result['mc'] = MsgCode['SkillLevelMax'] return consume = {1:0, 9:0} current_level = skills[skill_id] base_cfg = game_config.skill_cfg.get(skill_id) for i in range(current_level+1, current_level+level+1): level_cfg = game_config.skill_intensify_cfg.get("%s-%s" % (base_cfg["type"], i)) if not level_cfg: context.result['mc'] = MsgCode['SkillLevelFull'] return else: consume[1] += level_cfg["gold"] consume[9] += level_cfg["skill_point"] # 检查金币是否足够 if not user_logic.check_game_values1(ki_user, gold=consume[1]): context.result['mc'] = MsgCode['GoldNotEnough'] return # 检查技能点是否足够 if not user_logic.check_game_values1(ki_user, skill_point=consume[9]): context.result['mc'] = MsgCode['SkillPointNotEnough'] return user_logic.consume_game_values1(ki_user, gold=consume[1], current_skill_point=consume[9]) ki_user.skill.intensify(hero_id, skill_id, level) context.result['mc'] = MsgCode['SkillLevelUpSucc']
def intensify2(context): """两特殊装备加经验 Args: hero_id position 装备部位 items 经验道具 [] Raises: """ ki_user = context.user hero_id = context.get_parameter("hero_id") position = context.get_parameter("position") items = context.get_parameter("items", []) try: items = eval(items) if not isinstance(items, list): raise 1 if position < 5: context.result['mc'] = MsgCode['ParamIllegal'] return except: context.result['mc'] = MsgCode['ParamIllegal'] return if hero_id not in ki_user.hero.heros: context.result['mc'] = MsgCode['HeroNotExist'] return equip_data = ki_user.equip.get_by_hero_position(hero_id, position) if not equip_data: context.result['mc'] = MsgCode['EquipNotExist'] return equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"]) equip_quality_cfg = game_config.equip_upgrade_cfg.get(equip_quality_cfg_key) if equip_data["level"] > equip_quality_cfg["equip_max_level"]: context.result['mc'] = MsgCode['EquipLvOverLimit'] return add_exp = 0 exp_item_type = SPECIAL_EQUIP_EXP_ITEM_1 if position == 5 else SPECIAL_EQUIP_EXP_ITEM_2 # 检查材料是否足够 items = pack_logic.amend_goods([{item_id: 1} for item_id in items if item_id]) if not pack_logic.check_items_enough(ki_user, items): context.result['mc'] = MsgCode['PackageItemNotEnough'] return for item_id,num in items.items(): item_cfg = game_config.item_cfg.get(item_id) if not item_cfg: context.result['mc'] = MsgCode['GameConfigNotExist'] return if item_cfg["type"] != exp_item_type: context.result['mc'] = MsgCode['ParamIllegal'] return add_exp += item_cfg["effect_value"] * num total_exp = equip_data["exp"] + add_exp if not user_logic.check_game_values1(ki_user, gold=add_exp*50): context.result['mc'] = MsgCode['GoldNotEnough'] return level = level_checker(position, equip_data["quality"], total_exp) ki_user.equip.intensify(hero_id, position, level, total_exp) if items: pack_logic.remove_items(ki_user, items) user_logic.consume_game_values1(ki_user, gold=add_exp*50) context.result['mc'] = MsgCode['EquipIntensifySucc']
def send(context): """发送聊天 Args: ctype: 聊天类型 1 - 世界 2 - 公会 3 - 公告 4 - 私聊 (公告不能发) msg: 聊天内容 receiver: 私聊时,传接收消息的玩家uid Returns: mc """ ki_user = context.user ctype = context.get_parameter("ctype") msg = context.get_parameter("msg") receiver = context.get_parameter("receiver") if ctype not in [CHAT_CHANNEL_WORLD, CHAT_CHANNEL_GROUP, CHAT_CHANNEL_PRIVATE]: context.result["mc"] = MsgCode["ParamIllegal"] return if ctype == CHAT_CHANNEL_WORLD: if ki_user.ext_info.ban_chat and ki_user.ext_info.ban_chat > int(time.time()): context.result["mc"] = MsgCode["InvalidOperation"] return used_times = ki_user.daily_info.world_chat_times vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level, {}) if used_times >= vip_cfg["daily_world_chat_times"] and not user_logic.check_game_values1(ki_user, diamond=WORLD_CHAT_EXTRA_DIAMOND): context.result["mc"] = MsgCode["DiamondNotEnough"] return elif ctype == CHAT_CHANNEL_GROUP and ki_user.group.group_id == 0: context.result["mc"] = MsgCode["UserHasNoGroup"] return elif ctype == CHAT_CHANNEL_PRIVATE and int(receiver) == 0: context.result["mc"] = MsgCode["ChatPrivateTargetEmpty"] return elif ctype == CHAT_CHANNEL_PRIVATE and str(receiver) == ki_user.uid: context.result["mc"] = MsgCode["ChatCantToSelf"] return else: pass sender = {} sender["uid"] = ki_user.uid sender["avatar"] = ki_user.avatar sender["name"] = ki_user.name sender["level"] = ki_user.game_info.role_level msg = gfw.replace(msg) if ctype != CHAT_CHANNEL_PRIVATE: ChatService.send(ki_user.sid, ctype, msg, sender, ki_user.group.group_id) else: ChatService.send(ki_user.sid, ctype, msg, sender, ki_user.group.group_id, receiver) if ctype == CHAT_CHANNEL_WORLD: ki_user.daily_info.world_chat_times += 1 ki_user.daily_info.put() if ki_user.daily_info.world_chat_times > vip_cfg["daily_world_chat_times"]: user_logic.consume_game_values1(ki_user, diamond=WORLD_CHAT_EXTRA_DIAMOND) context.result["mc"] = MsgCode["ChatSendMsgSucc"]