1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerCrossRealmPK
#
# @todo:¿ç·þPK¾º¼¼³¡
# @author hxp
# @date 2018-12-21
# @version 1.0
#
# ÏêϸÃèÊö: ¿ç·þPK¾º¼¼³¡
#
#-------------------------------------------------------------------------------
#"""Version = 2018-12-21 18:00"""
#-------------------------------------------------------------------------------
 
import ShareDefine
import PlayerControl
import CrossRealmPlayer
import ChPyNetSendPack
import NetPackCommon
import GameWorld
import ChConfig
 
def DoPlayerOnDay(curPlayer):
    totalScore = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TotalScore)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_OnDayScore, totalScore)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayPKCount, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayBuyCount, 0)
    return
 
def IsCrossRealmPKOpen():
    ## ¿ç·þPKÆ¥ÅäÈüÊÇ·ñ¿ªÆô
    return 1
    return GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_MergePKState) == ChConfig.Def_Action_Open
 
def GetCrossPKZoneID():
    ## »ñÈ¡±¾·þ¿ç·þPKËùÊôÈüÇø
    return 1
 
def GetSeasonID():
    ## »ñÈ¡µ±Ç°Èü¼¾ID
    return 1
 
def IsCrossRealmPKSeasonOpen():
    return True
 
#// C1 01 ¿ç·þPKÆ¥Åä #tagCMCrossRealmPKMatch
#
#struct    tagCMCrossRealmPKMatch
#{
#    tagHead        Head;
#    BYTE        Type;    // 0-È¡ÏûÆ¥Åä; 1-½øÐÐÆ¥Åä
#};
def OnCrossRealmPKMatch(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    accID = curPlayer.GetAccID()
    playerID = curPlayer.GetPlayerID()
    requestType = clientData.Type
    
    if GameWorld.IsCrossServer():
        return
        
    if not IsCrossRealmPKOpen():
        GameWorld.Log("OnRequestMergePK ¿ç·þ»î¶¯Î´¿ªÆô£¬²»¿É½øÐÐÆ¥Å䣡", playerID)
        PlayerControl.NotifyCode(curPlayer, "GeRen_hgg_21675")
        return
    
    GameWorld.Log("ÊÕµ½¿ç·þPKÆ¥Åä: type=%s,accID=%s" % (requestType, accID), playerID)
    
    # ½øÐÐÆ¥Åä
    if requestType == 1:
#        pkCnt = __GetMergePKPDictValue(curPlayer, ChConfig.Def_PDict_MergePK_Cnt)
#        buyCnt = __GetMergePKPDictValue(curPlayer, ChConfig.Def_PDict_MergePK_BuyCnt)
#        unUsedBuyCnt = __GetMergePKPDictValue(curPlayer, ChConfig.Def_PDict_MergePK_UnUsedBuyCnt)
#        freeCnt, maxBuyCnt, moneyType, buyCostFormat = ReadChConfig.GetEvalChConfig("MergePK_BuyCost")
#        
#        # ³¬³öÃâ·Ñ´ÎÊý ÇÒ ÎÞ¿ÉÓõÄÒѹºÂò´ÎÊý  ÔòÐ蹺Âò´ÎÊý
#        if pkCnt >= freeCnt and unUsedBuyCnt <= 0:
#            
#            if buyCnt >= maxBuyCnt:
#                GameWorld.Log("    ÒÑ´ïµ½×î´ó¿É¹ºÂòPK´ÎÊý£¬²»¿ÉÔÙÂò£¡:buyCnt=%s,maxBuyCnt=%s,pkCnt=%s,unUsedBuyCnt=%s" 
#                              % (buyCnt, maxBuyCnt, pkCnt, unUsedBuyCnt), playerID)
#                return
#            
#            buyCost = eval(buyCostFormat)
#            infoDict = {"pkCnt":pkCnt, "freeCnt":freeCnt, "buyCnt":buyCnt, "buyCost":buyCost}
#            if not PlayerControl.PayMoney(curPlayer, moneyType, buyCost, ChConfig.Def_Cost_BuyMergePKCnt, infoDict):
#                return
#            
#            # Ôö¼Ó¹ºÂò´ÎÊý ¼° Î´Ê¹ÓõĹºÂò´ÎÊý
#            __SetMergePKPDictValue(curPlayer, ChConfig.Def_PDict_MergePK_BuyCnt, buyCnt + 1)
#            __SetMergePKPDictValue(curPlayer, ChConfig.Def_PDict_MergePK_UnUsedBuyCnt, unUsedBuyCnt + 1)
#            Sync_MergePKCnt(curPlayer)
#        
#            GameWorld.Log("    ¹ºÂòPK´ÎÊýÏûºÄ: pkCnt=%s,freeCnt=%s,buyCnt=%s,moneyType=%s,buyCost=%s" 
#                              % (pkCnt, freeCnt, buyCnt, moneyType, buyCost), playerID)
        
        dataMsg = {
                   "seasonID":GetSeasonID(), # Èü¼¾ID
                   "pkZoneID":GetCrossPKZoneID(), # PKÈüÇø
                   "accID":accID,
                   "playerID":playerID,
                   "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
                   "playerJob":curPlayer.GetJob(),
                   "playerLV":curPlayer.GetLV(),
                   "maxHP":curPlayer.GetMaxHP(),
                   "fightPower":curPlayer.GetFightPower(),
                   "pkScore":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TotalScore), # µ±Ç°»ý·Ö
                   "danLV":1, #curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_DanLV), # µ±Ç°¶Îλ
                   "cWinCount":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_CWinCount), # Á¬Ê¤´ÎÊý
                   "ondayScore":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_OnDayScore), # ¹ýÌìʱµÄ»ý·Ö
                   }
        GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_PKMatch, dataMsg)
        GameWorld.Log("    ·¢ËÍÇëÇóÆ¥Åäµ½¿ç·þ·þÎñÆ÷ dataMsg=%s" % str(dataMsg), playerID)
        
    # È¡ÏûÆ¥Åä
    else:
        sendMsg = "Client Cancel!"
        GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "CrossRealmPKCancel", sendMsg, len(sendMsg))
        GameWorld.Log("    ·¢ËÍÈ¡ÏûÆ¥Åäµ½GameServer sendMsg=%s" % str(sendMsg), playerID)
        
    return
 
def CrossServerMsg_PKOverInfo(curPlayer, overInfo):
    ## ÊÕµ½¿ç·þ·þÎñÆ÷µÄPK½áËãÐÅÏ¢
    playerID = curPlayer.GetPlayerID()
    roomID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, tagPlayerName, notifyState = overInfo
    isWinner = winnerID == playerID
    GameWorld.Log("µØÍ¼ÊÕµ½¿ç·þPK½áËã: isWinner=%s,roomID=%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, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, notifyState), playerID)
    curSeasonID = GetSeasonID()
    if curSeasonID != seasonID:
        GameWorld.Log("    ·Ç±¾Èü¼¾µÄ½áËãÐÅÏ¢£¬²»´¦Àí£¡curSeasonID=%s,seasonID=%s" % (curSeasonID, seasonID), playerID)
        return
    
    # Èü¼¾ÊÇ·ñÒѽáËã
    if not IsCrossRealmPKSeasonOpen():
        GameWorld.Log("    Èü¼¾ÒѾ­½áËã¹ýÁË£¬²»´¦Àí£¡seasonID=%s" % (seasonID), playerID)
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TotalScore, pkScore)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_DanLV, danLV)
    
    pkCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_PKCount) + 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_PKCount, pkCount)
    if isWinner:
        winCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_WinCount) + 1
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_WinCount, winCount)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_CWinCount, cWinCount)
    else:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_CWinCount, 0)
    
    # Í¬Ò»ÌìµÄ»°Ôö¼Óµ±ÈÕPK´ÎÊý
    if GameWorld.CheckTimeIsSameServerDayEx(GameWorld.ChangeTimeStrToNum(timeStr)):
        todayPKCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_TodayPKCount) + 1
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CrossPK_TodayPKCount, todayPKCount)
        
    ## ¿ç·þÒѾ­Í¨Öª¹ýÁË£¬Ö¤Ã÷»¹ÔÚ¿ç·þ·þÎñÆ÷£¬²»×öÒÔϵĴ¦Àí
    if notifyState:
        return
    
    overPack = ChPyNetSendPack.tagGCCrossRealmPKOverInfo()
    overPack.TimeStr = timeStr
    overPack.OverType = overType
    overPack.WinnerID = winnerID
    overPack.RoundWinnerID = roundWinnerIDList
    overPack.RoundCount = len(overPack.RoundWinnerID)
    overPack.AddScore = addScore
    overPack.Score = pkScore
    overPack.DanLV = danLV
    overPack.CWinCnt = cWinCount
    overPack.TagName = tagPlayerName
    overPack.TagNameLen = len(overPack.TagName)
    NetPackCommon.SendFakePack(curPlayer, overPack)
    return
 
 
#// C1 02 ¿ç·þPK¹ºÂò´ÎÊý #tagCMCrossRealmPKBuy
#
#struct    tagCMCrossRealmPKBuy
#{
#    tagHead        Head;
#};
def OnCrossRealmPKBuy(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    return
 
 
#// C1 03 ¿ç·þPKÁìÈ¡½±Àø #tagCMCrossRealmPKGetAward
#
#struct    tagCMCrossRealmPKGetAward
#{
#    tagHead        Head;
#    BYTE        AwardType;    // ½±ÀøÀàÐÍ£»1-ÿÈÕÆ¥Åä½±Àø£¬2-ÿÈÕʤÀû½±Àø£¬3-¶Îλ´ï±ê½±Àø£¬4-Èü¼¾½áËã½±Àø
#    BYTE        AwardData;    // ½±ÀøÀàÐͶÔÓ¦Áìȡֵ£»Ã¿ÈÕÆ¥Åä½±ÀøÊ±ÎªÆ¥Åä´ÎÊý£¬Ã¿ÈÕʤÀû½±ÀøÊ±ÎªÊ¤Àû´ÎÊý£¬¶Îλ´ï±ê½±ÀøÊ±ÎªÁìÈ¡µÄ¶Îλ
#};
def OnCrossRealmPKGetAward(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    return
 
 
def SyncCrossRealmPKPlayerInfo(curPlayer):
#    DWORD        Score;    // µ±Ç°»ý·Ö
#    BYTE        DanLV;    // µ±Ç°¶Îλ
#    WORD        PKCount;    // PK´ÎÊý
#    WORD        WinCount;    // Ê¤Àû´ÎÊý
#    WORD        CWinCount;    // Á¬Ê¤´ÎÊý
#    BYTE        DayPKCount;    // µ±ÈÕÒÑPK´ÎÊý
#    BYTE        DayWinCount;    // µ±ÈÕÒÑʤÀû´ÎÊý
#    BYTE        DayBuyCount; // µ±ÈÕÒѹºÂò´ÎÊý
    pkPlayerInfo = ChPyNetSendPack.tagMCCrossRealmPKPlayerInfo()
    pkPlayerInfo.Score = 0
    pkPlayerInfo.DanLV = 0
    return
    
def SyncCrossRealmPKAwardState(curPlayer):
#    DWORD        DayPKCountAwardState;    // Ã¿ÈÕÆ¥Åä´ÎÊý½±Àø¼Ç¼£¬¶þ½øÖÆÎ»´æ´¢ÊÇ·ñÒÑÁìÈ¡£¬°´Æ¥Åä´ÎÊýÉýÐòÅÅÐòË÷Òý´ú±í½±ÀøÎ»
#    DWORD        DayWinCountAwardState;    // Ã¿ÈÕʤÀû´ÎÊý½±Àø¼Ç¼£¬¶þ½øÖÆÎ»´æ´¢ÊÇ·ñÒÑÁìÈ¡£¬°´Ê¤Àû´ÎÊýÉýÐòÅÅÐòË÷Òý´ú±í½±ÀøÎ»
#    DWORD        DanLVAwardState;        // ¶Îλ´ï±ê½±Àø¼Ç¼£¬¶þ½øÖÆÎ»´æ´¢ÊÇ·ñÒÑÁìÈ¡£¬°´¶Îλ´ú±í½±ÀøÎ»
#    BYTE        SeasonAwardState;    // Èü¼¾½áËã½±ÀøÊÇ·ñÒÑÁìÈ¡
    return