hxp
5 天以前 26958aff1b844a743a805b4f9075bee800b72a46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/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 IpyGameDataPY
import DBDataMgr
import ItemCommon
import CommFunc
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")
        GameWorld.DebugAnswer(curPlayer, "·¢ËÍÈ«·þ: Mail s ÎïÆ·Êý [ÌìÊý]")
        GameWorld.DebugAnswer(curPlayer, "·¢ËÍÓʼþ: Mail pw ÌìÊý ÎïÆ·ID ¸öÊý [ID ¸öÊý ...]")
        GameWorld.DebugAnswer(curPlayer, "¸öÊý:Èç¹ûÊÇ×°±¸Ôò¸öÊýĬÈÏ1¸ö£¬¸öÊý²ÎÊý¸ÄΪ¶¨ÖÆÊôÐÔID")
        return
    
    value = gmList[0]
    
    if value == 0:
        ClearMail(curPlayer)
        return
    
    if value == "p":
        PrintPlayerMail(curPlayer)
        return
    
    if value == "s":
        SendServerMail(curPlayer, gmList)
        return
    
    if value == "pw":
        SendPlayerMailItem(curPlayer, gmList)
        return
    
    if value > 0:
        SendPlayerMail(curPlayer, gmList)
        return
    
    return
 
def SendPlayerMailItem(curPlayer, gmList):
    playerID = curPlayer.GetPlayerID()
    limitDays = gmList[1] if len(gmList) > 1 else 1
    itemList = gmList[2:]
    
    mailItemList = []
    while len(itemList) >= 2:
        itemID = itemList.pop(0)
        itemCount = itemList.pop(0)
        
        itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
        if not itemData:
            GameWorld.DebugAnswer(curPlayer, "ÎïÆ·ID²»´æÔÚ! %s" % itemID)
            continue
        
        if ItemCommon.GetIsEquip(itemData):
            appointID = itemCount
            ipyData = IpyGameDataPY.GetIpyGameData("AppointItem", appointID)
            if not ipyData:
                GameWorld.DebugAnswer(curPlayer, "¶¨ÖÆÊôÐÔID²»´æÔÚ! %s" % appointID)
                continue
            userData = CommFunc.JsonDump({ShareDefine.Def_CItemKey_AppointID:appointID})
            itemInfo = [itemID, 1, 0, userData] # ×°±¸Ä¬ÈÏ1¸ö
        else:
            itemInfo = [itemID, itemCount]
                
        mailItemList.append(itemInfo)
        
    PlayerMail.SendMailByKey("", playerID, mailItemList, limitDays=limitDays)
    GameWorld.DebugAnswer(curPlayer, "·¢Ë͸öÈËÓʼþÎïÆ·OK")
    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:]
    
    mailMgr = DBDataMgr.GetMailMgr()
    mailCntBef = mailMgr.GetPersonalMailCount(playerID)
    for _ in range(sendCnt):
        itemList = __randMailItem(mailItemCnt)
        PlayerMail.SendMailByKey(mailTypeKey, playerID, itemList, paramList, limitDays=random.randint(1, 7))
        
    mailCntAft = mailMgr.GetPersonalMailCount(playerID)
    GameWorld.DebugAnswer(curPlayer, "·¢Ë͸öÈËÓʼþOK:%s, %s~%s" % (sendCnt, mailCntBef, mailCntAft))
    return
 
def SendServerMail(curPlayer, gmList):
    mailItemCnt = gmList[1] if len(gmList) > 1 else 5
    limitDays = gmList[2] if len(gmList) > 2 else 7
    
    randValue = random.randint(1, 1000)
    title = GameWorld.GbkToCode("È«·þÓʼþ±êÌâ%s" % randValue)
    text = GameWorld.GbkToCode(
                               '''È«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝ
    È«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝÈ«·þÓʼþÄÚÈÝ%s
    ''' % randValue
    )
    itemList = __randMailItem(mailItemCnt)
    
    PlayerMail.SendSeverMail("", title, text, itemList, limitDays)
    GameWorld.DebugAnswer(curPlayer, "·¢ËÍÈ«·þÓʼþOK!")
    return
 
def __randMailItem(mailItemCnt):
    moneyIDList = [1, 2, 3]
    equipIDList = range(100501, 100512)
    heroIDList = range(510001, 510016)
    itemIDList = [4, 5, 7, 8, 9, 10, 11, 12, 13, 1000, 1001, 1002] #range(3501, 3530 + 1)
    
    isBind = 0
    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(equipIDList)
        for i in range(3):
            itemID = equipIDList[i%len(equipIDList)]
            itemCount = 1
            itemList.append([itemID, itemCount, isBind])
            if len(itemList) >= mailItemCnt:
                break
            
        random.shuffle(heroIDList)
        for i in range(3):
            itemID = heroIDList[i%len(heroIDList)]
            itemCount = 1
            itemList.append([itemID, itemCount, isBind])
            if len(itemList) >= mailItemCnt:
                break
            
        random.shuffle(itemIDList)
        for i in range(mailItemCnt):
            itemID = itemIDList[i%len(itemIDList)]
            itemCount = random.randint(1, 100000)
            itemList.append([itemID, itemCount, isBind])
            if len(itemList) >= mailItemCnt:
                break
            
    return itemList
 
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))
    PlayerMail.Sync_PlayerMailState(curPlayer, notifyGUIDState)
    
    guidList = mailMgr.GetServerMailGuids()
    for guid in guidList:
        PlayerMail.DelServerMail(guid, "GMDel")
    if len(guidList):
        GameWorld.DebugAnswer(curPlayer, "ɾ³ýÈ«·þÓʼþ:%s" % len(guidList))
    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