Пример #1
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()
Пример #2
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()
Пример #3
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()
Пример #4
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
Пример #5
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()
Пример #6
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()
Пример #7
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()
Пример #8
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()
Пример #9
0
def nickname_create_5(request_proto, player):
    argument = CreatePlayerRequest()
    argument.ParseFromString(request_proto)
    nickname = argument.nickname
    response = CommonResponse()

    # match = re.search(u'[\uD800-\uDBFF][\uDC00-\uDFFF]', nickname)
    match = re.search(u'^[a-zA-Z0-9\u4e00-\u9fa5]+$', nickname)
    if not match:
        response.result = False
        response.result_no = 868
        logger.info('not support emoji')
        return response.SerializeToString()

    if trie_tree.check.replace_bad_word(nickname) != nickname:
        response.result = False
        response.result_no = 869
        return response.SerializeToString()

    # 判断昵称是否重复
    nickname_obj = tb_character_info.getObj('nickname')
    result = nickname_obj.hsetnx(nickname, player.base_info.id)
    print 'is new player:', result
    if not result:
        response.result = False
        response.result_no = 870
        return response.SerializeToString()

    print type(nickname), '===============222'
    player.base_info.base_name = nickname
    player.base_info.save_data()

    # 加入聊天
    remote_gate.login_chat_remote(player.dynamic_id, player.base_info.id,
                                  player.guild.g_id, nickname,
                                  player.base_info.gag)

    tlog_action.log('CreateNickname', player, nickname)

    response.result = True
    return response.SerializeToString()
Пример #10
0
def reset_overcome_time_1509(data, player):
    request = pvp_rank_pb2.ResetPvpOvercomeTime()
    request.ParseFromString(data)
    response = CommonResponse()

    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_GGZJ):
        response.result = False
        response.result_no = 150901
        return response.SerializeToString()

    response.result = player.pvp.reset_overcome()
    return response.SerializeToString()
Пример #11
0
def reset_overcome_time_1509(data, player):
    request = pvp_rank_pb2.ResetPvpOvercomeTime()
    request.ParseFromString(data)
    response = CommonResponse()

    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_GGZJ):
        response.result = False
        response.result_no = 150901
        return response.SerializeToString()

    response.result = player.pvp.reset_overcome()
    return response.SerializeToString()
Пример #12
0
def nickname_create_5(request_proto, player):
    argument = CreatePlayerRequest()
    argument.ParseFromString(request_proto)
    nickname = argument.nickname
    response = CommonResponse()

    match = re.search(u'[\uD800-\uDBFF][\uDC00-\uDFFF]', nickname)
    if match:
        response.result = False
        response.result_no = 1
        logger.info('not support emoji')
        return response.SerializeToString()

    if trie_tree.check.replace_bad_word(nickname) != nickname:
        response.result = False
        response.result_no = 1
        return response.SerializeToString()

    # 判断昵称是否重复
    sql_result = util.GetOneRecordInfo('tb_character_info',
                                       dict(nickname=nickname))
    if sql_result:
        response.result = False
        response.result_no = 1
        return response.SerializeToString()

    character_obj = tb_character_info.getObj(player.base_info.id)
    if not character_obj:
        response.result_no = 2
        return response.SerializeToString()
    character_obj.update('nickname', nickname)

    # 加入聊天
    remote_gate.login_chat_remote(player.dynamic_id,
                                  player.base_info.id,
                                  player.guild.g_id,
                                  nickname)

    response.result = True
    return response.SerializeToString()
Пример #13
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()
Пример #14
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()
Пример #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]
    print need_gold, gold, "*"*80
    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()
Пример #16
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()
Пример #17
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()
Пример #18
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()
Пример #19
0
def unpar_upgrade_705(pro_data, player):
    """
    无双升级
    """
    response = CommonResponse()
    response.result = True
    _line_up = player.line_up_component
    peerless_grade_info = game_configs.skill_peerless_grade_config.get(_line_up._unpar_level)
    resource1 = peerless_grade_info.resource1
    resource2 = peerless_grade_info.resource2
    if not is_afford(player, resource1) or not is_afford(player, resource2):
        logger.error("resource not enough!")
        response.result = False
        response.result_no = 70501
        return response.SerializePartialToString()

    consume(player, resource1, const.UNPAR_UPGRADE)
    consume(player, resource2, const.UNPAR_UPGRADE)
    _line_up.unpar_level = _line_up.unpar_level + 1
    _line_up.save_data()
    tlog_action.log('UnparUpgrade', player,
                    _line_up.unpar_level)
    logger.debug("response %s" % response)
    return response.SerializePartialToString()
Пример #20
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()

    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
        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
        player.pay.pay(need_gold, const.ENCOURAGE_HEROS, func)

    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()
Пример #21
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()