Пример #1
0
    def get_stage_drop(self, stage_conf, drops):
        stage_obj = self.owner.stage_component.get_stage(stage_conf.id)

        elite_drop_stage, elite_drop2_stage = stage_obj.have_elite_drop(
            stage_conf)
        # stage_obj.attack_times += 1

        if elite_drop2_stage and stage_conf.eliteDrop2:  # 掉落保底
            elite_bag = BigBag(stage_conf.eliteDrop2)
            elite_drop2 = elite_bag.get_drop_items()
            drops.extend(elite_drop2)

        if not elite_drop_stage or not stage_conf.eliteDrop:
            return

        if stage_conf.type == 1:
            elite_bag = BigBag(stage_conf.eliteDrop)
            elite_drop = elite_bag.get_drop_items()
            drops.extend(elite_drop)
            if elite_drop:
                stage_obj.elite_drop_times += 1
        else:
            if elite_drop2_stage:
                return
            # 根据条件得到概率
            elite_drop2_condition_state = get_elite_drop2_condition_state(
                self.owner, stage_conf)
            if not elite_drop2_condition_state:
                return

            elite_bag = BigBag(stage_conf.eliteDrop)
            elite_drop = elite_bag.get_drop_items()
            drops.extend(elite_drop)
            if elite_drop:
                stage_obj.elite_drop_times += 1
Пример #2
0
def open_chest_836(data, player):

    response = OpenChestResponse()

    chest_time = player.travel_component.chest_time

    if time.localtime(chest_time).tm_year == time.localtime().tm_year \
            and time.localtime(chest_time).tm_yday == time.localtime().tm_yday:
        response.res.result = False
        response.res.result_no = 816
        return response.SerializeToString()

    res_drops = response.drops
    drops = []
    common_bag = BigBag(game_configs.base_config.get('travelChest'))
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)
    drop_data = gain(player, drops, const.TRAVEL_OPEN_CHEST)
    get_return(player, drop_data, res_drops)

    player.travel_component.chest_time = int(time.time())

    player.travel_component.save()

    response.res.result = True
    return response.SerializeToString()
Пример #3
0
def continus_sign_in_1402(pro_data, player):
    """连续签到"""
    request = ContinuousSignInRequest()
    request.ParseFromString(pro_data)
    days = request.sign_in_days
    response = ContinuousSignInResponse()

    sign_in_prize = base_config.get("signInPrize")
    if not sign_in_prize:
        return
    # 验证连续签到日期
    if player.sign_in_component.continuous_sign_in_days < days:
        response.res.result = False
        response.res.result_no = 1402
        return response.SerializePartialToString()
    if days in player.sign_in_component.continuous_sign_in_prize:
        response.res.result = False
        response.res.result_no = 1403
        return response.SerializePartialToString()

    player.sign_in_component.continuous_sign_in_prize.append(days)
    player.sign_in_component.save_data()

    drop_bag_id = sign_in_prize.get(days)
    big_bag = BigBag(drop_bag_id)
    gain_data = big_bag.get_drop_items()
    return_data = gain(player, gain_data)
    get_return(player, return_data, response.gain)

    response.res.result = True
    return response.SerializePartialToString()
Пример #4
0
def open_chest_836(data, player):

    response = OpenChestResponse()

    chest_time = player.travel_component.chest_time

    if time.localtime(chest_time).tm_year == time.localtime().tm_year \
            and time.localtime(chest_time).tm_yday == time.localtime().tm_yday:
        response.res.result = False
        response.res.result_no = 816
        return response.SerializeToString()

    res_drops = response.drops
    drops = []
    common_bag = BigBag(game_configs.base_config.get('travelChest'))
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)
    drop_data = gain(player, drops, const.TRAVEL_OPEN_CHEST)
    get_return(player, drop_data, res_drops)

    player.travel_component.chest_time = int(time.time())

    player.travel_component.save()

    response.res.result = True
    return response.SerializeToString()
Пример #5
0
def pvp_rob_treasure_more_times_1504(data, player):
    request = pvp_rank_pb2.RobTreasureMoreTimesRequest()
    response = pvp_rank_pb2.RobTreasureMoreTimesResponse()
    request.ParseFromString(data)
    uid = request.uid
    chip_id = request.chip_id
    times = request.times
    check_res, res_no, chip_conf = check_can_rob(player, uid, chip_id, times,
                                                 response)
    if not check_res:
        response.res.result = False
        response.res.result_no = res_no
        return response.SerializePartialToString()
    player.rob_treasure.truce = [0, 1]
    for _ in range(times):
        one_times_response = response.one_time_info.add()
        fight_response = one_times_response.fight_info
        fight_result = deal_pvp_rob_fight(player, uid, chip_id, fight_response,
                                          chip_conf)
        if fight_result:
            indiana_conf = get_indiana_conf(player, uid, chip_conf)
            common_bag = BigBag(indiana_conf.reward)
            drops = common_bag.get_drop_items()

            x = random.randint(0, 2)
            return_data = gain(player, [drops[x]], const.ROB_TREASURE_REWARD)
            get_return(player, return_data, one_times_response.gain)

    player.pvp.reset_rob_treasure()
    player.pvp.save_data()
    player.rob_treasure.save_data()
    response.res.result = True
    logger.debug("response ==================== : %s" % response)
    return response.SerializeToString()
Пример #6
0
def use_item_302(pro_data, player):
    """使用道具"""
    item_pb = item_pb2.ItemPB()
    item_pb.ParseFromString(pro_data)
    item_no = item_pb.item_no
    item_num = item_pb.item_num
    print("request:", item_pb)
    item_config_item = game_configs.item_config.get(item_no)
    if not item_config_item:
        return
    item_func = item_config_item.func
    drop_id = item_config_item.dropId
    func_args1 = item_config_item.funcArg1
    func_args2 = item_config_item.funcArg2

    response = ItemUseResponse()
    common_response = response.res  # = common_response
    common_response.result = True

    # 校验道具数量
    item = player.item_package.get_item(item_no)
    if not item or item.num < item_num:
        common_response.result = False
        common_response.result_no = 106
        print("error:", 106)
        # common_response.message = u"道具不足!"
        return response.SerializeToString()

    if item_func == 2:
        # 宝箱
        box_key_no = func_args1
        box_key = player.item_package.get_item(box_key_no)
        if not box_key or box_key.num < func_args2 * item_num:
            print("error:", 107)
            common_response.result = False
            common_response.result_no = 107
            # common_response.message = u"box key 不足!" + str(func_args2 * item_num) + "_" + str(box_key.num)
            return response.SerializeToString()
        # 消耗key
        #box_key.num -= func_args2 * item_num
        player.item_package.consume_item(box_key_no, item_num)
        player.item_package.save_data()

    big_bag = BigBag(drop_id)
    for i in range(item_num):
        drop_item_group = big_bag.get_drop_items()
        return_data = gain(player, drop_item_group, const.USE_ITEM)
        get_return(player, return_data, response.gain)

    logger.debug("item_no:%s", item_no)
    logger.debug("item_num:%s", item_num)

    # 使用招财符
    if item_config_item.canUse == 11:
        player.buy_coin.extra_can_buy_times += item_num

    player.item_package.consume_item(item_no, item_num)

    return response.SerializeToString()
Пример #7
0
def get_drops(stage_id):
    drops = []
    stage_info = game_configs.stage_config.get('stages').get(stage_id)
    common_bag = BigBag(stage_info.commonDrop)
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)

    return drops
Пример #8
0
def get_drops(stage_id):
    drops = []
    stage_info = game_configs.stage_config.get('stages').get(stage_id)
    common_bag = BigBag(stage_info.commonDrop)
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)

    return drops
Пример #9
0
def add_items(player, response, drop_ids):
    """ 添加道具给玩家 """
    for drop_id in drop_ids:
        big_bag = BigBag(drop_id)
        drop_item_group = big_bag.get_drop_items()
        return_data = item_group_helper.gain(player,
                                             drop_item_group,
                                             const.MINE_REWARD)
        item_group_helper.get_return(player, return_data, response.gain)
    return response
Пример #10
0
    def fighting_settlement(self, result):
        """战斗结算
        stage_type: 1剧情关卡 2副本关卡 3活动关卡
        """
        self.owner.stage_component.settlement(self._stage_id, result)
        self.owner.stage_component.save_data()
        drops = []
        if not result:
            return drops
        # 关卡掉落
        for _ in range(self._drop_num):
            common_bag = BigBag(self._common_drop)
            common_drop = common_bag.get_drop_items()
            drops.extend(common_drop)

        elite_bag = BigBag(self._elite_drop)
        elite_drop = elite_bag.get_drop_items()
        drops.extend(elite_drop)

        return drops
Пример #11
0
    def fighting_settlement(self, result):
        """战斗结算
        stage_type: 1剧情关卡 2副本关卡 3活动关卡
        """
        self.owner.stage_component.settlement(self._stage_id, result)
        self.owner.stage_component.update()
        drops = []
        if not result:
            return drops
        # 关卡掉落
        for _ in range(self._drop_num):
            common_bag = BigBag(self._common_drop)
            common_drop = common_bag.get_drop_items()
            drops.extend(common_drop)

        elite_bag = BigBag(self._elite_drop)
        elite_drop = elite_bag.get_drop_items()
        drops.extend(elite_drop)

        return drops
Пример #12
0
def add_items(player, response, drop_ids, num=1):
    """ 添加道具给玩家 """
    for drop_id in drop_ids:
        big_bag = BigBag(drop_id)
        drop_item_group = big_bag.get_drop_items()
        return_data = item_group_helper.gain(player,
                                             drop_item_group,
                                             const.MINE_REWARD,
                                             multiple=num
                                             )
        item_group_helper.get_return(player, return_data, response)
    return response
Пример #13
0
def use_item_302(pro_data, player):
    """使用道具"""
    item_pb = item_pb2.ItemPB()
    item_pb.ParseFromString(pro_data)
    item_no = item_pb.item_no
    item_num = item_pb.item_num
    item_config_item = item_config.get(item_no)
    if not item_config_item:
        return
    item_func = item_config_item.func
    drop_id = item_config_item.dropId
    func_args1 = item_config_item.funcArg1
    func_args2 = item_config_item.funcArg2

    response = ItemUseResponse()
    common_response = response.res  # = common_response
    common_response.result = True

    # 校验道具数量
    item = player.item_package.get_item(item_no)
    if not item or item.num < item_num:
        common_response.result = False
        common_response.result_no = 106
        # common_response.message = u"道具不足!"
        return response.SerializeToString()

    if item_func == 2:
        # 宝箱
        box_key_no = func_args1
        box_key = player.item_package.get_item(box_key_no)
        if not box_key or box_key.num < func_args2 * item_num:
            common_response.result = False
            common_response.result_no = 107
            # common_response.message = u"box key 不足!" + str(func_args2 * item_num) + "_" + str(box_key.num)
            return response.SerializeToString()
        # 消耗key
        box_key.num -= func_args2 * item_num
        player.item_package.consume_item(box_key_no, item_num)
        player.item_package.save_data()

    big_bag = BigBag(drop_id)
    for i in range(item_num):
        drop_item_group = big_bag.get_drop_items()
        return_data = gain(player, drop_item_group)
        get_return(player, return_data, response.gain)

    logger.debug("item_no:%s", item_no)
    logger.debug("item_num:%s", item_num)
    player.item_package.consume_item(item_no, item_num)

    return response.SerializeToString()
Пример #14
0
def do_get_draw_drop_bag(pseudo_bag_id, draw_times):
    pseudo_random_info = game_configs.pseudo_random_config.get(pseudo_bag_id)
    assert pseudo_random_info!=None, "can not find pseudo bag:%s" % pseudo_bag_id
    gain = pseudo_random_info.gain
    drop_items = []
    for k in sorted(gain.keys(), reverse=True):
        if draw_times >= k:
            bags = gain.get(k)
            for bag_id in bags:
                # logger.debug("drop_bag_id %s", bag_id)
                big_bag = BigBag(bag_id)
                drop_items.extend(big_bag.get_drop_items())
            break
    # logger.debug("drop_items %s", drop_items)
    return drop_items
Пример #15
0
def pvb_get_award_1708(data, player):
    response = PvbAwardResponse()
    boss = player.world_boss.get_boss("world_boss")
    award_type, award, rank_no, is_over = boss.get_award()
    player.world_boss.save_data()
    logger.debug("award_type %s, award %s, is_over %s" %
                 (award_type, award, is_over))
    response.is_over = is_over
    if not award:
        response.SerializePartialToString()
    response.award_type = award_type  # award_type
    if award_type == const.PVB_IN_AWARD:
        total_coin = 0
        total_soul = 0
        for demage_hp in award:
            all_vars = dict(damage=demage_hp)
            coin_world_boss_formula = game_configs.formula_config.get(
                "coinWorldboss").get("formula")
            assert coin_world_boss_formula != None, "isHit formula can not be None!"
            coin = eval(coin_world_boss_formula, all_vars)
            soul_world_boss_formula = game_configs.formula_config.get(
                "soulWorldboss").get("formula")
            assert soul_world_boss_formula != None, "isHit formula can not be None!"
            soul = eval(soul_world_boss_formula, all_vars)
            total_coin += int(coin)
            total_soul += int(soul)
            print("coin and soul", coin, soul)

        change = response.gain.finance.finance_changes.add()
        change.item_type = 107
        change.item_num = int(total_coin)
        change.item_no = const.COIN
        change = response.gain.finance.finance_changes.add()
        change.item_type = 107
        change.item_num = int(total_soul)
        change.item_no = const.HERO_SOUL
    elif award_type != 0:
        bigbag = BigBag(award)
        drop_items = bigbag.get_drop_items()
        return_data = gain(player, drop_items, const.WORLD_BOSS_AWARD)
        get_return(player, return_data, response.gain)
    #response.rank_no = remote_gate['world'].get_rank_no_remote(player.base_info.id, "world_boss")
    response.rank_no = rank_no
    logger.debug("pvb_get_award_1708:%s" % response)
    return response.SerializePartialToString()
Пример #16
0
def pvb_get_award_1708(data, player):
    response = PvbAwardResponse()
    boss = player.world_boss.get_boss("world_boss")
    award_type, award, rank_no, is_over = boss.get_award()
    player.world_boss.save_data()
    logger.debug("award_type %s, award %s, is_over %s" % (award_type, award, is_over))
    response.is_over = is_over
    if not award:
        response.SerializePartialToString()
    response.award_type = award_type # award_type
    if award_type == const.PVB_IN_AWARD:
        total_coin = 0
        total_soul = 0
        for demage_hp in award:
            all_vars = dict(damage=demage_hp)
            coin_world_boss_formula = game_configs.formula_config.get("coinWorldboss").get("formula")
            assert coin_world_boss_formula!=None, "isHit formula can not be None!"
            coin = eval(coin_world_boss_formula, all_vars)
            soul_world_boss_formula = game_configs.formula_config.get("soulWorldboss").get("formula")
            assert soul_world_boss_formula!=None, "isHit formula can not be None!"
            soul = eval(soul_world_boss_formula, all_vars)
            total_coin += int(coin)
            total_soul += int(soul)
            print("coin and soul" , coin, soul)

        change = response.gain.finance.finance_changes.add()
        change.item_type = 107
        change.item_num = int(total_coin)
        change.item_no = const.COIN
        change = response.gain.finance.finance_changes.add()
        change.item_type = 107
        change.item_num = int(total_soul)
        change.item_no = const.HERO_SOUL
    elif award_type != 0:
        bigbag = BigBag(award)
        drop_items = bigbag.get_drop_items()
        return_data = gain(player, drop_items, const.WORLD_BOSS_AWARD)
        get_return(player, return_data, response.gain)
    #response.rank_no = remote_gate['world'].get_rank_no_remote(player.base_info.id, "world_boss")
    response.rank_no = rank_no
    logger.debug("pvb_get_award_1708:%s" % response)
    return response.SerializePartialToString()
Пример #17
0
def rob_treasure_reward_863(data, player):
    """选择战利品"""
    response = rob_treasure_pb2.RobTreasureRewardResponse()
    if not player.rob_treasure.can_receive:
        logger.error('rob_treasure_reward_863, can not receive')
        response.res.result = False
        response.res.result_no = 800
        return response.SerializeToString()

    indiana_conf = game_configs.indiana_config.get('indiana').get(
        player.rob_treasure.can_receive)
    common_bag = BigBag(indiana_conf.reward)
    drops = common_bag.get_drop_items()

    # drops = []
    # common_bag = BigBag(self._common_drop)
    # common_drop = common_bag.get_drop_items()
    # drops.extend(common_drop)

    x = [0, 1, 2]
    random.shuffle(x)
    return_data = [[
        drops[x[0]].item_type, drops[x[0]].num, drops[x[0]].item_no
    ]]
    # gain(player, [drops[x[0]]], const.ROB_TREASURE_REWARD)
    get_return(player, return_data, response.look_gain.add())

    # return_data = gain(player, [drops[x[1]]], const.ROB_TREASURE_REWARD)
    return_data = [[
        drops[x[1]].item_type, drops[x[1]].num, drops[x[1]].item_no
    ]]
    get_return(player, return_data, response.look_gain.add())

    return_data = gain(player, [drops[x[2]]], const.ROB_TREASURE_REWARD)
    get_return(player, return_data, response.gain)

    player.rob_treasure.can_receive = 0
    player.rob_treasure.save_data()

    response.res.result = True
    return response.SerializeToString()
Пример #18
0
def rob_treasure_reward_863(data, player):
    """选择战利品"""
    response = rob_treasure_pb2.RobTreasureRewardResponse()
    if not player.rob_treasure.can_receive:
        logger.error('rob_treasure_reward_863, can not receive')
        response.res.result = False
        response.res.result_no = 800
        return response.SerializeToString()

    indiana_conf = game_configs.indiana_config.get('indiana').get(player.rob_treasure.can_receive)
    common_bag = BigBag(indiana_conf.reward)
    drops = common_bag.get_drop_items()

    # drops = []
    # common_bag = BigBag(self._common_drop)
    # common_drop = common_bag.get_drop_items()
    # drops.extend(common_drop)

    x = [0, 1, 2]
    random.shuffle(x)
    return_data = [[drops[x[0]].item_type, drops[x[0]].num, drops[x[0]].item_no]]
    # gain(player, [drops[x[0]]], const.ROB_TREASURE_REWARD)
    get_return(player, return_data, response.look_gain.add())

    # return_data = gain(player, [drops[x[1]]], const.ROB_TREASURE_REWARD)
    return_data = [[drops[x[1]].item_type, drops[x[1]].num, drops[x[1]].item_no]]
    get_return(player, return_data, response.look_gain.add())

    return_data = gain(player, [drops[x[2]]],
                       const.ROB_TREASURE_REWARD)
    get_return(player, return_data, response.gain)

    player.rob_treasure.can_receive = 0
    player.rob_treasure.save_data()

    response.res.result = True
    return response.SerializeToString()
Пример #19
0
 def test_get_drop_items(self):
     big_bag = BigBag(10001)
     drop_items = big_bag.get_drop_items()
     self.assertEqual(len(drop_items), 3, "%d_%d" % (len(drop_items), 3))
Пример #20
0
def travel_831(data, player):
    """游历"""
    args = TravelRequest()
    args.ParseFromString(data)
    stage_id = args.stage_id
    response = TravelResponse()

    if base_config.get('travelOpenLevel') > player.level.level:
        response.res.result = False
        response.res.result_no = 811  # 等级不够
        return response.SerializeToString()

    shoes = player.travel_component.shoes
    if shoes[0] + shoes[1] + shoes[2] == 0:
        response.res.result = False
        response.res.result_no = 812  # 鞋子不足
        return response.SerializeToString()

    travel_cache = player.travel_component.travel

    while (True):
        travel_event_id = get_travel_event_id()
        flag = 1
        if travel_cache.get(stage_id):
            for event in travel_cache.get(stage_id):
                if travel_event_id == event[0]:
                    flag = 0
            if flag:
                break
        else:
            travel_cache[stage_id] = []
            break
    event_info = 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 = travel_event_id

    res_drops = response.drops
    drops = []
    stage_info = stage_config.get('stages').get(stage_id)
    common_bag = BigBag(stage_info.commonDrop)
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)

    drop_data = get_drop_data(drops)

    get_return(player, drop_data, res_drops)

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

    if shoes[3] == 0:
        for i in [2, 1, 0]:
            if shoes[i] != 0:
                shoes[3] = i + 1
                shoes[4] = 1
                break
    else:
        if base_config.get("travelShoe" + str(shoes[3]))[1] == shoes[4] + 1:
            shoes[shoes[3] - 1] -= 1
            shoes[4] = 0
            shoes[3] = 0
        else:
            shoes[4] += 1

    player.travel_component.save()

    response.res.result = True
    return response.SerializeToString()
Пример #21
0
def gain(player, item_group, reason,
         result=None,
         multiple=1,
         event_id='',
         part_multiple=[],
         lucky_attr_id=0):
    """获取
    @param item_group: [obj,obj]
    act 掉落翻倍. [[type_ids], xs]  [[翻倍类型列表],系数]
    """
    if result is None:
        result = []
    after_num = 0
    itid = 0

    for group_item in item_group:
        type_id = group_item.item_type

        num = int(group_item.num * multiple)
        item_no = group_item.item_no

        multiple2 = 1
        for _part_multiple in part_multiple:
            _times = _part_multiple["times"]
            _item_type = _part_multiple["item_type"]
            _item_ids = _part_multiple["item_ids"]
            if type_id == _item_type:
                if not _item_ids[0] or item_no in _item_ids:
                    multiple2 = _times

        logger.debug("multiple %s multiple2 %s" % (multiple, multiple2))
        num = int(multiple2 * num)

        front_type_id = type_id # 记录类型,用于武将已存在的情况。
        if type_id == const.COIN:
            player.finance.coin += num
            player.finance.save_data()
            after_num = player.finance.coin

        elif type_id == const.RESOURCE:
            if item_no == 27:
                hook_task(player, CONDITIONId.GGZJ, num)
            elif item_no == const.TEAM_EXPERIENCE:
                player.base_info.addexp(num, reason)
                player.base_info.save_data()
                after_num = player.base_info.exp
            else:
                player.finance.add(item_no, num)
                player.finance.save_data()
                after_num = player.finance[item_no]

            if item_no == 1 or item_no == 2:
                tlog_action.log('MoneyFlow', player, after_num, num, reason,
                                const.ADD, item_no)

        elif type_id == const.GOLD:
            player.finance.add_gold(num, 0)
            player.finance.save_data()

        elif type_id == const.HERO_SOUL:
            player.finance.hero_soul += num
            player.finance.save_data()

        elif type_id == const.PVP:
            player.finance.pvp_score += num
            player.finance.save_data()

        elif type_id == const.HERO_CHIP:
            if game_configs.chip_config.get('chips').get(item_no):
                hero_chip = HeroChip(item_no, num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                after_num = player.hero_chip_component.get_chip(item_no).num
            else:
                logger.error('chip config not found:%', item_no)

        elif type_id == const.ITEM:
            item = Item(item_no, num)
            player.item_package.add_item(item)
            player.item_package.save_data()
            after_num = player.item_package.get_item(item_no).num

        elif type_id == const.HERO:
            is_have = player.hero_component.contain_hero(item_no)
            if not is_have:
                num -= 1
            if num != 0:
                # 已经存在该武将,自动转换为武将碎片
                # 获取hero对应的hero_chip_no, hero_chip_num
                hero_chip_config_item = game_configs.chip_config.get("mapping").get(item_no)
                hero_chip_no = hero_chip_config_item.id
                CardImparirment = 1
                if reason == const.SHOP_DRAW_HERO:
                    CardImparirment = game_configs.base_config.get("CardImparirment")
                hero_chip_num = int(hero_chip_config_item.needNum * num * CardImparirment)

                hero_chip = HeroChip(hero_chip_no, hero_chip_num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                after_num = player.hero_chip_component.get_chip(hero_chip_no).num

                result.append([const.HERO_CHIP, hero_chip_num, hero_chip_no])

                tlog_action.log('ItemFlow', player, const.ADD, type_id,
                                hero_chip_num, hero_chip_no, itid, reason,
                                after_num, event_id)
            if not is_have:
                hero = player.hero_component.add_hero(item_no)
                notice_item = game_configs.notes_config.get(2002)
                logger.debug("=================%s %s %s" % (reason, hero.hero_info.quality, notice_item.parameter1))
                if reason == const.SHOP_DRAW_HERO and hero.hero_info.quality in notice_item.parameter1:
                    push_notice(2002, player_name=player.base_info.base_name, hero_no=item_no)
                after_num = 1

                result.append([type_id, 1, item_no])

                tlog_action.log('ItemFlow', player, const.ADD, type_id,
                                1, item_no, itid, reason,
                                after_num, event_id)

        elif type_id == const.BIG_BAG:
            big_bag = BigBag(item_no)
            for i in range(num):
                temp = big_bag.get_drop_items()
                gain(player, temp, reason, result)
            return result

        elif type_id == const.EQUIPMENT:
            for _ in range(num):
                itid = item_no
                equipment = player.equipment_component.add_equipment(itid, lucky_attr_id)
                equ_item_no = equipment.base_info.id
                after_num = player.equipment_component.get_equipment_num(itid)
                notice_item = game_configs.notes_config.get(2004)
                if reason == const.COMMON_BUY_PVP and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2004, player_name=player.base_info.base_name, equipment_no=itid)

                notice_item = game_configs.notes_config.get(2005)
                if reason ==const.COMMON_BUY_MELT and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2005, player_name=player.base_info.base_name, equipment_no=itid)

                notice_item = game_configs.notes_config.get(2006)
                if reason == const.COMMON_BUY_EQUIPMENT and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2006, player_name=player.base_info.base_name, equipment_no=itid)

                result.append([type_id, 1, equ_item_no])
                tlog_action.log('ItemFlow', player, const.ADD, type_id, 1,
                                itid, item_no, reason, after_num, event_id)

        elif type_id == const.EQUIPMENT_CHIP:
            if game_configs.chip_config.get('chips').get(item_no):
                chip = EquipmentChip(item_no, num)
                player.equipment_chip_component.add_chip(chip)
                player.equipment_chip_component.save_data()
                after_num = player.equipment_chip_component.get_chip(item_no).chip_num
            else:
                logger.error('chip config not found:%', item_no)

        elif type_id == const.STAMINA:
            player.stamina.stamina += num
            # logger.debug(str(num)+" , stamina+++++++++++")
            player.stamina.save_data()

        elif type_id == const.TEAM_EXPERIENCE:
            player.base_info.addexp(num, reason)
            player.base_info.save_data()

        elif type_id == const.TRAVEL_ITEM:
            after_num = num
            stage_id = game_configs.travel_item_config.get('items').get(item_no).stageId
            flag1 = 1
            flag2 = 0
            stage_item_info = player.travel_component.travel_item.get(stage_id)
            for [travel_item_id, travel_item_num] in stage_item_info:
                if travel_item_id == item_no:
                    the_num = travel_item_num + num
                    stage_item_info[flag2] = \
                        [travel_item_id, the_num]
                    flag1 = 0
                    after_num = the_num
                    break
                flag2 += 1
            if flag1:
                stage_item_info.append([item_no, num])
            player.travel_component.save()

        elif type_id == const.RUNT:
            for _ in range(num):
                runt_id = player.runt.add_runt(item_no)
                result.append([type_id, 1, runt_id])
            player.runt.save()
            after_num = player.runt.get_runt_num(item_no)

        if type_id == const.COIN or type_id == const.GOLD:
            tlog_action.log('MoneyFlow', player, after_num, num, reason,
                            const.ADD, item_no)

        is_over = False       # 是否累加
        for i in result:
            if i[0] == type_id and i[2] == item_no and (front_type_id != const.HERO and type_id != const.HERO_CHIP and type_id != const.RUNT and type_id != const.EQUIPMENT and type_id != const.HERO):
                i[1] += num
                is_over = True
                continue

        if not is_over and type_id !=const.RUNT and type_id != const.HERO and type_id != const.EQUIPMENT:
            result.append([type_id, num, item_no])

        # ====tlog======
        if type_id != const.TEAM_EXPERIENCE and type_id != const.EQUIPMENT and type_id != const.HERO:
            tlog_action.log('ItemFlow', player, const.ADD, type_id, num,
                            item_no, itid, reason, after_num, event_id)
        # ==============

    return result
Пример #22
0
def stage_sweep(stage_id, times, player):
    response = stage_response_pb2.StageSweepResponse()
    drops = response.drops
    res = response.res

    need_money = 0
    if times == 1:
        if not game_configs.vip_config.get(player.vip_component.vip_level).openSweep:
            res.result = False
            res.result_no = 803
            return response.SerializePartialToString()
    if times == 10:
        if not game_configs.vip_config.get(player.vip_component.vip_level).openSweepTen:
            res.result = False
            res.result_no = 803
            return response.SerializePartialToString()

    if time.localtime(player.stage_component.sweep_times[1]).tm_mday == time.localtime().tm_mday \
            and game_configs.vip_config.get(player.vip_component.vip_level).freeSweepTimes - player.stage_component.sweep_times[0] < times:
        need_money = times-(game_configs.vip_config.get(player.vip_component.vip_level).freeSweepTimes-player.stage_component.sweep_times[0])
        if need_money > player.finance.gold:
            res.result = False
            res.result_no = 102
            return response.SerializePartialToString()
    state = player.stage_component.check_stage_state(stage_id)
    if state != 1:
        res.result = False
        res.result_no = 803
        return response.SerializePartialToString()

    stage_config = game_configs.stage_config.get('stages').get(stage_id)

    if player.stage_component.get_stage(stage_id).attacks + times > stage_config.limitTimes:
        res.result = False
        res.result_no = 810
        return response.SerializePartialToString()

    drop = []
    for _ in range(times):
        low = stage_config.low
        high = stage_config.high
        drop_num = random.randint(low, high)

        for __ in range(drop_num):
            common_bag = BigBag(stage_config.commonDrop)
            common_drop = common_bag.get_drop_items()
            drop.extend(common_drop)

        elite_bag = BigBag(stage_config.eliteDrop)
        elite_drop = elite_bag.get_drop_items()
        drop.extend(elite_drop)

    data = gain(player, drop)
    get_return(player, data, drops)

    if time.localtime(player.stage_component.sweep_times[1]).tm_mday == time.localtime().tm_mday:
        player.stage_component.sweep_times[0] += times
    else:
        player.stage_component.sweep_times[0] = times
        player.stage_component.sweep_times[1] = int(time.time())

    player.stage_component.get_stage(stage_id).attacks += times
    player.stage_component.update()

    player.stamina.stamina -= stage_config.vigor
    player.stamina.save_data()
    # 经验
    for (slot_no, lineUpSlotComponent) in player.line_up_component.line_up_slots.items():
        print lineUpSlotComponent,
        hero = lineUpSlotComponent.hero_slot.hero_obj
        if hero:
            hero.upgrade(stage_config.HeroExp)
    # 玩家金钱
    player.finance.coin += stage_config.currency
    player.finance.gold -= need_money
    # 玩家经验
    player.level.addexp(stage_config.playerExp)
    player.save_data()

    res.result = True
    return response.SerializePartialToString()
Пример #23
0
def travel_settle_833(data, player):
    """ settle,
        type 1 3 这此结算
    """
    args = TravelSettleRequest()
    args.ParseFromString(data)
    stage_id = args.stage_id
    event_id = args.event_id

    response = TravelSettleResponse()

    if player.travel_component.travel.get(stage_id):
        stage_cache = player.travel_component.travel.get(stage_id)
    else:
        logger.error("travel stage id not found")
        response.res.result = False
        response.res.result_no = 800
        return response.SerializeToString()

    event_cache = 0
    for event in stage_cache:
        if event[0] == event_id:
            event_cache = event
            break

    if not event_cache:
        logger.error("travel :event id not found")
        response.res.result = False
        response.res.result_no = 813
        return response.SerializeToString()

    event_info = game_configs.travel_event_config.get('events').get(args.event_id%xs)
    if event_info.type == 1:
        if not event_cache[2]:
            logger.error('event_cache[2] not find: %s' % event_cache)
            response.res.result = False
            response.res.result_no = 800
            return response.SerializeToString()
        if int(time.time()) - event_cache[2] < \
                event_info.parameter.items()[0][0]:
            response.res.result = False
            response.res.result_no = 814
            return response.SerializeToString()

    # 结算
    if event_info.type == 3 and not event_info.parameter[args.parameter]:
        common_bag = BigBag(event_info.wrong)
        common_drop = common_bag.get_drop_items()

        gain_data = gain(player, common_drop, const.TRAVEL)
        get_return(player, gain_data, response.drops)
    else:
        gain_data = gain(player, event_cache[1], const.TRAVEL)
        get_return(player, gain_data, response.drops)

    stage_cache.remove(event_cache)
    player.travel_component.save()


    response.res.result = True
    return response.SerializeToString()
Пример #24
0
    def fighting_settlement(self, result, star_num):
        """战斗结算
        stage_type: 1剧情关卡 6精英关卡 4活动宝库关卡5活动校场关卡 14隐藏关卡
        """
        stage_info = self._get_stage_config()
        self.owner.stage_component.settlement(self._stage_id, result, star_num)
        self.owner.stage_component.save_data()
        drops = []
        if result:
            # 关卡掉落
            for _ in range(self._drop_num):
                common_bag = BigBag(self._common_drop)
                common_drop = common_bag.get_drop_items()
                drops.extend(common_drop)
            if stage_info.type == 1 or stage_info.type == 14:
                self.get_stage_drop(stage_info, drops)
                self.owner.stage_component.save_data()
            else:
                if self._elite_drop:
                    elite_bag = BigBag(self._elite_drop)
                    elite_drop = elite_bag.get_drop_items()
                    drops.extend(elite_drop)

        if stage_info.type == 4:
            # 宝库活动副本
            formula = game_configs.formula_config.get("Activitycurrency").get(
                "formula")
            assert formula != None, "Activitycurrency formula can not be None!"
            coin_num = eval(
                formula, {
                    "damage_percent": self.damage_percent,
                    "currency": stage_info.currency
                })
            if coin_num:
                drops.append(
                    CommonGroupItem(const.COIN, coin_num, coin_num,
                                    const.RESOURCE))

        elif stage_info.type == 5:
            # 校场活动副本
            formula = game_configs.formula_config.get("ActivityExpDrop").get(
                "formula")
            assert formula != None, "ActivityExpDrop formula can not be None!"
            exp_drop = eval(
                formula, {
                    "damage_percent": self.damage_percent,
                    "ExpDrop": stage_info.ExpDrop
                })

            if stage_info.id % 10 == 1:
                formula = game_configs.formula_config.get(
                    "ActivityExpDropConvert_1").get("formula")
                assert formula != None, "ActivityExpDrop formula can not be None!"
                exp_item_num = eval(formula, {"ActivityExpDrop": exp_drop})
                if exp_item_num >= 1:
                    drops.append(
                        CommonGroupItem(10001, exp_item_num, exp_item_num,
                                        const.ITEM))
            elif stage_info.id % 10 == 2:
                formula = game_configs.formula_config.get(
                    "ActivityExpDropConvert_2").get("formula")
                assert formula != None, "ActivityExpDrop formula can not be None!"
                exp_item_num = eval(formula, {"ActivityExpDrop": exp_drop})
                if exp_item_num >= 1:
                    drops.append(
                        CommonGroupItem(10002, exp_item_num, exp_item_num,
                                        const.ITEM))
            elif stage_info.id % 10 == 3:
                formula = game_configs.formula_config.get(
                    "ActivityExpDropConvert_3").get("formula")
                assert formula != None, "ActivityExpDrop formula can not be None!"
                exp_item_num = eval(formula, {"ActivityExpDrop": exp_drop})
                if exp_item_num >= 1:
                    drops.append(
                        CommonGroupItem(10003, exp_item_num, exp_item_num,
                                        const.ITEM))
        elif stage_info.type == 6:
            # 精英活动副本
            hero_soul_num = stage_info.reward
            if hero_soul_num:
                drops.append(
                    CommonGroupItem(const.RESOURCE, hero_soul_num,
                                    hero_soul_num, const.HERO_SOUL))
            #drops.extend(stage_info.ClearanceReward)

        logger.debug("drops %s" % drops)

        return drops
Пример #25
0
def get_drop(bag_id):
    drops = []
    common_bag = BigBag(bag_id)
    common_drop = common_bag.get_drop_items()
    drops.extend(common_drop)
    return drops
Пример #26
0
    def func():

        # 武将乱入
        fight_cache_component = player.fight_cache_component
        fight_cache_component.stage_id = stage_id
        red_units, blue_units, drop_num, monster_unpara = fight_cache_component.fighting_start(
        )

        multiple, part_multiple = get_drop_activity(
            player, player.fight_cache_component.stage_id, 1,
            stage_obj.star_num)
        for _ in range(times):
            drop = []

            drops = response.drops.add()
            low = stage_config.low
            high = stage_config.high
            drop_num = random.randint(low, high)

            for __ in range(drop_num):
                common_bag = BigBag(stage_config.commonDrop)
                common_drop = common_bag.get_drop_items()
                drop.extend(common_drop)

            fight_cache_component.get_stage_drop(stage_config, drop)

            data = gain(player,
                        drop,
                        const.STAGE_SWEEP,
                        event_id=tlog_event_id,
                        multiple=multiple,
                        part_multiple=part_multiple)
            get_return(player, data, drops)

            # 乱入武将按概率获取碎片
            break_stage_id = player.fight_cache_component.break_stage_id
            if break_stage_id:
                break_stage_info = game_configs.stage_break_config.get(
                    break_stage_id)
                ran = random.random()
                if ran <= break_stage_info.reward_odds:
                    # logger.debug("break_stage_info=============%s %s" % (break_stage_info.reward, 1))
                    data = gain(player, break_stage_info.reward,
                                const.STAGE_SWEEP)
                    get_return(player, data, drops)

            player.finance.consume(const.STAMINA, stage_config.vigor,
                                   const.STAGE_SWEEP)
            # 经验
            for (slot_no, lineUpSlotComponent
                 ) in player.line_up_component.line_up_slots.items():
                hero = lineUpSlotComponent.hero_slot.hero_obj
                if hero:

                    beforelevel = hero.level
                    hero.upgrade(stage_config.HeroExp, player.base_info.level)
                    afterlevel = hero.level
                    changelevel = afterlevel - beforelevel
                    hero.save_data()
                    if changelevel:
                        tlog_action.log('HeroUpgrade', player, hero.hero_no,
                                        changelevel, afterlevel, 3, 0, 0, 0, 0)
            # 玩家金钱
            player.finance.coin += stage_config.currency
            # 玩家经验
            player.base_info.addexp(stage_config.playerExp, const.STAGE_SWEEP)
        # 更新等级相关属性
        player.set_level_related()

        # hook task
        hook_task(player, CONDITIONId.ANY_STAGE, times)
        logger.debug("sweep time %s %s" % (times, sweep_item))
        return_data = consume(player,
                              sweep_item,
                              const.STAGE_SWEEP,
                              multiple=times)
        get_return(player, return_data, response.consume)

        player.stage_component.get_stage(stage_id).attacks += times
        player.stage_component.save_data()

        player.stamina.save_data()
        player.base_info.save_data()
        player.finance.save_data()
Пример #27
0
def travel_settle_833(data, player):
    """ settle,
        type 1 3 这此结算
    """
    args = TravelSettleRequest()
    args.ParseFromString(data)
    stage_id = args.stage_id
    event_id = args.event_id

    response = TravelSettleResponse()

    if player.travel_component.travel.get(stage_id):
        stage_cache = player.travel_component.travel.get(stage_id)
    else:
        logger.error("travel stage id not found")
        response.res.result = False
        response.res.result_no = 800
        return response.SerializeToString()

    event_cache = 0
    for event in stage_cache:
        if event[0] == event_id:
            event_cache = event
            break

    if not event_cache:
        logger.error("travel :event id not found")
        response.res.result = False
        response.res.result_no = 813
        return response.SerializeToString()

    event_info = game_configs.travel_event_config.get('events').get(
        args.event_id % xs)
    if event_info.type == 1:
        if not event_cache[2]:
            logger.error('event_cache[2] not find: %s' % event_cache)
            response.res.result = False
            response.res.result_no = 800
            return response.SerializeToString()
        if int(time.time()) - event_cache[2] < \
                event_info.parameter.items()[0][0]:
            response.res.result = False
            response.res.result_no = 814
            return response.SerializeToString()

    # 结算
    if event_info.type == 3 and not event_info.parameter[args.parameter]:
        common_bag = BigBag(event_info.wrong)
        common_drop = common_bag.get_drop_items()

        gain_data = gain(player, common_drop, const.TRAVEL)
        get_return(player, gain_data, response.drops)
    else:
        gain_data = gain(player, event_cache[1], const.TRAVEL)
        get_return(player, gain_data, response.drops)

    stage_cache.remove(event_cache)
    player.travel_component.save()

    response.res.result = True
    return response.SerializeToString()
Пример #28
0
def gain(player, item_group, result=None):
    """获取
    @param item_group: [obj,obj]
    """
    if result is None:
        result = []

    for group_item in item_group:
        type_id = group_item.item_type
        num = group_item.num
        item_no = group_item.item_no
        if type_id == const.COIN:
            player.finance.coin += num
            player.finance.save_data()

        elif type_id == const.GOLD:
            player.finance.gold += num
            player.finance.save_data()

        elif type_id == const.HERO_SOUL:
            player.finance.hero_soul += num
            player.finance.save_data()

        elif type_id == const.JUNIOR_STONE:
            player.finance.junior_stone += num
            player.finance.save_data()
        elif type_id == const.MIDDLE_STONE:
            player.finance.middle_stone += num
            player.finance.save_data()
        elif type_id == const.HIGH_STONE:
            player.finance.high_stone += num
            player.finance.save_data()

        elif type_id == const.HERO_CHIP:
            hero_chip = HeroChip(item_no, num)
            player.hero_chip_component.add_chip(hero_chip)
            player.hero_chip_component.save_data()

        elif type_id == const.ITEM:
            item = Item(item_no, num)
            player.item_package.add_item(item)
            player.item_package.save_data()

        elif type_id == const.HERO:
            if player.hero_component.contain_hero(item_no):
                # 已经存在该武将,自动转换为武将碎片
                # 获取hero对应的hero_chip_no, hero_chip_num
                hero_chip_config_item = chip_config.get("mapping").get(item_no)
                hero_chip_no = hero_chip_config_item.id
                hero_chip_num = hero_chip_config_item.needNum

                hero_chip = HeroChip(hero_chip_no, hero_chip_num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                type_id = const.HERO_CHIP
                item_no = hero_chip_no
                num = hero_chip_num
            else:
                player.hero_component.add_hero(item_no)

        elif type_id == const.BIG_BAG:
            big_bag = BigBag(item_no)
            for i in range(num):
                gain(player, big_bag.get_drop_items(), result)
            return result

        elif type_id == const.EQUIPMENT:
            equipment = player.equipment_component.add_equipment(item_no)
            item_no = equipment.base_info.id

        elif type_id == const.EQUIPMENT_CHIP:
            chip = EquipmentChip(item_no, num)
            player.equipment_chip_component.add_chip(chip)
            player.equipment_chip_component.save_data()
        elif type_id == const.STAMINA:
            player.stamina.stamina += num
            logger.debug(str(num) + " , stamina+++++++++++")
            player.stamina.save_data()
        elif type_id == const.TRAVEL_ITEM:
            stage_id = travel_item_config.get(item_no).stageId
            flag1 = 1
            flag2 = 0
            stage_item_info = player.travel_component.travel_item.get(stage_id)
            for [travel_item_id, travel_item_num] in stage_item_info:
                if travel_item_id == item_no:
                    stage_item_info[flag2] = \
                        [travel_item_id, travel_item_num + num]
                    flag1 = 0
                    break
                flag2 += 1
            if flag1:
                stage_item_info.append([item_no, num])
            player.travel_component.save()
        elif type_id == u'107':
            shoes = player.travel_component.shoes
            if item_no == 18:
                shoes[0] += num
            elif item_no == 19:
                shoes[1] += num
            elif item_no == 20:
                shoes[2] += num

            player.travel_component.save()

        flag = 1
        for i in result:
            if i[0] == type_id and i[2] == item_no:
                i[1] += 1
                flag = 0
                continue
        if flag:
            result.append([type_id, num, item_no])
        # result.append([type_id, num, item_no])
    return result