129 【战斗】战斗系统-服务端(优化演武场匹配,不匹配无战斗缓存的玩家;优化真实玩家缓存存储逻辑;优化机器人、假人加载逻辑;)
4个文件已修改
141 ■■■■■ 已修改文件
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/TurnAttack.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Billboard.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerArena.py 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/TurnAttack.py
@@ -576,7 +576,7 @@
    olPlayer = PlayerOnline.GetOnlinePlayer(curPlayer)
    lineup = olPlayer.GetLineup(lineupID)
    if lineup.IsEmpty():
        GameWorld.DebugLog("玩家没有目标阵容默认取主阵容! lineupID=%s" % lineupID)
        GameWorld.DebugLog("玩家没有目标阵容默认取主阵容! lineupID=%s" % lineupID, curPlayer.GetPlayerID())
        lineup = olPlayer.GetLineup(ShareDefine.Lineup_Main)
    return lineup
@@ -1143,10 +1143,12 @@
    tagViewCache = PlayerViewCache.FindViewCache(tagPlayerID)
    if not tagViewCache:
        GameWorld.DebugLog("目标玩家没有缓存数据! tagPlayerID=%s" % tagPlayerID, playerID)
        return {}
        PlayerControl.NotifyCode(curPlayer, "TagNoViewCache")
        return
    defLineupInfo = GetCacheLineupInfo(tagViewCache, defLineupID)
    if not defLineupInfo:
        GameWorld.DebugLog("目标玩家没有该阵容数据! tagPlayerID=%s,defLineupID=%s" % (tagPlayerID, defLineupID), playerID)
        PlayerControl.NotifyCode(curPlayer, "TagNoLineup")
        return
    
    turnMax = GetTurnMax(mapID)
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Billboard.py
@@ -93,7 +93,7 @@
    maxDataCount = billboardObj.GetMaxCount()
    
    count = min(count, maxDataCount - curDataCount)
    FakeName = GameWorld.GbkToCode("假名字")
    FakeName = GameWorld.GbkToCode("主公")
    
    for i in xrange(count):
        dataPlayerID = curDataCount + 1 + i
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerArena.py
@@ -256,6 +256,7 @@
    toOrder = playerOrder + fromLowerCnt * matchPerRank # 从低名次往高名次匹配
    GameWorld.DebugLog("    fromLowerCnt=%s,matchPerRank=%s,toOrder=%s" % (fromLowerCnt, matchPerRank, toOrder), playerID)
    matchOrderList = [] # 匹配到的名次
    viewCacheDict = {}
    for _ in range(matchPlayerCnt):
        fromOrder = max(1, toOrder - matchPerRank)
        if toOrder <= fromOrder:
@@ -267,36 +268,26 @@
        if not orderList:
            break
        
        if fromOrder == 1:
            for order in orderList:
                if order > maxOrder:
                    continue
                matchOrderList.append(order)
        for order in orderList:
            if order > maxOrder:
                continue
            billData = billBoard.At(order - 1)
            tagID = billData.GetID()
            viewCache = PlayerViewCache.FindBattleViewCache(tagID)
            if not viewCache:
                GameWorld.DebugLog("    无战斗缓存的玩家不匹配: tagID=%s,order=%s,fromOrder=%s,toOrder=%s" % (tagID, order, fromOrder, toOrder), playerID)
                continue
            matchOrderList.append(order)
            viewCacheDict[tagID] = viewCache
            if fromOrder == 1:
                if len(matchOrderList) >= matchPlayerCnt:
                    break
        else:
            order = orderList[0]
            if order <= maxOrder:
                matchOrderList.append(order)
            else:
                break
        GameWorld.DebugLog("    匹配玩家: fromOrder=%s,toOrder=%s,matchOrderList=%s" % (fromOrder, toOrder, matchOrderList), playerID)
        toOrder = fromOrder - 1
    # GM指定匹配测试
    if gmMatchIDList != None and curPlayer.GetGMLevel():
        for gmMatchID in gmMatchIDList:
            if gmMatchID == playerID:
                GameWorld.DebugAnswer(curPlayer, "目标ID不能是自己!无法匹配!%s" % gmMatchID)
                continue
            gmMatchOrder = billBoard.IndexOfByID(gmMatchID) + 1
            if gmMatchOrder <= 0:
                GameWorld.DebugAnswer(curPlayer, "目标ID不在榜单上!无法匹配!%s" % gmMatchID)
                continue
            GameWorld.DebugAnswer(curPlayer, "指定匹配ID(%s),order(%s)" % (gmMatchID, gmMatchOrder))
            if gmMatchID not in matchOrderList:
                matchOrderList.insert(0, gmMatchOrder)
        matchOrderList = matchOrderList[:needMatchCount]
        
    matchOrderList.sort()
    matchIDList = [] # 最终匹配的玩家ID列表
@@ -304,10 +295,34 @@
        if matchOrder > maxOrder or matchOrder <= 0:
            break
        billData = billBoard.At(matchOrder - 1)
        matchIDList.append(billData.GetID())
        tagID = billData.GetID()
        matchIDList.append(tagID)
    GameWorld.DebugLog("    匹配榜单结果: matchIDList=%s,matchOrderList=%s" % (matchIDList, matchOrderList), playerID)
    # GM指定匹配测试
    if gmMatchIDList != None and curPlayer.GetGMLevel():
        for gmMatchID in gmMatchIDList:
            if gmMatchID == playerID:
                GameWorld.DebugAnswer(curPlayer, "不能匹配自己!%s" % gmMatchID)
                continue
            if gmMatchID in matchIDList:
                continue
            viewCache = PlayerViewCache.FindBattleViewCache(gmMatchID)
            if not viewCache:
                GameWorld.DebugAnswer(curPlayer, "没有战斗缓存目标不匹配!%s" % gmMatchID)
                continue
            GameWorld.DebugAnswer(curPlayer, "指定匹配ID(%s)" % (gmMatchID))
            matchIDList.append(gmMatchID)
            viewCacheDict[gmMatchID] = viewCache
        matchOrderList = matchOrderList[:needMatchCount]
        GameWorld.DebugLog("    指定匹配结果: matchIDList=%s" % (matchIDList), playerID)
        
    needRobotCnt = needMatchCount - len(matchIDList)
    GameWorld.DebugLog("    匹配榜单结果: matchIDList=%s,matchOrderList=%s,needRobotCnt=%s" % (matchIDList, matchOrderList, needRobotCnt), playerID)
    GameWorld.DebugLog("    还需机器人数=%s" % (needRobotCnt), playerID)
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    robotMax = ipyDataMgr.GetRobotCount()
    doCnt = 100
@@ -322,16 +337,21 @@
    GameWorld.DebugLog("    最终匹配结果: matchIDList=%s" % matchIDList, playerID)
    
    PyGameData.g_arenaPlayerMatchDict[playerID] = matchIDList
    __SyncMatchList(curPlayer, matchIDList)
    __SyncMatchList(curPlayer, matchIDList, viewCacheDict)
    return
def __SyncMatchList(curPlayer, matchIDList):
def __SyncMatchList(curPlayer, matchIDList, viewCacheDict={}):
    ## 同步匹配列表
    objPool = ObjPool.GetPoolMgr()
    clientPack = objPool.acquire(ChPyNetSendPack.tagSCArenaMatchList)
    clientPack.MatchList = []
    for matchID in matchIDList:
        viewCache = PlayerViewCache.FindViewCache(matchID)
        if matchID in viewCacheDict:
            viewCache = viewCacheDict[matchID]
        else:
            viewCache = PlayerViewCache.FindBattleViewCache(matchID)
        if not viewCache:
            continue
        matchInfo = objPool.acquire(ChPyNetSendPack.tagSCArenaMatchInfo)
        matchInfo.PlayerID = matchID
        if viewCache:
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
@@ -37,8 +37,6 @@
    return
def OnPlayerLogout(curPlayer):
    if curPlayer.GetLV() < IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1):
        return
    
    playerID = curPlayer.GetPlayerID()
    curCache = FindViewCache(playerID)
@@ -112,6 +110,17 @@
        
    return False
def FindBattleViewCache(playerID):
    ## 获取可战斗的玩家缓存
    # @return: None-无;curCache-有返回该缓存对象
    curCache = FindViewCache(playerID)
    if not curCache:
        return
    plusDict = curCache.GetPlusDict()
    if "Lineup" not in plusDict:
        return
    return curCache
def FindViewCache(playerID):
    '''查找玩家缓存,如果不存在,则会有额外逻辑,如从redis、db直接找,
            本服玩家理论上一定有查看缓存,因为如果不存在会直接从db读,除非该玩家数据被删除
@@ -146,23 +155,35 @@
            # 逻辑待扩展
            
    # 机器人
    elif ShareDefine.RobotIDStart <= playerID <= ShareDefine.RobotIDMax:
        curCache = UpdRobotViewCache(playerID)
    #elif ShareDefine.RobotIDStart <= playerID <= ShareDefine.RobotIDMax:
    elif IpyGameDataPY.GetIpyGameDataNotLog("Robot", playerID):
        GameWorld.DebugLog("加载机器人缓存: %s" % playerID)
        curCache = viewCacheMgr.AddPlayerViewCache(playerID)
        curCache = UpdRobotViewCache(curCache, playerID)
        curCache.SetPlayerName("%s%s" % (GameWorld.GbkToCode("主公"), playerID))
        
    # 假玩家,默认添加
    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) # 先随机,外层有需要的话再自己设置
        GameWorld.DebugLog("加载假玩家缓存: %s" % playerID)
        # 随机复制个机器人数据
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        robotIpyData = ipyDataMgr.GetRobotByIndex(random.randint(0, ipyDataMgr.GetRobotCount() - 1))
        
        curCache = viewCacheMgr.AddPlayerViewCache(playerID)
        curCache.SetPlayerName("%s%s" % (GameWorld.GbkToCode("神秘道友"), playerID))
        curCache = UpdRobotViewCache(curCache, robotIpyData.GetID())
        # 再覆盖部分数据
        serverID = playerID % 100 + 1 # 1 ~ 100 服
        accID = "fake%s@test@s%s" % (playerID, serverID)
        #fightPower = random.randint(1000000, 100000000) # 先随机,外层有需要的话再自己设置
        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.SetLV(random.randint(100, 200))
        #curCache.SetJob(random.randint(1, 2))
        #curCache.SetRealmLV(random.randint(5, 15))
        #curCache.SetFightPowerTotal(fightPower)
        curCache.SetOffTime(int(time.time()) - random.randint(1, 3600 * 24 * 10)) # 随机离线 0~10天
        
    return curCache
@@ -332,7 +353,7 @@
                 }
    return robotDict
def UpdRobotViewCache(robotID):
def UpdRobotViewCache(curCache, robotID):
    ## 更新机器人查看缓存
    robotIpyData = IpyGameDataPY.GetIpyGameData("Robot", robotID)
    if not robotIpyData:
@@ -342,10 +363,6 @@
    except:
        return
    
    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
    curCache = viewCacheMgr.GetPlayerViewCache(robotID)
    if not curCache:
        curCache = viewCacheMgr.AddPlayerViewCache(robotID)
    #curCache.SetAccID(dbPlayer.AccID)
    
    curCache.SetPlayerName(robotInfo.get("PlayerName", "p%s" % robotID))