From b61d2dfe79f9d3ef67a0561a0b640f888df32a58 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 31 十二月 2024 15:07:16 +0800
Subject: [PATCH] 10350 【后端】【越南】【英文】【BT】【砍树】跨服竞技场优化

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCrossRealmPK.py |  175 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 113 insertions(+), 62 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCrossRealmPK.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCrossRealmPK.py
index e402266..c94c0bb 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCrossRealmPK.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCrossRealmPK.py
@@ -36,20 +36,12 @@
 import GameObj
 import PlayerGubao
 
-## 是否匹配中
-def SetIsCrossPKMatching(curPlayer, isMatching):
-    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PlayerKey_IsCrossPKMatching, isMatching)
-    return
-def GetIsCrossPKMatching(curPlayer):
-    return curPlayer.NomalDictGetProperty(ChConfig.Def_PlayerKey_IsCrossPKMatching) and IsCrossRealmPKMatchState()
-
 def DoPlayerOnDay(curPlayer):
     if GameWorld.IsCrossServer():
         return
     totalScore = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TotalScore)
     if not totalScore:
         return
-    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_OnDayScore, totalScore)
     
     zoneID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_ZoneID)
     seasonID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_SeasonID)
@@ -71,6 +63,7 @@
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayWinCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayBuyCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_ItemAddCount, 0)
+    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_RefreshCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DayPKCountAwardState, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DayWinCountAwardState, 0)
     SyncCrossRealmPKPlayerInfo(curPlayer)
@@ -176,7 +169,6 @@
         
     # 重置状态
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TotalScore, 0)
-    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_OnDayScore, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DanLV, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_PKCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_WinCount, 0)
@@ -186,6 +178,7 @@
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayWinCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayBuyCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_ItemAddCount, 0)
+    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_RefreshCount, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DayPKCountAwardState, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DayWinCountAwardState, 0)
     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DanLVAwardState, 0)
@@ -205,7 +198,7 @@
 #struct    tagCMCrossRealmPKMatch
 #{
 #    tagHead        Head;
-#    BYTE        Type;    // 0-取消匹配; 1-进行匹配
+#    BYTE        Type;    // 0-查询匹配;1-刷新匹配
 #};
 def OnCrossRealmPKMatch(index, clientData, tick):
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
@@ -213,6 +206,46 @@
     playerID = curPlayer.GetPlayerID()
     requestType = clientData.Type
     
+    GameWorld.DebugLog("跨服PK匹配请求: type=%s,accID=%s" % (requestType, accID), playerID)
+    
+    # 刷新匹配
+    if requestType == 1:
+        if not CheckCanMatch(curPlayer):
+            return
+        
+        refreshCount  = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_RefreshCount)
+        freeRefreshCountMax = IpyGameDataPY.GetFuncCfg("CrossRealmPKMatchRefresh", 1)
+        if freeRefreshCountMax <= 0 or refreshCount < freeRefreshCountMax:
+            GameWorld.DebugLog("免费刷新: refreshCount=%s < %s" % (refreshCount, freeRefreshCountMax), playerID)
+        else:
+            refreshBuyCount = max(0, refreshCount - freeRefreshCountMax)
+            refreshBuyCountMax = IpyGameDataPY.GetFuncCfg("CrossRealmPKMatchRefresh", 2)
+            if refreshBuyCountMax and refreshBuyCount >= refreshBuyCountMax:
+                GameWorld.DebugLog("购买刷新次数已达每日上限! refreshBuyCount=%s >= %s" % (refreshBuyCount, refreshBuyCountMax), playerID)
+                return
+            costMoney = eval(IpyGameDataPY.GetFuncCompileCfg("CrossRealmPKMatchRefresh", 3))
+            moneyType = IpyGameDataPY.GetFuncCfg("CrossRealmPKMatchRefresh", 4)
+            GameWorld.DebugLog("付费刷新: refreshCount=%s,refreshBuyCount=%s,costMoney=%s,moneyType=%s" 
+                               % (refreshCount, refreshBuyCount, costMoney, moneyType), playerID)
+            if not PlayerControl.PayMoney(curPlayer, moneyType, costMoney, ChConfig.Def_Cost_CrossRealmPK, {"Event":"Refresh", "refreshBuyCount":refreshBuyCount}):
+                return
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_RefreshCount, refreshCount + 1)
+        SyncCrossRealmPKPlayerInfo(curPlayer)
+        
+    dataMsg = {
+               "requestType":requestType,
+               "seasonID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKSeasonID), # 赛季ID
+               "zoneID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKZoneID), # PK赛区
+               "playerID":playerID,
+               "fightPower":PlayerControl.GetFightPower(curPlayer),
+               }
+    GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKMatch, dataMsg)
+    GameWorld.DebugLog("发送请求匹配到跨服服务器 dataMsg=%s" % str(dataMsg), playerID)
+    return
+
+def CheckCanMatch(curPlayer):
+    ## 可否匹配、挑战
+    playerID = curPlayer.GetPlayerID()
     if GameWorld.IsCrossServer():
         GameWorld.DebugLog("跨服服务器无法发起匹配!", playerID)
         return
@@ -239,43 +272,7 @@
         #PlayerControl.NotifyCode(curPlayer, "MatchIsNotOpen")
         return
     
-    GameWorld.Log("收到跨服PK匹配: type=%s,accID=%s" % (requestType, accID), playerID)
-    
-    # 进行匹配
-    if requestType == 1:
-        if not CheckHavePKCount(curPlayer):
-            return
-        
-        dataMsg = {
-                   "seasonID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKSeasonID), # 赛季ID
-                   "pkZoneID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKZoneID), # PK赛区
-                   "accID":accID,
-                   "playerID":playerID,
-                   "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
-                   "playerJob":curPlayer.GetJob(),
-                   "playerLV":curPlayer.GetLV(),
-                   "face":curPlayer.GetFace(),
-                   "facePic":curPlayer.GetFacePic(),
-                   "maxHP":GameObj.GetMaxHP(curPlayer),
-                   "maxProDef":PlayerControl.GetMaxProDef(curPlayer),
-                   "fightPower":PlayerControl.GetFightPower(curPlayer),
-                   "realmLV":curPlayer.GetOfficialRank(),
-                   "pkScore":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TotalScore), # 当前积分
-                   "danLV":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_DanLV), # 当前段位
-                   "cWinCount":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_CWinCount), # 连胜次数
-                   "cLoseCount":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_CLoseCount), # 连败次数
-                   "ondayScore":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_OnDayScore), # 过天时的积分
-                   }
-        GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKMatch, dataMsg)
-        GameWorld.Log("    发送请求匹配到跨服服务器 dataMsg=%s" % str(dataMsg), playerID)
-        
-    # 取消匹配
-    else:
-        sendMsg = "ClientCancel"
-        GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "CrossRealmPKCancel", sendMsg, len(sendMsg))
-        GameWorld.Log("    发送取消匹配到GameServer sendMsg=%s" % str(sendMsg), playerID)
-        
-    return
+    return True
 
 def CheckHavePKCount(curPlayer):
     ## 检查是否有PK次数
@@ -294,24 +291,20 @@
 def CrossServerMsg_PKOverInfo(curPlayer, overInfo):
     ## 收到跨服服务器的PK结算信息
     playerID = curPlayer.GetPlayerID()
-    roomID, zoneID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, tagPlayerName, notifyState = overInfo
+    zoneID, seasonID, timeStr, winnerID, pkScore, danLV, cWinCount, addScore, tagPlayerID, tagPlayerName = overInfo
     isWinner = winnerID == playerID
-    GameWorld.Log("地图收到跨服PK结算: isWinner=%s,roomID=%s,zoneID=%s,seasonID=%s,timeStr=%s,overType=%s,winnerID=%s,roundWinnerIDList=%s,pkScore=%s,danLV=%s,cWinCount=%s,addScore=%s,tagPlayerID=%s,notifyState=%s" 
-                  % (isWinner, roomID, zoneID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, notifyState), playerID)
+    GameWorld.Log("地图收到跨服PK结算: isWinner=%s,zoneID=%s,seasonID=%s,timeStr=%s,winnerID=%s,pkScore=%s,danLV=%s,cWinCount=%s,addScore=%s,tagPlayerID=%s" 
+                  % (isWinner, zoneID, seasonID, timeStr, winnerID, pkScore, danLV, cWinCount, addScore, tagPlayerID), playerID)
     
     isToday = GameWorld.CheckTimeIsSameServerDayEx(GameWorld.ChangeTimeStrToNum(timeStr))
     if not __DoAddPKOverData(curPlayer, zoneID, seasonID, danLV, pkScore, cWinCount, isWinner, isToday):
         return
     
-    ## 跨服已经通知过了,证明还在跨服服务器,不做以下的处理
-    if notifyState:
-        return
-    
     overPack = ChPyNetSendPack.tagGCCrossRealmPKOverInfo()
     overPack.TimeStr = timeStr
-    overPack.OverType = overType
+    overPack.OverType = 0
     overPack.WinnerID = winnerID
-    overPack.RoundWinnerID = roundWinnerIDList
+    overPack.RoundWinnerID = []
     overPack.RoundCount = len(overPack.RoundWinnerID)
     overPack.AddScore = addScore
     overPack.Score = pkScore
@@ -385,11 +378,13 @@
 #{
 #    tagHead        Head;
 #    BYTE        IsWin;    //是否获胜
+#    DWORD        TagPlayerID;    //目标玩家ID
 #};
 def OnCrossRealmPKRobotOver(index, clientData, tick):
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
     playerID = curPlayer.GetPlayerID()
     isWinner = clientData.IsWin
+    tagPlayerID = clientData.TagPlayerID
     
     if GameWorld.IsCrossServer():
         GameWorld.DebugLog("跨服服务器无法发起机器人结算!", playerID)
@@ -398,14 +393,69 @@
     if not CheckHavePKCount(curPlayer):
         return
     
-    dataMsg = {
-               "playerID":playerID,
-               "isWinner":isWinner,
-               }
-    GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKRobotOver, dataMsg)
-    GameWorld.Log("同步跨服服务器与机器人PK结算: %s" % str(dataMsg), playerID)
+    SendPKOver(curPlayer, tagPlayerID, isWinner)
     return
 
+def SendPKOver(curPlayer, tagPlayerID, isWinner):
+    ## 发送给跨服PK结算
+    playerID = curPlayer.GetPlayerID()
+    dataMsg = {
+               "playerID":playerID,
+               "tagPlayerID":tagPlayerID,
+               "isWinner":isWinner,
+               "seasonID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKSeasonID), # 赛季ID
+               "pkZoneID":GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKZoneID), # PK赛区
+               "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
+               "playerJob":curPlayer.GetJob(),
+               "face":curPlayer.GetFace(),
+               "facePic":curPlayer.GetFacePic(),
+               "realmLV":curPlayer.GetOfficialRank(),
+               "fightPower":PlayerControl.GetFightPower(curPlayer),
+               "pkScore":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TotalScore), # 当前积分
+               "danLV":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_DanLV), # 当前段位
+               "cWinCount":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_CWinCount), # 连胜次数
+               }
+    GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKOver, dataMsg)
+    GameWorld.DebugLog("同步跨服服务器PK结算: %s" % str(dataMsg), playerID)
+    return
+
+def GMSetPlayerCrossPKData(curPlayer, danLV, pkScore, cWinCount=None, resultDict=None):
+    ## GM设置玩家跨服PK数据,一般用于测试或修复外网数据
+    zoneID = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKZoneID)
+    seasonID = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKSeasonID)
+    seasonState = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossPKSeasonState)
+    
+    errorMsg = "" 
+    playerInfoDict = {}
+    if not zoneID or not seasonID or seasonState == 2:
+        errorMsg = "zone season or state error."
+    else:
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DanLV, danLV)
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TotalScore, pkScore)
+        if cWinCount >= 0:
+            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_CWinCount, cWinCount)
+            if cWinCount > 0:
+                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_CLoseCount, 0)
+        else:
+            cWinCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_CLoseCount)
+            
+        # 请求查询跨服服务器
+        playerInfoDict = {"accID":curPlayer.GetAccID(),
+                          "playerID":curPlayer.GetPlayerID(),
+                          "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
+                          "playerJob":curPlayer.GetJob(),
+                          "face":curPlayer.GetFace(),
+                          "facePic":curPlayer.GetFacePic(),
+                          "realmLV":curPlayer.GetOfficialRank(),
+                          "pkScore":pkScore, "danLV":danLV, "cWinCount":cWinCount,
+                          }
+        dataMsg = {"ZoneID":zoneID, "SeasonID":seasonID, "PlayerInfo":playerInfoDict}
+        GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKBillboard, dataMsg)
+        SyncCrossRealmPKPlayerInfo(curPlayer)
+        
+    if resultDict:
+        resultDict.update({"zoneID":zoneID, "seasonID":seasonID, "seasonState":seasonState, "errorMsg":errorMsg, "PlayerInfo":playerInfoDict})
+    return errorMsg
 
 #// C1 02 跨服PK购买次数 #tagCMCrossRealmPKBuy
 #
@@ -721,6 +771,7 @@
     pkPlayerInfo.DayWinCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TodayWinCount)
     pkPlayerInfo.DayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TodayBuyCount)
     pkPlayerInfo.DayItemAddCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_ItemAddCount)
+    pkPlayerInfo.DayRefreshCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_RefreshCount)
     NetPackCommon.SendFakePack(curPlayer, pkPlayerInfo)
     return
     

--
Gitblit v1.8.0