From 6a93c58b83b1072f3247e56b636442ee4f06580c Mon Sep 17 00:00:00 2001 From: xdh <xiefantasy@qq.com> Date: 星期三, 13 三月 2019 11:09:09 +0800 Subject: [PATCH] 6349 【后端】【2.0】boss掉血根据人数加快 --- ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py | 175 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 136 insertions(+), 39 deletions(-) diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py index cde4e6f..5438e00 100644 --- a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py +++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py @@ -22,12 +22,12 @@ import ChConfig import PlayerControl import PlayerViewCache +import PlayerCompensation import ChPyNetSendPack import PlayerDBGSEvent import NetPackCommon import IpyGameDataPY import PyGameData - # 获取玩家跨服服务器上的名字 #=============================================================================== # def GetCrossPlayerName(curPlayer): @@ -45,7 +45,7 @@ # 获取玩家跨服服务器上的名字 def GetCrossPlayerName(curPlayer): # 通过游戏账号中的平台标志获取名称,目前为spid - playerName = curPlayer.GetPlayerName() + playerName = curPlayer.GetName() opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s_%s" % (GameWorld.GetPlayerPlatform(curPlayer), GameWorld.GetPlayerServerSID(curPlayer))) @@ -55,20 +55,19 @@ return opName.decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName -def GetServerCrossZoneIpyData(mapID, serverGroupID=0): - ## 获取本服对应跨服玩法分区地图信息 - if mapID not in ChConfig.Def_CrossZoneTableName: +def GetCrossCommZoneIpyDataByZoneID(zoneID): + ## 获取跨服常规分区 + crossZoneName = GameWorld.GetCrossZoneName() + ipyData = IpyGameDataPY.GetIpyGameDataNotLog("CrossZoneComm", crossZoneName, zoneID) + return ipyData + +def GetCrossCommZoneIpyDataByServerGroupID(serverGroupID): + ## 获取跨服常规分区 + crossZoneName = GameWorld.GetCrossZoneName() + ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True) + if not ipyDataList: return - if not serverGroupID: - serverGroupID = GameWorld.GetServerGroupID() - - tableName = ChConfig.Def_CrossZoneTableName[mapID] - ipyDataMgr = IpyGameDataPY.IPY_Data() - if not hasattr(ipyDataMgr, "Get%sCount" % tableName): - return - - for i in xrange(getattr(ipyDataMgr, "Get%sCount" % tableName)()): - ipyData = getattr(ipyDataMgr, "Get%sByIndex" % tableName)(i) + for ipyData in ipyDataList: serverGroupIDList = ipyData.GetServerGroupIDList() for serverGroupIDInfo in serverGroupIDList: if (isinstance(serverGroupIDInfo, tuple) and serverGroupIDInfo[0] <= serverGroupID <= serverGroupIDInfo[1]) \ @@ -76,15 +75,47 @@ return ipyData return +def GetCrossCommZoneIpyDataListByServerGroupID(serverGroupID): + ## 获取跨服常规分区列表 + if serverGroupID: + ipyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID) + if not ipyData: + return + ipyDataList = [ipyData] + else: + crossZoneName = GameWorld.GetCrossZoneName() + ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True) + return ipyDataList + +def GetServerCrossZoneMapIpyData(mapID, serverGroupID=0): + ## 获取本服对应跨服玩法分区地图信息 + if mapID not in ChConfig.Def_CrossZoneMapTableName: + return + tableName = ChConfig.Def_CrossZoneMapTableName[mapID] + if not serverGroupID: + if GameWorld.IsCrossServer(): + return + serverGroupID = GameWorld.GetServerGroupID() + zoneIpyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID) + if not zoneIpyData: + return + commZoneID = zoneIpyData.GetZoneID() + return IpyGameDataPY.GetIpyGameDataByCondition(tableName, {"ZoneID":commZoneID}) + def IsCrossServerOpen(): ## 跨服服务器是否开放中 return GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen) -def ClientServerMsg_ServerInitOK(serverGroupID): - ## 子服连接成功 +def Sync_CrossCommInitDataToClientServer(serverGroupID=0): + ''' 同步跨服常规通用数据到子服务器 + @param serverGroupID: 为0时同步所有子服 + ''' + isOpen = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen) - GameWorld.Log("子服连接成功,通知当前跨服服务器状态: isOpen=%s" % isOpen) - CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen}, [serverGroupID]) + crossZoneName = GameWorld.GetCrossZoneName() + GameWorld.Log("通知当前跨服服务器状态: isOpen=%s,crossZoneName=%s,syncServerGroupID=%s" % (isOpen, crossZoneName, serverGroupID)) + serverGroupIDList = [serverGroupID] if serverGroupID else [] + CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen, "crossZoneName":crossZoneName}, serverGroupIDList) return def DoChangeCrossServerState(isOpen): @@ -100,7 +131,7 @@ curPlayer = playerManager.GetActivePlayerAt(i) if curPlayer == None: continue - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) curPlayer.Kick(0) # 广播所有子服,本服务器进入维护 @@ -109,6 +140,10 @@ def CrossServerMsg_CrossServerState(msgData): ## 子服收到跨服服务器状态变更,子服不存DB,默认跨服维护中,连接跨服成功后由跨服同步状态直接更新到字典即可,没连上就默认维护中 + if "crossZoneName" in msgData: + PyGameData.g_crossZoneName = msgData["crossZoneName"] + GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossZoneName, PyGameData.g_crossZoneName) + isOpen = msgData["isOpen"] isOpen = 1 if isOpen else 0 GameWorld.Log("收到跨服服务器状态变更: 是否正常开放中=%s" % isOpen) @@ -120,8 +155,9 @@ curPlayer = playerManager.GetActivePlayerAt(i) if curPlayer == None: continue - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) + GameWorld.GetGameWorld().SendCrossServerStateToLoginServer(isOpen) # 通知地图 GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen) return @@ -138,7 +174,7 @@ CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ExitCrossServer, playerID, [serverGroupID]) # 设置非跨服状态,踢下线 - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) curPlayer.Kick(0) GameWorld.Log("PlayerExitCrossServer...serverGroupID=%s" % serverGroupID, playerID) return @@ -151,18 +187,18 @@ if not curPlayer: GameWorld.Log(" 退出跨服时本服玩家不在线!", playerID) return - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) return -def SendCrossRealmReg(curPlayer, registerType, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0): +def SendCrossRealmReg(curPlayer, registerMap, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0): # 发送跨服账号注册上传数据 # 设置上传数据的活动类型 - curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterType, registerType) - sysMsg = str([registerType, mapID, dataMapID, copyMapID, posX, posY]) + curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterMap, registerMap) + sysMsg = str([registerMap, mapID, dataMapID, copyMapID, posX, posY]) curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossRealmReg", sysMsg, len(sysMsg)) - GameWorld.Log("SendCrossRealmReg registerType=%s,mapID=%s,dataMapID=%s,copyMapID=%s,posX=%s,posY=%s" - % (registerType, mapID, dataMapID, copyMapID, posX, posY), curPlayer.GetPlayerID()) + GameWorld.Log("SendCrossRealmReg registerMap=%s,mapID=%s,dataMapID=%s,copyMapID=%s,posX=%s,posY=%s" + % (registerMap, mapID, dataMapID, copyMapID, posX, posY), curPlayer.GetPlayerID()) return def OnCrossRealmRegOK(playerID, msgList, tick): @@ -175,16 +211,16 @@ if not IsCrossServerOpen(): return - registerType = msgList[0] - playerRegisterType = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_CrossRegisterType) - if playerRegisterType and registerType != playerRegisterType: + registerMap = msgList[0] + playerRegisterMap = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_CrossRegisterMap) + if playerRegisterMap and registerMap != playerRegisterMap: return - curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterType, 0) + curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterMap, 0) - GameWorld.Log("跨服报名成功 , registerType=%s" % (registerType), playerID) + GameWorld.Log("跨服报名成功 , registerMap=%s" % (registerMap), playerID) # 跨服PK上传数据完毕,通知跨服服务器,准备完毕 - if registerType == ChConfig.Def_FBMapID_CrossRealmPK: + if registerMap == ChConfig.Def_FBMapID_CrossRealmPK: regVSRoomID = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_MergeRegisterRoomID) vsRoomID = curPlayer.GetVsRoomId() @@ -203,13 +239,13 @@ # 其他的,在上传数据完毕后,使用通用的通知可进入跨服 else: - NotifyCanEnterMergeServer(curPlayer, registerType) + NotifyCanEnterMergeServer(curPlayer, registerMap) # hxp 2015.09.10 跨服boss,后面的暂时不需要 return -def NotifyCanEnterMergeServer(curPlayer, registerType): +def NotifyCanEnterMergeServer(curPlayer, registerMap): # 通用包,通知客户端可进入跨服服务器 return @@ -225,7 +261,7 @@ ''' curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) GameWorld.ErrLog("某些异常情况下,前端强制发包退出跨服状态! ", curPlayer.GetPlayerID()) - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) return #// C0 02 查看跨服玩家信息 #tagCGViewCrossPlayerInfo @@ -315,10 +351,71 @@ sendPack.ItemDataSize = len(sendPack.ItemData) sendPack.PlusData = PlusData sendPack.PlusDataSize = len(sendPack.PlusData) - sendPack.CrossPlayer = 1 NetPackCommon.SendFakePack(curPlayer, sendPack) return - +def CrossServerMsg_PutInItem(itemInfo): + ## 跨服获得物品 + GameWorld.DebugLog("收到跨服服务器获得物品!") + playerID = itemInfo["PlayerID"] + itemData = itemInfo["ItemData"] + event = itemInfo["Event"] + curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID) + if curPlayer: + # 在线的话推到MapServer处理 + itemMsg = str(itemInfo) + curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossPutInItem", itemMsg, len(itemMsg)) + return + # 离线的话直接发邮件 + GameWorld.Log("收到跨服获得物品,玩家不在线,直接发邮件! itemInfo=%s" % str(itemInfo), playerID) + itemID, itemCount, isBind, itemUserData = itemData + addItemList = [{"ItemID":itemID, "Count":itemCount, "IsBind":isBind, "UserData":itemUserData}] + PlayerCompensation.SendMailByKey("", [playerID], addItemList, detail={"CrossPutInItem":1, "Event":event}) + return + +def CrossServerMsg_GiveMoney(msgInfo): + ## 跨服获得货币 + + playerID = msgInfo["PlayerID"] + curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID) + if not curPlayer: + GameWorld.ErrLog("跨服获得货币时玩家不在线! msgInfo=%s" % str(msgInfo), playerID) + return + msgInfo = str(msgInfo) + curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossGiveMoney", msgInfo, len(msgInfo)) + return + +def SetCrossPlayerAttrValue(msgInfo, tick): + ## 设置跨服玩家属性值 + playerID, setType, setDict, isDelay = msgInfo + if not PyGameData.g_crossSetPlayerAttr: + GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick, tick) + playerSetInfoList = PyGameData.g_crossSetPlayerAttr.get(playerID, []) + playerSetInfoList.append([setType, setDict]) + PyGameData.g_crossSetPlayerAttr[playerID] = playerSetInfoList + if not isDelay: + __SendCrossServerSetPlayerAttr(0) + return + +def OnCrossProcess(tick): + __SendCrossServerSetPlayerAttr(tick) + return + +def __SendCrossServerSetPlayerAttr(tick): + if not PyGameData.g_crossSetPlayerAttr: + return + + if tick: + # 延迟10秒一次性同步,主要是比如OnDay的时候当多个玩家同时跨服时,减少同步次数,延迟统一发送 + if tick - GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick) < 10 * 1000: + return + GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick, tick) + + CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_SetPlayerAttrValue, PyGameData.g_crossSetPlayerAttr) + PyGameData.g_crossSetPlayerAttr = {} + return + + + \ No newline at end of file -- Gitblit v1.8.0