| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GM.Commands.Mail  | 
| #  | 
| # @todo:Óʼþ  | 
| # @author hxp  | 
| # @date 2025-05-14  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: Óʼþ  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2025-05-14 12:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import PlayerMail  | 
| import ShareDefine  | 
| import DataRecordPack  | 
| import DBDataMgr  | 
| import random  | 
|   | 
| ## Ö´ÐÐÂß¼  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param gmList []  | 
| #  @return None  | 
| def OnExec(curPlayer, gmList):  | 
|       | 
|     if not gmList:  | 
|         GameWorld.DebugAnswer(curPlayer, "Çå¿ÕÓʼþ: Mail 0")  | 
|         GameWorld.DebugAnswer(curPlayer, "·¢ËÍÓʼþ: Mail ¼¸·â ÎïÆ·Êý [Ä£°åkey ²ÎÊý1 ...]")  | 
|         GameWorld.DebugAnswer(curPlayer, "Êä³öÓʼþ: Mail p")  | 
|         return  | 
|       | 
|     value = gmList[0]  | 
|       | 
|     if value == 0:  | 
|         ClearMail(curPlayer)  | 
|         return  | 
|       | 
|     if value == "p":  | 
|         PrintPlayerMail(curPlayer)  | 
|         return  | 
|       | 
|     if value > 0:  | 
|         SendPlayerMail(curPlayer, gmList)  | 
|         return  | 
|       | 
|     return  | 
|   | 
| def SendPlayerMail(curPlayer, gmList):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     sendCnt = gmList[0]  | 
|     mailItemCnt = gmList[1] if len(gmList) > 1 else 5  | 
|     mailTypeKey = gmList[2] if len(gmList) > 2 else ""  | 
|     paramList = gmList[3:]  | 
|       | 
|     itemIDList = range(3501, 3530 + 1)  | 
|     moneyIDList = [20, 30]  | 
|       | 
|     mailMgr = DBDataMgr.GetMailMgr()  | 
|     mailCntBef = mailMgr.GetPersonalMailCount(playerID)  | 
|       | 
|     isBind = 0  | 
|     for _ in range(sendCnt):  | 
|           | 
|         itemList = []  | 
|         if mailItemCnt:  | 
|             for moneyID in moneyIDList:  | 
|                 itemCount = random.choice([100, 1000, 10000, 20000, 50000, 100000, 200000, 300000, 500000])  | 
|                 itemList.append([moneyID, itemCount, isBind])  | 
|                 if len(itemList) >= mailItemCnt:  | 
|                     break  | 
|                   | 
|             random.shuffle(itemIDList)  | 
|             for i in range(mailItemCnt):  | 
|                 itemID = itemIDList[i]  | 
|                 itemCount = random.randint(1, 100000)  | 
|                 itemList.append([itemID, itemCount, isBind])  | 
|                 if len(itemList) >= mailItemCnt:  | 
|                     break  | 
|                   | 
|         PlayerMail.SendMailByKey(mailTypeKey, playerID, itemList, paramList)  | 
|           | 
|     mailCntAft = mailMgr.GetPersonalMailCount(playerID)  | 
|     GameWorld.DebugAnswer(curPlayer, "·¢Ë͸öÈËÓʼþOK:%s, %s~%s" % (sendCnt, mailCntBef, mailCntAft))  | 
|     return  | 
|   | 
| def ClearMail(curPlayer):  | 
|     notifyGUIDState = {}  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     mailMgr = DBDataMgr.GetMailMgr()      | 
|     guidList = mailMgr.GetPersonalMailGuids(playerID)  | 
|     for guid in guidList:  | 
|         mailMgr.DelPersonalMail(playerID, guid)  | 
|         DataRecordPack.DR_MailDel(playerID, guid, "GMDel")  | 
|         notifyGUIDState[guid] = ShareDefine.MailState_Del  | 
|     GameWorld.DebugAnswer(curPlayer, "ɾ³ý¸öÈËÓʼþ:%s" % len(guidList))  | 
|       | 
|     guidList = mailMgr.GetServerMailGuids()  | 
|     for guid in guidList:  | 
|         playerStateDict = mailMgr.DelServerMail(guid)  | 
|         if playerID in playerStateDict and playerStateDict[playerID] < ShareDefine.MailState_Del:  | 
|             notifyGUIDState[guid] = ShareDefine.MailState_Del  | 
|     if len(guidList):  | 
|         GameWorld.DebugAnswer(curPlayer, "ɾ³ýÈ«·þÓʼþ:%s" % len(guidList))  | 
|     PlayerMail.Sync_PlayerMailState(curPlayer, notifyGUIDState)  | 
|     return  | 
|   | 
| def PrintPlayerMail(curPlayer):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     mailMgr = DBDataMgr.GetMailMgr()      | 
|     guidList = mailMgr.GetPersonalMailGuids(playerID)  | 
|     GameWorld.DebugAnswer(curPlayer, "¸öÈËÓʼþÊý:%s" % len(guidList))  | 
|     for num, guid in enumerate(guidList, 1):  | 
|         mailObj = mailMgr.GetPersonalMail(playerID, guid)  | 
|         __printMailLog(curPlayer, mailMgr, mailObj, num, False)  | 
|               | 
|     guidList = mailMgr.GetServerMailGuids()  | 
|     GameWorld.DebugAnswer(curPlayer, "È«·þÓʼþÊý:%s" % len(guidList))  | 
|     for num, guid in enumerate(guidList, 1):  | 
|         mailObj = mailMgr.GetServerMail(guid)  | 
|         __printMailLog(curPlayer, mailMgr, mailObj, num, True)  | 
|           | 
|     GameWorld.DebugAnswer(curPlayer, "ÓʼþÃ÷ϸÏê¼ûµØÍ¼ÈÕÖ¾")  | 
|     return  | 
|   | 
| def __printMailLog(curPlayer, mailMgr, mailObj, num, isServerMail):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     GUID = mailObj.GetGUID()  | 
|     Title = mailObj.GetTitle()  | 
|     Text = mailObj.GetText()  | 
|     CreateTime = mailObj.GetCreateTime()  | 
|     LimitDays = mailObj.GetLimitDays()  | 
|     mailState = mailMgr.GetPlayerMailState(GUID, playerID)  | 
|     mailItemCount = mailMgr.GetMailItemCount(GUID)  | 
|     GameWorld.DebugLog("%s,%s,mailState=%s,mailItemCount=%s" % (num, GUID, mailState, mailItemCount), playerID)  | 
|     GameWorld.DebugLog("    CreateTime=%s,LimitDays=%s,Title=%s,Text=%s" % (CreateTime, LimitDays, Title, Text), playerID)  | 
|     if isServerMail:  | 
|         LimitLV = mailObj.GetLimitLV()  | 
|         LimitLVType = mailObj.GetLimitLVType()  | 
|         CheckState = mailObj.GetCheckState()  | 
|         GameWorld.DebugLog("    LimitLV=%s,Éý¼¶¿ÉÁì=%s,ÐèÒªÉóºË=%s" % (LimitLV, LimitLVType, CheckState), playerID)  | 
|           | 
|     itemList = []  | 
|     for index in range(mailItemCount):  | 
|         mailItem = mailMgr.GetMailItemAt(GUID, index)  | 
|         itemID = mailItem.GetItemID()  | 
|         itemCount = mailItem.GetCount()  | 
|         isBind = mailItem.GetIsBind()  | 
|         userData = mailItem.GetUserData()  | 
|         itemList.append([itemID, itemCount, isBind, userData])  | 
|     if itemList:  | 
|         GameWorld.DebugLog("    %s,itemList=%s" % (mailItemCount, itemList), playerID)  | 
|     return  | 
|   |