hxp
4 天以前 4e3d1ff7e0b98fc18b0b6e63e449f3d7577c0ba6
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerChatBox
#
# @todo:ÁÄÌìÆøÅݱíÇé
# @author hxp
# @date 2024-09-13
# @version 1.0
#
# ÏêϸÃèÊö: ÁÄÌìÆøÅݱíÇé
#
#-------------------------------------------------------------------------------
#"""Version = 2024-09-13 16:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import PlayerHJG
import PlayerControl
import IPY_GameWorld
import ChPyNetSendPack
import IpyGameDataPY
import NetPackCommon
import ItemCommon
import ChConfig
import ObjPool
 
import time
 
def OnPlayerLogin(curPlayer):
    SyncChatBoxInfo(curPlayer)
    #SyncEmojiPackInfo(curPlayer)
    return
 
def OnMinute(curPlayer):
    curTime = int(time.time())
    delBoxList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetChatBoxCount()):
        ipyData = ipyDataMgr.GetChatBoxByIndex(index)
        boxID = ipyData.GetBoxID()
        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID):
            # Î´¼¤»îµÄ²»´¦Àí
            continue
        endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID)
        if not endTime or endTime > curTime:
            # ÓÀ¾Ã»òδ¹ýÆÚ
            continue
        if DelChatBox(curPlayer, boxID, False, "ChatBoxTimeout"):
            delBoxList.append(boxID)
            
    if delBoxList:
        RefreshBoxAttr(curPlayer)
        
#    # ±íÇé°ü
#    for index in range(ipyDataMgr.GetEmojiPackCount()):
#        ipyData = ipyDataMgr.GetEmojiPackByIndex(index)
#        packID = ipyData.GetEmojiPackID()
#        if ipyData.GetUnlockDefault():
#            # Ä¬Èϼ¤»îµÄ²»´¦Àí
#            continue
#        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID):
#            # Î´¼¤»îµÄ²»´¦Àí
#            continue
#        endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID)
#        if not endTime or endTime > curTime:
#            # ÓÀ¾Ã»òδ¹ýÆÚ
#            continue
#        DelEmojiPack(curPlayer, packID, "EmojiPackTimeout")
        
    return
 
def AddChatBox(curPlayer, boxID, setExpireTimes=None, isFree=False):
    if boxID <= 0:
        return
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    if ipyData.GetUnlockWay() != 2:
        GameWorld.DebugLog("·ÇµÀ¾ß¼¤»îµÄ²»ÓÃÌí¼Ó: boxID=%s" % (boxID), playerID)
        return
    if not isFree:
        itemID = ipyData.GetUnlockValue()
        itemCount = ipyData.GetUnlockNeedCnt()
        if not itemID or not itemCount:
            return
        needItemList = [[itemID, itemCount]]
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
        if lackItemDict:
            GameWorld.DebugLog("¼¤»îËùÐèÎïÆ·²»×ã! boxID=%s,lackItemDict=%s" % (boxID, lackItemDict), playerID)
            return
        ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "AddChatBox")
        
    ipyExpireSeconds = ipyData.GetExpireMinutes() * 60
    
    curTime = int(time.time())
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
    endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID)
    GameWorld.Log("Ìí¼ÓÆøÅÝ¿ò: boxID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s" 
                  % (boxID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID)
    updEndTime = endTime
    
    # Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨
    if setExpireTimes >= 0:
        updEndTime = curTime + setExpireTimes
        GameWorld.Log("    Ö¸¶¨Ê±³¤: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        
    # ÓÀ¾Ã
    elif ipyExpireSeconds == 0:
        updEndTime = 0
        GameWorld.Log("    ÓÀ¾Ãʱ³¤: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        
    else:
        # Î´¹ýÆÚ
        if endTime > curTime:
            updEndTime = endTime + ipyExpireSeconds
            GameWorld.Log("    ÀÛ¼Óʱ³¤: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        else:
            updEndTime = curTime + ipyExpireSeconds
            GameWorld.Log("    ÖØÐ¼¤»î: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
            
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID, 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, updEndTime)
    RefreshBoxAttr(curPlayer)
    SyncChatBoxInfo(curPlayer, [boxID])
    return True
 
def DelChatBox(curPlayer, boxID, isRefreshAttr=True, notifyMail=""):
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID):
        return
    GameWorld.Log("ɾ³ýÆøÅÝ¿ò: boxID=%s,notifyMail=%s" % (boxID, notifyMail), playerID)
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, 0)
    # ÐǼ¶²»ÖØÖã¬ÖØÐ¼¤»îºóÔÙ´ÎÉúЧ
    
    if PlayerControl.GetChatBox(curPlayer) == boxID:
        canUseID = GetCanUseBoxID(curPlayer)
        PlayerControl.SetChatBox(curPlayer, canUseID)
        GameWorld.DebugLog("Íæ¼ÒÁÄÌìÆøÅÝ¿ò±»É¾³ý£¬ÖØÐÂÉèÖÿÉÓÃID=%s" % canUseID, playerID)
        
    if isRefreshAttr:
        RefreshBoxAttr(curPlayer)
    SyncChatBoxInfo(curPlayer, [boxID])
    if notifyMail:
        PlayerControl.SendMailByKey(notifyMail, [playerID], [], [boxID])
    return True
 
def GetCanUseBoxID(curPlayer):
    ## »ñȡһ¸ö¿ÉÓÃµÄÆøÅÝ¿ò
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetChatBoxCount())[::-1]:
        ipyData = ipyDataMgr.GetChatBoxByIndex(index)
        boxID = ipyData.GetBoxID()
        if IsBoxCanUse(curPlayer, boxID, ipyData):
            return boxID
    return 0
 
def IsBoxCanUse(curPlayer, boxID, ipyData=None):
    ## ÆøÅÝ¿òÊÇ·ñ¿ÉÓÃ
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
    if state:
        return True
    
    if not ipyData:
        ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if ipyData:
        unlockWay = ipyData.GetUnlockWay()
        if unlockWay == 1: # Ä¬Èϼ¤»îµÄ
            return True
        
    return False
 
def RefreshBoxAttr(curPlayer):
    PlayerHJG.RefreshHJGAttr(curPlayer)
    return
 
def OnUseChatBox(curPlayer, useBoxID):
    playerID = curPlayer.GetPlayerID()
    if not IsBoxCanUse(curPlayer, useBoxID):
        GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓã¬ÎÞ·¨ÉèÖÃ! useBoxID=%s" % useBoxID, playerID)    
        return
    GameWorld.DebugLog("ÉèÖÃʹÓõÄÁÄÌìÆøÅÝ¿òID: useBoxID=%s" % useBoxID, playerID)    
    PlayerControl.SetChatBox(curPlayer, useBoxID)
    return
 
def OnChatBoxStarUP(curPlayer, boxID):
    playerID = curPlayer.GetPlayerID()
    if not IsBoxCanUse(curPlayer, boxID):
        GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓÃ! boxID=%s" % (boxID), playerID)
        return
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    starMax = ipyData.GetStarMax()
    curStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID)
    if curStar >= starMax:
        GameWorld.DebugLog("ÐǼ¶ÒÑÂú! boxID=%s,curStar=%s >= %s" % (boxID, curStar, starMax), playerID)
        return
    if ipyData.GetUnlockWay() != 2:
        return
    itemID = ipyData.GetUnlockValue()
    itemCount = ipyData.GetUnlockNeedCnt()
    if not itemID or not itemCount:
        return
    needItemList = [[itemID, itemCount]]
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
    if lackItemDict:
        GameWorld.DebugLog("ÉýÐÇËùÐèÎïÆ·²»×ã! boxID=%s,lackItemDict=%s" % (boxID, lackItemDict), playerID)
        return
    ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "ChatBoxStarUP")
    
    nextStar = curStar + 1
    GameWorld.DebugLog("ÉýÐÇ! boxID=%s,nextStar=%s" % (boxID, nextStar), playerID)
    SetChatBoxStar(curPlayer, boxID, nextStar)
    return
 
def SetChatBoxStar(curPlayer, boxID, setStar):
    if not IsBoxCanUse(curPlayer, boxID):
        return
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    setStar = min(setStar, ipyData.GetStarMax())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxStar % boxID, setStar)
    RefreshBoxAttr(curPlayer)
    SyncChatBoxInfo(curPlayer, [boxID])
    return True
 
def SyncChatBoxInfo(curPlayer, boxIDList=None):
    if boxIDList == None:
        syncIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetChatBoxCount()):
            ipyData = ipyDataMgr.GetChatBoxByIndex(index)
            syncIDList.append(ipyData.GetBoxID())
    else:
        syncIDList = boxIDList
        
    boxList = []
    for boxID in syncIDList:
        state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
        if not state and boxIDList == None:
            continue
        box = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBox)
        box.BoxID = boxID
        box.State = state
        box.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID)
        box.Star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID)
        boxList.append(box)
        
    if not boxList:
        return
    
    clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBoxInfo)
    clientPack.BoxList = boxList
    clientPack.Count = len(clientPack.BoxList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
##-------------------------------------------------------------------------------------------------
 
def AddEmojiPack(curPlayer, packID, setExpireTimes=None):
    if packID <= 0:
        return
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("EmojiPack", packID)
    if not ipyData:
        return
    if ipyData.GetUnlockDefault():
        GameWorld.DebugLog("±íÇé°üĬÈϽâËøµÄ²»ÓÃÌí¼Ó: packID=%s" % (packID), playerID)
        return
    ipyExpireSeconds = ipyData.GetExpireMinutes() * 60
    
    curTime = int(time.time())
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID)
    endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID)
    GameWorld.Log("Ìí¼Ó±íÇé°ü: packID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s" 
                  % (packID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID)
    updEndTime = endTime
    
    # Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨
    if setExpireTimes >= 0:
        updEndTime = curTime + setExpireTimes
        GameWorld.Log("    Ö¸¶¨±íÇé°üʱ³¤: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID)
        
    # ÓÀ¾Ã
    elif ipyExpireSeconds == 0:
        updEndTime = 0
        GameWorld.Log("    Ìí¼ÓÓÀ¾Ã±íÇé°ü: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID)
        
    else:
        # Î´¹ýÆÚ
        if endTime > curTime:
            updEndTime = endTime + ipyExpireSeconds
            GameWorld.Log("    ÀÛ¼Ó±íÇé°üʱ³¤: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID)
        else:
            updEndTime = curTime + ipyExpireSeconds
            GameWorld.Log("    ÖØÐ¼¤»î±íÇé°ü: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID)
            
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID, 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EmojiPackEndTime % packID, updEndTime)
    
    SyncEmojiPackInfo(curPlayer, [packID])
    return True
 
def DelEmojiPack(curPlayer, packID, notifyMail=""):
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("EmojiPack", packID)
    if not ipyData:
        return
    if ipyData.GetUnlockDefault():
        return
    GameWorld.Log("ɾ³ýÍæ¼ÒÁÄÌì±íÇé°ü: packID=%s,notifyMail=%s" % (packID, notifyMail), playerID)
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EmojiPackEndTime % packID, 0)
    
    SyncEmojiPackInfo(curPlayer, [packID])
    if notifyMail:
        PlayerControl.SendMailByKey(notifyMail, [playerID], [], [packID])
    return True
 
def SyncEmojiPackInfo(curPlayer, packIDList=None):
    if packIDList == None:
        syncIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetEmojiPackCount()):
            ipyData = ipyDataMgr.GetEmojiPackByIndex(index)
            syncIDList.append(ipyData.GetEmojiPackID())
    else:
        syncIDList = packIDList
        
    packList = []
    for packID in syncIDList:
        state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID)
        if not state and packIDList == None:
            continue
        pack = ChPyNetSendPack.tagMCEmojiPack()
        pack.PackID = packID
        pack.State = state
        pack.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID)
        packList.append(pack)
        
    if not packList:
        return
    
    clientPack = ChPyNetSendPack.tagMCEmojiPackInfo()
    clientPack.EmojiPackList = packList
    clientPack.Count = len(clientPack.EmojiPackList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return