예제 #1
0
def synthesis(context):
    """碎片合成机甲

    Args:
        合成目标机甲ID int

    Returns:
        bool 成功 or 失败
    Raises:
        MsgCode['HeroAlreadyExist']
        MsgCode['PackageItemNotEnough']

    """
    ki_user = context.user

    index = context.get_parameter("index")
    synt_cfg = game_config.hero_synt_cfg.get(index)
    if not synt_cfg:
        context.result['mc'] = MsgCode['GameConfigNotExist']
        return

    if synt_cfg["hero_id"] in ki_user.hero.heros:
        context.result['mc'] = MsgCode['HeroAlreadyExist']
        return

    if not pack_logic.check_items_enough(ki_user, {synt_cfg["chip_id"]: synt_cfg["num"]}):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    add_heros(ki_user, [{synt_cfg["hero_id"]: synt_cfg["star"]}])
    pack_logic.remove_items(ki_user, {synt_cfg["chip_id"]: synt_cfg["num"]})

    context.result['mc'] = MsgCode['HeroSynthesisSucc']
예제 #2
0
def upgrade(context):
    """提升品质

    Args:
        hero_id
        position  装备部位
    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_id")
    position = context.get_parameter("position")

    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 equip_data["quality"] >= game_config.equip_max_quality:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if not _check_module_open(position, ki_user.game_info.role_level):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"] + 1)
    equip_quality_cfg = game_config.equip_upgrade_cfg.get(
        equip_quality_cfg_key)

    if equip_data["level"] < equip_quality_cfg["need_equip_level"]:
        context.result['mc'] = MsgCode['EquipQualityLevelLimit']
        return

    if ki_user.game_info.role_level < equip_quality_cfg["need_user_level"]:
        context.result['mc'] = MsgCode['EquipQualityLevelLimit']
        return

    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user,
                                         equip_quality_cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    ki_user.equip.upgrade(hero_id, position)
    level = level_checker(position, equip_data["quality"], equip_data["exp"])
    if position >= 5 and level != equip_data["level"]:
        ki_user.equip.intensify(hero_id, position, level, equip_data["exp"])

    pack_logic.remove_items(ki_user, equip_quality_cfg["material"])

    context.result['mc'] = MsgCode['EquipUpgradeSucc']
예제 #3
0
def weak(context):
    """卡牌升级星等

    卡牌升级星星,需要对应的碎片升级
    升级星星成功后,更换hero_base_cfg中对应的hero_id,卡牌属性等级保留
    消耗碎片数量走配置表

    Args:
        hero_id  当前星级卡牌对应的hero_id

    Returns:
        bool 成功 or 失败

    Raises:
        MsgCode['HeroNotExist']
        MsgCode['HeroMaxStar']
        MsgCode['PackageItemNotEnough']

    """
    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

    next_star_cfg = game_config.hero_weak_cfg.get("%s-%s" % (hero_id, hero["star"]+1), {})
    if not next_star_cfg:
        context.result['mc'] = MsgCode['HeroMaxStar']
        return

    need_chip_id = next_star_cfg["chip"]["id"]
    need_chip_num = next_star_cfg["chip"]["up_star_num"]

    if not pack_logic.check_items_enough(ki_user, {need_chip_id: need_chip_num, 1: next_star_cfg["consume_gold"]}):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    pack_logic.remove_items(ki_user, {need_chip_id: need_chip_num, 1: next_star_cfg["consume_gold"]})
    ki_user.hero.update_hero_star(hero_id)

    # 更新技能信息
    skill_logic.append_hero_skill(ki_user, hero_id, hero["star"])

    if hero["star"] >= 5:
        try:
            trigger = {'uid': ki_user.uid, 'name': ki_user.name}
            data = {'hero_id': hero_id, 'star': hero["star"], 'quality': hero["quality"]}
            NoticeService.broadcast(ki_user.sid, 12, trigger, data)
        except:
            logging.error("升星炫耀时发生错误。")

    context.result['mc'] = MsgCode['HeroWeakSucc']
예제 #4
0
def upgrade(context):
    """提升品质

    Args:
        hero_id
        position  装备部位
    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_id")
    position = context.get_parameter("position")

    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 equip_data["quality"] >= game_config.equip_max_quality:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if not _check_module_open(position, ki_user.game_info.role_level):
        context.result['mc'] = MsgCode['UserModuleNotOpen']
        return

    equip_quality_cfg_key = "%s-%s" % (position, equip_data["quality"]+1)
    equip_quality_cfg = game_config.equip_upgrade_cfg.get(equip_quality_cfg_key)

    if equip_data["level"] < equip_quality_cfg["need_equip_level"]:
        context.result['mc'] = MsgCode['EquipQualityLevelLimit']
        return

    if ki_user.game_info.role_level < equip_quality_cfg["need_user_level"]:
        context.result['mc'] = MsgCode['EquipQualityLevelLimit']
        return

    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user, equip_quality_cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    ki_user.equip.upgrade(hero_id, position)
    level = level_checker(position, equip_data["quality"], equip_data["exp"])
    if position >= 5 and level != equip_data["level"]:
        ki_user.equip.intensify(hero_id, position, level, equip_data["exp"])

    pack_logic.remove_items(ki_user, equip_quality_cfg["material"])

    context.result['mc'] = MsgCode['EquipUpgradeSucc']
예제 #5
0
def exchange_chip(context):
    """转换万能碎片,万能碎片 -》 机甲碎片

    规则:
        将万能碎片转换成普通碎片,只能用于升级星等
        转换类型分为转换1个和10个
        如果选择转换10个,若当前数量小于等于10个,则全部转换

    Args:
        target_chip_id 目标碎片道具ID int
        exchange_type 转换类型 (转换一个或者转换十个)

    Raises:
        MsgCode['ParamIllegal']
        MsgCode['HeroNotExist']
        MsgCode['PackageItemNotExist']

    """
    ki_user = context.user

    target_chip_id = context.get_parameter("target_chip_id")
    exchange_type = context.get_parameter("exchange_type")

    if exchange_type not in [CHIP_EXCHANGE_ONE, CHIP_EXCHANGE_TEN]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    chip_cfg = game_config.item_cfg.get(target_chip_id, {})
    if not chip_cfg:
        context.result['mc'] = MsgCode['GameConfigNotExist']
        return

    # 判断是否有这个碎片对应的机甲
    if chip_cfg["chip_hero_id"] not in ki_user.hero.heros:
        context.result['mc'] = MsgCode['HeroNotExist']
        return

    if not pack_logic.check_items_enough(ki_user, {SPECIAL_CHIP_ID: 1}):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    num = 1
    if exchange_type == CHIP_EXCHANGE_TEN:
        had_num = ki_user.package.get_item_num_by_id(SPECIAL_CHIP_ID)
        num = 10 if had_num >= 10 else had_num

    pack_logic.add_items(ki_user, {target_chip_id: num})
    pack_logic.remove_items(ki_user, {SPECIAL_CHIP_ID: num})

    context.result['mc'] = MsgCode['HeroExchangeChipSucc']
예제 #6
0
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']
예제 #7
0
def 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

    if equip_data["star"] >= game_config.equip_max_star:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    cfg_key = "%s-%s" % (equip_data["equip_id"], equip_data["star"] + 1)
    cfg = game_config.equip_weak_cfg.get(cfg_key)
    if not cfg:
        context.result['mc'] = MsgCode['GameConfigNotExist']
        return

    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user, cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    ki_user.equip.weak(hero_id, position)
    pack_logic.remove_items(ki_user, cfg["material"])

    # 武器第一次觉醒时,更新该机甲的必杀技能
    if position == EQUIP_POSITION_WEAPON and equip_data["star"] == 1:
        from apps.logics import skill as skill_logic
        skill_logic.replace_bs_skill(ki_user, hero_id)

    context.result['mc'] = MsgCode['EquipWeakSucc']
예제 #8
0
def 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

    if equip_data["star"] >= game_config.equip_max_star:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    cfg_key = "%s-%s" % (equip_data["equip_id"], equip_data["star"]+1)
    cfg = game_config.equip_weak_cfg.get(cfg_key)
    if not cfg:
        context.result['mc'] = MsgCode['GameConfigNotExist']
        return

    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user, cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    ki_user.equip.weak(hero_id, position)
    pack_logic.remove_items(ki_user, cfg["material"])

    # 武器第一次觉醒时,更新该机甲的必杀技能
    if position == EQUIP_POSITION_WEAPON and equip_data["star"] == 1:
        from apps.logics import skill as skill_logic
        skill_logic.replace_bs_skill(ki_user, hero_id)

    context.result['mc'] = MsgCode['EquipWeakSucc']
예제 #9
0
def upgrade(context):
    """卡牌升级品质

    卡牌初始等级为0,凑齐四样材料并且达到对应等级之后可以升级卡牌的品质

    Args:
        卡牌ID hero_id int

    Returns:
        bool 成功 or 失败

    Raises:
        MsgCode['HeroNotExist']
        MsgCode['HeroMaxQuality']
        MsgCode['HeroQualityLvLimit']
        MsgCode['PackageItemNotEnough']

    """
    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

    hero_cfg = game_config.hero_base_cfg.get(hero_id)

    quality_key = "%s-%s" % (hero_cfg["type"], hero["quality"] + 1)
    quality_cfg = game_config.hero_upgrade_cfg.get(quality_key, {})
    if not quality_cfg:
        context.result['mc'] = MsgCode['HeroMaxQuality']
        return

    if hero["level"] < quality_cfg["need_level"]:
        context.result['mc'] = MsgCode['HeroQualityLvLimit']
        return

    if not pack_logic.check_items_enough(ki_user, quality_cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    ki_user.hero.update_quality(hero_id)
    pack_logic.remove_items(ki_user, quality_cfg["material"])
    # 更新战魂信息
    spirit_logic.append_hero_spirit(ki_user, hero_id, hero["quality"])

    context.result['mc'] = MsgCode['HeroUpgradeSucc']
예제 #10
0
def upgrade(context):
    """战舰升品

    Args:
        ship_id 战舰ID

    Returns:
        code 成功 | 失败
    """
    ki_user = context.user

    ship_id = context.get_parameter("ship_id")

    ship = ki_user.warship.get_warship_by_id(ship_id)
    if not ship:
        context.result['mc'] = MsgCode['WarshipNotExist']
        return

    if ship["quality"] >= game_config.warship_max_quality:
        context.result['mc'] = MsgCode['WarshipQualityMax']
        return

    quality_cfg = game_config.warship_upgrade_cfg["%s-%s" %
                                                  (ship_id,
                                                   ship["quality"] + 1)]
    if ship["level"] < quality_cfg["need_level"] or \
        ki_user.game_info.role_level < quality_cfg["need_user_level"]:
        context.result['mc'] = MsgCode['WarshipLimitsNotEnough']
        return

    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user, quality_cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    pack_logic.remove_items(ki_user, quality_cfg["material"])
    ki_user.warship.upgrade(ship_id)

    context.result['mc'] = MsgCode['WarshipUpgradeSucc']
예제 #11
0
def weak(context):
    """战舰升星

    升级战斗星星,战舰觉醒技能或技能品级相应增加
    即战舰星级=战舰技能品级

    Args:
        ship_id 战舰ID

    Returns:
        code 成功 | 失败
    """
    ki_user = context.user

    ship_id = context.get_parameter("ship_id")

    ship = ki_user.warship.get_warship_by_id(ship_id)
    if not ship:
        context.result['mc'] = MsgCode['WarshipNotExist']
        return

    if ship["star"] >= game_config.warship_max_star:
        context.result['mc'] = MsgCode['WarshipStarMax']
        return

    weak_cfg = game_config.warship_weak_cfg["%s-%s" %
                                            (ship_id, ship["star"] + 1)]
    # 检查材料是否足够
    if not pack_logic.check_items_enough(ki_user, weak_cfg["material"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    pack_logic.remove_items(ki_user, weak_cfg["material"])
    ki_user.warship.weak(ship_id)

    # 升星成功之后监测是否开启战舰技能
    update_warship_skills(ki_user, ship_id, ship["star"])

    context.result['mc'] = MsgCode['WarshipWeakSucc']
예제 #12
0
def marry(context):
    """与机甲许下誓言

    Args:
        hero_id 姬甲ID
        marry_id 契约ID
    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_id")
    marry_id = context.get_parameter("marry_id")

    hero = ki_user.hero.get_by_hero_id(hero_id)
    if not hero:
        context.result['mc'] = MsgCode['HeroNotExist']
        return

    # 是否满足等级条件
    title_id = _get_title_by_favor(hero["favor"])
    if title_id < HERO_MARRY_TITLE_ID:
        context.result['mc'] = MsgCode['HeroMarryFavorNotEnough']
        return

    # 是否重复誓言
    if hero["marry_id"]:
        context.result['mc'] = MsgCode['HeroAlreadyMarried']
        return

    # 检测消耗
    marry_cfg = game_config.favor_marry_cfg.get(marry_id)
    if not pack_logic.check_items_enough(ki_user, marry_cfg["items"]):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    pack_logic.remove_items(ki_user, marry_cfg["items"]) # 扣除物品
    ki_user.hero.marry(hero_id, marry_id) # 许誓

    context.result['mc'] = MsgCode['HeroFavorMarrySucc']
예제 #13
0
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']
예제 #14
0
def donate(context):
    """公会成员捐献

    Args:
        target 捐献目标 1-公会经验 2-老虎机参与次数 3-老虎机改投次数 4-小鸟次数 5-小鸟金币上限加成
        type 捐献类型

    Returns:

    """
    ki_user = context.user

    target = context.get_parameter("target")
    dtype = context.get_parameter("type")

    if target not in [1, 2, 3, 4, 5] or dtype not in [1, 2, 3, 4, 5]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    group_id = ki_user.group.group_id
    if not group_id:
        context.result['mc'] = MsgCode['GroupHaveNoGroup']
        return

    vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level)
    if target == 1 and dtype == 3 and not vip_cfg["group_advance_donate"]:
        context.result['mc'] = MsgCode['UserVipTooLow']
        return

    group_daily_data = ki_user.daily_info.group_info
    # 每日次数已用完
    if group_daily_data["donate_times"] >= DAILY_DONATE_TIMES:
        context.result['mc'] = MsgCode['GroupDonateTimesUseUp']
        return

    # 判断公会存在
    group_data = GroupService.find(ki_user.sid, group_id)
    if not group_data:
        context.result['mc'] = MsgCode['GroupNotExist']
        return

    if target == 1 and group_data["daily_exp"] >= DAILY_MAX_GROUP_EXP:
        context.result['mc'] = MsgCode['GroupDailyExpMax']
        return

    # TODO 根据捐献类型获取玩家捐献消费和获得数值
    cfg = game_config.group_donate_cfg.get("%s-%s" % (target, dtype))
    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        if 1 in cfg["consume"].keys():
            context.result['mc'] = MsgCode['GoldNotEnough']
            return

        if 2 in cfg["consume"].keys():
            context.result['mc'] = MsgCode['DiamondNotEnough']
            return

    pack_logic.remove_items(ki_user, cfg["consume"])
    exp, tag = cfg["exp"].get(target), "%s#%s" % (target, dtype)
    if target == 1:
        GroupService.donate(ki_user.sid, group_id, ki_user.uid, ki_user.name,
                            exp, tag)
    else:
        ki_user.group.donate_game_exp(target, exp)
        GroupService.create_group_log(ki_user.sid, group_id,
                                      GROUP_LOG_TYPE_DONATE, ki_user.uid,
                                      ki_user.name, int(time.time()), tag)

    # 增加帮贡
    ki_user.game_info.group_point += cfg["group_point"]
    ki_user.game_info.put()

    # 更新公会成员贡献
    GroupService.set_member_info_by_uid(ki_user.sid, group_id, ki_user.uid,
                                        "donate", cfg["group_point"])

    ki_user.daily_info.group_update("donate_times")

    context.result['mc'] = MsgCode['GroupDonateSucc']
예제 #15
0
def buy(context):
    """购买某个商店的某个物品

    Args:
        mtype 商品类别  1-杂货 2-荣誉 3-试炼 4-社团 5-碎片兑换

    Returns:

    Raises:

    """
    ki_user = context.user

    mtype = context.get_parameter("mtype")
    item_tag = context.get_parameter("item_tag")

    if mtype not in [
            MALL_MISC, MALL_HONOR, MALL_TRIAL, MALL_GROUP, MALL_CHIP,
            MALL_MYSTERY
    ]:
        context.result['mc'] = MsgCode['ParamIllegal']
        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
    elif mtype == MALL_GROUP:
        info = ki_user.mall.group
    elif mtype == MALL_MYSTERY:
        info = ki_user.mall.mystery
        # 神秘商店只能存在一个小时
        if int(time.time()) - info["last_refresh"] >= 3600:
            context.result['mc'] = MsgCode['MallMysteryExpired']
            return
    else:
        pass

    cfg = None
    if mtype in range(1, 6):
        if item_tag not in info["items"]:
            context.result['mc'] = MsgCode['ParamIllegal']
            return

        if item_tag in info["bought"]:
            context.result['mc'] = MsgCode['MallItemSaleOut']
            return

        cfg = game_config.mall_tmp_cfg.get(item_tag, {})
    else:
        cfg = game_config.mall_shop_cfg.get(item_tag, {})

    if not cfg:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        consume_type = cfg["consume"].keys()[0]
        if consume_type == 2:
            context.result['mc'] = MsgCode['DiamondNotEnough']
        else:
            context.result['mc'] = MsgCode['GoldNotEnough']

        return

    pack_logic.remove_items(ki_user, cfg["consume"])
    pack_logic.add_items(ki_user, cfg["item"])  # 加抽到的物品

    if mtype in range(1, 6):
        info["bought"].append(item_tag)
        ki_user.mall.put()

    context.result["mc"] = MsgCode["MallBuySucc"]
예제 #16
0
def pick(context):
    """商店抽奖 - 装备觉醒石头

    Args:
        ptype 抽奖类型  1-单次 2-十连抽

    Returns:

    Raises:

    """
    ki_user = context.user

    ptype = context.get_parameter("ptype")

    if ptype not in [PICK_TYPE_1, PICK_TYPE_2]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    cur_package_len = len(ki_user.package.items)
    if cur_package_len >= pack_logic.PACKAGE_MAX_SLOTS:
        context.result['mc'] = MsgCode['PackageIsFull']
        return

    free = _is_pick_free(ki_user.daily_info.mall_pick_cd, ptype)

    final_type = _fix_pick_type(free, ptype, ki_user.game_info.box_key)

    if not final_type:
        context.result['mc'] = MsgCode['ServerInternalError']
        return

    cfg = game_config.mall_pick_cfg[final_type]
    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        context.result['mc'] = MsgCode['DiamondNotEnough']
        return

    # 十连抽 or 单次
    loop_index = 0 if ptype == 1 else 9
    picked_items = []
    broadcast_list = []

    while loop_index >= 0:
        broadcast, lib = _get_pick_rand_lib(_pick_lib_type(final_type, loop_index))
        target = random.choice(lib)
        picked_items.append(target)
        if broadcast:
            broadcast_list += target.keys()

        loop_index -= 1

    picked_items_c2s = copy.copy(picked_items)
    picked_items.append(cfg["items"])
    final_items = common_helper.handle_pack_items(picked_items)

    # 加物品&扣除消耗品
    if not free:
        pack_logic.remove_items(ki_user, cfg["consume"])

    pack_logic.add_items(ki_user, final_items)   # 加抽到的物品

    # 更新数据
    if final_type == 5:
        ki_user.daily_info.mall_pick_cd = 1
        ki_user.daily_info.put()

    act_helper.update_after_mall_pick(ki_user, 1 if ptype == 1 else 10)

    # 炫耀
    try:
        for item_id in broadcast_list:
            trigger = {'uid': ki_user.uid, 'name': ki_user.name}
            NoticeService.broadcast(ki_user.sid, 14, trigger, item_id)
    except:
        logging.error("【商店获得物品】炫耀广播发生错误。")

    context.result["data"] = {}
    context.result["data"]["picked_items"] = picked_items_c2s
예제 #17
0
def buy(context):
    """购买某个商店的某个物品

    Args:
        mtype 商品类别  1-杂货 2-荣誉 3-试炼 4-社团 5-碎片兑换

    Returns:

    Raises:

    """
    ki_user = context.user

    mtype = context.get_parameter("mtype")
    item_tag = context.get_parameter("item_tag")

    if mtype not in [MALL_MISC, MALL_HONOR, MALL_TRIAL, MALL_GROUP, MALL_CHIP, MALL_MYSTERY]:
        context.result['mc'] = MsgCode['ParamIllegal']
        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
    elif mtype == MALL_GROUP:
        info = ki_user.mall.group
    elif mtype == MALL_MYSTERY:
        info = ki_user.mall.mystery
        # 神秘商店只能存在一个小时
        if int(time.time()) - info["last_refresh"] >= 3600:
            context.result['mc'] = MsgCode['MallMysteryExpired']
            return
    else:
        pass

    cfg = None
    if mtype in range(1,6):
        if item_tag not in info["items"]:
            context.result['mc'] = MsgCode['ParamIllegal']
            return

        if item_tag in info["bought"]:
            context.result['mc'] = MsgCode['MallItemSaleOut']
            return

        cfg = game_config.mall_tmp_cfg.get(item_tag, {})
    else:
        cfg = game_config.mall_shop_cfg.get(item_tag, {})

    if not cfg:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        consume_type = cfg["consume"].keys()[0]
        if consume_type == 2:
            context.result['mc'] = MsgCode['DiamondNotEnough']
        else:
            context.result['mc'] = MsgCode['GoldNotEnough']

        return

    pack_logic.remove_items(ki_user, cfg["consume"])
    pack_logic.add_items(ki_user, cfg["item"])   # 加抽到的物品

    if mtype in range(1,6):
        info["bought"].append(item_tag)
        ki_user.mall.put()

    context.result["mc"] = MsgCode["MallBuySucc"]
예제 #18
0
def pick(context):
    """玩家抽卡

    背包是否已满 -》今日免费抽取次数是否用完 -》cd是否冷却 -》
    钱够不够 -》 抽卡 -》 抽到的卡片是否已拥有 -》加物品 -》 扣除消耗 -》 更新数据
    -》 返回抽到的物品

    Args:
        ptype 抽奖类型  1-金币单次 2-金币连抽 3-钻石单次 4-钻石连抽

    Returns:
        {"heros":[hero_id, ], "items": {item_id: item_num, }}  获得物品

    Raises:
        MsgCode['ParamIllegal']
        MsgCode['PackageIsFull']
        MsgCode['GoldNotEnough']
        MsgCode['DiamondNotEnough']
    """
    ki_user = context.user

    ptype = context.get_parameter("ptype")
    if ptype not in [1,2,3,4]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    cur_package_len = len(ki_user.package.items)
    if cur_package_len >= pack_logic.PACKAGE_MAX_SLOTS:
        context.result['mc'] = MsgCode['PackageIsFull']
        return

    hero_daily_info = ki_user.daily_info.hero_pick_info
    pick_info = ki_user.hero.pick_info

    cfg = game_config.hero_pick_cfg[ptype]

    now = int(time.time())
    is_free = False

    if ptype == GOLD_ONE and \
       hero_daily_info["gold"] < cfg["limit_times"] and \
       now > pick_info["gold_cd"] + cfg["cd"]:
       is_free = True

    # if ptype == DIAMOND_ONE and \
    #    hero_daily_info["diamond"] < cfg["limit_times"] and \
    #    now > pick_info["diamond_cd"] + cfg["cd"]:
    if ptype == DIAMOND_ONE and hero_daily_info["diamond"]:
       is_free = True

    if not is_free and not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        context.result['mc'] = MsgCode['GoldNotEnough'] if ptype in [GOLD_ONE, GOLD_TEN] else MsgCode['DiamondNotEnough']
        return

    # 十连抽 or 单次
    loop_index = 0 if ptype in [GOLD_ONE, DIAMOND_ONE] else 9

    picked_items = {}
    picked_items["heros"] = []
    picked_items["items"] = []

    while loop_index >= 0:
        rand_type = hero_helper.get_rand_type(is_free, ptype, pick_info, loop_index)
        rand_lib = hero_helper.get_pick_rand_lib(rand_type)

        # 随机出获得的物品
        target = random.choice(rand_lib["lib"])
        target_type = rand_lib["lib_type"]

        if target_type == PICK_ITEM_HERO:
            picked_items["heros"].append(target)
        else:
            picked_items["items"].append(target)

        loop_index -= 1

    # 加物品&扣除消耗品
    if not is_free:
        pack_logic.remove_items(ki_user, cfg["consume"])

    add_heros(ki_user, picked_items["heros"])  # 加抽到的机甲卡牌

    srv_add_items = copy.copy(picked_items["items"])
    srv_add_items.append(cfg["goods"])
    pack_logic.add_items(ki_user, common_helper.handle_pack_items(srv_add_items))   # 加抽到的物品

    # 更新数据
    if is_free and ptype == GOLD_ONE:
        ki_user.daily_info.hero_pick_info["gold"] += 1
        ki_user.daily_info.put()

        ki_user.hero.pick_info["gold_cd"] = now
        ki_user.hero.put()

    elif is_free and ptype == DIAMOND_ONE:
        ki_user.daily_info.hero_pick_info["diamond"] = 0
        ki_user.daily_info.put()

        ki_user.hero.pick_info["diamond_pick_times"] += 1
        ki_user.hero.put()

    elif not is_free and ptype == DIAMOND_ONE:
        ki_user.hero.pick_info["diamond_pick_times"] += 1
        ki_user.hero.put()

    elif ptype == DIAMOND_TEN:
        ki_user.hero.pick_info["diamond_ten_times"] += 1
        ki_user.hero.put()

    else:
        pass

    # 整理抽奖所得物品
    # picked_items["items"] = common_helper.handle_pack_items(picked_items["items"])

    # 更新运维活动数据
    try:
        if ptype == DIAMOND_ONE:
            act_helper.update_after_diamond_pick_hero(ki_user, 1)
        elif ptype == DIAMOND_TEN:
            act_helper.update_after_diamond_pick_hero(ki_user, 10)
        else:
            pass
    except:
        logging.error("【钻石抽取姬甲达到指定数量】活动更新失败")

    context.result["data"] = picked_items
예제 #19
0
def pick(context):
    """商店抽奖 - 装备觉醒石头

    Args:
        ptype 抽奖类型  1-单次 2-十连抽

    Returns:

    Raises:

    """
    ki_user = context.user

    ptype = context.get_parameter("ptype")

    if ptype not in [PICK_TYPE_1, PICK_TYPE_2]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    cur_package_len = len(ki_user.package.items)
    if cur_package_len >= pack_logic.PACKAGE_MAX_SLOTS:
        context.result['mc'] = MsgCode['PackageIsFull']
        return

    free = _is_pick_free(ki_user.daily_info.mall_pick_cd, ptype)

    final_type = _fix_pick_type(free, ptype, ki_user.game_info.box_key)

    if not final_type:
        context.result['mc'] = MsgCode['ServerInternalError']
        return

    cfg = game_config.mall_pick_cfg[final_type]
    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        context.result['mc'] = MsgCode['DiamondNotEnough']
        return

    # 十连抽 or 单次
    loop_index = 0 if ptype == 1 else 9
    picked_items = []
    broadcast_list = []

    while loop_index >= 0:
        broadcast, lib = _get_pick_rand_lib(
            _pick_lib_type(final_type, loop_index))
        target = random.choice(lib)
        picked_items.append(target)
        if broadcast:
            broadcast_list += target.keys()

        loop_index -= 1

    picked_items_c2s = copy.copy(picked_items)
    picked_items.append(cfg["items"])
    final_items = common_helper.handle_pack_items(picked_items)

    # 加物品&扣除消耗品
    if not free:
        pack_logic.remove_items(ki_user, cfg["consume"])

    pack_logic.add_items(ki_user, final_items)  # 加抽到的物品

    # 更新数据
    if final_type == 5:
        ki_user.daily_info.mall_pick_cd = 1
        ki_user.daily_info.put()

    act_helper.update_after_mall_pick(ki_user, 1 if ptype == 1 else 10)

    # 炫耀
    try:
        for item_id in broadcast_list:
            trigger = {'uid': ki_user.uid, 'name': ki_user.name}
            NoticeService.broadcast(ki_user.sid, 14, trigger, item_id)
    except:
        logging.error("【商店获得物品】炫耀广播发生错误。")

    context.result["data"] = {}
    context.result["data"]["picked_items"] = picked_items_c2s
예제 #20
0
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']
예제 #21
0
def donate(context):
    """公会成员捐献

    Args:
        target 捐献目标 1-公会经验 2-老虎机参与次数 3-老虎机改投次数 4-小鸟次数 5-小鸟金币上限加成
        type 捐献类型

    Returns:

    """
    ki_user = context.user

    target = context.get_parameter("target")
    dtype = context.get_parameter("type")

    if target not in [1,2,3,4,5] or dtype not in [1,2,3,4,5]:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    group_id = ki_user.group.group_id
    if not group_id:
        context.result['mc'] = MsgCode['GroupHaveNoGroup']
        return

    vip_cfg = game_config.vip_priv_cfg.get(ki_user.game_info.vip_level)
    if target == 1 and dtype == 3 and not vip_cfg["group_advance_donate"]:
        context.result['mc'] = MsgCode['UserVipTooLow']
        return

    group_daily_data = ki_user.daily_info.group_info
    # 每日次数已用完
    if group_daily_data["donate_times"] >= DAILY_DONATE_TIMES:
        context.result['mc'] = MsgCode['GroupDonateTimesUseUp']
        return

    # 判断公会存在
    group_data = GroupService.find(ki_user.sid, group_id)
    if not group_data:
        context.result['mc'] = MsgCode['GroupNotExist']
        return

    if target == 1 and group_data["daily_exp"] >= DAILY_MAX_GROUP_EXP:
        context.result['mc'] = MsgCode['GroupDailyExpMax']
        return

    # TODO 根据捐献类型获取玩家捐献消费和获得数值
    cfg = game_config.group_donate_cfg.get("%s-%s" % (target, dtype))
    if not pack_logic.check_items_enough(ki_user, cfg["consume"]):
        if 1 in cfg["consume"].keys():
            context.result['mc'] = MsgCode['GoldNotEnough']
            return

        if 2 in cfg["consume"].keys():
            context.result['mc'] = MsgCode['DiamondNotEnough']
            return

    pack_logic.remove_items(ki_user, cfg["consume"])
    exp, tag = cfg["exp"].get(target), "%s#%s" % (target, dtype)
    if target == 1:
        GroupService.donate(ki_user.sid, group_id, ki_user.uid, ki_user.name, exp, tag)
    else:
        ki_user.group.donate_game_exp(target, exp)
        GroupService.create_group_log(ki_user.sid, group_id, GROUP_LOG_TYPE_DONATE, ki_user.uid, ki_user.name, int(time.time()), tag)

    # 增加帮贡
    ki_user.game_info.group_point += cfg["group_point"]
    ki_user.game_info.put()

    # 更新公会成员贡献
    GroupService.set_member_info_by_uid(ki_user.sid, group_id, ki_user.uid, "donate", cfg["group_point"])

    ki_user.daily_info.group_update("donate_times")

    context.result['mc'] = MsgCode['GroupDonateSucc']
예제 #22
0
def intensify(context):
    """卡牌升级

    升级操作为玩家吞食经验道具,道具类型分为几等
    卡牌等级受主角总等级限制

    Args:
        卡牌ID hero_id int
        经验道具ID item_id int
        经验道具数量 item_num int

    Returns:
        bool 成功 or 失败

    Raises:
        MsgCode['PackageItemNotEnough']
        MsgCode['HeroNotExist']
        MsgCode['HeroUpLevelFail']

    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_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

    if hero["level"] >= ki_user.game_info.role_level:
        context.result['mc'] = MsgCode['HeroUserLevelLimit']
        return

    if not pack_logic.check_items_enough(ki_user, items):
        context.result['mc'] = MsgCode['PackageItemNotEnough']
        return

    total_add_exp = 0
    for item_id, item_num in items.iteritems():
        item_cfg = game_config.item_cfg.get(item_id)
        if not item_cfg:
            context.result['mc'] = MsgCode['GameConfigNotExist']
            return

        if item_cfg["type"] != SPECIAL_HERO_EXP_ITEM_TYPE:
            context.result['mc'] = MsgCode['ParamIllegal']
            return
        else:
            total_add_exp = item_cfg["effect_value"] * item_num

    after_exp = hero["exp"] + total_add_exp
    after_level = common_helper.get_level_by_exp(game_config.hero_exp_level_cfg, after_exp)

    ki_user.hero.update_exp_level(hero_id, after_exp, min(ki_user.game_info.role_level, after_level))
    pack_logic.remove_items(ki_user, items)

    context.result['mc'] = MsgCode['HeroIntensifySucc']