def random_tiger_point(point): """随机老虎机里威震天个数 Args: point 当前威震天个数 """ cfgs = [{c["id"]: c["weight"]} for c in game_config.group_game_tiger_cfg.values() if c["cur_num"] == point] target = common_helper.weight_random(pack_logic.amend_goods(cfgs)) return game_config.group_game_tiger_cfg[target]["final_num"]
def award(context): """金币副本和经验副本领取累计伤害奖励 Args: act_mission_type :活动副本类型 经验 / 金币 award_ids :累计奖品索引列表 【支持一键领取】 Returns: """ ki_user = context.user mtype = context.get_parameter("mtype") award_ids = context.get_parameter("award_ids", "[]") try: award_ids = eval(award_ids) if not isinstance(award_ids, list): raise 1 except: context.result['mc'] = MsgCode['ParamIllegal'] return daily_data = ki_user.daily_info.act_missions.get(mtype, {}) if not daily_data: context.result['mc'] = MsgCode['MissionAwardNotSatisfied'] return total_awards = [] for index in award_ids: cfg_key = "%s-%s" % (mtype, index) cfg = game_config.mission_act_awards_cfg.get(cfg_key, {}) if not cfg: context.result['mc'] = MsgCode['MissionAwardNotExist'] return if cfg["need_scores"] > daily_data["score"]: context.result['mc'] = MsgCode['MissionAwardNotSatisfied'] return if index in daily_data["award_index"]: context.result['mc'] = MsgCode['MissionAlreadyAwarded'] return total_awards.append(cfg["awards"]) pack_logic.add_items(ki_user, pack_logic.amend_goods(total_awards)) ki_user.daily_info.act_mission_award(mtype, award_ids) context.result['mc'] = MsgCode['MissionAwardSucc']
def random_tiger_point(point): """随机老虎机里威震天个数 Args: point 当前威震天个数 """ cfgs = [{ c["id"]: c["weight"] } for c in game_config.group_game_tiger_cfg.values() if c["cur_num"] == point] target = common_helper.weight_random(pack_logic.amend_goods(cfgs)) return game_config.group_game_tiger_cfg[target]["final_num"]
def award(context): """金币副本和经验副本领取累计伤害奖励 Args: act_mission_type :活动副本类型 经验 / 金币 award_ids :累计奖品索引列表 【支持一键领取】 Returns: """ ki_user = context.user mtype = context.get_parameter("mtype") award_ids = context.get_parameter("award_ids", "[]") try: award_ids = eval(award_ids) if not isinstance(award_ids, list): raise 1 except: context.result['mc'] = MsgCode['ParamIllegal'] return daily_data = ki_user.daily_info.act_missions.get(mtype, {}) if not daily_data: context.result['mc'] = MsgCode['MissionAwardNotSatisfied'] return total_awards = [] for index in award_ids: cfg_key = "%s-%s" % (mtype, index) cfg = game_config.mission_act_awards_cfg.get(cfg_key, {}) if not cfg: context.result['mc'] = MsgCode['MissionAwardNotExist'] return if cfg["need_scores"] > daily_data["score"]: context.result['mc'] = MsgCode['MissionAwardNotSatisfied'] return if index in daily_data["award_index"]: context.result['mc'] = MsgCode['MissionAlreadyAwarded'] return total_awards.append(cfg["awards"]) pack_logic.add_items(ki_user, pack_logic.amend_goods(total_awards)) ki_user.daily_info.act_mission_award(mtype, award_ids) context.result['mc'] = MsgCode['MissionAwardSucc']
def intensify(context): """战舰升级 战舰等级受战队等级和品质限制 Args: ship_id 战舰ID to_level 到达的等级 Returns: code 成功 | 失败 """ ki_user = context.user ship_id = context.get_parameter("ship_id") to_level = context.get_parameter("to_level") ship = ki_user.warship.get_warship_by_id(ship_id) if not ship: context.result['mc'] = MsgCode['WarshipNotExist'] return if to_level <= ship["level"] or to_level > game_config.warship_max_level: context.result['mc'] = MsgCode['ParamIllegal'] return quality_key = "%s-%s" % (ship_id, ship["quality"]) quality_cfg = game_config.warship_upgrade_cfg[quality_key] if to_level > quality_cfg["max_level"]: context.result['mc'] = MsgCode['WarshipLevelOverLimit'] return need_items = [ game_config.warship_intensify_cfg[level] for level in range(ship["level"] + 1, to_level + 1) ] need_items1 = pack_logic.amend_goods(need_items) # 检查升级材料是否足够 if not pack_logic.check_items_enough(ki_user, need_items1): import logging logging.error("%s -> %s need: %s need2: %s" % (ship["level"], to_level, need_items, need_items1)) context.result['mc'] = MsgCode['PackageItemNotEnough'] return ki_user.warship.intensify(ship_id, to_level) pack_logic.remove_items(ki_user, need_items1) context.result['mc'] = MsgCode['WarshipIntensifySucc']
def _handle_refresh_action(cfg, role_level): """刷新操作 """ new_random_list = [] for i in range(1, len(cfg)+1): slot_cfg = cfg[i] libs = [{item["id"]: item["weight"]} for item in slot_cfg if item["level_limit"]["min"] <= role_level <= item["level_limit"]["max"]] rand_libs = [] for a in libs: rand_libs.append(a) target = common_helper.weight_random(pack_logic.amend_goods(rand_libs)) new_random_list.append(target) return new_random_list
def _handle_refresh_action(cfg, role_level): """刷新操作 """ new_random_list = [] for i in range(1, len(cfg) + 1): slot_cfg = cfg[i] libs = [{ item["id"]: item["weight"] } for item in slot_cfg if item["level_limit"]["min"] <= role_level <= item["level_limit"]["max"]] rand_libs = [] for a in libs: rand_libs.append(a) target = common_helper.weight_random(pack_logic.amend_goods(rand_libs)) new_random_list.append(target) return new_random_list
def add_game_values(user, items): """游戏数值增长接口 金币,钻石,体力,经验,vip经验... Args: user 用户对象 items 参数字典 eg: {1:1000, 2:1000} Returns: """ for key, value in items.iteritems(): if key == static_const.ROLE_EXP: add_items = user.game_info.add_role_exp(value) # 升级给物品。为了引导而搞 if add_items: from apps.logics import package as pack_logic pack_logic.add_items(user, pack_logic.amend_goods(add_items)) elif key == static_const.VIP_EXP: user.game_info.add_vip_exp(value) elif key == static_const.ENERGY: user.game_info.update_energy(value) else: # 等级和vip等级不能直接修改数值,只能通过经验来更变 if key in [5, 7]: return value_tag = static_const.SPECIAL_ITEMS_MAPPING.get(key, None) if value_tag: exec("user.game_info.%s += %s" % (value_tag, value)) user.game_info.put()
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 past(context): """活动副本结算 Args: mission_id :关卡ID hurt :伤害值 Returns: """ ki_user = context.user mission_id = context.get_parameter("mission_id") hurt_percent = context.get_parameter("hurt_percent") hurt = context.get_parameter("hurt") star = context.get_parameter("star") if star not in range(0, 4) or not hurt_percent: context.result['mc'] = MsgCode['ParamIllegal'] return cfg = game_config.mission_act_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 extra = ki_user.mission.extra_data if extra.get("last_act_mission", 0) != mission_id: context.result['mc'] = MsgCode['MissionNotIn'] return # ====================== 计算奖励 金币经验 和 烈焰冰封幻想 不同========================= data = {} add_awards = [] if cfg["type"] in [ MISSION_ACT_TYPE_GOLD, MISSION_ACT_TYPE_EXP, MISSION_ACT_TYPE_PHANTOM ]: award_pack_list = [ pack for t, pack in cfg["awards"].items() if t <= float(hurt_percent) ] awards = [game_config.item_pack_cfg.get(id) for id in award_pack_list] base_awards = common_helper.handle_pack_items(awards) add_awards.append(base_awards) data["base"] = copy.copy(base_awards) # 金币副本,最终奖励和上阵机甲的总星级挂钩 hero_stars = _get_fight_hero_stars(ki_user, cfg["type"]) star_cfg = game_config.mission_act_star_award_cfg.get(hero_stars) data["extra"] = star_cfg[cfg["type"]] add_awards.append(star_cfg[cfg["type"]]) else: # 随机获得物品数量 # 输了不得奖励 if star not in range(1, 4): add_awards = {} else: awards_num = common_helper.weight_random(cfg["awards_num"]) awards_lib = [{ item_pack_id: weight } for item_pack_id, weight in cfg["awards"].items()] awards_pack_list = mission_helper.random_mission_award( awards_lib, awards_num) base_awards = [ game_config.item_pack_cfg.get(pack_id) for pack_id in awards_pack_list ] base_awards = common_helper.handle_pack_items(base_awards) add_awards.append(base_awards) data["base"] = base_awards if star in range(1, 4): ki_user.mission.act_past(cfg["type"], mission_id, star) ki_user.daily_info.act_mission_past(cfg["type"], hurt, 1) # 增加最终物品 pack_logic.add_items(ki_user, pack_logic.amend_goods(add_awards)) # 更新排行榜数据 if cfg["type"] in [MISSION_ACT_TYPE_GOLD, MISSION_ACT_TYPE_EXP]: rank_service.update_act_mission_rank(ki_user.sid, cfg["type"], ki_user.uid, hurt) else: if star in range(1, 4): rank_service.update_act_mission_rank(ki_user.sid, cfg["type"], ki_user.uid, int(time.time())) context.result["data"] = data
def game_bird(context): """【公会游戏之小鸟快飞】 Args: type 游戏操作类型 1-开始 2-结算 process 进度 Returns: """ ki_user = context.user action_type = context.get_parameter("type") process = context.get_parameter("process") if action_type not in [1,2]: 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(3, ki_user.group.donate["bird_exp1"]) if group_daily_data["bird_times"] >= max_times: context.result['mc'] = MsgCode['GroupGameBirdTimesUseUp'] return ki_user.daily_info.group_update("bird_times") elif action_type == 2: awards = [v for k,v in game_config.group_game_bird_awards_cfg.items() if k <= process] # [{1:2000}, {2:3}, {120001:1}] if not awards: context.result['mc'] = MsgCode['ParamIllegal'] return daily_awards = group_daily_data["bird_awards"] awards1 = pack_logic.amend_goods(awards) # {1:2000, 2:3, 120001:1} gold_limit = get_game_max_times(4, ki_user.group.donate["bird_exp2"]) history, add_awards = count_add_awards(awards1, daily_awards, gold_limit) # 背包增加物品 pack_logic.add_items(ki_user, add_awards) if process > ki_user.group.game_data["bird_best_score"]: ki_user.group.bird_update(process) if process > group_daily_data["bird_daily_best"]: group_daily_data["bird_daily_best"] = process GroupService.update_game_bird_rank(ki_user.sid, ki_user.uid, ki_user.group.group_id, process) # 进入排行榜 ki_user.daily_info.group_game_bird_update("bird_awards", history) # if process == 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['GroupGameBirdSucc']
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 game_bird(context): """【公会游戏之小鸟快飞】 Args: type 游戏操作类型 1-开始 2-结算 process 进度 Returns: """ ki_user = context.user action_type = context.get_parameter("type") process = context.get_parameter("process") if action_type not in [1, 2]: 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(3, ki_user.group.donate["bird_exp1"]) if group_daily_data["bird_times"] >= max_times: context.result['mc'] = MsgCode['GroupGameBirdTimesUseUp'] return ki_user.daily_info.group_update("bird_times") elif action_type == 2: awards = [ v for k, v in game_config.group_game_bird_awards_cfg.items() if k <= process ] # [{1:2000}, {2:3}, {120001:1}] if not awards: context.result['mc'] = MsgCode['ParamIllegal'] return daily_awards = group_daily_data["bird_awards"] awards1 = pack_logic.amend_goods(awards) # {1:2000, 2:3, 120001:1} gold_limit = get_game_max_times(4, ki_user.group.donate["bird_exp2"]) history, add_awards = count_add_awards(awards1, daily_awards, gold_limit) # 背包增加物品 pack_logic.add_items(ki_user, add_awards) if process > ki_user.group.game_data["bird_best_score"]: ki_user.group.bird_update(process) if process > group_daily_data["bird_daily_best"]: group_daily_data["bird_daily_best"] = process GroupService.update_game_bird_rank(ki_user.sid, ki_user.uid, ki_user.group.group_id, process) # 进入排行榜 ki_user.daily_info.group_game_bird_update("bird_awards", history) # if process == 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['GroupGameBirdSucc']
def past(context): """活动副本结算 Args: mission_id :关卡ID hurt :伤害值 Returns: """ ki_user = context.user mission_id = context.get_parameter("mission_id") hurt_percent = context.get_parameter("hurt_percent") hurt = context.get_parameter("hurt") star = context.get_parameter("star") if star not in range(0,4) or not hurt_percent: context.result['mc'] = MsgCode['ParamIllegal'] return cfg = game_config.mission_act_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 extra = ki_user.mission.extra_data if extra.get("last_act_mission", 0) != mission_id: context.result['mc'] = MsgCode['MissionNotIn'] return # ====================== 计算奖励 金币经验 和 烈焰冰封幻想 不同========================= data = {} add_awards = [] if cfg["type"] in [MISSION_ACT_TYPE_GOLD, MISSION_ACT_TYPE_EXP, MISSION_ACT_TYPE_PHANTOM]: award_pack_list = [pack for t, pack in cfg["awards"].items() if t <= float(hurt_percent)] awards = [game_config.item_pack_cfg.get(id) for id in award_pack_list] base_awards = common_helper.handle_pack_items(awards) add_awards.append(base_awards) data["base"] = copy.copy(base_awards) # 金币副本,最终奖励和上阵机甲的总星级挂钩 hero_stars = _get_fight_hero_stars(ki_user, cfg["type"]) star_cfg = game_config.mission_act_star_award_cfg.get(hero_stars) data["extra"] = star_cfg[cfg["type"]] add_awards.append(star_cfg[cfg["type"]]) else: # 随机获得物品数量 # 输了不得奖励 if star not in range(1,4): add_awards = {} else: awards_num = common_helper.weight_random(cfg["awards_num"]) awards_lib = [{item_pack_id: weight} for item_pack_id, weight in cfg["awards"].items()] awards_pack_list = mission_helper.random_mission_award(awards_lib, awards_num) base_awards = [game_config.item_pack_cfg.get(pack_id) for pack_id in awards_pack_list] base_awards = common_helper.handle_pack_items(base_awards) add_awards.append(base_awards) data["base"] = base_awards if star in range(1,4): ki_user.mission.act_past(cfg["type"], mission_id, star) ki_user.daily_info.act_mission_past(cfg["type"], hurt, 1) # 增加最终物品 pack_logic.add_items(ki_user, pack_logic.amend_goods(add_awards)) # 更新排行榜数据 if cfg["type"] in [MISSION_ACT_TYPE_GOLD, MISSION_ACT_TYPE_EXP]: rank_service.update_act_mission_rank(ki_user.sid, cfg["type"], ki_user.uid, hurt) else: if star in range(1,4): rank_service.update_act_mission_rank(ki_user.sid, cfg["type"], ki_user.uid, int(time.time())) context.result["data"] = data