def team4304(dwid,plist):
    '''队伍详细信息
    @param dwid: int 队伍id
    @param plist: [] 队伍中角色的id列表[1,2,3]
    '''
    from app.scense.protoFile.zudui import GetGroupInfo4304_pb2
    from app.scense.core.teamfight.TeamFight import TeamFight
    
    response=GetGroupInfo4304_pb2.GetGroupInfoResponse()
    response.message=u''
    response.result=True
    if TeamFight().ishaveteam(dwid):#如果有队伍
        result=TeamFight().getTeamInfoByPlayerId1(dwid)
        if len(result)>0:
            for item in result:
                info=response.dwMemberInfo.add()
                info.roleId=item.get('roleId')
                info.pos=item.get('pos')
                info.level=item.get('level')
                info.roleName=item.get('roleName')
                info.proType=item.get('roleType')
    else:#如果没有队伍
        response.dwMemberInfo.extend([])
    data=response.SerializeToString()
    pushObjectByCharacterId(4304,data,plist)
 def pushTaskCanFinished(self):
     '''推送任务已完成的消息
     '''
     response = TaskFinshNotify1422_pb2.TaskFinshNotify()
     response.finshID = 0
     msg = response.SerializeToString()
     pushObjectByCharacterId(1422, msg, [self._owner.baseInfo.id])
def getzudui_4308(data1,plist,msg,zy):
    '''多人副本战斗
    @param data1: obj 战斗信息 
    @param plist: [角色id] 托送的角色id列表
    @param msg: str 战斗结束后的消息
    @param zy: int 场景资源id
    '''
    from app.scense.protoFile.zudui import GroupBattle4308_pb2
    response=GroupBattle4308_pb2.FightResponse()
    
    response.result = True
    response.data.battleResult = data1.battleResult
    response.data.centerX = data1.center
    response.data.centerY = 325
    response.data.fightmsg=msg
    response.data.zyid=zy
    rResArr = response.data.rResArr
    startData = response.data.startData
    setpdata = response.data.stepData
    data1.SerializationResource(rResArr)
    data1.SerializationInitBattleData(startData)
    data1.SerializationStepData(setpdata)
    
    data=response.SerializeToString()
    pushObjectByCharacterId(4308,data,plist)
def pushzhFriend(id,name,level):
    '''当角色升级后推送当前角色的等级信息到该角色的所有在线好友,用以祝贺只用
    @param id: int 角色id
    @param name: str 角色名称
    @param level: int 角色的等级
    '''
    
    from app.scense.protoFile.friend import FriendLevelUpNotify310_pb2
    response=FriendLevelUpNotify310_pb2.FriendLevelUpNotify()
    player=PlayersManager().getPlayerByID(id)
    if player:
        cityid=player.baseInfo.getTown()#角色所在城市
        list=[] #存储好友动态id
        val=player.friend.getFriends()
        if not val or len(val)<1:#如果该角色没有好友
            return
        for itid in val: 
            playert=PlayersManager().getPlayerByID(itid)
            if playert and playert.baseInfo.getTown()==cityid:#如果角色在线并且和升级角色在同一个城市
                list.append(playert.baseInfo.getId())
        if len(list)<1: #如果该角色好友都没有在线
            return
       
        response.id=id
        response.name=name
        response.level=level
        msg = response.SerializeToString()
        pushObjectByCharacterId(310,msg,list)
def pushOtherMessageByCharacterId(msg ,sendList):
    '''推送其他提示信息'''
    request = pushOtherMessage_pb2.OtherMessage()
    try:
        request.msg = msg
    except Exception:
        request.msg = unicode(msg,'gbk')
    data = request.SerializeToString()
    pushObjectByCharacterId(905,data,sendList)
def pushScenceNpcQuestStatus(stausList,dynamicId):
    '''推送场景中NPC的任务状态'''
    from protoFile.quest import getScenceNpcQuestStatus_pb2
    response = getScenceNpcQuestStatus_pb2.getScenceNpcQuestStatusResponse()
    for statu in stausList:
        npcStatu = response.NPCQuestStatusList.add()
        npcStatu.npcID = statu['npcID']
        npcStatu.statu = statu['statu']
    msg = response.SerializeToString()
    pushObjectByCharacterId(1408,msg,[dynamicId])
def StrengthenTime2120(pid,sstime):
    '''推送强化剩余时间
    @param pid: int 角色id
    @param sstime: int 剩余秒数    
    '''
    r = StrengthenTime2120_pb2.StrengthenTimeResponse()
    r.message=u''
    r.result=True
    r.reTime=sstime
    data = r.SerializeToString()
    pushObjectByCharacterId(2120,data,[pid])
def teamClean4304(dwid,plist):
    '''队伍详细信息
    @param dwid: int 队伍id
    @param plist: [] 队伍中角色的id列表[1,2,3]
    '''
    from app.scense.protoFile.zudui import GetGroupInfo4304_pb2
    
    response=GetGroupInfo4304_pb2.GetGroupInfoResponse()
    response.message=u''
    response.result=True
    response.dwMemberInfo.extend([])
    data=response.SerializeToString()
    pushObjectByCharacterId(4304,data,plist)
def pushCharacterLevelMessage(sendList,name,level):
    '''推送角色升级消息'''
    from app.scense.protoFile.playerInfo import pushCharacterLevelMessage_pb2
    response = pushCharacterLevelMessage_pb2.pushCharacterLevelMessage()
    response.Signal = 1
    msg = response.SerializeToString()
    pushObjectByCharacterId(218,msg,sendList)
    #-------发送给所有在线好友升级提示
#    player=PlayersManager().getPlayerBydynamicId(sendList[0])
#    id=player.baseInfo.getId()
#    name=player.baseInfo.getNickName()
#    level=player.level.getLevel()
    #print"推送升级消息"+name+str(level)
    pushzhFriend(sendList[0],name,level)
def pushGameTopTitle2400(sendList,typelist):
    '''推送奖励图标
    @param sendList: 角色id列表
    @param typeid: int 奖励类型 1为殖民  2殖民管理
    '''
    from app.scense.protoFile.defence import GameTopTitle2400_pb2
    response=GameTopTitle2400_pb2.GameTopTitleResponse()
    if len(typelist)<1:
        response.anouInfo.extend([])
    else:
        for typeid in typelist:
            an=response.anouInfo.add()
            an.anouType=typeid
    data = response.SerializeToString()
    pushObjectByCharacterId(2400 , data, sendList)
def pushCorpsApplication(recCharacterId,sysOpeType,tishiStr,contentStr,caozuoStr,
                         roleId = 0,roleName = u'',icon =0,
                         type = 0,pos=0,curPage = 0,toposition = 0,guaJiInfo={}):
    '''推送角色国申请
    @param roleId: int 申请者的ID
    @param roleName: str 角色的名称
    @param recCharacterId: int 接受消息的角色的ID
    '''
    response = SysOpeCorps2900_pb2.SysOpeCorpsResponse()
    response.roleId = roleId
    response.roleName = roleName
    response.sysOpeType = sysOpeType
    response.icon = icon
    response.type = type
    response.pos = pos
    response.curPage = curPage
    try:
        response.tishiStr = tishiStr
    except Exception:
        response.tishiStr = tishiStr.decode('utf8')
    try:
        response.contentStr = contentStr
    except Exception:
        response.contentStr = contentStr.decode('utf8')
    try:
        response.caozuoStr = caozuoStr
    except Exception:
        response.caozuoStr = caozuoStr.decode('utf8')
    response.toposition = toposition
    if guaJiInfo:
        response.guaJiInfo.exp = guaJiInfo.get('exp',0)
        response.guaJiInfo.time = guaJiInfo.get('time',0)
    msg = response.SerializeToString()
    pushObjectByCharacterId(2900, msg, [recCharacterId])
    
    
    
    
def pushQuestProcessList(data,dynamicId):
    '''推送任务追踪信息
    @param data: 追踪的信息
    @param dynamicId: 客户端的动态ID
    '''
    response  = TaskTracNotify1421_pb2.TaskTracListNotify()
    cur_list = data.get('cur_list')
    acceptable_list = data.get('acceptable_list')
    for task in cur_list:
        taskResponse = response.cur_list.add()
        taskResponse.is_trac = task.get('is_trac')
        taskResponse.task_id = task.get('task_id')
        taskResponse.task_state = task.get('task_state')
        taskResponse.task_accpet_npc_id = task.get('task_accpet_npc_id')
        taskResponse.cur_num = task.get('cur_num')
        taskResponse.need_num = task.get('need_num')
        taskResponse.task_running_des = task.get('task_running_des')
        taskResponse.task_complete_des = task.get('task_complete_des')
        taskResponse.task_name = task.get('task_name')
        for runningargs in task.get('runing_args'):
            runing_arg = taskResponse.runing_args.add()
            runing_arg.id = runningargs.get('id')
            runing_arg.label = runningargs.get('label')
        for completeargs in task.get('complete_args'):
            complete_arg = taskResponse.complete_args.add()
            complete_arg.id = completeargs.get('id')
            complete_arg.label = completeargs.get('label','')
            
    for task in acceptable_list:
        taskResponse = response.acceptable_list.add()
        taskResponse.task_id = int(task.format.get('taskID'))
        taskResponse.task_name = task.format.get('taskName')
        taskResponse.task_accpet_npc_id = task.format.get('providerNPC')
        taskResponse.task_accpet_city_id = task.format.get('providerScene')
        taskResponse.need_lv = int(task.format.get('levelRequired'))
    msg = response.SerializeToString()
    pushObjectByCharacterId(1421, msg, [dynamicId])
def psuhCharacterArenaCD(CD, CharacterId):
    '''推送角色竞技场CD'''
    response = JingJiCD3701_pb2.JingJiCDResponse()
    response.cdTime = CD
    msg = response.SerializeToString()
    pushObjectByCharacterId(3701, msg, [CharacterId])
def pushTaskCanFinished(sendList):
    '''推送任务已完成的消息
    '''
    response = TaskFinshNotify1422_pb2.TaskFinshNotify()
    msg = response.SerializeToString()
    pushObjectByCharacterId(1422, msg, sendList)
def psuhCharacterArenaCD(CD,CharacterId):
    '''推送角色竞技场CD'''
    response = JingJiCD3701_pb2.JingJiCDResponse()
    response.cdTime = CD
    msg = response.SerializeToString()
    pushObjectByCharacterId(3701, msg, [CharacterId])