| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package PlayerUniversalGameRec.py  | 
| #  | 
| # @todo:Íæ¼ÒÐÅϢͨÓüǼ±í  | 
| #  | 
| # @author jiang  | 
| # @date 2012-03-16   | 
| # @version 2.6  | 
| # @note:  | 
| #  | 
| # @change: "2012-09-27 12:00" jiang Í¨Öª¿Í»§¶Ëʱ·â°üÔö¼ÓÀàÐÍ  | 
| # @change: "2012-09-27 18:00" linyonggui Ð޸Ĵ洢µÄʱ¼ä  | 
| # @change: "2012-11-06 13:20" whx Ôö¼ÓÉèÖÃStrValue3ÐÅÏ¢  | 
| # @change: "2012-12-19 14:30" jiang ÐÞ¸ÄÍæ¼Òʱ¼ä¼ä¸ô´íÎóbug  | 
| # @change: "2012-12-20 18:00" hyx Ôö¼Ó½Ó¿Úº¯Êý  | 
| # @change: "2012-12-21 11:00" jiang Íæ¼Òʱ¼ä¼ä¸ôʹÓÃGameWorld.RefurbishPlayerTick()º¯Êý  | 
| # @change: "2013-01-11 11:00" wdb Ôö¼Ó²»¿É²éѯµÄ×Ô¶¨Òå±í  | 
| # @change: "2013-01-23 17:50" hyx MapServer_PlayerUniversalGameRecº¯ÊýÌí¼Ó·µ»ØÖµ  | 
| # @change: "2013-09-10 20:10" Alee ÓÃGetDebugLevel²ÅÓÐЧ  | 
| # @change: "2014-12-30 09:30" hxp Ôö¼Ó֪ͨº¯Êý  | 
| # @change: "2015-10-26 12:00" hxp Í¨Öªº¯ÊýÔö¼ÓStrValue3  | 
| # @change: "2015-11-18 10:30" hxp Ôö¼Ó¿½±´º¯Êý; Ôö¼Óͬ²½µ¥ÌõÊý¾Ý  | 
| # @change: "2016-08-29 17:30" hxp ÉèÖüǼÊý¾ÝÂß¼ÐÞ¸Ä  | 
| # @change: "2016-12-21 17:30" hxp Í¨Öª×ÔÉíÊý¾ÝÖ§³Ö  | 
| # @change: "2017-06-22 15:00" hxp ºé»ÄÖ®Á¦»î¶¯ÐÅϢֻͬ²½¿ç·þǰ3¡¢±¾·þǰ3¡¢¼°Íæ¼Ò×Ô¼ºµÄÊý¾Ý  | 
| # @change: "2017-07-03 20:00" hxp ÐÞ¸´»ì·þģʽÏ·þÎñÆ÷¹é×éIDÎÊÌâ  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2017-07-03 20:00"""  | 
| #------------------------------------------------------------------------------   | 
| import GameWorld  | 
| import ChConfig  | 
| import ShareDefine  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import PlayerControl  | 
|   | 
| import time  | 
| #---------------------------------------------------------------------  | 
| def MapServer_UniversalGameRec(curPlayer, recType, valueList, strValueList, notifyType=0, isSort=1):  | 
|     '''  | 
|     @todo:  ÉèÖÃÍæ¼ÒÐÅϢͨÓüǼ  | 
|     @param curPlayer: Íæ¼ÒʾÀý£¬¿ÉΪNone£¬Í¨ÖªÍæ¼Ò¸öÈËʱ¿ÉÓà  | 
|     @param recType: ¼Ç¼ÀàÐÍ  | 
|     @param valueList: [Value1,...,Value5]  | 
|     @param strValueList: [StrValue1, StrValue2, StrValue3]  | 
|     @param notifyType: 0-²»Í¨Öª; 1-֪ͨ±¾ÈË; 2-֪ͨȫ·þ£»3-֪ͨ±¾È˵¥Ìõ£»4-֪ͨȫ·þµ¥Ìõ  | 
|     @param isSort: É¾³ýʱÊÇ·ñÐèÒªÏÈÅÅÐò, Ä¬ÈÏÊÇ  | 
|     '''  | 
|     if recType not in ShareDefine.Def_UniversalGameRecTypeList:  | 
|         #¼Ç¼ÀàÐÍ´íÎó  | 
|         GameWorld.ErrLog("Íæ¼ÒÐÅϢͨÓüǼ:%s ´íÎó"%recType)  | 
|         return None  | 
|       | 
|     #ËùÓÐÍæ¼ÒÐÅϢͨÓüǼ¶ÔÏó¹ÜÀíÆ÷  | 
|     universalRecMgr = GameWorld.GetUniversalRecMgr()    | 
|       | 
|     #ijһÀàÐͼǼµÄËùÓÐÊý¾Ý  | 
|     recTypeListData = universalRecMgr.GetTypeList(recType)  | 
|     recCount = recTypeListData.Count()  | 
|     if recCount >= ChConfig.UniversalGameRecTypeSaveCnt.get(recType, 0):  | 
|         if isSort:  | 
|             recTypeListData.SortByTime()  # °´Ê±¼äÉýÐò  | 
|         recTypeListData.Delete(0)  # É¾³ýµÚÒ»¸ö  | 
|           | 
|     curTimeStr = GameWorld.GetCurrentDataTimeStr()  | 
|     curTimeTuple = time.strptime(curTimeStr, ChConfig.TYPE_Time_Format)  | 
|     curTimeNum = int(time.mktime(curTimeTuple))  | 
|           | 
|     #Ìí¼ÓÒ»¸ö¼Ç¼¶ÔÏó  | 
|     recObj = recTypeListData.AddRec()  | 
|       | 
|     #---ÉèÖüǼ¶ÔÏóÊý¾Ý---  | 
|     recObj.SetTime(curTimeNum)  | 
|       | 
|     recStrDataListLen = len(strValueList)  | 
|     if recStrDataListLen >= 1:  | 
|         recObj.SetStrValue1(str(strValueList[0]))  | 
|       | 
|     if recStrDataListLen >= 2:  | 
|         recObj.SetStrValue2(str(strValueList[1]))  | 
|       | 
|     if recStrDataListLen >= 3:  | 
|         SetUniversalGameRecStrValue3(recObj, str(strValueList[2]))  | 
|       | 
|     recValueDataListLen = len(valueList)  | 
|     if recValueDataListLen >= 1:  | 
|         value1 = GameWorld.ToIntDef(valueList[0])  | 
|         recObj.SetValue1(min(ChConfig.Def_UpperLimit_DWord, value1))  | 
|           | 
|     if recValueDataListLen >= 2:  | 
|         value2 = GameWorld.ToIntDef(valueList[1])  | 
|         recObj.SetValue2(min(ChConfig.Def_UpperLimit_DWord, value2))  | 
|           | 
|     if recValueDataListLen >= 3:  | 
|         value3 = GameWorld.ToIntDef(valueList[2])  | 
|         recObj.SetValue3(min(ChConfig.Def_UpperLimit_DWord, value3))  | 
|           | 
|     if recValueDataListLen >= 4:  | 
|         value4 = GameWorld.ToIntDef(valueList[3])  | 
|         recObj.SetValue4(min(ChConfig.Def_UpperLimit_DWord, value4))  | 
|           | 
|     if recValueDataListLen >= 5:  | 
|         value5 = GameWorld.ToIntDef(valueList[4])  | 
|         recObj.SetValue5(min(ChConfig.Def_UpperLimit_DWord, value5))  | 
|       | 
|     if notifyType == 1:  | 
|         SendUniversalGameRecInfo(curPlayer, recType)  | 
|     elif notifyType == 2:  | 
|         SendUniversalGameRecInfo(None, recType)  | 
|     elif notifyType == 3:  | 
|         SendUniversalGameRecSingle(curPlayer, recObj)  | 
|     elif notifyType == 4:  | 
|         SendUniversalGameRecSingle(None, recObj)  | 
|           | 
|     return recObj  | 
|   | 
|   | 
| ## ÉèÖÃStrValue3×Ö·û´®ÐÅÏ¢  | 
| #  @param recObj:ʵÀý   | 
| #  @param tagStr:Ä¿±ê×Ö·û   | 
| #  @return:   | 
| def SetUniversalGameRecStrValue3(recObj, tagStr):  | 
|     if len(tagStr) > 255 and GameWorld.GetGameWorld().GetDebugLevel():  | 
|         raise Exception("SetStrValue3 len(tagStr) > 255 tagStr=%s"%tagStr)  | 
|       | 
|     recObj.SetStrValue3(tagStr)  | 
|     return  | 
|   | 
|   | 
| #===============================================================================  | 
| # //A0 01 ²é¿´Íæ¼ÒÐÅϢͨÓüǼ #tagViewUniversalGameRec  | 
| #   | 
| # struct    tagViewUniversalGameRec  | 
| #   | 
| # {  | 
| #    tagHead        Head;  | 
| #    BYTE        ViewType;    //²é¿´¼Ç¼µÄÀàÐÍ  | 
| # };  | 
| #===============================================================================  | 
| ## ²é¿´Íæ¼ÒÐÅϢͨÓüǼ  | 
| #  @param index:Íæ¼ÒË÷Òý   | 
| #  @param clientData:·â°ü½á¹¹Ìå   | 
| #  @param tick:ʱ¼ä´Á   | 
| #  @return:   | 
| def ViewUniversalGameRec(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     viewType = clientData.ViewType  # ²é¿´¼Ç¼µÄÀàÐÍ  | 
|       | 
|     if viewType not in [ShareDefine.Def_UniversalGameRecType_FamilyWarChampion, ShareDefine.Def_UniversalGameRecType_BossFirstKill]:  | 
|         if not GameWorld.RefurbishPlayerTick(curPlayer, ChConfig.TYPE_Player_Tick_Def_ViewUniversalGameRec, tick):  | 
|             #¼ä¸ôδµ½  | 
|             return  | 
|           | 
|     if viewType not in ShareDefine.Def_UniversalGameRecTypeList:  | 
|         #²é¿´ÀàÐÍ´íÎó  | 
|         GameWorld.ErrLog("ViewUniversalGameRec viewType = %s not in %s"%\  | 
|                          (viewType, ShareDefine.Def_UniversalGameRecTypeList))  | 
|         return  | 
|       | 
|     if viewType in ShareDefine.Def_Confidential_UniversalRecList:  | 
|         return  | 
|       | 
|     SendUniversalGameRecInfo(curPlayer, viewType)  | 
|     return  | 
|   | 
| ## Í¨ÖªÍæ¼ÒÐÅϢͨÓüǼ  | 
| #  @param curPlayer:Íæ¼Ò, None±íʾȫ·þ֪ͨ   | 
| #  @param viewType:֪ͨÀàÐÍ   | 
| #  @return:   | 
| def SendUniversalGameRecInfo(curPlayer, viewType):  | 
|     syncSelfDataCnt = None  | 
|     if viewType in ShareDefine.Def_Sync_UniversalRecSelfDict:  | 
|         if not curPlayer:  | 
|             return  | 
|         syncSelfDataCnt = ShareDefine.Def_Sync_UniversalRecSelfDict[viewType]  | 
|       | 
|     #ËùÓÐÍæ¼ÒÐÅϢͨÓüǼ¶ÔÏó¹ÜÀíÆ÷  | 
|     universalRecMgr = GameWorld.GetUniversalRecMgr()    | 
|       | 
|     #ijһÀàÐͼǼµÄËùÓÐÊý¾Ý  | 
|     recTypeListData = universalRecMgr.GetTypeList(viewType)  | 
|     recCount = recTypeListData.Count()  | 
|       | 
|     #curServerGroupID = GameWorld.GetServerGroupID()  | 
|     packList = []  | 
|     for index in xrange(0, recCount):  | 
|         universalRecData = recTypeListData.At(index)  | 
|         recTime = universalRecData.GetTime()  | 
|         recStrValue1 = universalRecData.GetStrValue1()  | 
|         recStrValue2 = universalRecData.GetStrValue2()  | 
|         recStrValue3 = universalRecData.GetStrValue3()  | 
|         recValue1 = universalRecData.GetValue1()  | 
|         recValue2 = universalRecData.GetValue2()  | 
|         recValue3 = universalRecData.GetValue3()  | 
|         recValue4 = universalRecData.GetValue4()  | 
|         recValue5 = universalRecData.GetValue5()  | 
|           | 
|         # Ö»Í¬²½×Ô¼ºµÄrecValue1¹Ì¶¨ÎªPlayerID  | 
|         if viewType in ShareDefine.Def_Sync_UniversalRecSelfDict:  | 
|             if recValue1 != curPlayer.GetPlayerID():  | 
|                 continue  | 
|                   | 
|         universalGameRec = ChPyNetSendPack.tagUniversalGameRec()  | 
|         universalGameRec.Time = recTime  | 
|         universalGameRec.StrValue1Len = len(recStrValue1)  | 
|         universalGameRec.StrValue1 = recStrValue1  | 
|         universalGameRec.StrValue2Len = len(recStrValue2)  | 
|         universalGameRec.StrValue2 = recStrValue2  | 
|         universalGameRec.StrValue3Len = len(recStrValue3)  | 
|         universalGameRec.StrValue3 = recStrValue3  | 
|         universalGameRec.Value1 = recValue1  | 
|         universalGameRec.Value2 = recValue2  | 
|         universalGameRec.Value3 = recValue3  | 
|         universalGameRec.Value4 = recValue4  | 
|         universalGameRec.Value5 = recValue5  | 
|         packList.append(universalGameRec)  | 
|           | 
|         if viewType in ShareDefine.Def_Sync_UniversalRecSelfDict:  | 
|             # Ö»Í¬²½×Ô¼ºµÄÒÑ´ïµ½ÌõÊý  | 
|             if syncSelfDataCnt > 0 and len(packList) >= syncSelfDataCnt:  | 
|                 break  | 
|               | 
|     universalGameRecInfo = ChPyNetSendPack.tagUniversalGameRecInfo()  | 
|     universalGameRecInfo.Clear()  | 
|     universalGameRecInfo.Count = len(packList)  | 
|     universalGameRecInfo.Type = viewType  | 
|     universalGameRecInfo.UniversalGameRec = packList  | 
|       | 
|     if not curPlayer:  | 
|         # È«·þ¹ã²¥ÔÚÏßÍæ¼Ò  | 
|         playerManager = GameWorld.GetPlayerManager()  | 
|         for i in range(0, playerManager.GetPlayerCount()):  | 
|             curPlayer = playerManager.GetPlayerByIndex(i)  | 
|             if curPlayer == None or not curPlayer.GetInitOK():  | 
|                 continue  | 
|               | 
|             NetPackCommon.SendFakePack(curPlayer, universalGameRecInfo)  | 
|     else:  | 
|         NetPackCommon.SendFakePack(curPlayer, universalGameRecInfo)  | 
|     return  | 
|   | 
|   | 
| ## Í¨ÖªÍæ¼ÒÐÅÏ¢µ¥ÌõͨÓüǼ  | 
| #  @param curPlayer:Íæ¼Ò, None±íʾȫ·þ֪ͨ   | 
| #  @param recData   | 
| #  @return:   | 
| def SendUniversalGameRecSingle(curPlayer, recData):  | 
|     packList = []  | 
|       | 
|     universalGameRec = ChPyNetSendPack.tagUniversalGameRec()  | 
|     universalGameRec.Time = recData.GetTime()  | 
|     universalGameRec.StrValue1 = recData.GetStrValue1()  | 
|     universalGameRec.StrValue1Len = len(universalGameRec.StrValue1)  | 
|     universalGameRec.StrValue2 = recData.GetStrValue2()  | 
|     universalGameRec.StrValue2Len = len(universalGameRec.StrValue2)  | 
|     universalGameRec.StrValue3 = recData.GetStrValue3()  | 
|     universalGameRec.StrValue3Len = len(universalGameRec.StrValue3)  | 
|     universalGameRec.Value1 = recData.GetValue1()  | 
|     universalGameRec.Value2 = recData.GetValue2()  | 
|     universalGameRec.Value3 = recData.GetValue3()  | 
|     universalGameRec.Value4 = recData.GetValue4()  | 
|     universalGameRec.Value5 = recData.GetValue5()  | 
|     packList.append(universalGameRec)  | 
|       | 
|     universalGameRecInfo = ChPyNetSendPack.tagUniversalGameRecInfo()  | 
|     universalGameRecInfo.Clear()  | 
|     universalGameRecInfo.Count = len(packList)  | 
|     universalGameRecInfo.Type = recData.GetType()  | 
|     universalGameRecInfo.UniversalGameRec = packList  | 
|       | 
|     if not curPlayer:  | 
|         # È«·þ¹ã²¥ÔÚÏßÍæ¼Ò  | 
|         playerManager = GameWorld.GetPlayerManager()  | 
|         for i in range(0, playerManager.GetPlayerCount()):  | 
|             curPlayer = playerManager.GetPlayerByIndex(i)  | 
|             if curPlayer == None or not curPlayer.GetInitOK() or PlayerControl.GetIsTJG(curPlayer):  | 
|                 continue  | 
|               | 
|             NetPackCommon.SendFakePack(curPlayer, universalGameRecInfo)  | 
|     else:  | 
|         NetPackCommon.SendFakePack(curPlayer, universalGameRecInfo)  | 
|     return  | 
|   | 
| ## »ñȡijÀàÐ͵ļǼÊý  | 
| #  @param recType ¼Ç¼ÀàÐÍ  | 
| #  @return ¼Ç¼Êý  | 
| def GetRecordCount(recType):  | 
|     recMgr = GameWorld.GetGameWorld().GetUniversalRecMgr()  | 
|     recTypeListData = recMgr.GetTypeList(recType)  | 
|     recCount = recTypeListData.Count()  | 
|     return recCount  | 
|       | 
|   | 
| ## »ñȡijÌõ¼Ç¼ÁÐ±í  | 
| #  @param recType ¼Ç¼ÀàÐÍ  | 
| #  @return ¼Ç¼ÁÐ±í  | 
| def GetRecordList(recType):  | 
|     recMgr = GameWorld.GetGameWorld().GetUniversalRecMgr()  | 
|     recTypeListData = recMgr.GetTypeList(recType)  | 
|     return recTypeListData  | 
|       | 
| ## ÔÑù¿½±´RecÊý¾Ý  | 
| #  @param newRecType: ÐÂÀàÐÍ  | 
| #  @param oldRecType: ¾ÉÀàÐÍ  | 
| #  @return:   | 
| def CopyRecData(newRecType, oldRecType):  | 
|       | 
|     universalRecMgr = GameWorld.GetUniversalRecMgr()  | 
|     oldRecordList = universalRecMgr.GetTypeList(oldRecType)  | 
|   | 
|     if not oldRecordList:  | 
|         return False  | 
|       | 
|     universalRecMgr.Delete(newRecType)  | 
|     newRecordList = universalRecMgr.GetTypeList(newRecType)  | 
|       | 
|     for i in range(oldRecordList.Count()):          | 
|         oldRecData = oldRecordList.At(i)  | 
|           | 
|         if not oldRecData:  | 
|             continue  | 
|           | 
|         #Ìí¼ÓÒ»¸ö¼Ç¼¶ÔÏó  | 
|         newRecData = newRecordList.AddRec()  | 
|           | 
|         #---ÉèÖüǼ¶ÔÏóÊý¾Ý---  | 
|         newRecData.SetTime(oldRecData.GetTime())  | 
|         newRecData.SetValue1(oldRecData.GetValue1())  | 
|         newRecData.SetValue2(oldRecData.GetValue2())  | 
|         newRecData.SetValue3(oldRecData.GetValue3())  | 
|         newRecData.SetValue4(oldRecData.GetValue4())  | 
|         newRecData.SetValue5(oldRecData.GetValue5())  | 
|         newRecData.SetStrValue1(oldRecData.GetStrValue1())  | 
|         newRecData.SetStrValue2(oldRecData.GetStrValue2())  | 
|         newRecData.SetStrValue3(oldRecData.GetStrValue3())  | 
|   | 
|     return True  | 
|   | 
|   |