Example #1
0
def add_stamina_7(request_proto, player):
    """按时自动增长体力"""
    response = CommonResponse()

    # 校验时间是否足够
    current_time = int(time.time())
    last_gain_stamina_time = player.stamina.stamina

    if current_time - last_gain_stamina_time < 270:
        logger.debug("add stamina time not enough +++++++++++++++++++++")
        response.result_no = 12
        response.result = False
        return response.SerializePartialToString()

    max_stamina = player.stamina.max_of_stamina
    if player.stamina.stamina >= max_stamina:
        logger.debug("has reach max stamina ++++++++++++++++++++++")
        response.result_no = 13
        response.result = False
        return response.SerializePartialToString()
    player.stamina.stamina += 1

    player.stamina.last_gain_stamina_time = current_time
    player.stamina.save_data()
    response.result = True
    return response.SerializePartialToString()
Example #2
0
def add_friend_request_1100(data, player):
    """ request to invite target as friend """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    if len(request.target_ids) < 1:
        response.result = False
        response.result_no = 11005  # fail
        return response.SerializePartialToString()  # fail

    max_num_friend = game_configs.base_config.get('max_of_UserFriend')
    if len(player.friends.friends) >= max_num_friend:
        response.result = False
        response.result_no = 11003  # fail
        return response.SerializePartialToString()  # fail

    target_id = request.target_ids[0]

    if target_id == player.base_info.id:
        response.result = False  # cant invite oneself as friend
        response.result_no = 11004  # fail
        return response.SerializePartialToString()  # fail

    if not push_message('add_friend_request_remote', target_id,
                        player.base_info.id):
        response.result = False
        response.result_no = 11002
        return response.SerializePartialToString()  # fail

    return response.SerializePartialToString()
Example #3
0
def hero_refine_118(data, player):
    request = hero_request_pb2.HeroRefineRequest()
    request.ParseFromString(data)
    response = CommonResponse()
    response.result = False

    hero = player.hero_component.get_hero(request.hero_no)
    _refine_item = game_configs.seal_config.get(request.refine)
    if not hero:
        logger.error('cant find hero:%s', request.hero_no)
        return response.SerializePartialToString()
    if not _refine_item:
        logger.error('cant find refine item:%s', request.refine)
        return response.SerializePartialToString()

    if not player.brew.consume(_refine_item.expend):
        logger.error('cant afford refine:%s:cur%s', _refine_item.expend,
                     player.brew.nectar)
        return response.SerializePartialToString()

    response.result = True
    hero.refine = request.refine
    player.brew.save_data()
    hero.save_data()
    return response.SerializePartialToString()
Example #4
0
def pvb_reborn_1704(data, player):
    """
    使用元宝复活。
    """
    response = CommonResponse()
    # 1. 校验元宝
    gold = player.finance.gold
    money_relive_price = base_config.get('money_relive_price')
    need_gold = money_relive_price
    print need_gold, gold, "*" * 80
    if gold < need_gold:
        logger.debug("reborn error: %s" % 102)
        response.result = False
        response.result_no = 102
        return response.SerializePartialToString()

    #2. 校验CD
    current_time = get_current_timestamp()
    if current_time - player.world_boss.last_fight_time > base_config.get(
            "free_relive_time"):
        logger.debug("reborn error: %s" % 1701)
        response.result = False
        response.result_no = 1701
        return response.SerializePartialToString()

    player.finance.gold -= need_gold
    player.finance.save_data()
    response.result = True
    print response
    return response.SerializePartialToString()
Example #5
0
def add_friend_request_1100(data, player):
    """ request to invite target as friend """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    if len(request.target_ids) < 1:
        response.result = False
        response.result_no = 5  # fail
        return response.SerializePartialToString()  # fail

    target_id = request.target_ids[0]

    if target_id == player.base_info.id:
        response.result = False  # cant invite oneself as friend
        response.result_no = 4  # fail
        return response.SerializePartialToString()  # fail

    if not push_message('add_friend_request_remote', target_id,
                        player.base_info.id):
        response.result = False
        response.result_no = 2
        return response.SerializePartialToString()  # fail

    return response.SerializePartialToString()
Example #6
0
def given_stamina_1108(data, player):
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)
    target_id = request.target_ids[0]

    player_data = tb_character_info.getObjData(target_id)
    open_receive = player_data.get('stamina').get('open_receive')

    if not player.friends.given_stamina(target_id, if_present=open_receive):
        response.result = False
        response.result_no = 1  # fail
        return response.SerializePartialToString()  # fail

    player.friends.save_data()

    lively_event = CountEvent.create_event(EventType.PRESENT, 1, ifadd=True)
    tstatus = player.tasks.check_inter(lively_event)
    if tstatus:
        task_data = task_status(player)
        remote_gate.push_object_remote(1234, task_data, [player.dynamic_id])
    return response.SerializePartialToString()  # fail
Example #7
0
def encourage_heros_1703(data, player):
    """
    使用金币或者元宝鼓舞士气。
    """
    # 1. 校验金币或者元宝
    # 3. 减少金币
    # 4. 更新战斗力
    response = CommonResponse()

    request = EncourageHerosRequest()
    request.ParseFromString(data)

    if request.finance_type == 1:
        # 金币鼓舞
        goldcoin_inspire_price = base_config.get("goldcoin_inspire_price")
        goldcoin_inspire_price_multiple = base_config.get(
            "goldcoin_inspire_price_multiple")
        coin = player.finance.coin
        need_coin = goldcoin_inspire_price * (pow(
            goldcoin_inspire_price_multiple,
            player.world_boss.encourage_coin_num))
        if coin < need_coin:
            response.result = False
            response.result_no = 101
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()

        player.finance.coin -= need_coin
        player.finance.save_data()
        player.world_boss.encourage_coin_num += 1

    if request.finance_type == 2:
        # 钻石鼓舞
        money_inspire_price = base_config.get("money_inspire_price")
        #money_inspire_price_multiple = base_config.get("money_inspire_price_multiple")
        gold = player.finance.gold
        need_gold = money_inspire_price
        if gold < need_gold:
            response.result = False
            response.result_no = 102
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()
        player.finance.gold -= need_gold
        player.finance.save_data()
        player.world_boss.encourage_gold_num += 1

    player.world_boss.save_data()
    response.result = True
    logger.debug("encourage_coin_num %s" %
                 player.world_boss.encourage_coin_num)
    logger.debug("encourage_gold_num %s" %
                 player.world_boss.encourage_gold_num)
    return response.SerializePartialToString()
Example #8
0
def add_friend_respond_accept_1101(data, player):
    """ respond to inviter """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    for target_id in request.target_ids:
        if not player.friends.add_friend(target_id):
            response.result = False
            continue

        # save data
        player.friends.save_data()

        if not push_message('become_friends_remote', target_id,
                            player.base_info.id):
            response.result = False

        send_mail(conf_id=301,
                  nickname=player.base_info.base_name,
                  receive_id=target_id)

    return response.SerializePartialToString()
Example #9
0
def unpar_upgrade_705(pro_data, player):
    request = line_up_pb2.LineUpUnparUpgrade()
    request.ParseFromString(pro_data)
    response = CommonResponse()
    __line_up = player.line_up_component
    response.result = __line_up.unpar_upgrade(request.skill_id,
                                              request.skill_level)
    return response.SerializePartialToString()
Example #10
0
def change_battle_speed_848(data, player):
    request = player_request_pb2.ChangeBattleSpeed()
    request.ParseFromString(data)
    player.base_info.battle_speed = request.speed
    player.base_info.save_data()
    response = CommonResponse()
    response.result = True
    return response.SerializePartialToString()
Example #11
0
def delete_mail_1303(proto_data, player):
    """删除邮件"""
    request = DeleteMailRequest()
    mail_ids = request.mail_ids
    player.mail_component.delete_mails(mail_ids)
    response = CommonResponse()
    response.result = True
    return response.SerializePartialToString()
Example #12
0
def change_stage_story_2205(data, player):
    request = player_request_pb2.ChangeStageStory()
    request.ParseFromString(data)
    player.base_info.story_id = request.story_id
    player.base_info.save_data()
    response = CommonResponse()
    response.result = True
    return response.SerializePartialToString()
Example #13
0
def close_friend_receive_1062(data, player):
    """ 关闭好友活力赠送
    @author: jiang
    """
    response = CommonResponse()
    player.stamina.close_receive()
    player.stamina.save_data()
    response.result = True
    return response.SerializePartialToString()
Example #14
0
def up_guide_1816(data, player):
    request = UpGuideRequest()
    request.ParseFromString(data)
    response = CommonResponse()
    guide_id = request.guide_id

    tlog_action.log('UpGuide', player, guide_id)
    response.result = True
    return response.SerializePartialToString()
Example #15
0
def pvb_reborn_1704(data, player):
    """
    使用元宝复活。
    """
    request = PvbRequest()
    request.ParseFromString(data)
    boss_id = request.boss_id
    boss = player.world_boss.get_boss(boss_id)
    base_config = boss.get_base_config()

    response = CommonResponse()
    gold = player.finance.gold

    money_relive_price = base_config.get('gold_relive_price')
    need_gold = money_relive_price[-1] if boss.gold_reborn_times >= len(
        money_relive_price) else money_relive_price[boss.gold_reborn_times]
    current_time = get_current_timestamp()

    not_free = current_time - boss.last_fight_time < base_config.get(
        "free_relive_time")
    if not_free and gold < need_gold:
        logger.debug("reborn CD error: %s" % 1701)
        response.result = False
        response.result_no = 1701
        return response.SerializePartialToString()

    if not_free and need_gold == -1:
        logger.debug("reborn times max : %s" % 1702)
        response.result = False
        response.result_no = 1702

    if not_free:

        def func():
            boss.last_fight_time = 0
            boss.gold_reborn_times += 1
            player.world_boss.save_data()

        player.pay.pay(need_gold, const.PVB_REBORN, func)
    response.result = True
    print response
    return response.SerializePartialToString()
Example #16
0
def button_one_time_2203(request_proto, player):

    request = player_request_pb2.ButtonOneTimeRequest()
    request.ParseFromString(request_proto)
    button_id = request.button_id
    logger.debug("button_one_time request %s" % button_id)
    player.base_info._button_one_time[button_id] = 1
    player.base_info.save_data()
    logger.debug("button_one_time %s" % player.base_info._button_one_time)
    response = CommonResponse()
    response.result = True
    return response.SerializePartialToString()
Example #17
0
def buy_stamina_6(request_proto, player):
    """购买体力"""
    response = CommonResponse()

    current_vip_level = player.vip_component.vip_level
    current_buy_stamina_times = player.stamina.buy_stamina_times
    current_stamina = player.stamina.stamina
    current_gold = player.finance.gold

    available_buy_stamina_times = vip_config.get(current_vip_level).get("buyStaminaMax")

    logger.debug("available_buy_stamina_times:", available_buy_stamina_times,
                 current_buy_stamina_times)
    # 校验购买次数上限
    if current_buy_stamina_times >= available_buy_stamina_times:
        response.result = False
        response.result_no = 11
        return response.SerializePartialToString()

    need_gold = base_config.get("price_buy_manual").get(current_buy_stamina_times+1)[1]
    logger.debug("need_gold++++++++++++++++", need_gold)
    # 校验金币是否不足
    if need_gold > current_gold:
        logger.debug("gold not enough++++++++++++")
        response.result = False
        response.result_no = 102
        return response.SerializePartialToString()

    player.finance.gold -= need_gold
    player.finance.save_data()

    player.stamina.buy_stamina_times += 1
    player.save_data()

    player.stamina.stamina += 120
    player.stamina.save_data()

    response.result = True
    return response.SerializePartialToString()
Example #18
0
def friend_private_chat_1060(data, player):
    """ 发送好友单聊邮件
    @author: jiang
    """
    response = CommonResponse()
    request = friend_pb2.FriendPrivateChatRequest()
    request.ParseFromString(data)
    target_id = request.target_uid
    content = request.content

    title_display_len = 10
    if len(content) <= title_display_len:
        title = content
    else:
        title = content[:title_display_len] + "..."

    mail = {
        'sender_id': player.base_info.id,
        'sender_name': player.base_info.base_name,
        'sender_icon': player.line_up_component.lead_hero_no,
        'receive_id': target_id,
        'receive_name': '0',
        'title': title,
        'content': content,
        'mail_type': MailComponent.TYPE_MESSAGE,
        'prize': 0
    }

    if not mail:
        response.result = False
        return response.SerializePartialToString()

    mail['send_time'] = int(time.time())
    receive_id = mail['receive_id']
    # command:id 为收邮件的命令ID
    netforwarding.push_message('receive_mail_remote', receive_id, mail)

    response.result = True
    return response.SerializePartialToString()
Example #19
0
def given_stamina_1108(data, player):
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    target_id = request.target_ids[0]

    player_data = tb_character_info.getObj(target_id)
    stamina_db = Stamina_DB()
    stamina_db.ParseFromString(player_data.hget('stamina'))
    open_receive = stamina_db.open_receive

    if not player.friends.given_stamina(target_id, if_present=open_receive):
        response.result = False
        response.result_no = 1  # fail
        return response.SerializePartialToString()  #

    player.friends.save_data()
    hook_task(player, CONDITIONId.SEND_STAMINA, 1)
    return response.SerializePartialToString()
Example #20
0
def del_black_list_1105(data, player):
    """ delete a player from blacklist """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    for target_id in request.target_ids:
        if not player.friends.del_blacklist(target_id):
            response.result = False
        response.result_no += 1

    # save data
    player.friends.save_data()
    return response.SerializePartialToString()
Example #21
0
def add_friend_respond_refuse_1102(data, player):
    """ refuse inviting """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)

    for target_id in request.target_ids:
        if not player.friends.del_applicant(target_id):
            response.result = False
        response.result_no += 1

    # save data
    player.friends.save_data()
    return response.SerializePartialToString()
Example #22
0
def del_friend_request_1103(data, player):
    """ delete friend from friend list """
    response = CommonResponse()
    response.result = True
    response.result_no = 0
    request = friend_pb2.FriendCommon()
    request.ParseFromString(data)
    for target_id in request.target_ids:
        if not player.friends.del_friend(target_id):
            response.result = False

        # save data
        player.friends.save_data()

        response.result = push_message('delete_friend_remote', target_id,
                                       player.base_info.id)
        response.result_no += 1

    return response.SerializePartialToString()
Example #23
0
def send_mail_1304(proto_data, player):
    """发送邮件"""
    request = SendMailRequest()
    request.ParseFromString(proto_data)
    mail = request.mail
    mail = {'sender_id': mail.sender_id,
            'sender_name': mail.sender_name,
            'receive_id': mail.receive_id,
            'receive_name': mail.receive_name,
            'title': mail.title,
            'content': mail.content,
            'mail_type': mail.mail_type,
            'send_time': mail.send_time,
            'prize': mail.prize}
    response = CommonResponse()
    """发送邮件, mail为json类型"""
    mail['send_time'] = int(time.time())
    receive_id = mail['receive_id']
    # command:id 为收邮件的命令ID
    response.result = netforwarding.push_message('receive_mail_remote', receive_id, mail)
    logger.debug('send_mail_1304 %s', response.result)
    return response.SerializePartialToString()
Example #24
0
def encourage_heros_1703(data, player):
    """
    使用金币或者元宝鼓舞士气。
    """
    # 1. 校验金币或者元宝
    # 3. 减少金币
    # 4. 更新战斗力
    response = CommonResponse()

    request = EncourageHerosRequest()
    request.ParseFromString(data)
    boss_id = request.boss_id
    boss = player.world_boss.get_boss(boss_id)
    base_config = boss.get_base_config()

    times = 0
    if request.finance_type == 1:
        # 金币鼓舞
        goldcoin_inspire_price = base_config.get("coin_inspire_price")
        goldcoin_inspire_price_multiple = base_config.get(
            "coin_inspire_price_multi")
        goldcoinInspireLimited = base_config.get("coin_inspire_limit")
        goldcoin_inspire_CD = base_config.get("coin_inspire_cd")
        if get_current_timestamp(
        ) - boss.last_coin_encourage_time < goldcoin_inspire_CD:
            logger.debug("coin encourage CD not enough %s, %s" %
                         (boss.last_coin_encourage_time, goldcoin_inspire_CD))
            response.result = False
            response.result_no = 1704
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()

        if boss.encourage_coin_num >= goldcoinInspireLimited:
            logger.debug("coin encourage too many times %s, %s" %
                         (boss.encourage_coin_num, goldcoinInspireLimited))
            response.result = False
            response.result_no = 1703
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()

        coin = player.finance.coin
        need_coin = goldcoin_inspire_price * (pow(
            goldcoin_inspire_price_multiple, boss.encourage_coin_num))
        if coin < need_coin:
            response.result = False
            response.result_no = 101
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()

        player.finance.coin -= need_coin
        player.finance.save_data()
        boss.encourage_coin_num += 1
        times = boss.encourage_coin_num
        boss.last_coin_encourage_time = get_current_timestamp()

    if request.finance_type == 2:
        # 钻石鼓舞
        money_inspire_price = base_config.get("gold_inspire_price")
        moneyInspireLimited = base_config.get("gold_inspire_limit")
        #money_inspire_price_multiple = base_config.get("money_inspire_price_multiple")
        if boss.encourage_gold_num >= moneyInspireLimited:
            logger.error("gold encourage too many times %s, %s" %
                         (boss.encourage_gold_num, moneyInspireLimited))
            response.result = False
            response.result_no = 1704
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()
        gold = player.finance.gold
        need_gold = money_inspire_price
        if gold < need_gold:
            response.result = False
            response.result_no = 102
            logger.debug("*" * 80)
            print response
            return response.SerializePartialToString()

        def func():
            boss.encourage_gold_num += 1

        times = boss.encourage_gold_num
        player.pay.pay(need_gold, const.ENCOURAGE_HEROS, func)

    tlog_action.log('WorldBossEncourage', player, request.finance_type, times)
    player.world_boss.save_data()
    response.result = True
    logger.debug("encourage_coin_num %s" % boss.encourage_coin_num)
    logger.debug("encourage_gold_num %s" % boss.encourage_gold_num)
    return response.SerializePartialToString()