hxp
2024-09-18 458f8ad37f944f5a4334dc9e522e6640e4aa2def
ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorship.py
@@ -20,12 +20,12 @@
import NetPackCommon
import PlayerControl
import ChPyNetSendPack
import CrossChampionship
import PlayerViewCache
import PlayerRecData
import CrossRealmMsg
import IpyGameDataPY
import GameWorld
import ChConfig
import random
import time
@@ -38,33 +38,73 @@
def SetWorshipValue(recData, worshipValue): recData.SetValue2(worshipValue)
def GetWorshipDays(recData): return recData.GetValue3() # 持续天数: 0永久,>0-天数
def SetWorshipDays(recData, days): recData.SetValue3(days)
def GetWorshipZoneID(recData): return recData.GetValue4() # 膜拜分区,跨服膜拜类型有用
def SetWorshipZoneID(recData, zoneID): recData.SetValue4(zoneID)
def GetModelShowInfo(recData): return recData.GetEvalUserData({}) # 模型外观显示信息,备用,缓存没有时取这里
def SetModelShowInfo(recData, modelShow): return recData.SetEvalUserData(modelShow)
def GetPlayerModelShow(playerID):
    ## 获取膜拜对象的外观显示信息 - 本服跨服通用
    cacheDict = PlayerViewCache.GetCachePropDataDict(PlayerViewCache.FindViewCache(playerID))
    if not cacheDict:
        return {}
    modelShow = {
                 "Name":cacheDict.get("Name", ""),
                 "AccID":cacheDict.get("AccID", ""),
                 "LV":cacheDict.get("LV", 0),
                 "RealmLV":cacheDict.get("RealmLV", 0),
                 "Job":cacheDict.get("Job", 0),
                 "VIPLV":cacheDict.get("VIPLV", 0),
                 "TitleID":cacheDict.get("TitleID", 0),
                 "FightPower":cacheDict.get("FightPower", 0),
                 "EquipShowSwitch":cacheDict.get("EquipShowSwitch", 0),
                 "EquipShowID":cacheDict.get("EquipShowID", []),
                 }
    return modelShow
# 玩家每日膜拜记录  RecType = ShareDefine.Def_PlayerRecType_WorshipDaily
def GetTodayWorshipRecord(recData): return recData.GetEvalUserData({}) # 今日已膜拜记录 {tagPlayerID:[[膜拜类型, 膜拜值], ...], ...}
# 今日已膜拜记录 {tagPlayerID:[[膜拜类型, 膜拜值], ...], ...}
# 今日是否已膜拜过该玩家某个膜拜
def HasWorshipRecordToday(recData, tagPlayerID, worshipType, worshipValue):
    worshipRecordList = recData.GetUserDataByKey(tagPlayerID, [])
    if not worshipRecordList:
        return False
    return [worshipType, worshipValue] in worshipRecordList
# 设置今日已膜拜过该玩家某个膜拜
def SetWorshipRecordToday(recData, tagPlayerID, worshipType, worshipValue):
    worshipRecordList = recData.GetUserDataByKey(tagPlayerID, [])
    recordInfo = [worshipType, worshipValue]
    if recordInfo not in worshipRecordList:
        worshipRecordList.append(recordInfo)
    recData.SetUserDataByKey(tagPlayerID, worshipRecordList)
    return
##--------------------------------------------------------------------------------------------------
def OnServerStart():
    ## 修改了膜拜UserData的存储内容及格式,需要对老数据进行处理
    #  因为活动类的活动结束后无法根据分区ID识别是否可膜拜,故改为同仙宫一样指定可膜拜的服务器ID列表
    isCrossServer = GameWorld.IsCrossServer()
    crossZoneName = GameWorld.GetCrossZoneName()
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    recDict = playerRecMgr.GetPlayerRecDataDict(ShareDefine.Def_PlayerRecType_WorshipPlayer)
    for recDataList in recDict.values():
        for recData in recDataList:
            playerID = recData.GetPlayerID()
            worshipType = GetWorshipType(recData)
            worshipValue = GetWorshipValue(recData)
            if isCrossServer:
                if worshipType != ShareDefine.Def_WorshipType_CrossChampionship:
                    # 跨服服务器只修正跨服排位膜拜
                    continue
            else:
                if worshipType != ShareDefine.Def_WorshipType_ServerNaming:
                    # 子服服务器只修正服务器冠名膜拜
                    continue
            userData = recData.GetUserData()
            try:
                userDataOld = eval(userData)
            except:
                userDataOld = {}
            if ChConfig.Def_RecDataKey_PlayerInfo in userDataOld:
                GameWorld.Log("该膜拜数据已经被修正过了! worshipType=%s,worshipValue=%s" % (worshipType, worshipValue), playerID)
                continue
            recData.SetUserData({})
            recData.SetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, userDataOld)
            if worshipType == ShareDefine.Def_WorshipType_CrossChampionship:
                zoneID = recData.GetValue4()
                zoneIpyData = IpyGameDataPY.GetIpyGameData("CrossZonePK", crossZoneName, zoneID)
                serverIDRangeList = zoneIpyData.GetServerGroupIDList() if zoneIpyData else []
                recData.SetUserDataByKey(ChConfig.Def_RecDataKey_ServerIDList, serverIDRangeList)
            userDataNew = recData.GetUserData()
            GameWorld.Log("修正膜拜数据! worshipType=%s,worshipValue=%s,userData=%s,userDataNew=%s"
                          % (worshipType, worshipValue, userData, userDataNew), playerID)
    return
def GetPlayerViewInfo(playerID):
    ## 获取膜拜对象的外观显示信息 - 本服跨服通用
    return PlayerViewCache.GetShotCacheDict(playerID, "AccID", "VIPLV", "FightPower", "Model")
def OnPlayerLogin(curPlayer):
    
@@ -136,9 +176,9 @@
def __UpdWorshipByDay(isCrossServer, worshipList, recData):
    ## 过天更新未过期膜拜信息
    playerID = recData.GetPlayerID()
    modelShow = GetPlayerModelShow(playerID)
    if modelShow:
        SetModelShowInfo(recData, modelShow)
    playerInfo = GetPlayerViewInfo(playerID)
    if playerInfo:
        recData.SetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, playerInfo)
        
    if isCrossServer:
        worshipList.append(recData.GetString())
@@ -153,14 +193,8 @@
        return True
    return False
def GetWorshipIpyData(worshipType, worshipValue):
    ## 获取膜拜配置数据
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog("Worship", worshipType, worshipValue)
    return ipyData
def AddWorshipPlayer(playerID, worshipType, worshipValue, days=None, zoneID=0, isNotify=True):
def AddWorshipPlayer(worshipType, worshipValue, playerID, serverIDList, syncList=None, days=None):
    ## 添加膜拜玩家,本服跨服通用
    # @param isNotify: 本服-是否通知玩家;跨服-是否通知子服
    
    if worshipType in ShareDefine.Def_WorshipTypeCross:
        if not GameWorld.IsCrossServer():
@@ -171,7 +205,7 @@
            GameWorld.ErrLog("跨服服务器不允许添加非跨服膜拜! worshipType=%s" % (worshipType))
            return
        
    ipyData = IpyGameDataPY.GetIpyGameData("Worship", worshipType, worshipValue)
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog("Worship", worshipType, worshipValue)
    if not ipyData:
        return
    
@@ -181,23 +215,41 @@
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    recData = playerRecMgr.GetPlayerRecData(ShareDefine.Def_PlayerRecType_WorshipPlayer, playerID, [worshipType, worshipValue])
    if not recData:
        GameWorld.Log("添加膜拜数据: playerID=%s,worshipType=%s,worshipValue=%s,days=%s,zoneID=%s" % (playerID, worshipType, worshipValue, days, zoneID))
        GameWorld.Log("添加膜拜数据: playerID=%s,worshipType=%s,worshipValue=%s,days=%s,%s" % (playerID, worshipType, worshipValue, days, serverIDList))
        recData = playerRecMgr.AddPlayerRecData(ShareDefine.Def_PlayerRecType_WorshipPlayer, playerID)
    else:
        GameWorld.Log("更新膜拜数据: playerID=%s,worshipType=%s,worshipValue=%s,days=%s,zoneID=%s" % (playerID, worshipType, worshipValue, days, zoneID))
        GameWorld.Log("更新膜拜数据: playerID=%s,worshipType=%s,worshipValue=%s,days=%s,%s" % (playerID, worshipType, worshipValue, days, serverIDList))
        recData.SetTime(int(time.time()))
    SetWorshipType(recData, worshipType)
    SetWorshipValue(recData, worshipValue)
    SetWorshipDays(recData, days)
    SetModelShowInfo(recData, GetPlayerModelShow(playerID))
    SetWorshipZoneID(recData, zoneID)
    
    if isNotify:
        if GameWorld.IsCrossServer():
            SyncAddCrossWorship([recData])
        else:
            Sync_UnWorshipInfo(None, [recData])
    playerInfo = GetPlayerViewInfo(playerID)
    serverID = GameWorld.GetAccIDServerID(playerInfo.get("AccID", ""))
    saveServerIDList = [] + serverIDList # 重新创建一份存储,不改变传入值
    # 确保玩家自身一定能看到自己,跨服排位赛历史分区问题
    if saveServerIDList and serverID and not GameWorld.CheckServerIDInList(serverID, saveServerIDList):
        saveServerIDList.append(serverID)
    recData.SetUserDataByKey(ChConfig.Def_RecDataKey_ServerIDList, saveServerIDList) # 保存当下的区服ID范围
    recData.SetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, playerInfo) # 保存当下的玩家基本信息
    if isinstance(syncList, list):
        syncList.append(recData)
    else:
        SendNewWorshipPlayer([recData])
    return recData
def SendNewWorshipPlayer(syncList):
    ## 同步新膜拜数据
    if not syncList:
        return
    if GameWorld.IsCrossServer():
        SyncAddCrossWorship(syncList)
    else:
        Sync_UnWorshipInfo(None, syncList)
    return
def DelWorshipPlayer(worshipType, worshipValue=None, delPlayerID=None):
    ## 删除膜拜玩家,本服跨服通用
@@ -259,7 +311,9 @@
    
    GameWorld.DebugLog("膜拜: tagPlayerID=%s,worshipType=%s,worshipValue=%s,moneyType=%s,moneyValue=%s" 
                       % (tagPlayerID, worshipType, worshipValue, moneyType, moneyValue), playerID)
    __AddWorshipRecord(playerID, recData)
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    worshipRecData = playerRecMgr.GetPlayerRecDataFirst(ShareDefine.Def_PlayerRecType_WorshipDaily, playerID)
    SetWorshipRecordToday(worshipRecData, tagPlayerID, worshipType, worshipValue)
    
    __SyncWorshipResult(curPlayer, tagPlayerID, worshipType, worshipValue, 0, moneyType, moneyValue)
    # 同步地图发放货币
@@ -270,63 +324,37 @@
    ## 检查玩家是否可膜拜该对象
    playerID = curPlayer.GetPlayerID()
    recPlayerID = recData.GetPlayerID()
    #if playerID == recPlayerID:
    #    GameWorld.DebugLog("不能膜拜自己!", playerID)
    #    return
    modelShow = GetModelShowInfo(recData)
    if not modelShow:
    playerInfo = recData.GetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, {})
    if not playerInfo:
        GameWorld.DebugLog("没有外观展示的不同步! recPlayerID=%s" % recPlayerID, playerID)
        return
    accID = modelShow.get("AccID", "")
    accID = playerInfo.get("AccID", "")
    if not accID:
        return
    serverID = GameWorld.GetAccIDServerID(accID)
    playerServerID = GameWorld.GetPlayerServerID(curPlayer)
    worshipType = GetWorshipType(recData)
    worshipValue = GetWorshipValue(recData)
    zoneID = GetWorshipZoneID(recData)
    if worshipType == ShareDefine.Def_WorshipType_ServerNaming:
        #只同步给同ServerID的
        serverID = GameWorld.GetAccIDServerID(accID)
        playerServerID = GameWorld.GetPlayerServerID(curPlayer)
        if serverID != playerServerID:
            GameWorld.DebugLog("只同步给同ServerID的! recPlayerID=%s,accID=%s,serverID=%s != playerServerID=%s" 
                               % (recPlayerID, accID, serverID, playerServerID), playerID)
            return
    elif worshipType == ShareDefine.Def_WorshipType_CrossChampionship:
        #只同步给同分区的
        playerZoneID = CrossChampionship.GetChampionshipMgr().GetPlayerOfficialZoneID(playerID)
        if playerZoneID != zoneID:
            GameWorld.DebugLog("只同步给同分区的! recPlayerID=%s,zoneID=%s != playerZoneID=%s" % (recPlayerID, zoneID, playerZoneID), playerID)
    else:
        serverIDList = recData.GetUserDataByKey(ChConfig.Def_RecDataKey_ServerIDList)
        if not GameWorld.CheckServerIDInList(playerServerID, serverIDList):
            GameWorld.DebugLog("该玩家不能膜拜目标玩家! playerServerID=%s not in %s" % (playerServerID, serverIDList), playerID)
            return
        
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    worshipRecData = playerRecMgr.GetPlayerRecDataFirst(ShareDefine.Def_PlayerRecType_WorshipDaily, playerID)
    worshipRecordDict = GetTodayWorshipRecord(worshipRecData)
    if recPlayerID in worshipRecordDict and [worshipType, worshipValue] in worshipRecordDict[recPlayerID]:
        GameWorld.DebugLog("已膜拜过! recPlayerID=%s,worshipType=%s, worshipValue=%s,worshipRecordDict=%s"
                           % (recPlayerID, worshipType, worshipValue, worshipRecordDict), playerID)
    if HasWorshipRecordToday(worshipRecData, recPlayerID, worshipType, worshipValue):
        GameWorld.DebugLog("今日已膜拜过! recPlayerID=%s,worshipType=%s, worshipValue=%s" % (recPlayerID, worshipType, worshipValue), playerID)
        return
    
    return True
def __AddWorshipRecord(playerID, recData):
    ## 添加玩家膜拜目标记录
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    worshipRecData = playerRecMgr.GetPlayerRecDataFirst(ShareDefine.Def_PlayerRecType_WorshipDaily, playerID)
    worshipRecordDict = GetTodayWorshipRecord(worshipRecData)
    tagPlayerID = recData.GetPlayerID()
    worshipType = GetWorshipType(recData)
    worshipValue = GetWorshipValue(recData)
    recordInfo = [worshipType, worshipValue]
    if tagPlayerID not in worshipRecordDict:
        worshipRecordDict[tagPlayerID] = []
    worshipRecordList = worshipRecordDict[tagPlayerID]
    if recordInfo not in worshipRecordList:
        worshipRecordList.append(recordInfo)
    #GameWorld.DebugLog("更新今日膜拜记录: %s" % GetTodayWorshipRecord(worshipRecData), playerID)
    return
def __SyncWorshipResult(curPlayer, tagPlayerID, worshipType, worshipValue, result, moneyType=0, moneyValue=0):
    ## 同步膜拜结果
@@ -372,13 +400,15 @@
        playerID = recData.GetPlayerID()
        
        # 如果存在本服的最新外观数据则已本服的为准
        modelShow = GetPlayerModelShow(playerID)
        if modelShow:
            SetModelShowInfo(recData, modelShow)
        playerInfo = GetPlayerViewInfo(playerID)
        if playerInfo:
            recData.SetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, playerInfo)
            
        sysnList.append(recData)
        GameWorld.Log("    更新跨服膜拜: worshipType=%s,zoneID=%s,playerID=%s,worshipValue=%s,days=%s"
                      % (GetWorshipType(recData), GetWorshipZoneID(recData), playerID, GetWorshipValue(recData), GetWorshipDays(recData)))
        serverIDList = recData.GetUserDataByKey(ChConfig.Def_RecDataKey_ServerIDList)
        GameWorld.Log("    更新跨服膜拜: worshipType=%s,worshipValue=%s,playerID=%s,days=%s,%s"
                      % (GetWorshipType(recData), GetWorshipValue(recData), playerID, GetWorshipDays(recData), serverIDList))
        
    #更新数据的可不同步,每个人的膜拜记录都不一样,由登录触发及添加新膜拜触发即可
    #Sync_UnWorshipInfo(None, sysnList)
@@ -409,8 +439,10 @@
            recData = playerRecMgr.AddPlayerRecDataByDict(attrDict)
            
        sysnList.append(recData)
        GameWorld.Log("    添加跨服膜拜: worshipType=%s,zoneID=%s,playerID=%s,worshipValue=%s,days=%s"
                      % (GetWorshipType(recData), GetWorshipZoneID(recData), playerID, GetWorshipValue(recData), GetWorshipDays(recData)))
        serverIDList = recData.GetUserDataByKey(ChConfig.Def_RecDataKey_ServerIDList)
        GameWorld.Log("    添加跨服膜拜: worshipType=%s,worshipValue=%s,playerID=%s,days=%s,%s"
                      % (GetWorshipType(recData), GetWorshipValue(recData), playerID, GetWorshipDays(recData), serverIDList))
        
    Sync_UnWorshipInfo(None, sysnList)
    return
@@ -432,13 +464,13 @@
    infoList = []
    for recData in unWorshipList:
        recPlayerID = recData.GetPlayerID()
        modelShow = GetPlayerModelShow(recPlayerID)
        if modelShow:
        playerInfo = GetPlayerViewInfo(recPlayerID)
        if playerInfo:
            # 更新本服最新的外观显示,跨服玩家由跨服每日同步更新 __UpdWorshipByDay
            SetModelShowInfo(recData, modelShow)
            recData.SetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo, playerInfo)
        else:
            modelShow = GetModelShowInfo(recData)
        if not modelShow:
            playerInfo = recData.GetUserDataByKey(ChConfig.Def_RecDataKey_PlayerInfo)
        if not playerInfo:
            # 没有外观展示的不同步
            continue
        
@@ -450,7 +482,7 @@
        infoPack.PlayerID = recPlayerID
        infoPack.WorshipType = GetWorshipType(recData)
        infoPack.WorshipValue = GetWorshipValue(recData)
        infoPack.PlayerInfo = json.dumps(modelShow, ensure_ascii=False).replace(" ", "")
        infoPack.PlayerInfo = json.dumps(playerInfo, ensure_ascii=False).replace(" ", "")
        infoPack.InfoLen = len(infoPack.PlayerInfo)
        
        if curPlayer: