Exemple #1
0
def melting_equipment(equipment_id, response, player):
    """熔炼
    @param dynamic_id:
    @param equipment_ids:
    @param kwargs:
    @return:
    """
    if is_not_open(player, FO_EQUIP_SACRIFICE):
        return {"result": False, "result_no": 837}
    equipment_obj = player.equipment_component.get_equipment(equipment_id)
    if not equipment_obj:
        return {'result': False, 'result_no': 401, 'message': u''}
    melting_items = equipment_obj.melting_item
    gain = item_group_helper.gain(player, melting_items, const.MELTING_EQUIPMENT)

    item_group_helper.get_return(player, gain, response.cgr)

    tlog_action.log('EquipmentMelting', player,
                    equipment_obj.base_info.equipment_no,
                    equipment_obj.base_info.id)

    # 删除装备
    player.equipment_component.delete_equipment(equipment_id)

    # 添加强化金币
    strength_coin = 0
    for record in equipment_obj.enhance_record.enhance_record:
        strength_coin += record[2]

    strength_coin = int(strength_coin*game_configs.base_config.get("equRefundRatio"))
    return strength_coin
def fight_start(stage, fid, player):
    """开始战斗
    """
    # 校验信息:是否开启,是否达到次数上限等
    res = stage.check()
    if not res.get('result'):
        return res

    fight_cache_component = player.fight_cache_component
    fight_cache_component.stage_id = stage.stage_id
    fight_cache_component.stage = stage
    red_units, blue_units, drop_num, monster_unpara = fight_cache_component.fighting_start()

    # 好友
    char_obj = tb_character_info.getObj(fid)
    lord_data = char_obj.hget('lord_attr_info')
    f_unit = None
    if lord_data and not is_not_open(player, FO_FRIEND_SUPPORT):
        info = lord_data.get('info')
        f_unit = BattleUnit.loads(info)
    else:
        logger.debug('can not find friend id :%d' % fid)

    return dict(result=True,
                red_units=red_units,
                blue_units=blue_units,
                drop_num=drop_num,
                monster_unpara=monster_unpara,
                f_unit=f_unit,
                result_no=0)
Exemple #3
0
def compose_equipment(chip_no, player):
    """合成装备
    """
    if is_not_open(player, FO_EQUIP_COMPOSE):
        return {"result": False, "result_no": 837}
    chip = player.equipment_chip_component.get_chip(chip_no)
    # 没有碎片
    if not chip:
        return {'result': False, 'result_no': 102, 'message': u''}

    compose_num = chip.compose_num
    chip_num = chip.chip_num
    # print "chip_num", compose_num, chip_num
    # 碎片不足
    if chip_num < compose_num:
        return {'result': False, 'result_no': 102, 'message': u''}
    equipment_obj = player.equipment_component.add_equipment(
        chip.combine_result)
    chip.chip_num -= compose_num
    player.equipment_chip_component.save_data()
    notice_item = game_configs.notes_config.get(2007)
    if equipment_obj.equipment_config_info.quality in notice_item.parameter1:
        push_notice(2007,
                    player_name=player.base_info.base_name,
                    equipment_no=chip.combine_result)

    return {'result': True, 'equipment_obj': equipment_obj}
Exemple #4
0
def inherit_equipment_152(pro_data, player):
    """
    装备传承
    """
    request = inherit_pb2.InheritEquipmentRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()
    origin = player.equipment_component.get_equipment(origin_id)
    target = player.equipment_component.get_equipment(target_id)
    # print origin.attribute.strengthen_lv, target.attribute.strengthen_lv, "+"*10

    if not origin or (not target):
        logger.error("equip %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin.attribute.strengthen_lv <= target.attribute.strengthen_lv:
        logger.error(
            "origin equip %s strengthen_lv <= target equip %s strengthen_lv!" %
            (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin.equipment_config_info.get(
            "quality") != target.equipment_config_info.get("quality"):
        logger.error("origin.quality!=target.quality")
        response.result = False
        return response.SerializeToString()

    i_value = 0

    def func():
        """docstring for func"""
        target.attribute.strengthen_lv = origin.attribute.strengthen_lv
        i_value = target.attribute.strengthen_lv

        origin.attribute.strengthen_lv = 1
        # 传承强化过程
        target.enhance_record.enhance_record = origin.enhance_record.enhance_record
        origin.enhance_record.enhance_record = []

        target.save_data()
        origin.save_data()
        print origin.attribute.strengthen_lv, target.attribute.strengthen_lv, "+" * 10

    gold = game_configs.base_config.get("equInheritPrice")
    player.pay.pay(gold, const.INHERIT_EQUIPMENT, func)
    response.result = True
    tlog_action.log('Inherit', player, 2, origin.base_info.id,
                    origin.base_info.equipment_no, target.base_info.id,
                    target.base_info.equipment_no, i_value)
    return response.SerializeToString()
Exemple #5
0
def melting_equipment(equipment_id, response, player):
    """熔炼
    @param dynamic_id:
    @param equipment_ids:
    @param kwargs:
    @return:
    """
    if is_not_open(player, FO_EQUIP_SACRIFICE):
        return {"result": False, "result_no": 837}
    equipment_obj = player.equipment_component.get_equipment(equipment_id)
    if not equipment_obj:
        return {'result': False, 'result_no': 401, 'message': u''}
    melting_items = equipment_obj.melting_item
    gain = item_group_helper.gain(player, melting_items,
                                  const.MELTING_EQUIPMENT)

    item_group_helper.get_return(player, gain, response.cgr)

    tlog_action.log('EquipmentMelting', player,
                    equipment_obj.base_info.equipment_no,
                    equipment_obj.base_info.id)

    # 删除装备
    player.equipment_component.delete_equipment(equipment_id)

    # 添加强化金币
    strength_coin = 0
    for record in equipment_obj.enhance_record.enhance_record:
        strength_coin += record[2]

    strength_coin = int(strength_coin *
                        game_configs.base_config.get("equRefundRatio"))
    return strength_coin
def fight_start(stage, fid, player):
    """开始战斗
    """
    # 校验信息:是否开启,是否达到次数上限等
    res = stage.check()
    if not res.get('result'):
        return res

    fight_cache_component = player.fight_cache_component
    fight_cache_component.stage_id = stage.stage_id
    fight_cache_component.stage = stage
    red_units, blue_units, drop_num, monster_unpara = fight_cache_component.fighting_start(
    )

    # 好友
    char_obj = tb_character_info.getObj(fid)
    lord_data = char_obj.hget('lord_attr_info')
    f_unit = None
    if lord_data and not is_not_open(player, FO_FRIEND_SUPPORT):
        info = lord_data.get('info')
        f_unit = BattleUnit.loads(info)
    else:
        logger.debug('can not find friend id :%d' % fid)

    return dict(result=True,
                red_units=red_units,
                blue_units=blue_units,
                drop_num=drop_num,
                monster_unpara=monster_unpara,
                f_unit=f_unit,
                result_no=0)
Exemple #7
0
def change_equipment(slot_no, no, equipment_id, player):
    """
    @param dynamic_id: 动态ID
    @param slot_no: 阵容位置
    @param no: 装备位置
    @param equipment_id: 装备ID
    @return:
    """
    # logger.debug("change equipment id %s %s %s", slot_no, no, equipment_id)
    if is_not_open(player, FO_CHANGE_EQUIPMENT):
        return {"result": False, "result_no": 837}

    # 检验装备是否存在
    if equipment_id != '0' and not check_have_equipment(player, equipment_id):
        logger.debug("1check_have_equipment %s", equipment_id)
        return {"result": False, "result_no": 702}

    # 校验该装备是否已经装备
    if equipment_id != '0' and equipment_id in player.line_up_component.on_equipment_ids:
        logger.debug("2check_have_equipment")
        return {"result": False, "result_no": 703}

    # 校验装备类型
    if not player.line_up_component.change_equipment(slot_no, no, equipment_id):
        logger.debug("3check_have_equipment")
        return {"result": False, "result_no": 704}
    player.line_up_component.save_data()
    # 更新 七日奖励
    target_update(player, [55])
    return {"result": True}
Exemple #8
0
def inherit_equipment_152(pro_data, player):
    """
    装备传承
    """
    request = inherit_pb2.InheritEquipmentRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()
    origin = player.equipment_component.get_equipment(origin_id)
    target = player.equipment_component.get_equipment(target_id)
    # print origin.attribute.strengthen_lv, target.attribute.strengthen_lv, "+"*10

    if not origin or (not target):
        logger.error("equip %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin.attribute.strengthen_lv <= target.attribute.strengthen_lv:
        logger.error("origin equip %s strengthen_lv <= target equip %s strengthen_lv!" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin.equipment_config_info.get("quality") != target.equipment_config_info.get("quality"):
        logger.error("origin.quality!=target.quality")
        response.result = False
        return response.SerializeToString()

    i_value = 0

    def func():
        """docstring for func"""
        target.attribute.strengthen_lv = origin.attribute.strengthen_lv
        i_value = target.attribute.strengthen_lv

        origin.attribute.strengthen_lv = 1
        # 传承强化过程
        target.enhance_record.enhance_record = origin.enhance_record.enhance_record
        origin.enhance_record.enhance_record = []

        target.save_data()
        origin.save_data()
        print origin.attribute.strengthen_lv, target.attribute.strengthen_lv, "+"*10

    gold = game_configs.base_config.get("equInheritPrice")
    player.pay.pay(gold, const.INHERIT_EQUIPMENT, func)
    response.result = True
    tlog_action.log('Inherit', player, 2, origin.base_info.id,
                    origin.base_info.equipment_no,
                    target.base_info.id,
                    target.base_info.equipment_no,
                    i_value)
    return response.SerializeToString()
Exemple #9
0
def runt_set_841(data, player):
    """镶嵌符文"""
    args = RuntSetRequest()
    args.ParseFromString(data)
    hero_no = args.hero_no
    runt_type = args.runt_type
    runt_set_infos = args.runt_set_info

    response = RuntSetResponse()
    if is_not_open(player, FO_RUNT_ADD):
        response.res.result = False
        response.res.result_no = 837
        return response.SerializeToString()

    hero = player.hero_component.get_hero(hero_no)
    for runt_set_info in runt_set_infos:
        runt_po = runt_set_info.runt_po
        runt_no = runt_set_info.runt_no

        if runt_po > game_configs.base_config.get('totemSpaceNum'+str(runt_type)):
            response.res.result = False
            response.res.result_no = 827
            return response.SerializeToString()

        if hero.runt.get(runt_type):
            if hero.runt.get(runt_type).get(runt_po):
                response.res.result = False
                response.res.result_no = 821
                return response.SerializeToString()
        else:
            hero.runt[runt_type] = {}

        runt_info = player.runt.m_runt.get(runt_no)
        if not runt_info:
            response.res.result = False
            response.res.result_no = 825
            return response.SerializeToString()

    now = int(time.time())
    for runt_set_info in runt_set_infos:
        runt_po = runt_set_info.runt_po
        runt_no = runt_set_info.runt_no
        runt_info = player.runt.m_runt.get(runt_no)
        hero.runt.get(runt_type)[runt_po] = [runt_no] + runt_info
        player.runt.reduce_runt(runt_no)
        tlog_action.log('HeroRuntSet', player, hero_no, now,
                        runt_no, runt_po, runt_info[0])

    target_update(player, [55])
    hero.save_data()
    player.runt.save()

    response.res.result = True
    return response.SerializeToString()
    def level(self, value):
        if self._level != value:
            logger.info('player id:%s level up ++ %s>>%s', self.id,
                        self._level, value)
            # hook task
            hook_task(self.owner, CONDITIONId.LEVEL, self._level)
            target_update(self.owner, [43])
            self._level = value
            tb_character_level.zadd(self._level, self.id)

            # feature open
            if feature_open.is_not_open(self.owner, feature_open.FO_MINE):
                self.owner.mine.reset_data()
Exemple #11
0
def inherit_refine_151(pro_data, player):
    """
    炼体传承
    """
    request = inherit_pb2.InheritRefineRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    origin = player.hero_component.get_hero(origin_id)
    target = player.hero_component.get_hero(target_id)

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()

    print "origin:", origin.refine, "target:", target.refine
    if not origin or (not target):
        logger.error("hero %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if not origin.refine:
        logger.error("origin hero %s do not have refine!" % origin_id)
        response.result = False
        return response.SerializeToString()

    if origin.refine <= target.refine:
        logger.error("origin hero %s refine <= target hero %s refine!" %
                     (origin_id, target_id))
        response.result = False
        return response.SerializeToString()
    i_value = 0

    def func():
        target.refine = origin.refine
        origin.refine = 0
        target.save_data()
        origin.save_data()
        i_value = target.refine

    gold = game_configs.base_config.get("heroInheritPrice")
    player.pay.pay(gold, const.INHERIT_REFINE, func)

    player.finance.save_data()
    response.result = True
    tlog_action.log('Inherit', player, 1, 0, origin_id, 0, target_id, i_value)
    return response.SerializeToString()
Exemple #12
0
def inherit_refine_151(pro_data, player):
    """
    炼体传承
    """
    request = inherit_pb2.InheritRefineRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    origin = player.hero_component.get_hero(origin_id)
    target = player.hero_component.get_hero(target_id)

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()

    print "origin:", origin.refine, "target:", target.refine
    if not origin or (not target):
        logger.error("hero %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if not origin.refine:
        logger.error("origin hero %s do not have refine!" % origin_id)
        response.result = False
        return response.SerializeToString()

    if origin.refine <= target.refine:
        logger.error("origin hero %s refine <= target hero %s refine!" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()
    i_value = 0

    def func():
        target.refine = origin.refine
        origin.refine = 0
        target.save_data()
        origin.save_data()
        i_value = target.refine
    gold = game_configs.base_config.get("heroInheritPrice")
    player.pay.pay(gold, const.INHERIT_REFINE, func)

    player.finance.save_data()
    response.result = True
    tlog_action.log('Inherit', player, 1, 0, origin_id, 0, target_id, i_value)
    return response.SerializeToString()
Exemple #13
0
def hero_break_logic(hero_no, player, response):
    if is_not_open(player, FO_HERO_BREAK):
        return {'result': False, 'result_no': 837}
    hero = player.hero_component.get_hero(hero_no)
    hero_info = game_configs.hero_config.get(hero_no)
    break_through = game_configs.base_config.get('breakthrough')
    target_break_level = hero.break_level + 1
    logger.debug("target_break_level %s" % target_break_level)
    if target_break_level not in break_through:
        logger.debug("hero_break_logic can find target break level %s" % target_break_level)
        return {"result": False, "result_no": 10401}

    if hero.level < break_through[target_break_level][0]:
        logger.debug("hero_break_logic level is not enough %s" % hero.level)
        return {"result": False, "result_no": 10402}

    # 验证武将是否突破到上限
    if hero.break_level == hero_info.breakLimit:
        return {"result": False, "result_no": 201}

    consume_info = hero_info.get('consume' + str(hero.break_level+1))
    item_group = parse(consume_info)
    hero_info = game_configs.hero_config.get(hero.hero_no)
    # 判断是否足够
    result = is_afford(player, item_group)  # 校验
    if not result.get('result'):
        return {"result": False, "result_no": result.get('result_no')}

    # 返回消耗
    return_data = consume(player, item_group, const.HERO_BREAK)
    get_return(player, return_data, response.consume)

    for item in item_group:
        if item.item_type == 105 and item.item_no == 20006:
            hero.break_item_num += item.num
            hero.save_data()

    hero.break_level += 1
    notice_item = game_configs.notes_config.get(2003)
    if hero.break_level in notice_item.parameter1:
        push_notice(2003, player_name=player.base_info.base_name, hero_no=hero.hero_no, hero_break_level=hero.break_level)
    hero.save_data()
    # 3、返回
    tlog_action.log('HeroBreak', player, hero_no, hero.break_level)
    return {"result": True, "break_level": hero.break_level, "break_item_num": hero.break_item_num}
Exemple #14
0
def hero_compose_106(data, player):
    """武将合成"""
    args = hero_request_pb2.HeroComposeRequest()
    args.ParseFromString(data)
    hero_chip_no = args.hero_chip_no
    response = hero_response_pb2.HeroComposeResponse()
    if is_not_open(player, FO_HERO_COMPOSE):
        response.res.result = False
        response.res.result_no = 837
        return response
    hero_no = game_configs.chip_config.get("chips").get(hero_chip_no).combineResult
    need_num = game_configs.chip_config.get("chips").get(hero_chip_no).needNum
    if not hero_no or not need_num:
        logger.error("chip_config数据不全!")
    hero_chip = player.hero_chip_component.get_chip(hero_chip_no)
    # 服务器校验
    if hero_chip.num < need_num:
        response.res.result = False
        response.res.message = u"碎片不足,合成失败!"
        logger.error("碎片不足,合成失败!")
        return response.SerializeToString()
    if player.hero_component.contain_hero(hero_no):
        response.res.result = False
        response.res.result_no = 202
        logger.error("武将已存在,合成失败!")
        response.res.message = u"武将已存在,合成失败!"
        return response.SerializeToString()
    hero = player.hero_component.add_hero(hero_no)
    hero_chip.consume_chip(need_num)  # 消耗碎片
    player.hero_chip_component.save_data()
    notice_item = game_configs.notes_config.get(2008)
    logger.debug("=================%s %s" % (hero.hero_info.quality, notice_item.parameter1))
    if hero.hero_info.quality in notice_item.parameter1:
        push_notice(2008, player_name=player.base_info.base_name, hero_no=hero_no)

    # tlog
    log_action.hero_flow(player, hero.hero_no, 1, 1)
    log_action.chip_flow(player, hero_chip.chip_no, 1, 0,
                         need_num, hero_chip.num, 1)
    # 3、返回
    response.res.result = True
    hero.update_pb(response.hero)
    logger.debug(response)
    return response.SerializeToString()
Exemple #15
0
def check_can_rob(player, uid, chip_id, times, response):
    if is_not_open(player, FO_ROB_TREASURE):
        return False, 837, None

    player_ids = player.pvp.rob_treasure
    flag = 0
    for player_id, ap in player_ids:
        if uid == player_id:
            flag = 1
            break

    if not flag:
        logger.error('pvp_rob_treasure_864, uid error')
        return False, 8641, None

    chip_conf = game_configs.chip_config.get('chips', {}).get(chip_id, None)
    if not chip_conf:
        logger.error('pvp_rob_treasure_864, chip_id error')
        return False, 8642, None
    treasure_id = chip_conf.combineResult

    chips = game_configs.chip_config.get('map').get(treasure_id)

    can_rob = 0
    for x in chips:
        chip = player.equipment_chip_component.get_chip(x)
        # 没有碎片
        if chip and chip.chip_num >= 1:
            can_rob = 1

    default_chips = game_configs.base_config.get('indianaDefaultId')
    if not can_rob and treasure_id not in default_chips:
        logger.error('pvp_rob_treasure_864, dont have one chip')
        return False, 8643, None

    price = game_configs.base_config.get('indianaConsume')
    is_afford_res = is_afford(player, price, multiple=times)  # 校验

    if not is_afford_res.get('result'):
        logger.error('rob_treasure_truce_841, item not enough')
        return False, 8644, None
    print chip_conf, '=====================================chip config'
    return True, 0, chip_conf
Exemple #16
0
def do_hero_refine(player, hero_no, refine, response):
    if is_not_open(player, FO_REFINE):
        return {"result": False, "result_no": 837}
    hero = player.hero_component.get_hero(hero_no)
    _refine_item = game_configs.seal_config.get(refine)
    if not hero:
        logger.error('cant find hero:%s', hero_no)
        return {'result': False, 'result_no': 11801}
    if not _refine_item:
        logger.error('cant find refine item:%s', refine)
        return {'result': False, 'result_no': 11802}

    if _refine_item.get('heroLevelRestrictions') > hero.level:
        logger.error('refine player level is error:%s-%s',
                     _refine_item.get('heroLevelRestrictions'),
                     hero.level)
        return {'result': False, 'result_no': 11805}

    current_refine_item = game_configs.seal_config.get(hero.refine)
    if current_refine_item and _refine_item.id != current_refine_item.get('next'):
        logger.error('not next refine item:%s', refine)
        return {'result': False, 'result_no': 11803}

    result = is_afford(player, _refine_item.expend)  # 校验
    if not result.get('result'):
        logger.error('cant afford refine:%s:cur%s',
                     _refine_item.expend,
                     player.brew.nectar)
        return {'result': False, 'result_no': 11804}

    tlog_action.log('HeroRefine', player, hero_no, refine)

    return_data = consume(player, _refine_item.expend, const.HERO_REFINE)
    get_return(player, return_data, response.consume)

    hero.refine = refine
    player.brew.save_data()
    hero.save_data()

    return {'result': True}
Exemple #17
0
def inherit_upara_153(pro_data, player):
    """
    无双传承
    """
    request = inherit_pb2.InheritUnparaRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()

    origin_level = player.line_up_component.unpars.get(origin_id)
    target_level = player.line_up_component.unpars.get(target_id)

    if not origin_level:
        logger.error("unpara %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin_level <= target_level:
        logger.error("origin.level!=target.level")
        response.result = False
        return response.SerializeToString()

    def func():
        player.line_up_component.unpars[target_id] = origin_level
        player.line_up_component.unpars[origin_id] = 1
        player.line_up_component.save_data()

    need_gold = game_configs.base_config.get("warriorsInheritPrice")
    player.pay.pay(need_gold, const.INHERIT_UPARA, func)
    response.result = True
    tlog_action.log('Inherit', player, 1, 0, origin_id, 0, target_id, 0)
    return response.SerializeToString()
Exemple #18
0
def inherit_upara_153(pro_data, player):
    """
    无双传承
    """
    request = inherit_pb2.InheritUnparaRequest()
    request.ParseFromString(pro_data)
    origin_id = request.origin
    target_id = request.target

    response = common_pb2.CommonResponse()

    if is_not_open(player, FO_INHERIT):
        response.result = False
        response.result_no = 837
        return response.SerializeToString()

    origin_level = player.line_up_component.unpars.get(origin_id)
    target_level = player.line_up_component.unpars.get(target_id)

    if not origin_level:
        logger.error("unpara %s or %s not exists" % (origin_id, target_id))
        response.result = False
        return response.SerializeToString()

    if origin_level <= target_level:
        logger.error("origin.level!=target.level")
        response.result = False
        return response.SerializeToString()

    def func():
        player.line_up_component.unpars[target_id] = origin_level
        player.line_up_component.unpars[origin_id] = 1
        player.line_up_component.save_data()

    need_gold = game_configs.base_config.get("warriorsInheritPrice")
    player.pay.pay(need_gold, const.INHERIT_UPARA, func)
    response.result = True
    tlog_action.log('Inherit', player, 1, 0, origin_id, 0, target_id, 0)
    return response.SerializeToString()
Exemple #19
0
def compose_equipment(chip_no, player):
    """合成装备
    """
    if is_not_open(player, FO_EQUIP_COMPOSE):
        return {"result": False, "result_no": 837}
    chip = player.equipment_chip_component.get_chip(chip_no)
    # 没有碎片
    if not chip:
        return {'result': False, 'result_no': 102, 'message': u''}

    compose_num = chip.compose_num
    chip_num = chip.chip_num
    # print "chip_num", compose_num, chip_num
    # 碎片不足
    if chip_num < compose_num:
        return {'result': False, 'result_no': 102, 'message': u''}
    equipment_obj = player.equipment_component.add_equipment(chip.combine_result)
    chip.chip_num -= compose_num
    player.equipment_chip_component.save_data()
    notice_item = game_configs.notes_config.get(2007)
    if equipment_obj.equipment_config_info.quality in notice_item.parameter1:
        push_notice(2007, player_name=player.base_info.base_name, equipment_no=chip.combine_result)

    return {'result': True, 'equipment_obj': equipment_obj}
Exemple #20
0
def travel_831(data, player):
    """游历"""
    args = TravelRequest()
    args.ParseFromString(data)
    stage_id = args.stage_id
    response = TravelResponse()

    if is_not_open(player, FO_TRAVEL):
        response.res.result = False
        response.res.result_no = 811  # 等级不够
        return response.SerializeToString()

    # ====================判断够不够
    need_items = game_configs.base_config.get('travelExpend')
    result = is_afford(player, need_items)  # 校验
    if not result.get('result'):
        response.res.result = False
        response.res.result_no = 888
        return response.SerializePartialToString()
    travel_cache = player.travel_component.travel

    travel_event_id = get_travel_event_id()
    flag = 10
    if travel_cache.get(stage_id):
        for event in travel_cache.get(stage_id):
            if travel_event_id == event[0] % xs:
                flag += 1
    else:
        travel_cache[stage_id] = []

    res_travel_event_id = flag * xs + travel_event_id

    event_info = game_configs.travel_event_config.get('events').get(
        travel_event_id)
    if not event_info:
        logger.error('get travel event config error')
        response.res.result = False
        response.res.result_no = 800  # 未知错误
        return response.SerializeToString()

    response.event_id = res_travel_event_id

    res_drops = response.drops

    drops = get_drops(stage_id)
    drop_data = get_drop_data(drops)

    get_return(player, drop_data, res_drops)

    # 等待 战斗 答题 领取
    if event_info.type == 4:
        gain(player, drops, const.TRAVEL)
    else:
        travel_cache.get(stage_id).append([res_travel_event_id, drops])

    # ====================消耗
    return_data = consume(player, need_items, const.TRAVEL)
    get_return(player, return_data, response.consume)
    player.travel_component.save()

    hook_task(player, CONDITIONId.TRAVEL, 1)

    response.res.result = True
    return response.SerializeToString()
Exemple #21
0
def enhance_equipment(equipment_id, enhance_type, player):
    """装备强化
    @param dynamic_id:  客户端动态ID
    @param equipment_id: 装备ID
    @param enhance_type: 强化类型
    @param kwargs:
    @return:
    """
    if is_not_open(player, FO_EQUIP_ENHANCE):
        return {"result": False, "result_no": 837}

    equipment_obj = player.equipment_component.get_equipment(equipment_id)
    # print equipment_obj, "equipment_obj"

    if enhance_type == 2 and not player.base_info.equipment_strength_one_key:
        logger.debug('enhance_equipment_vip_error!%d' %
                     player.base_info.equipment_strength_one_key)
        return {'result': False, 'result_no': 403, 'message': u''}

    if not equipment_obj:
        logger.debug('enhance_equipment_no_equipment!')
        return {'result': False, 'result_no': 401, 'message': u''}

    enhance_record = []

    curr_coin = player.finance.coin  # 用户金币
    # curr_coin = 1000000
    enhance_cost = equipment_obj.attribute.enhance_cost  # 强化消耗
    if not enhance_cost or curr_coin < enhance_cost:
        return {'result': False, 'result_no': 101, 'message': u''}

    strength_max = equipment_obj.strength_max(player)
    current_strength_lv = equipment_obj.attribute.strengthen_lv

    if strength_max <= current_strength_lv:
        return {'result': False, 'result_no': 402, 'message': u''}

    num = 0
    if enhance_type == 1:
        result = __do_enhance(player, equipment_obj)
        if result.get('record')[1] >= strength_max:
            result['record'] = (result.get('record')[0], strength_max, result.get('record')[2])
        enhance_record.append(result.get('record'))
        num += 1
    else:
        while strength_max > current_strength_lv and curr_coin > enhance_cost:
            num += 1
            result = __do_enhance(player, equipment_obj)
            if not result.get('result'):
                return result

            if result.get('record')[1] >= strength_max:
                result['record'] = (result.get('record')[0], strength_max, result.get('record')[2])
                enhance_record.append(result.get('record'))
                break
            enhance_record.append(result.get('record'))
            current_strength_lv = equipment_obj.attribute.strengthen_lv
            enhance_cost = equipment_obj.attribute.enhance_cost  # 强化消耗
            curr_coin = player.finance.coin  # 用户金币

    print equipment_obj.enhance_record
    equipment_obj.enhance_record.enhance_record.extend(enhance_record)

    # 保存
    equipment_obj.save_data()
    player.finance.save_data()

    return {'result': True, 'enhance_record': enhance_record, 'num': num,
            'equipment_no': equipment_obj.base_info.equipment_no}
Exemple #22
0
def enhance_equipment(equipment_id, enhance_type, player):
    """装备强化
    @param dynamic_id:  客户端动态ID
    @param equipment_id: 装备ID
    @param enhance_type: 强化类型
    @param kwargs:
    @return:
    """
    if is_not_open(player, FO_EQUIP_ENHANCE):
        return {"result": False, "result_no": 837}

    equipment_obj = player.equipment_component.get_equipment(equipment_id)
    # print equipment_obj, "equipment_obj"

    if enhance_type == 2 and not player.base_info.equipment_strength_one_key:
        logger.debug('enhance_equipment_vip_error!%d' %
                     player.base_info.equipment_strength_one_key)
        return {'result': False, 'result_no': 403, 'message': u''}

    if not equipment_obj:
        logger.debug('enhance_equipment_no_equipment!')
        return {'result': False, 'result_no': 401, 'message': u''}

    enhance_record = []

    curr_coin = player.finance.coin  # 用户金币
    # curr_coin = 1000000
    enhance_cost = equipment_obj.attribute.enhance_cost  # 强化消耗
    if not enhance_cost or curr_coin < enhance_cost:
        return {'result': False, 'result_no': 101, 'message': u''}

    strength_max = equipment_obj.strength_max(player)
    current_strength_lv = equipment_obj.attribute.strengthen_lv

    if strength_max <= current_strength_lv:
        return {'result': False, 'result_no': 402, 'message': u''}

    num = 0
    if enhance_type == 1:
        result = __do_enhance(player, equipment_obj)
        if result.get('record')[1] >= strength_max:
            result['record'] = (result.get('record')[0], strength_max,
                                result.get('record')[2])
        enhance_record.append(result.get('record'))
        num += 1
    else:
        while strength_max > current_strength_lv and curr_coin > enhance_cost:
            num += 1
            result = __do_enhance(player, equipment_obj)
            if not result.get('result'):
                return result

            if result.get('record')[1] >= strength_max:
                result['record'] = (result.get('record')[0], strength_max,
                                    result.get('record')[2])
                enhance_record.append(result.get('record'))
                break
            enhance_record.append(result.get('record'))
            current_strength_lv = equipment_obj.attribute.strengthen_lv
            enhance_cost = equipment_obj.attribute.enhance_cost  # 强化消耗
            curr_coin = player.finance.coin  # 用户金币

    print equipment_obj.enhance_record
    equipment_obj.enhance_record.enhance_record.extend(enhance_record)

    # 保存
    equipment_obj.save_data()
    player.finance.save_data()

    return {
        'result': True,
        'enhance_record': enhance_record,
        'num': num,
        'equipment_no': equipment_obj.base_info.equipment_no
    }
Exemple #23
0
def hero_sacrifice_oper(heros, player):
    """
    武将献祭,返回总武魂、经验药水
    :param heros: 被献祭的武将
    :return total_hero_soul:总武魂数量, exp_item_no:经验药水编号, exp_item_num:经验药水数量
    """
    total_exp = 0
    exp_item_no = 0
    exp_item_num = 0
    awake_item_no = 90001
    awake_item_num = 0
    break_item_no = 20006
    break_item_num = 0

    response = hero_response_pb2.HeroSacrificeResponse()
    if is_not_open(player, FO_HERO_SACRIFICE):
        response.res.result = False
        response.res.result_no = 837
        return response
    gain_response = response.gain
    for hero in heros:
        sacrifice_gain = game_configs.hero_config.get(hero.hero_no).sacrificeGain
        return_data = gain(player, sacrifice_gain, const.HERO_SACRIFICE_OPER)
        get_return(player, return_data, gain_response)
        # 经验
        exp = hero.get_all_exp()
        total_exp += exp
        tlog_action.log('HeroSacrifice', player, hero.hero_no)
        # 觉醒丹
        awake_item_num += hero.awake_item_num
        # 突破丹
        break_item_num += hero.break_item_num

    # baseconfig {1000000: 'item_id'}

    logger.debug("total_exp %s" % total_exp)
    formula_info = game_configs.formula_config.get("sacrificeExp_3")
    pre_formula = formula_info.get("precondition")
    formula = formula_info.get("formula")
    cal_vars = dict(expHero=total_exp)
    if eval(pre_formula, cal_vars):
        exp_item_no = 10003
        exp_item_num = eval(formula, cal_vars)
    formula_info = game_configs.formula_config.get("sacrificeExp_2")
    pre_formula = formula_info.get("precondition")
    formula = formula_info.get("formula")
    cal_vars = dict(expHero=total_exp)
    if eval(pre_formula, cal_vars):
        exp_item_no = 10002
        exp_item_num = eval(formula, cal_vars)
    formula_info = game_configs.formula_config.get("sacrificeExp_1")
    pre_formula = formula_info.get("precondition")
    formula = formula_info.get("formula")
    cal_vars = dict(expHero=total_exp)
    if eval(pre_formula, cal_vars):
        exp_item_no = 10001
        exp_item_num = eval(formula, cal_vars)
    heroAwakeBack = game_configs.base_config.get('heroAwakeBack')
    heroBreakBack = game_configs.base_config.get('heroBreakBack')
    awake_item_num = int(awake_item_num * heroAwakeBack)
    break_item_num = int(break_item_num * heroBreakBack)

    player.item_package.add_item(Item(exp_item_no, exp_item_num))
    player.item_package.add_item(Item(awake_item_no, awake_item_num))
    player.item_package.add_item(Item(break_item_no, break_item_num))
    player.item_package.save_data()
    if exp_item_no:
        item_pb = gain_response.items.add()
        item_pb.item_no = exp_item_no
        item_pb.item_num = exp_item_num
    if awake_item_num:
        item_pb = gain_response.items.add()
        item_pb.item_no = awake_item_no
        item_pb.item_num = awake_item_num
    if break_item_num:
        item_pb = gain_response.items.add()
        item_pb.item_no = break_item_no
        item_pb.item_num = break_item_num
    response.res.result = True
    # print "*"*80
    # print response
    return response
Exemple #24
0
def do_hero_awake(player, hero_no, awake_item_num, response):
    """docstring for do_hero_awake"""
    if is_not_open(player, FO_HERO_AWAKE):
        return {'result': False, 'result_no': 837}

    hero = player.hero_component.get_hero(hero_no)
    if not hero:
        logger.error("hero not exist! hero_no %s" % hero_no)
        return {'result': False, 'result_no': 11901}

    awake_info = game_configs.awake_config.get(hero.awake_level)
    logger.debug("hero.awake_level %s, hero_no %s, awake_item_num %s" % (hero.awake_level, hero_no, awake_item_num))

    singleConsumption = awake_info.singleConsumption
    logger.debug("singleConsumption %s" % singleConsumption)
    singleCoin = awake_info.silver

    if not is_afford(player, singleConsumption).get("result"):
        logger.error("singleConsumption is not afford!")
        return {'result': False, 'result_no': 11902}

    if not is_afford(player, singleCoin).get("result"):
        logger.error("singleCoin is not afford!")
        return {'result': False, 'result_no': 11903}

    if hero.awake_level >= 10:
        logger.error("the hero has reached the max awake level!")
        return {'result': False, 'result_no': 11904}

    singleConsumptionNum = singleConsumption[0].num
    left_awake_item = awake_item_num


    before_num = hero.awake_item_num

    while left_awake_item >= singleConsumptionNum:
        # consume
        if not is_afford(player, singleConsumption) or \
            not is_afford(player, singleCoin):
                break
        return_data1 = consume(player, singleConsumption, const.HERO_AWAKE)
        return_data2 = consume(player, singleCoin, const.HERO_AWAKE)
        get_return(player, return_data1, response.consume)
        get_return(player, return_data2, response.consume)

        # record awake item num
        hero.awake_item_num += singleConsumptionNum

        # trigger or not, add exp, add level
        exp_percent = hero.awake_exp * 1.0 / awake_info.experience
        is_trigger = False
        for k in sorted(awake_info.triggerProbability.keys(), reverse=True):
            if exp_percent > k:
                v = awake_info.triggerProbability[k]
                target_percent = random.uniform(v[0], v[1])
                if random.random() < target_percent:
                    is_trigger = True
                    break

        if is_trigger:  # 触发满级概率
            logger.debug("is_trigger!")
            hero.awake_exp = 0
            hero.awake_level += 1
            break
        else:
            logger.debug("not is_trigger!")
            hero.awake_exp += singleConsumptionNum
            if hero.awake_exp >= awake_info.experience:
                hero.awake_exp = hero.awake_exp - awake_info.experience
                hero.awake_level += 1

        left_awake_item -= singleConsumptionNum

    # actual_consume_item_num = 0
    hero.save_data()
    response.awake_level = hero.awake_level
    response.awake_exp = hero.awake_exp
    response.awake_item_num = hero.awake_item_num
    use_num = hero.awake_item_num - before_num
    tlog_action.log('HeroAwake', player, hero_no, use_num, hero.awake_level-1)

    return {'result': True}
Exemple #25
0
def travel_831(data, player):
    """游历"""
    args = TravelRequest()
    args.ParseFromString(data)
    stage_id = args.stage_id
    response = TravelResponse()

    if is_not_open(player, FO_TRAVEL):
        response.res.result = False
        response.res.result_no = 811  # 等级不够
        return response.SerializeToString()

    # ====================判断够不够
    need_items = game_configs.base_config.get('travelExpend')
    result = is_afford(player, need_items)  # 校验
    if not result.get('result'):
        response.res.result = False
        response.res.result_no = 888
        return response.SerializePartialToString()
    travel_cache = player.travel_component.travel

    travel_event_id = get_travel_event_id()
    flag = 10
    if travel_cache.get(stage_id):
        for event in travel_cache.get(stage_id):
            if travel_event_id == event[0] % xs:
                flag += 1
    else:
        travel_cache[stage_id] = []

    res_travel_event_id = flag * xs + travel_event_id

    event_info = game_configs.travel_event_config.get('events').get(travel_event_id)
    if not event_info:
        logger.error('get travel event config error')
        response.res.result = False
        response.res.result_no = 800  # 未知错误
        return response.SerializeToString()

    response.event_id = res_travel_event_id

    res_drops = response.drops

    drops = get_drops(stage_id)
    drop_data = get_drop_data(drops)

    get_return(player, drop_data, res_drops)

    # 等待 战斗 答题 领取
    if event_info.type == 4:
        gain(player, drops, const.TRAVEL)
    else:
        travel_cache.get(stage_id).append([res_travel_event_id, drops])

    # ====================消耗
    return_data = consume(player, need_items, const.TRAVEL)
    get_return(player, return_data, response.consume)
    player.travel_component.save()

    hook_task(player, CONDITIONId.TRAVEL, 1)

    response.res.result = True
    return response.SerializeToString()
Exemple #26
0
def battle_1253(data, player):
    """docstring for battle"""
    request = mine_pb2.MineBattleRequest()
    request.ParseFromString(data)
    pos = request.pos                    # 矿所在位置
    line_up = request.lineup            # 阵容顺序
    red_best_skill_id = request.unparalleled  # 无双编号
    red_units = {}
    blue_units = {}
    response = mine_pb2.MineBattleResponse()

    logger.debug("%s pos" % pos)
    if is_not_open(player, FO_MINE):
        response.res.result = True
        response.res.result_no = 837
        return response.SerializePartialToString()

    mine_info = player.mine.get_info(pos)

    is_pvp = player.mine.is_pvp(pos)  # 根据矿所在位置判断pve or pvp
    # print mine_info, "*"*80
    detail_info = player.mine.detail_info(request.pos)
    if not is_pvp:
        # pve
        stage_id = mine_info.get("stage_id")        # todo: 根据pos获取关卡id
        stage_type = 8                              # 关卡类型
        stage_info = pve_process(stage_id,
                                 stage_type,
                                 line_up,
                                 0,
                                 player
                                 )
        result = stage_info.get('result')
        response.res.result = result
        if not result:
            logger.info('进入关卡返回数据:%s', response)
            response.res.result_no = stage_info.get('result_no')
            return response.SerializePartialToString()
        red_units = stage_info.get('red_units')
        blue_units = stage_info.get('blue_units')
        blue_units = blue_units[0]

        seed1, seed2 = get_seeds()
        player.fight_cache_component.seed1 = seed1
        player.fight_cache_component.seed2 = seed2
        player.fight_cache_component.red_best_skill_id = red_best_skill_id
        player.fight_cache_component.stage_info = stage_info
        response.seed1 = seed1
        response.seed2 = seed2
        # print red_units, blue_units

    else:
        # pvp
        normal = detail_info['normal']
        lucky = detail_info['lucky']
        num = sum(normal.values()) + sum(lucky.values())
        if player.runt.bag_is_full(num):
            response.res.result = False
            response.res.result_no = 125308
            logger.error('mine harvest bag is full!')
            return response.SerializePartialToString()

        player.fight_cache_component.stage_id = 0
        red_units = player.fight_cache_component.get_red_units()
        blue_data = get_blue_units(detail_info['uid'])
        blue_units = blue_data.get('copy_units')
        seed1, seed2 = get_seeds()
        if not blue_units:
            fight_result = True
        else:
            fight_result = pvp_process(player,
                                       line_up,
                                       red_units,
                                       blue_units,
                                       seed1, seed2,
                                       const.BATTLE_MINE_PVP)
        hold = request.hold
        process_mine_result(player, pos, fight_result, response, 1, hold)

        response.fight_result = fight_result
        response.seed1 = seed1
        response.seed2 = seed2

        # print red_units, blue_units

    pvp_assemble_units(red_units, blue_units, response)
    response.res.result = True
    response.hold = request.hold
    logger.debug('battle_1253:%s', response)
    return response.SerializePartialToString()
Exemple #27
0
def pvp_fight_request_1505(data, player):
    """
    pvp战斗开始
    """
    request = pvp_rank_pb2.PvpFightRequest()
    response = pvp_rank_pb2.PvpFightResponse()
    request.ParseFromString(data)
    # player.pvp.check_time()
    if is_not_open(player, FO_PVP_RANK):
        response.res.result = False
        response.res.result_no = 837
        return response.SerializePartialToString()

    arena_consume = game_configs.base_config.get('arenaConsume')
    result = is_afford(player, arena_consume)  # 校验
    if not result.get('result'):
        logger.error('not enough consume:%s', arena_consume)
        response.res.result = False
        response.res.result_no = 150501
        return response.SerializePartialToString()

    # if player.pvp.pvp_times <= 0:
    #     logger.error('not enough pvp times:%s-%s', player.pvp.pvp_times,
    #                  game_configs.base_config.get('arena_free_times'))
    #     response.res.result = False
    #     response.res.result_no = 836
    #     return response.SerializeToString()

    challenge_rank = request.challenge_rank
    if challenge_rank < 0 and player.pvp.pvp_upstage_challenge_rank != 0:
        challenge_rank = player.pvp.pvp_upstage_challenge_rank

    if challenge_rank < 0:
        logger.error('pvp challenge rank error!!%s-%s', challenge_rank,
                     player.pvp.pvp_upstage_challenge_rank)
        response.res.result = False
        response.res.result_no = 839
        return response.SerializeToString()

    line_up = request.lineup
    skill = request.skill
    target_id = int(
        tb_pvp_rank.zrangebyscore(challenge_rank, challenge_rank)[0])
    if target_id != request.challenge_id:
        logger.error('pvp challenge id changed!!%s-%s', target_id,
                     request.challenge_id)
        response.res.result = False
        response.res.result_no = 150508
        return response.SerializeToString()

    before_player_rank = tb_pvp_rank.zscore(player.base_info.id)
    if not before_player_rank:
        before_player_rank = int(tb_pvp_rank.getObj('incr').incr())
        tb_pvp_rank.zadd(before_player_rank, player.base_info.id)
        player.pvp.pvp_high_rank = before_player_rank
    elif before_player_rank != request.self_rank:
        logger.error('pvp self rank changed!!%s-%s', before_player_rank,
                     request.self_rank)
        response.res.result = False
        response.res.result_no = 150509
        return response.SerializeToString()

    before_player_rank = int(before_player_rank)

    if before_player_rank == challenge_rank:
        logger.error('cant not fight self')
        response.res.result = False
        response.res.result_no = 1505
        return response.SerializeToString()

    return_data = consume(player, arena_consume, const.PVP)
    get_return(player, return_data, response.consume)

    fight_result = pvp_fight(player, target_id, line_up, skill, response)

    rank_incr = 0
    response.top_rank = player.pvp.pvp_high_rank
    response.before_rank = before_player_rank
    if fight_result:
        logger.debug("fight result:True:%s:%s", before_player_rank,
                     challenge_rank)

        _arena_win_points = game_configs.base_config.get('arena_win_points')
        if _arena_win_points:
            return_data = gain(player, _arena_win_points, const.ARENA_WIN)
            get_return(player, return_data, response.gain)
        else:
            logger.debug('arena win points is not find')

        push_config = game_configs.push_config[1003]
        rank_count = push_config.conditions[0]
        if challenge_rank - before_player_rank >= rank_count:
            txt = game_configs.push_config[1003].text
            message = game_configs.language_config.get(str(txt)).get('cn')
            remote_gate['push'].add_push_message_remote(
                player.base_info.id, 3, message, int(time.time()))

        push_message('add_blacklist_request_remote', target_id,
                     player.base_info.id)

        if challenge_rank < before_player_rank:
            tb_pvp_rank.zadd(challenge_rank, player.base_info.id,
                             before_player_rank, target_id)
            send_mail(conf_id=123,
                      receive_id=target_id,
                      pvp_rank=before_player_rank,
                      nickname=player.base_info.base_name)

        if challenge_rank < player.pvp.pvp_high_rank:
            rank_incr = player.pvp.pvp_high_rank - challenge_rank
        if player.pvp.pvp_high_rank > challenge_rank:
            hook_task(player, CONDITIONId.PVP_RANK, challenge_rank)
        formula = game_configs.formula_config.get(
            "arenaRankUpRewardsValue").get("formula")
        gain_num = eval(
            formula,
            dict(upRank=challenge_rank, highestRank=player.pvp.pvp_high_rank))

        # stage award
        stage_info_before = get_player_pvp_stage(player.pvp.pvp_high_rank)
        stage_info_current = get_player_pvp_stage(challenge_rank)
        before_gradient = stage_info_before.get('Gradient')
        current_gradient = stage_info_current.get('Gradient')
        if stage_info_current and stage_info_current \
           and before_gradient > current_gradient:
            arena_stage_reward = stage_info_current.get('Reward')
            stage_reward_data = gain(player, arena_stage_reward,
                                     const.ARENA_WIN)
            get_return(player, stage_reward_data, response.award2)
            logger.debug('stage award %s %s', stage_info_current,
                         stage_info_before)

        player.pvp.pvp_high_rank = min(player.pvp.pvp_high_rank,
                                       challenge_rank)
        logger.debug("history_high_rank %s current %s" %
                     (player.pvp.pvp_high_rank, before_player_rank))

        # 首次达到某名次的奖励
        arena_rank_rewards = game_configs.base_config.get('arenaRankUpRewards')

        if arena_rank_rewards:
            return_data = gain(player,
                               arena_rank_rewards,
                               const.ARENA_WIN,
                               multiple=int(gain_num))
            get_return(player, return_data, response.award)
        else:
            logger.debug('arena rank up points is not find')
    else:
        logger.debug("fight result:False")
        send_mail(conf_id=124,
                  receive_id=target_id,
                  nickname=player.base_info.base_name)

    hook_task(player, CONDITIONId.PVP_RANk_TIMES, 1)

    player.pvp.pvp_times -= 1
    player.pvp.pvp_refresh_time = time.time()
    player.pvp.save_data()
    response.res.result = True
    # response.top_rank = player.pvp.pvp_high_rank
    response.rank_incr = rank_incr
    logger.debug(response)

    return response.SerializeToString()
Exemple #28
0
def trigger_hjqy(player, result, times=1):
    """docstring for trigger_hjqy 触发黄巾起义
    return: stage id
    """
    if is_not_open(player, FO_HJQY_STAGE):
        return 0
    # 如果战败则不触发
    if not result:
        return 0
    logger.debug("trigger_hjqy")
    # 活动是否开启
    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_HJQY):
        logger.debug("hjqy have not open.")
        return 0

    # 如果已经触发过hjqy,则不触发
    if not remote_gate['world'].is_can_trigger_hjqy_remote(
            player.base_info.id):
        return 0

    stage_info = player.fight_cache_component._get_stage_config()
    if stage_info.type not in [1, 2, 3]:
        # 只有在剧情关卡时,才能触发黄巾起义
        return 0
    logger.debug(stage_info.chapter)
    logger.debug(stage_info.type)
    logger.debug(stage_info.id)

    logger.debug("can_trigger_hjqy")
    # 触发hjqy
    open_stage_id = player.stage_component.stage_progress
    player.fight_cache_component.stage_id = open_stage_id
    stage_info = player.fight_cache_component._get_stage_config()

    #rate = 0.01 # for test
    hjqytrigger = game_configs.base_config.get("hjqytrigger")
    hjqyRandomCheckpoint = game_configs.base_config.get("hjqyRandomCheckpoint")
    rate = 1
    for i in range(times):
        rate = random.random()
        if rate <= hjqytrigger[0]:
            break
    logger.debug("rate: %s, hjqytrigger:%s" % (rate, hjqytrigger))
    if rate > hjqytrigger[0]:
        return 0

    info = {}
    for i in range(1, 4):
        info[i] = hjqytrigger[i]

    stage_index = random_pick_with_weight(info)

    logger.debug(
        "chapter: %s, stage_index: %s, stage_id: %s, open_stage_id: %s" %
        (stage_info.chapter, stage_index,
         player.fight_cache_component.stage_id, open_stage_id))

    if stage_info.chapter not in hjqyRandomCheckpoint:
        return 0

    stage_id = hjqyRandomCheckpoint.get(stage_info.chapter)[stage_index - 1]

    monster_lv = hjqyRandomCheckpoint.get(stage_info.chapter)[3]

    hjqyRule2 = game_configs.base_config.get("hjqyRule2")
    if monster_lv - player.base_info.level > hjqyRule2:
        logger.debug("monster_lv %s, player.base_info.level %s, hjqyRule2 %s" %
                     (monster_lv, player.base_info.level, hjqyRule2))
        if (stage_info.chapter - 1) not in hjqyRandomCheckpoint:
            return 0
        stage_id = hjqyRandomCheckpoint.get(stage_info.chapter -
                                            1)[stage_index - 1]

    player.fight_cache_component.stage_id = stage_id

    blue_units = player.fight_cache_component._assemble_monster()

    str_blue_units = cPickle.dumps(blue_units[0])
    result = remote_gate['world'].create_hjqy_remote(
        player.base_info.id, player.base_info.base_name, str_blue_units,
        stage_id)
    logger.debug("8============= %s %s" % (stage_id, open_stage_id))
    if not result:
        return 0
    # send trigger reward
    hjqyOpenReward = game_configs.base_config.get("hjqyOpenRewardID")
    send_mail(conf_id=hjqyOpenReward, receive_id=player.base_info.id)

    return stage_id
Exemple #29
0
def stage_start_903(pro_data, player):
    """pve开始战斗
    """
    request = stage_request_pb2.StageStartRequest()
    request.ParseFromString(pro_data)

    stage_id = request.stage_id  # 关卡编号
    line_up = request.lineup  # 阵容顺序
    red_best_skill_id = request.unparalleled  # 无双编号
    fid = request.fid  # 好友ID

    # logger.debug("red_best_skill_id,%s" % red_best_skill_id)
    # logger.debug("fid,%s" % fid)
    response = stage_response_pb2.StageStartResponse()
    player.fight_cache_component.stage_id = stage_id
    stage_config = player.fight_cache_component._get_stage_config()
    not_open = False
    if stage_config.type == 6:  # 精英
        not_open = is_not_open(player, FO_ELI_STAGE)
    if stage_config.type in [4, 5]:  # 活动
        not_open = is_not_open(player, FO_ACT_STAGE)
    if not_open:
        response.res.result = False
        response.res.result_no = 837
        return response.SerializeToString()

    stage_info = pve_process(stage_id, stage_config.type, line_up, fid, player)
    result = stage_info.get('result')

    res = response.res
    res.result = result

    if not result:
        # logger.info('进入关卡返回数据:%s', response)
        res.result_no = stage_info.get('result_no')
        return response.SerializePartialToString()

    red_units = stage_info.get('red_units')
    blue_groups = stage_info.get('blue_units')
    drop_num = stage_info.get('drop_num')
    blue_skill = stage_info.get('monster_unpara')
    f_unit = stage_info.get('f_unit')

    pve_assemble_units(red_units, blue_groups, response)
    pve_assemble_friend(f_unit, response)
    if blue_skill:
        response.monster_unpar = blue_skill
    response.hero_unpar = 0
    response.hero_unpar_level = 0

    response.drop_num = drop_num

    seed1, seed2 = get_seeds()
    player.fight_cache_component.seed1 = seed1
    player.fight_cache_component.seed2 = seed2
    player.fight_cache_component.red_best_skill_id = red_best_skill_id
    player.fight_cache_component.stage_info = stage_info
    response.seed1 = seed1
    response.seed2 = seed2

    if f_unit:
        player.fight_cache_component.fid = fid
    else:
        player.fight_cache_component.fid = 0

    player.fight_cache_component.red_best_skill_id = 0
    logger.debug(response)
    return response.SerializePartialToString()