hxp
2025-05-23 fdebf36f0d9201c6a6949a08cdfeebb718c25ce2
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerViewCache
#
# @todo:Íæ¼Ò»º´æ
# @author hxp
# @date 2025-5-22
# @version 1.0
#
# ÏêϸÃèÊö: Íæ¼Ò»º´æ
#
#-------------------------------------------------------------------------------
#"""Version = 2025-5-22 ÏÂÎç6:37:10"""
#-------------------------------------------------------------------------------
 
import ChConfig
import GameWorld
import PyMongoMain
import PlayerControl
import NetPackCommon
import ChPyNetSendPack
import IpyGameDataPY
import ShareDefine
import DBDataMgr
import GameObj
 
import random
import time
 
Key_UpdViewCacheTick = "UpdViewCacheTick"
 
def OnDay():
    DelOutofTimeViewCacheData()
    return
 
def OnPlayerLogout(curPlayer):
    if curPlayer.GetLV() < 10:
        return
    
    curCache = UpdPlayerViewCache(curPlayer)
    if curCache and not IsSaveDBViewCache(curCache):
        DBDataMgr.GetPlayerViewCacheMgr().DelPlayerViewCache(curPlayer.GetPlayerID())
        
    return
 
def DelOutofTimeViewCacheData():
    ## É¾³ý¹ýÆÚµÄ²é¿´»º´æÊý¾Ý
    
    playerManager = GameWorld.GetPlayerManager()
    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
    for index in range(viewCacheMgr.GetCount())[::-1]: # ÓÐɾ³ýÐèµ¹Ðò±éÀú
        viewCache = viewCacheMgr.At(index)
        playerID = viewCache.GetPlayerID()
        curPlayer = playerManager.FindPlayerByID(playerID)
        if curPlayer:
            continue
        if IsSaveDBViewCache(viewCache):
            continue
        viewCacheMgr.DelPlayerViewCache(playerID)
        
    return
 
def IsSaveDBViewCache(viewCache):
    ## »º´æÊý¾ÝÊÇ·ñÈë¿â
    if not viewCache:
        return False
    
    playerID = viewCache.GetPlayerID()
    
    #ij¸ö¹¦ÄÜÖв»ÄÜɾ³ýµÄ
    #...
    
    
    #ÅÅÐаæÉϵÄĬÈϱ£Áô
    billboardMgr = DBDataMgr.GetBillboardMgr()
    for bType in ShareDefine.BillboardTypeAllList:
        if bType in ShareDefine.FamilyBillboardList:
            continue
        groupList = billboardMgr.GetBillboardGroupList(bType)
        for billboardType, groupValue1, groupValue2 in groupList:
            billboardObj = billboardMgr.GetBillboard(billboardType, groupValue1, groupValue2)
            if billboardObj.FindByID(playerID):
                return True
            
    # ÒÔÉÏÊÇÏà¹Ø¹¦ÄÜÐèÒªÓõ½µÄÊý¾Ý£¬±Ø¶¨²»ÄÜɾ³ýµÄ
    
    # ÒÔÏÂÊDZ£Áô½üÆÚ»îÔ¾Íæ¼Ò£¬µÈ¼¶ÏÞÖÆ
    playerLV = viewCache.GetLV()
    if playerLV >= IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1):
        maxDays = IpyGameDataPY.GetFuncCfg("PlayerViewCache", 2)
        if not maxDays:
            maxDays = 7 # Ä¬ÈÏ7Ìì
        MaxTime = maxDays * 3600 * 24
        curTime = int(time.time())
        passTime = curTime - viewCache.GetOffTime()
        if passTime < MaxTime:
            return True
        
    return False
 
def FindViewCache(playerID, isAdd=False):
    '''²éÕÒÍæ¼Ò»º´æ£¬Èç¹û²»´æÔÚ£¬Ôò»áÓжîÍâÂß¼­£¬Èç´Óredis¡¢dbÖ±½ÓÕÒ£¬
            ±¾·þÍæ¼ÒÀíÂÛÉÏÒ»¶¨Óв鿴»º´æ£¬ÒòΪÈç¹û²»´æÔÚ»áÖ±½Ó´Ódb¶Á£¬³ý·Ç¸ÃÍæ¼ÒÊý¾Ý±»É¾³ý
            ¿ç·þÍæ¼ÒÀíÂÛÉÏÒ²Ò»¶¨Óлº´æ£¬Ö»ÊÇͨ¹ý¿ç·þ»ò´Ó×Ó·þ²éѯ£¬ÑÓ³Ù»ñµÃ
            ¡¾×¢¡¿Íâ²ãµ÷ÓÃÒÀȻҪÅжÏÊÇ·ñÓÐÊý¾Ý
    '''
    
    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
    curCache = viewCacheMgr.GetPlayerViewCache(playerID)
    if curCache:
        updCache = __CheckUpdViewCache(playerID)
        if updCache:
            curCache = updCache
            
    # ÕæÊµÍæ¼Ò
    elif playerID > ShareDefine.FackPlayerIDMax:
        curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
        # ±¾·þÔÚÏßÍæ¼Ò£¬Ö±½ÓÉú³ÉÐÂÊý¾Ý
        if curPlayer:
            curCache = viewCacheMgr.AddPlayerViewCache(playerID)
            UpdPlayerViewCache(curPlayer)
            
        # ±¾·þÀëÏßÍæ¼Ò
        elif GameWorld.GetDBPlayerAccIDByID(playerID):
            # ±¾·þÍæ¼Ò£¬´Óredis»òdb¶ÁÈ¡ÖØÐ¼ÓÔØ¶ÁÈ¡£¬»»¾ä»°Ëµ£¬±¾·þÍæ¼ÒÖ»Òª»ñȡһ¶¨Óв鿴»º´æÊý¾Ý
            curCache = UpdPlayerViewCacheByDB(playerID)
            
        # ¿ç·þÍæ¼Ò
        else:
            pass
            # ¿ç·þÍæ¼Ò£¬È¥×Ó·þÀ­È¡Êý¾Ý£¬ÀíÂÛÉÏÒ²Ò»¶¨ÓУ¬µ«ÊÇÈç¹ûÐèÒªÀ­Êý¾Ý£¬ÓÐÒ»¶¨ÑÓ³Ù
            # Âß¼­´ýÀ©Õ¹
            
    # ¼ÙÍæ¼Ò£¬Ä¬ÈÏÌí¼Ó
    elif ShareDefine.FackPlayerIDStart <= playerID <= ShareDefine.FackPlayerIDMax:
        serverID = playerID % 100 + 1 # 1 ~ 100 ·þ
        accID = "fake%s@test@s%s" % (playerID, serverID)
        fightPower = random.randint(1000000, 100000000) # ÏÈËæ»ú£¬Íâ²ãÓÐÐèÒªµÄ»°ÔÙ×Ô¼ºÉèÖÃ
        
        curCache = viewCacheMgr.AddPlayerViewCache(playerID)
        curCache.SetPlayerName("%s%s" % (GameWorld.GbkToCode("ÉñÃØµÀÓÑ"), playerID))
        curCache.SetAccID(accID)
        curCache.SetLV(random.randint(100, 200))
        curCache.SetJob(random.randint(1, 2))
        curCache.SetRealmLV(random.randint(5, 15))
        curCache.SetFightPowerTotal(fightPower)
        curCache.SetServerID(serverID)
        curCache.SetOffTime(int(time.time()) - random.randint(1, 3600 * 24 * 10)) # Ëæ»úÀëÏß 0~10Ìì
        
    return curCache
 
def __CheckUpdViewCache(playerID):
    if playerID <= ShareDefine.FackPlayerIDMax:
        return
    curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
    if not curPlayer:
        return
    lastUpdTick = curPlayer.GetDictByKey(Key_UpdViewCacheTick)
    tick = GameWorld.GetGameWorld().GetTick()
    if lastUpdTick and tick - lastUpdTick < 60000:
        GameWorld.DebugLog("1·ÖÖÓÄÚÖ»¸üÐÂÒ»´ÎÍæ¼Ò»º´æ", playerID)
        return
    curPlayer.SetDict(Key_UpdViewCacheTick, tick)
    return UpdPlayerViewCache(curPlayer)
 
def UpdPlayerViewCache(curPlayer, isOffline=False):
    '''¸üÐÂÍæ¼Ò²é¿´»º´æÊý¾Ý£¬¸üÐÂʱ»úÓÉÍâ²ã×Ô¼ºÅжϣ¬ÕâÀïÖ»×ö¸üÐÂÂß¼­
    1. ÏÂÏßÊ±Ç¿ÖÆ¸üÐÂÒ»´Î£¬ÉÏÏßÔݲ»¸üУ¬ÉÏÏßʱÓɸ÷¹¦ÄÜÈç¹ûÓÐÐèÒªÓõ½´¥·¢¸üÐÂ
    2. ÓÐÐèÒªÓõ½»º´æÊý¾Ýʱ£¬Èç¹ûÍæ¼ÒÔÚÏߣ¬1·ÖÖÓÄÚ¶à´Î»ñȡʱ×î¶à¸üÐÂÒ»´Î£¬Ã»ÓлñÈ¡»º´æÊý¾ÝÔò²»¸üÐÂ
    '''
    if not curPlayer:
        return
    
    playerID = curPlayer.GetPlayerID()
    curCache = DBDataMgr.GetPlayerViewCacheMgr().GetPlayerViewCache(playerID)
    if not curCache:
        return
    
    tick = GameWorld.GetGameWorld().GetTick()
    curPlayer.SetDict(Key_UpdViewCacheTick, tick)
    GameWorld.DebugLog("¸üÐÂÍæ¼Ò²é¿´»º´æÊý¾Ý! isOffline=%s" % isOffline, playerID)
    curCache.SetAccID(curPlayer.GetAccID())
    curCache.SetPlayerName(curPlayer.GetPlayerName())
    curCache.SetLV(curPlayer.GetLV())
    curCache.SetJob(curPlayer.GetJob())
    curCache.SetRealmLV(curPlayer.GetOfficialRank())
    curCache.SetFace(curPlayer.GetFace())
    curCache.SetFacePic(curPlayer.GetFacePic())
    curCache.SetFamilyID(curPlayer.GetFamilyID())
    curCache.SetFamilyName(curPlayer.GetFamilyName())
    curCache.SetFamilyEmblemID(PlayerControl.GetFamilyEmblemID(curPlayer))
    curCache.SetTitleID(PlayerControl.GetTitleID(curPlayer))
    curCache.SetFightPowerTotal(PlayerControl.GetFightPower(curPlayer))
    curCache.SetServerID(GameWorld.GetPlayerServerID(curPlayer))
    if isOffline:
        curCache.SetOffTime(int(time.time()))
        
    plusDict = curCache.GetPlusDict()
        
    #Õ½¶·ÊôÐÔ
    plusDict.update({
                     "MinAtk":curPlayer.GetMinAtk(),
                     "MaxAtk":curPlayer.GetMaxAtk(),
                     "Def":curPlayer.GetDef(),
                     "MaxHP":GameObj.GetMaxHP(curPlayer),
                     "Hit":curPlayer.GetHit(),
                     "Miss":curPlayer.GetMiss(),
                     "SuperHitRate":curPlayer.GetSuperHitRate(), # ±©»÷ÂÊ
                     })
    
    # ¹¦ÄÜÊý¾Ý
    
    # ÆäËû
    
    return curCache
 
def UpdPlayerViewCacheByDB(playerID):
    '''¸üÐÂÍæ¼Ò²é¿´»º´æÊý¾Ý£¬Ö±½Ó´ÓdbÊý¾Ý¸üУ¬½ö¸üÐÂdbPlayer±íÓеÄÊôÐÔ£¬
    '''
    GameWorld.DebugLog("UpdPlayerViewCacheByDB", playerID)
    curCache = None
    dbPlayer = PyMongoMain.GetUserCtrlDB().findDBPlayer(playerID)
    if not dbPlayer:
        GameWorld.DebugLog("1111111111111111", playerID)
        return curCache
    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
    curCache = viewCacheMgr.GetPlayerViewCache(playerID)
    if not curCache:
        curCache = viewCacheMgr.AddPlayerViewCache(playerID)
    familyID = dbPlayer.FamilyID
    GameWorld.DebugLog("db²éÕÒÖ±½Ó¸üÐÂÍæ¼Ò²é¿´»º´æÊý¾Ý!", playerID)
    curCache.SetAccID(dbPlayer.AccID)
    curCache.SetPlayerName(dbPlayer.PlayerName)
    curCache.SetLV(dbPlayer.LV)
    curCache.SetJob(dbPlayer.Job)
    curCache.SetRealmLV(dbPlayer.OfficialRank)
    curCache.SetFace(dbPlayer.Face)
    curCache.SetFacePic(dbPlayer.FacePic)
    curCache.SetFamilyID(familyID)
    family = DBDataMgr.GetFamilyMgr().FindFamily(familyID)
    curCache.SetFamilyName(family.GetName() if family else "")
    curCache.SetFamilyEmblemID(family.GetEmblemID() if family else 0)
    #curCache.SetTitleID(PlayerControl.GetTitleID(curPlayer))
    curCache.SetFightPowerTotal(dbPlayer.FightPowerEx * ChConfig.Def_PerPointValue + dbPlayer.FightPower)
    curCache.SetServerID(GameWorld.GetAccIDServerID(dbPlayer.AccID))
    curCache.SetOffTime(GameWorld.ChangeTimeStrToNum(dbPlayer.LogoffTime) if dbPlayer.LogoffTime else 0)
    return curCache
 
#//A2 12 ²é¿´Íæ¼ÒÏêϸÐÅÏ¢#tagCMViewPlayerInfo
#struct tagCMViewPlayerInfo
#{
#    tagHead        Head;
#    DWORD        PlayerID;
#    BYTE        EquipClassLV;    //´óÓÚ0Ϊ²é¿´Ö¸¶¨¾³½ç½××°±¸ÐÅÏ¢,  0Ϊ²é¿´Ä¬ÈÏÐÅÏ¢
#};
def OnCMViewPlayerInfo(index, clientPack, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    findPlayerID = clientPack.PlayerID
    #equipClassLV = clientPack.EquipClassLV
    
    clientPack = GetPack_ViewCache(findPlayerID)
    if clientPack:
        NetPackCommon.SendFakePack(curPlayer, clientPack)
        return
    if GameWorld.GetDBPlayerAccIDByID(findPlayerID):
        PlayerControl.NotifyCode(curPlayer, "ViewPlayer_OffLine")
        return
    
    # ¿ç·þÍæ¼Ò·¢ËÍ¿ç·þ²éѯ£¬´ýÀ©Õ¹...
    
    return
 
def GetPack_ViewCache(playerID):
    ## »ñȡͬ²½·â°ü - Íæ¼Ò²é¿´»º´æ
    curCache = FindViewCache(playerID)
    if not curCache:
        return
    clientPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult()
    clientPack.PlayerID = curCache.GetPlayerID()
    clientPack.PlayerName = curCache.GetPlayerName()
    clientPack.LV = curCache.GetLV()
    clientPack.Job = curCache.GetJob()
    clientPack.RealmLV = curCache.GetRealmLV()
    clientPack.Face = curCache.GetFace()
    clientPack.FacePic = curCache.GetFacePic()
    clientPack.TitleID = curCache.GetTitleID()
    clientPack.ServerID = curCache.GetServerID()
    clientPack.FightPower = curCache.GetFightPower()
    clientPack.FightPowerEx = curCache.GetFightPowerEx()
    clientPack.FamilyID = curCache.GetFamilyID()
    clientPack.FamilyName = curCache.GetFamilyName()
    clientPack.FamilyEmblemID = curCache.GetFamilyEmblemID()
    clientPack.PlusData = curCache.GetPlusData()
    clientPack.PlusDataSize = len(clientPack.PlusData)
    return clientPack