#!/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
|