| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GMT_AddEntireCompensation.py  | 
| #  | 
| # @todo:Ìí¼ÓÈ«·þ²¹³¥  | 
| # @author xmnathan  | 
| # @date 2014-09-29 13:00  | 
| # @version 1.4  | 
| #  | 
| # @change: "2014-10-24 17:30" hxp Ôö¼Ó²¹³¥Áìȡʱ¼äÅжϣ¬ÒѹýÆÚ·µ»ØGM¹¤¾ßʱ¼ä´íÎó  | 
| # @change: "2015-06-19 17:00" hxp ÎÞÎïÆ·¿ÉÌí¼Ó²¹³¥  | 
| # @change: "2017-04-26 16:30" hxp ÓÅ»¯´úÂ룬 ×°±¸ÐÅÏ¢×Öµäͳһ´¦Àí  | 
| # @change: "2018-08-10 12:00" hxp Ôö¼ÓÉèÖÃÓʼþÏÞÖÆµÈ¼¶Éý¼¶ºóÊÇ·ñ¿ÉÁ죬ÉèÖÃÓʼþÊÇ·ñÐèÒªÉóºË  | 
| #  | 
| # ÏêϸÃèÊö: Ìí¼ÓÈ«·þ²¹³¥  | 
| #  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2018-08-10 12:00"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| #µ¼Èë  | 
| import DataRecordPack  | 
| import GMT_AddPersonalCompensation  | 
| import PlayerCompensation  | 
| import GameWorld  | 
| import GMCommon  | 
| import uuid  | 
| import ChConfig  | 
| #---------------------------------------------------------------------  | 
|   | 
| ## ÇåÀí×Öµä  | 
| #  @param gmCmdDict µ±Ç°Íæ¼Ò  | 
| #  @return None  | 
| def ClearEmptyFromDict(gmCmdDict):  | 
|     keysList = gmCmdDict.keys()[::]  | 
|     for key in keysList:  | 
|         if gmCmdDict[key] == '':  | 
|             gmCmdDict.pop(key)  | 
|             continue  | 
|     return gmCmdDict  | 
|   | 
| ## Ö´ÐÐÂß¼  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param gmCmdDict: ÃüÁî×Öµä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def OnExec(orderId, gmCmdDict):  | 
|     gmCmdDict = ClearEmptyFromDict(gmCmdDict)  | 
|     GameWorld.DebugLog("GMT_AddEntireCompensation gmCmdDict:%s" % gmCmdDict)  | 
|     LimitTime = gmCmdDict.get('EndTime', '2050-12-13 00:00:00')  | 
|     curServerTime = GameWorld.GetCurrentDataTimeStr()  | 
|     # µ±Ç°Ê±¼äÒѾ³¬¹ýÁìȡʱ¼ä  | 
|     if not curServerTime or curServerTime >= LimitTime:  | 
|         GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_InvalidTime)  | 
|         return  | 
|       | 
|     MailType = int(gmCmdDict.get('MailType', '0'))  | 
|     Title = gmCmdDict.get('Title', '')  | 
|     Text = gmCmdDict.get('Text', '')  | 
|     GUID = gmCmdDict.get('GUID', '') # GM¹¤¾ßÐèÒª¶ÔÈ«·þÓʼþ½øÐжà·þÅúÁ¿¹ÜÀí£¬ËùÒÔÕâÀïGUIDÔÝÓÉGM¹¤¾ß¾ö¶¨  | 
|     if not GUID:  | 
|         GUID = str(uuid.uuid1())  | 
|     if GUID.startswith("{") and GUID.endswith("}"):  | 
|         GUID = GUID[1:-1]  | 
|     limitLV = min(99999, int(gmCmdDict.get('PlayerLV', '0'))) # Ö§³ÖµÄ×î´óµÈ¼¶  | 
|     limitLVType = int(gmCmdDict.get('LimitLVType', '0')) # ÔÏÈδ´ïµ½ÓʼþÁìÈ¡µÈ¼¶µÄÍæ¼ÒÖ®ºóÉý¼¶ÉÏÀ´ÊÇ·ñ¿ÉÁìÈ¡Óʼþ, Ä¬ÈÏ0-²»¿É£¬1-¿ÉÒÔ  | 
|     checkState = int(gmCmdDict.get('CheckState', '0')) # ÓʼþÉóºË״̬£¬Îª¼æÈÝÀÏÓʼþ£¬Ä¬ÈÏ0-ÒÑÉóºË£¬1-δÉóºË  | 
|     mailInfo = PlayerCompensation.GetEntireCompensationInfo(checkState, limitLVType, limitLV)  | 
|     PlayerJob = int(gmCmdDict.get('PlayerJob', '127'))  | 
|       | 
|     gold = int(gmCmdDict.get('Gold', '0'))  | 
|     goldPaper = int(gmCmdDict.get('GoldPaper', '0'))  | 
|     silver = int(gmCmdDict.get('Silver', '0'))   | 
|     sender = gmCmdDict.get('Sender', ChConfig.Def_Mail_SenderSys)  | 
|     detail = gmCmdDict.get('Detail', "")  | 
|     serverID = int(gmCmdDict.get('OnlyServerID', "0"))  | 
|       | 
|     ''' ÐèÒªÑéÖ¤guidÊÇ·ñÒÑ´æÔÚ£¬Èç¹û´æÔÚ  | 
|         µ± serverID Îª0ʱ£¬²»ÔÊÐí²åÈë  | 
|         µ± serverID ²»Îª0ʱ£¬ÐèÖØÐÂÉú³ÉGUID£¬ÒòΪ²¹³¥ÎïÆ·ÊǸù¾ÝGUID²éÕҵģ¬Èç¹û serverID ²»Ò»Ñùµ«ÊÇGUIDÒ»Ñù£¬¾Í»áµ¼ÖÂÁìÈ¡¶à±¶²¹³¥ÎïÆ·   | 
|     '''  | 
|     compensationMgr = GameWorld.GetCompensationMgr()  | 
|     entireCnt = compensationMgr.GetEntireCompensationCount()  | 
|     for i in xrange(entireCnt):  | 
|         compensation = compensationMgr.AtEntireCompensation(i)  | 
|         if not compensation:  | 
|             continue  | 
|           | 
|         if compensation.GUID != GUID:  | 
|             continue  | 
|           | 
|         if not serverID:  | 
|             GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_NoNeed, "GUID already existed!")  | 
|             return  | 
|           | 
|         # Èç¹ûÊǵ¥·þµÄ£¬GUIDÒѾ´æÔÚµÄÇé¿öÏ£¬ÖØÐ·ÖÅä¸öGUID£¬·ÀÖ¹ÖØ¸´²åÈëÏàͬGUIDµÄÓʼþ£¬µ¼ÖÂÁìÈ¡¶à±¶²¹³¥  | 
|         newGUID = str(uuid.uuid1())  | 
|         gmCmdDict['GUIDNEW'] = newGUID  | 
|         GameWorld.Log("·¢Ë͵¥·þ²¹³¥Óʼþ£¬ÔGUID(%s)ÒÑ´æÔÚ£¬Éú³ÉÐÂGUID(%s), serverID=%s" % (GUID, newGUID, serverID))  | 
|         GUID = newGUID  | 
|         break  | 
|       | 
|     #¹¤¾ß·¢¹ýÀ´µÄÎïÆ·Ï±êÒÀ¾Ý 'index,index,...'  ²»Ò»¶¨ÊÇ´Ó0¿ªÊ¼²¢°´Ë³ÐòÁ¬Ðø =_=#  | 
|     intemIndexStrList = []  | 
|     itemNums = gmCmdDict.get('itemNums', '')  | 
|     if itemNums.strip() != '':  | 
|         intemIndexStrList = itemNums.split(',')  | 
|     #Ìí¼ÓÎïÆ·  | 
|     addItemDictList = []  | 
|     for itemIndexStr in intemIndexStrList:  | 
|         addItemDict = GMT_AddPersonalCompensation.GetGMTCompensationItemDict(gmCmdDict, itemIndexStr)  | 
|         if not addItemDict:  | 
|             continue  | 
|         #Ìí¼Óµ½ÎïÆ·ÐÅÏ¢ÁÐ±í  | 
|         addItemDictList.append(addItemDict)  | 
|           | 
|     #if len(addItemDictList) == 0:  | 
|     #    GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)  | 
|     #    return  | 
|     PlayerCompensation.AddEntireItem(GUID, addItemDictList, LimitTime,  | 
|                                      mailInfo, PlayerJob, PlayerCompensation.GetMailText(Title, Text, MailType, sender),  | 
|                                      gold, goldPaper, silver, detail, serverID)  | 
|   | 
|     #Ö´Ðгɹ¦  | 
|     GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, {"GUID":GUID})    | 
|     # Á÷Ïò  | 
|     DataRecordPack.DR_ToolGMOperate(0, '', '', 'GMT_AddEntireCompensation', str(gmCmdDict))  | 
|     return  | 
|   | 
|   | 
|       |