Пример #1
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()
Пример #2
0
def month_reward(player):
    """
    发放月卡永久奖励
    """
    mail_id, times = player.rebate.month_mails()
    for _ in range(times):
        send_mail(conf_id=mail_id, receive_id=player.base_info.id)
    player.rebate.save_data()
Пример #3
0
def share_2102(pro_data, player):
    """分享hjqy, 广播协议号2112
    """
    response = CommonResponse()
    result = remote_gate['world'].share_hjqy_remote(player.base_info.id)
    friend_ids = player.friends.friends
    boss_info = remote_gate['world'].get_boss_info_remote(player.base_info.id)
    for fid in friend_ids:
        send_mail(conf_id=512, receive_id=fid, nickname=player.base_info.base_name, boss_id=boss_info.get('stage_id'))

    #remote_gate.push_object_remote(2112, '', friend_ids)
    response.result = result
    return response.SerializeToString()
Пример #4
0
def share_2102(pro_data, player):
    """分享hjqy, 广播协议号2112
    """
    response = CommonResponse()
    result = remote_gate['world'].share_hjqy_remote(player.base_info.id)
    friend_ids = player.friends.friends
    boss_info = remote_gate['world'].get_boss_info_remote(player.base_info.id)
    for fid in friend_ids:
        send_mail(conf_id=512,
                  receive_id=fid,
                  nickname=player.base_info.base_name,
                  boss_id=boss_info.get('stage_id'))

    #remote_gate.push_object_remote(2112, '', friend_ids)
    response.result = result
    return response.SerializeToString()
Пример #5
0
def process_mine_result(player, position, result, response, stype, hold=1):
    """
    玩家占领其他人的野怪矿,更新矿点数据,给玩家发送奖励,给被占领玩家发送奖励
    @param gain: true or false
    """
    # print 'process_mine_result', position, response, result, stype

    normal, lucky, target, nickname = player.mine.settle(position, result, hold)

    if stype != 1:
        return

    if result is not True:
        send_mail(conf_id=122, receive_id=target, nickname=nickname )
        return

#     warFogLootRatio = game_configs.base_config['warFogLootRatio']
    harvest_stone = {}
    harvest_stone.update(normal)
    harvest_stone.update(lucky)

    harvest_a = {}
    harvest_b = {}
#     for k, v in harvest_stone.items():
#         if v > 0:
#             harvest_b[k] = int(v * warFogLootRatio)
#             harvest_a[k] = v - harvest_b[k]

    prize = []
    prize_num = 0
    for k, v in harvest_stone.items():
        if v > 0:
            prize.append({108: [v, v, k]})
            prize_num += v
    logger.debug('pvp mine total:%s a:%s b:%s prize:%s',
                 harvest_stone, harvest_a, harvest_b, prize)

    if not add_stones(player, harvest_stone, response):
        response.res.result = False
        response.res.result_no = 824
        logger.debug('add_stones fail!!!!!!')

    mail_id = game_configs.base_config.get('warFogRobbedMail')
    send_mail(conf_id=mail_id, receive_id=target, rune_num=prize_num,
              nickname=player.base_info.base_name)
Пример #6
0
    def given_stamina(self, target_id, if_present=True):
        if target_id not in self._friends.keys():
            logger.error('given_stamina can not find friend!:%s', target_id)
            return False
        given_time_list = self._friends[target_id]
        given_times = len(given_time_list)
        if given_times >= 1:
            logger.error('given_stamina times!:%s', given_times)
            return False

        given_time_list.append(datetime.datetime.now())
        if not if_present:
            logger.error('given_stamina present!:%s', if_present)
            return True

        send_mail(conf_id=1, receive_id=target_id,
                  nickname=self.owner.base_info.base_name)
        self._given_record.append(target_id)

        return True
Пример #7
0
    def given_stamina(self, target_id, if_present=True):
        if target_id not in self._friends.keys():
            logger.error('given_stamina can not find friend!:%s', target_id)
            return False
        given_time_list = self._friends[target_id]
        given_times = len(given_time_list)
        if given_times >= 1:
            logger.error('given_stamina times!:%s', given_times)
            return False

        given_time_list.append(datetime.datetime.now())
        if not if_present:
            logger.error('given_stamina present!:%s', if_present)
            return True

        send_mail(conf_id=1,
                  receive_id=target_id,
                  nickname=self.owner.base_info.base_name)
        self._given_record.append(target_id)

        return True
Пример #8
0
def deal_target_player(player, target_id, chip_id):
    target_data_obj = tb_character_info.getObj(target_id)
    isexist = target_data_obj.exists()
    if not isexist:
        logger.error('deal_target_player, player id error')
        return

    target_data = target_data_obj.hmget(['equipment_chips', 'truce'])
    now = int(time.time())
    truce = target_data.get('truce', [0, 0])
    item_config_item = game_configs.item_config.get(130001)
    end_time = truce[1] + truce[0] * item_config_item.funcArg1 * 60
    if truce[1] and end_time > now:
        return
    chips = target_data.get('equipment_chips')
    chips_obj = {}
    for chip_id_x, chip_num in chips.items():
        equipment_chip = EquipmentChip(chip_id_x, chip_num)
        chips_obj[chip_id_x] = equipment_chip

    chip_obj = chips_obj.get(chip_id)
    if not chip_obj or chip_obj.chip_num == 0:
        return
    # 如果对方有的话
    is_online = remote_gate.is_online_remote('modify_equ_chip_remote',
                                             target_id, {'chip_id': chip_id})
    if is_online == "notonline":
        chip_obj.chip_num -= 1

        props = {}
        for chip_id_x, chip_obj in chips_obj.items():
            if chip_obj.chip_num:  # 如果chip num == 0, 则不保存
                props[chip_id_x] = chip_obj.chip_num
        target_data_obj.hset('equipment_chips', props)

    mail_arg1 = [{104: [1, 1, chip_id]}]
    send_mail(conf_id=701,
              receive_id=target_id,
              nickname=player.base_info.base_name,
              arg1=str(mail_arg1))
Пример #9
0
def rebate_call(player, recharge_item):
    """
    购买返利卡
    """
    rid = recharge_item.get('id')
    days = recharge_item.get('giftDays')
    switch, _, _ = player.rebate.rebate_status(rid, days)
    if switch:
        rebate = player.rebate.rebate_info(rid)
        rebate.new_rebate(days)
        player.rebate.set_rebate(rid, rebate)
        if days == 30:
            player.rebate.month_start(recharge_item.get('mailForEver'))
        mail_id, times = player.rebate.month_mails()
        for _ in range(times):
            send_mail(conf_id=mail_id, receive_id=player.base_info.id)
        player.rebate.save_data()

        notify = rebate_info(player)
        remote_gate.push_object_remote(5432,
                                           notify.SerializePartialToString(),
                                           [player.dynamic_id])
Пример #10
0
def notify_mail(player):
    """
    通知可以购买返利卡了
    """
    plat = 'ios'
    if player.base_info.plat_id == 1:
        plat = 'android'
    recharge_items = {}
    all_rebates = player.rebate.all_rebates()
    for item in game_configs.recharge_config[plat].values():
        recharge_items[item.id] = item
    for rid in all_rebates:
        recharge_item = recharge_items.get(rid)
        if not recharge_item:
            continue
        if player.rebate.need_mail(rid, recharge_item.get('giftDays')):
            if recharge_item.get('giftDays') == 30:
                mail_id = game_configs.base_config.get('moonCardRemindMail')
                send_mail(conf_id=mail_id, receive_id=player.base_info.id)
            else:
                mail_id = game_configs.base_config.get('weekCardRemindMail')
                send_mail(conf_id=mail_id, receive_id=player.base_info.id)
            player.rebate.send_mail(rid)
            player.rebate.save_data()
Пример #11
0
def trigger_hjqy(player, result, times=1):
    """docstring for trigger_hjqy 触发黄巾起义
    return: stage id
    """
    if is_not_open(player, FO_HJQY_STAGE):
        return 0
    # 如果战败则不触发
    if not result:
        return 0
    logger.debug("trigger_hjqy")
    # 活动是否开启
    if player.base_info.is_firstday_from_register(const.OPEN_FEATURE_HJQY):
        logger.debug("hjqy have not open.")
        return 0

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

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

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

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

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

    stage_index = random_pick_with_weight(info)

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

    if stage_info.chapter not in hjqyRandomCheckpoint:
        return 0

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

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

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

    player.fight_cache_component.stage_id = stage_id

    blue_units = player.fight_cache_component._assemble_monster()

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

    return stage_id
Пример #12
0
def pvp_fight_request_1505(data, player):
    """
    pvp战斗开始
    """
    request = pvp_rank_pb2.PvpFightRequest()
    response = pvp_rank_pb2.PvpFightResponse()
    request.ParseFromString(data)
    # player.pvp.check_time()
    if is_not_open(player, FO_PVP_RANK):
        response.res.result = False
        response.res.result_no = 837
        return response.SerializePartialToString()

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

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

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

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

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

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

    before_player_rank = int(before_player_rank)

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

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

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

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

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

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

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

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

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

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

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

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

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

    hook_task(player, CONDITIONId.PVP_RANk_TIMES, 1)

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

    return response.SerializeToString()
Пример #13
0
    def settle(player, fight_result):
        rank_incr = 0
        response.top_rank = player.pvp.pvp_high_rank
        if fight_result:
            logger.debug("fight result:True:%s:%s",
                         before_player_rank, request.challenge_rank)

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

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

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

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

            if request.challenge_rank < player.pvp.pvp_high_rank:
                rank_incr = player.pvp.pvp_high_rank - request.challenge_rank
            if player.pvp.pvp_high_rank > request.challenge_rank:
                hook_task(player, CONDITIONId.PVP_RANK, request.challenge_rank)
            player.pvp.pvp_high_rank = min(player.pvp.pvp_high_rank,
                                           request.challenge_rank)
            logger.debug(" history_high_rank %s current %s" % (player.pvp.pvp_high_rank, before_player_rank))

            # 首次达到某名次的奖励
            arena_rank_up_rewards = game_configs.base_config.get('arenaRankUpRewards')
            if arena_rank_up_rewards:
                return_data = gain(player, arena_rank_up_rewards,
                                   const.ARENA_WIN, multiple=rank_incr)
                get_return(player, return_data, response.award)
            else:
                logger.debug('arena rank up points is not find')
        else:
            logger.debug("fight result:False")
            send_mail(conf_id=124, receive_id=target_id,
                      nickname=player.base_info.base_name)

        hook_task(player, CONDITIONId.PVP_RANk_TIMES, 1)

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

        return response.SerializeToString()
Пример #14
0
def process_mine_result(player, position, fight_result,
                        response, stype, hold=1):
    """
    玩家占领其他人的野怪矿,更新矿点数据,给玩家发送奖励,给被占领玩家发送奖励
    @param gain: true or false
    """
    result = player.mine.settle(position, fight_result, hold)
    normal = result['normal']
    lucky = result['lucky']

    if stype != 1:
        return
    # print 'process mine result:', normal, lucky

    target = result['old_uid']
    nickname = result['old_nickname']

    if fight_result is not True:
        send_mail(conf_id=122, receive_id=target, nickname=player.base_info.base_name)
        return

    warFogLootRatio = game_configs.base_config['warFogLootRatio']
    normal_a = {}
    normal_b = {}
    lucky_a = {}
    lucky_b = {}

    for k, v in normal.items():
        if v > 0:
            normal_a[k] = int(v*warFogLootRatio)
            normal_b[k] = v - int(v*warFogLootRatio)

    for k, v in lucky.items():
        if v > 0:
            lucky_a[k] = int(v*warFogLootRatio)
            lucky_b[k] = v - int(v*warFogLootRatio)

    prize = []
    prize_num = 0
    for k, v in normal_b.items():
        prize.append({106: [v, v, k]})
        prize_num += v
    for k, v in lucky_b.items():
        prize.append({106: [v, v, k]})
        prize_num += v

    logger.debug('pvp mine total:normal %s-%s lucky %s-%s prize:%s',
                 normal_a, normal_b, lucky_a, lucky_b, prize)

    if not add_stones(player, normal_a, response.gain):
        response.res.result = False
        response.res.result_no = 824
        logger.error('add_stones fail!!!!!!')
    if not add_stones(player, lucky_a, response.gain):
        response.res.result = False
        response.res.result_no = 824
        logger.error('add_stones fail!!!!!!')

    mail_id = game_configs.base_config.get('warFogRobbedMail')
    send_mail(conf_id=mail_id, receive_id=target, rune_num=prize_num,
              prize=str(prize), nickname=player.base_info.base_name)
Пример #15
0
 def send_mail(self, recharge_item):
     mail_id = recharge_item.get('mailId')
     send_mail(conf_id=mail_id, receive_id=self._owner.base_info.id)
Пример #16
0
 def send_mail(self, recharge_item):
     mail_id = recharge_item.get('mailId')
     send_mail(conf_id=mail_id, receive_id=self._owner.base_info.id)