| | |
| | | import GameWorld
|
| | | import PlayerControl
|
| | | import CrossRealmMsg
|
| | | import DataRecordPack
|
| | | import ChPyNetSendPack
|
| | | import CrossRealmPlayer
|
| | | import PyGameDataStruct
|
| | |
| | | self.pkScore = 0
|
| | | self.danLV = 0
|
| | | self.matchTick = 0
|
| | | self.prepareOKTick = 0
|
| | | self.cWinCount = 0 # 连胜次数
|
| | | self.ondayScore = 0 # 过天时的积分
|
| | | self.serverGroupID = 0 # 所属服务器ID,一个服务器ID由多个服组成
|
| | | self.pkZoneID = 0 # 所属赛区ID,一个赛区由多个服务器ID组成
|
| | | self.seasonID = 0 # 赛季ID
|
| | | return
|
| | | |
| | | def GetDRInfo(self):
|
| | | ## 流向记录信息
|
| | | return {"accID":self.accID, "playerID":self.playerID, "fightPower":self.fightPower, "pkScore":self.pkScore, |
| | | "danLV":self.danLV, "matchTick":self.matchTick, "prepareOKTick":self.prepareOKTick, "cWinCount":self.cWinCount, |
| | | "ondayScore":self.ondayScore, "serverGroupID":self.serverGroupID, "ondayScore":self.ondayScore}
|
| | |
|
| | | class CrossPKRoom():
|
| | | ## 跨服PK房间类
|
| | |
| | | self.roomState = ShareDefine.Def_VsRoom_State_WaitPlayer # 默认状态
|
| | | self.roomPlayerIDList = [] # 对战玩家ID列表
|
| | | self.readyPlayerIDList = [] # 已经准备好的玩家ID列表
|
| | | self.isMapOpen = False # 地图是否已经开启该房间,未开启的房间超时后,本次匹配视为无效,有玩家进地图才会开启副本分线
|
| | | self.mapFBOpenTick = 0 # 地图开启该房间tick,未开启的房间超时后,本次匹配视为无效,有玩家进地图才会开启副本分线
|
| | | return
|
| | |
|
| | | def GetDRInfo(self):
|
| | | return {"zoneID":self.pkZoneID, "seasonID":self.seasonID, "roomID":self.roomID, "mapID":self.mapID, "openTick":self.openTick, |
| | | "readyTick":self.readyTick, "roomPlayerIDList":self.roomPlayerIDList, "mapFBOpenTick":self.mapFBOpenTick}
|
| | | |
| | | #跨服PK排行榜管理,注意该类只处理数据逻辑,功能相关逻辑不要写在该类,不然重读脚本不会生效
|
| | | class CrossPKBillboardManager(object):
|
| | |
|
| | |
| | | vsRoomID = playerInfoDict["vsRoomID"] # 所属对战房间ID
|
| | | if vsRoomID in PyGameData.g_crossPKRoomDict:
|
| | | pkRoom = PyGameData.g_crossPKRoomDict[vsRoomID]
|
| | | if pkRoom.isMapOpen or pkRoom.readyTick:
|
| | | if pkRoom.mapFBOpenTick or pkRoom.readyTick:
|
| | | GameWorld.Log("跨服对战房间已经开启了线路,或者双方数据都已传输完毕,不可再取消匹配!vsRoomID=%s" % vsRoomID)
|
| | | return
|
| | |
|
| | |
| | |
|
| | | PyGameData.g_crossPKRoomDict.pop(roomID)
|
| | | GameWorld.Log(" 移除房间: popRoomID=%s" % (roomID))
|
| | | |
| | | # 记录流向
|
| | | dataDict = {"cancelPlayerID":playerID}
|
| | | dataDict.update(pkRoom.GetDRInfo())
|
| | | DR_CrossReamlPK("CancelRoom", dataDict)
|
| | | break
|
| | |
|
| | | return
|
| | |
| | | if playerID not in PyGameData.g_crossPKPlayerDict:
|
| | | GameWorld.ErrLog("玩家跨服对战数据准备OK, 但找不到该对战玩家信息!vsRoomID=%s,playerID=%s" % (vsRoomID, playerID))
|
| | | return
|
| | | #pkPlayer = PyGameData.g_crossPKPlayerDict[playerID]
|
| | | |
| | | pkPlayer = PyGameData.g_crossPKPlayerDict[playerID]
|
| | | pkPlayer.prepareOKTick = tick
|
| | | |
| | | if vsRoomID not in PyGameData.g_crossPKRoomDict:
|
| | | GameWorld.ErrLog("玩家跨服对战数据准备OK, 但找不到该对战房间(%s)!可能对手已取消!" % vsRoomID)
|
| | | return
|
| | |
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_PKReadyOKRoomList, sendReadyOKRoomList, serverGroupIDList)
|
| | |
|
| | | return
|
| | | #
|
| | | #def TestAddMatch(tick, addCount, maxDanLV=None, isClear=False):
|
| | | # if isClear:
|
| | | # PyGameData.g_crossPKPlayerDict = {}
|
| | | # PyGameData.g_crossPKZoneMatchPlayerDict = {}
|
| | | # PyGameData.g_crossPKRoomDict = {}
|
| | | # PyGameData.g_crossPKRoomID = 0
|
| | | # |
| | | # ipyDataMgr = IpyGameDataPY.IPY_Data()
|
| | | # if maxDanLV == None:
|
| | | # maxDanLV = ipyDataMgr.GetCrossRealmPKDanCount() - 1
|
| | | # for index in xrange(ipyDataMgr.GetCrossRealmPKZoneCount()):
|
| | | # zoneIpyData = ipyDataMgr.GetCrossRealmPKZoneByIndex(index)
|
| | | # pkZoneID = zoneIpyData.GetZoneID()
|
| | | # |
| | | # addPlayerList = []
|
| | | # zoneMatchPlayerList = PyGameData.g_crossPKZoneMatchPlayerDict.get(pkZoneID, [])
|
| | | # maxPlayerID = pkZoneID * 1000 if not zoneMatchPlayerList else max(zoneMatchPlayerList)
|
| | | # for i in xrange(1, addCount + 1):
|
| | | # playerID = maxPlayerID + i
|
| | | # |
| | | # pkPlayer = CrossPKPlayer()
|
| | | # pkPlayer.playerID = playerID
|
| | | # danLV = random.randint(0, maxDanLV)
|
| | | # pkPlayer.danLV = danLV
|
| | | # pkPlayer.matchTick = tick
|
| | | # pkPlayer.pkScore = danLV * 1000 + random.randint(0, 999)
|
| | | # pkPlayer.pkZoneID = pkZoneID
|
| | | # pkPlayer.seasonID = 1
|
| | | # |
| | | # PyGameData.g_crossPKPlayerDict[playerID] = pkPlayer
|
| | | # addPlayerList.append([playerID, danLV])
|
| | | # # 加入赛区匹配列表
|
| | | # zoneMatchPlayerList.append(playerID)
|
| | | # PyGameData.g_crossPKZoneMatchPlayerDict[pkZoneID] = zoneMatchPlayerList
|
| | | # GameWorld.Log("Add zoneID=%s,addPlayerList=%s" % (pkZoneID, addPlayerList))
|
| | | # |
| | | # #GameWorld.Log("PyGameData.g_crossPKPlayerDict=%s" % PyGameData.g_crossPKPlayerDict)
|
| | | # return
|
| | |
|
| | | def OnPKMatchProcess(tick):
|
| | | ## 玩家跨服PK匹配定时处理逻辑
|
| | |
| | | matchPlayerVSList = matchPlayerVSList[:maxGroupCnt]
|
| | | __DoSetVSRoom(pkZoneID, matchPlayerVSList, tick)
|
| | | GameWorld.Log("==========匹配结束(总匹配队伍:%s)==========" % len(matchPlayerVSList))
|
| | | #GameWorld.Log("crossPlayerIDList=%s" % PyGameData.g_crossPKPlayerDict.keys())
|
| | | #GameWorld.Log("matchPlayerIDList=%s" % PyGameData.g_crossPKZoneMatchPlayerDict[pkZoneID])
|
| | | return
|
| | |
|
| | |
|
| | |
| | | for i, matchPlayer in enumerate(matchTickSortList):
|
| | | # 只有一个玩家
|
| | | if len(scoreSortList) <= 1:
|
| | | GameWorld.Log(" 当前玩家数%s<=1,不再匹配!" % len(scoreSortList))
|
| | | #GameWorld.Log(" 当前玩家数%s<=1,不再匹配!" % len(scoreSortList))
|
| | | break
|
| | |
|
| | | if tick - matchPlayer.matchTick < outTimeTick:
|
| | | GameWorld.Log(" i=%s,玩家未超时,不再匹配!" % (i))
|
| | | #GameWorld.Log(" i=%s,玩家未超时,不再匹配!" % (i))
|
| | | break
|
| | |
|
| | | GameWorld.Log(" i=%s,超时玩家, %s-%s=%s >= outTimeTick(%s)"
|
| | |
| | |
|
| | | GameWorld.Log(" 积分分段个数: %s, %s" % (len(danList), danList))
|
| | |
|
| | | # 日志输出分组明细
|
| | | for danLV in danList:
|
| | | strList = []
|
| | | for player in danPlayerListDict[danLV]:
|
| | | strList.append((player.playerID, player.pkScore, player.fightPower))
|
| | | GameWorld.Log(" 积分段组, danLV=%s, %s" % (danLV, str(strList)))
|
| | | |
| | | # 优先匹配相同段位
|
| | | doCount = 0
|
| | | while len(matchPlayerVSList) < maxGroupCnt and doCount < maxGroupCnt:
|
| | | doCount += 1
|
| | | isMatchOK = False
|
| | | # # 日志输出分组明细
|
| | | # GameWorld.Log(" -------------")
|
| | | # for danLV in danList:
|
| | | # strList = []
|
| | | # for player in danPlayerListDict[danLV]:
|
| | | # strList.append((player.playerID, player.pkScore, player.fightPower))
|
| | | # GameWorld.Log(" 积分段组, danLV=%s, %s" % (danLV, str(strList)))
|
| | | # # -------------------------------
|
| | | |
| | | for danLV in danList:
|
| | | danPlayerList = danPlayerListDict[danLV]
|
| | | danPlayerCount = len(danPlayerList)
|
| | | if danPlayerCount < 2:
|
| | | GameWorld.Log(" 段位人数少于2个,此段位本轮轮空!doCount=%s,danLV=%s" % (doCount, danLV))
|
| | | #GameWorld.Log(" 段位人数少于2个,不处理!doCount=%s,danLV=%s" % (doCount, danLV))
|
| | | continue
|
| | |
|
| | | vsIndexList = random.sample(xrange(danPlayerCount), 2) # 随机取两个索引对战
|
| | |
| | |
|
| | | matchPlayerVSList.append([aPlayer, bPlayer])
|
| | | isMatchOK = True
|
| | | GameWorld.Log(" 成功匹配玩家: aPlayerID=%s,aScore=%s,aFP=%s VS bPlayerID=%s,bScore=%s,bFP=%s" |
| | | % (aPlayer.playerID, aPlayer.pkScore, aPlayer.fightPower, bPlayer.playerID, bPlayer.pkScore, bPlayer.fightPower))
|
| | | GameWorld.Log(" 成功匹配相同段位玩家: aPlayerID=%s,aDanLV=%s VS bPlayerID=%s,bDanLV=%s" % (aPlayer.playerID, aPlayer.danLV, bPlayer.playerID, bPlayer.danLV))
|
| | |
|
| | | if len(matchPlayerVSList) >= maxGroupCnt:
|
| | | GameWorld.Log(" 已经达到最大匹配数! 已匹配对战数=%s, 不再匹配!doCount=%s" % (len(matchPlayerVSList), doCount))
|
| | |
| | |
|
| | | if not isMatchOK:
|
| | | GameWorld.Log(" 已经没有满足匹配条件的玩家! 不再匹配!doCount=%s" % (doCount))
|
| | | break
|
| | | |
| | | # 不足再匹配范围段位
|
| | | doCount = 0
|
| | | while len(matchPlayerVSList) < maxGroupCnt and doCount < maxGroupCnt:
|
| | | doCount += 1
|
| | | isMatchOK = False
|
| | | # # 日志输出分组明细
|
| | | # GameWorld.Log(" -------------")
|
| | | # for danLV in danList:
|
| | | # strList = []
|
| | | # for player in danPlayerListDict[danLV]:
|
| | | # strList.append((player.playerID, player.pkScore, player.fightPower))
|
| | | # GameWorld.Log(" 积分段组, danLV=%s, %s" % (danLV, str(strList)))
|
| | | # # -------------------------------
|
| | | |
| | | for danLV in danList:
|
| | | danMatchRange = []
|
| | | danMatchPlayerList = []
|
| | | danIpyData = IpyGameDataPY.GetIpyGameData("CrossRealmPKDan", danLV)
|
| | | matchDanRange = [] if not danIpyData else danIpyData.GetMatchRange()
|
| | | if matchDanRange and len(matchDanRange) == 2:
|
| | | danMatchRange = range(matchDanRange[0], matchDanRange[1] + 1)
|
| | | |
| | | if danLV not in danMatchRange:
|
| | | danMatchRange.append(danLV)
|
| | | |
| | | for matchDanLV in danMatchRange:
|
| | | if matchDanLV not in danPlayerListDict:
|
| | | continue
|
| | | danMatchPlayerList += danPlayerListDict[matchDanLV]
|
| | | |
| | | #matchPlayerIDList = [matchPlayer.playerID for matchPlayer in danMatchPlayerList]
|
| | | #GameWorld.Log("danLV=%s,danMatchRange=%s,matchPlayerIDList=%s" % (danLV, danMatchRange, matchPlayerIDList))
|
| | | matchPlayerCount = len(danMatchPlayerList)
|
| | | if matchPlayerCount < 2:
|
| | | #GameWorld.Log(" 段位范围人数少于2个,不处理!doCount=%s,danLV=%s,danMatchRange=%s" % (doCount, danLV, danMatchRange))
|
| | | continue
|
| | | |
| | | vsIndexList = random.sample(xrange(matchPlayerCount), 2) # 随机取两个索引对战
|
| | | aPlayer, bPlayer = danMatchPlayerList[vsIndexList[0]], danMatchPlayerList[vsIndexList[1]]
|
| | | |
| | | aDanPlayerList = danPlayerListDict.get(aPlayer.danLV, [])
|
| | | bDanPlayerList = danPlayerListDict.get(bPlayer.danLV, [])
|
| | | if aPlayer in aDanPlayerList and bPlayer in bDanPlayerList:
|
| | | aDanPlayerList.remove(aPlayer)
|
| | | bDanPlayerList.remove(bPlayer)
|
| | | else:
|
| | | continue
|
| | | |
| | | matchPlayerVSList.append([aPlayer, bPlayer])
|
| | | isMatchOK = True
|
| | | GameWorld.Log(" 成功匹配范围段位玩家: aPlayerID=%s,aDanLV=%s VS bPlayerID=%s,bDanLV=%s | danLV=%s,danMatchRange=%s" |
| | | % (aPlayer.playerID, aPlayer.danLV, bPlayer.playerID, bPlayer.danLV, danLV, danMatchRange))
|
| | | |
| | | if len(matchPlayerVSList) >= maxGroupCnt:
|
| | | GameWorld.Log(" 已经达到最大匹配数! 已匹配对战数=%s, 不再匹配!doCount=%s" % (len(matchPlayerVSList), doCount))
|
| | | break
|
| | | |
| | | if not isMatchOK:
|
| | | GameWorld.Log(" 已经没有满足匹配条件的玩家! 不再匹配! doCount=%s" % (doCount))
|
| | | break
|
| | |
|
| | | return
|
| | |
| | | GameWorld.Log(" 开房:pkZoneID=%s,mapID=%s,roomID=%s,aPlayerID=%s,bPlayerID=%s" % (pkZoneID, mapID, roomID, aPlayerID, bPlayerID))
|
| | | vsRoomDict[roomID] = [mapID, [[aServerGroupID, aPlayerID], [bServerGroupID, bPlayerID]]]
|
| | |
|
| | | # 记录流向
|
| | | dataDict = {"aPlayer":aPlayer.GetDRInfo(), "bPlayer":bPlayer.GetDRInfo()}
|
| | | dataDict.update(newRoom.GetDRInfo())
|
| | | DR_CrossReamlPK("OpenRoom", dataDict)
|
| | | |
| | | serverGroupIDList.append(aServerGroupID)
|
| | | serverGroupIDList.append(bServerGroupID)
|
| | |
|
| | |
| | | serverGroupIDList = []
|
| | | roomTimeout = IpyGameDataPY.GetFuncCfg("CrossRealmPKCfg", 2) * 1000 # 这个时间尽量长点,目前暂时不确定玩家从准备到进入到地图的时长
|
| | | for roomID, pkRoom in PyGameData.g_crossPKRoomDict.items():
|
| | | if pkRoom.isMapOpen or not pkRoom.readyTick:
|
| | | if pkRoom.mapFBOpenTick or not pkRoom.readyTick:
|
| | | continue
|
| | | if tick - pkRoom.readyTick <= roomTimeout:
|
| | | continue
|
| | |
| | | timeoutRoomDict[roomID] = roomPlayerInfo
|
| | | PyGameData.g_crossPKRoomDict.pop(roomID)
|
| | |
|
| | | # 记录流向
|
| | | DR_CrossReamlPK("TimeoutRoom", pkRoom.GetDRInfo())
|
| | | |
| | | # 将超时房间广播到子服
|
| | | if timeoutRoomDict:
|
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_PKTimeoutRoomList, timeoutRoomDict, serverGroupIDList)
|
| | | return
|
| | |
|
| | | def MapServer_CrossPKRoomOpen(msgList):
|
| | | def MapServer_CrossPKRoomOpen(msgList, tick):
|
| | | roomID = msgList[0]
|
| | | if roomID not in PyGameData.g_crossPKRoomDict:
|
| | | GameWorld.ErrLog("MapServer_CrossPKRoomOpen => PK房间不存在!roomID=%s" % roomID)
|
| | | return
|
| | | pkRoom = PyGameData.g_crossPKRoomDict[roomID]
|
| | | pkRoom.isMapOpen = True
|
| | | pkRoom.mapFBOpenTick = tick
|
| | | GameWorld.Log("MapServer_CrossPKRoomOpen => roomID=%s" % roomID)
|
| | | return
|
| | |
|
| | | def MapServer_CrossPKOver(infoList):
|
| | | def MapServer_CrossPKOver(infoList, tick):
|
| | | ## 收到MapServer副本跨服PK结果同步
|
| | |
|
| | | GameWorld.Log("收到MapServer_跨服PK战斗结果: %s" % str(infoList))
|
| | |
| | | % (seasonID, timeStr, roomID, overType, winnerID, roundWinnerIDList))
|
| | | # 同步子服
|
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_PKOverInfo, playerOverDict, serverGroupIDList)
|
| | | |
| | | # 记录流向
|
| | | dataDict = {"roundWinnerIDList":roundWinnerIDList, "overType":overType, "winner":winner.GetDRInfo(), "loser":loser.GetDRInfo()}
|
| | | dataDict.update(vsRoom.GetDRInfo())
|
| | | DR_CrossReamlPK("PKOverRoom", dataDict)
|
| | | return
|
| | |
|
| | | ##================================== 以下是子服逻辑 ==========================================
|
| | |
| | | % (roomID, zoneID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, notifyState, curPlayer.GetMapID()), playerID)
|
| | | return
|
| | |
|
| | | def DR_CrossReamlPK(eventName, dataDict={}):
|
| | | drDataDict = {}
|
| | | drDataDict.update(dataDict)
|
| | | DataRecordPack.SendEventPack("CrossPK_%s" % eventName, drDataDict)
|
| | | return
|
| | |
|