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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerMergeKing
#
# @todo:¿ç·þÍõÕßÕù°Ô
# @author hxp
# @date 2015-11-18
# @version 1.0
#
# ÏêϸÃèÊö: ¿ç·þÍõÕßÕù°Ô
#
#---------------------------------------------------------------------
"""Version = 2015-11-18 18:30"""
#---------------------------------------------------------------------
 
import ShareDefine
import ReadChConfig
import PlayerControl
import ChPyNetSendPack
import DataRecordPack
import NetPackCommon
import IPY_GameWorld
import ItemControler
import ItemCommon
import GameWorld
import ChConfig
 
 
(
MergeKing_GSQType_Support,  # Ñº×¢
MergeKing_GSQType_Bribe, # »ß¸
MergeKing_GSQType_SupportAward, # ÁìÈ¡»ý·Ö½±Àø
) = range(3)
 
## ¿ç·þÍõÕßÕù°Ô»î¶¯ID±ä¸ü
def OnMergeKingActionChange(key, value):
    # ¿ç·þ·þÎñÆ÷²»´¦Àí
    if GameWorld.IsMergeServer():
        return
    
    gameWorld = GameWorld.GetGameWorld()
    mapKeyValue = gameWorld.GetGameWorldDictByKey(key)
    if mapKeyValue == value:
        return
    
    GameWorld.Log("¿ç·þÍõÕßÕù°Ô»î¶¯ID±ä¸ükey=%s,value=%s,mapKeyValue=%s" % (key, value, mapKeyValue))
    
    for i in range(0, GameWorld.GetPlayerManager().GetPlayerCount()):
        curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(i)
        
        if curPlayer == None or not curPlayer.GetPlayerID():
            continue
    
        #¼ì²éÖØÖÃÍæ¼ÒÐÅÏ¢
        __CheckResetPlayerMergeKingData(curPlayer, key, value)
    return
 
## Çå³ýÍæ¼ÒÐÅÏ¢
#  @param curPlayer: Íæ¼Ò
#  @param key: Ìػݻkey£¬Ä¬ÈÏÈ«²¿¼ì²é£¬Ò»°ãµÇ¼ʱȫ²¿¼ì²é
#  @return: None
def __CheckResetPlayerMergeKingData(curPlayer, key, value, isSync=True):
    playerID = curPlayer.GetPlayerID()
    
    # Íæ¼ÒÉíÉÏÊý¾ÝµÄ»î¶¯id
    playerActionIDKey = ChConfig.Def_PDict_MergeKing_ID % key
    playerActionID = __GetMergeKingPDictValue(curPlayer, playerActionIDKey)
    if playerActionID == value:
        GameWorld.DebugLog("¿ç·þÍõÕßÕù°Ô»î¶¯IDÏàͬ£¬²»´¦Àíkey=%s,actionID=%s" % (key, value), playerID)
        return
    GameWorld.Log("¿ç·þÍõÕßÕù°Ô»î¶¯ID²»Í¬£¬Êý¾ÝÖØÖÃkey=%s,actionID=%s,playerActionID=%s" 
                  % (key, value, playerActionID), playerID)
    __SetMergeKingPDictValue(curPlayer, playerActionIDKey, value)
 
    # Õù°ÔÈü¿ªÊ¼Ê±ÖØÖÃ
    if key == ShareDefine.Def_Notify_WorldKey_Merge_KingStartID:
        __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_SupportAward, 0)
        
    # Õù°ÔÈü½áÊøÊ±ÖØÖÃ
    elif key == ShareDefine.Def_Notify_WorldKey_Merge_KingOverID:
        __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_ServerHonourAward, 0)
        __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_RankAward, 0)
        
    if isSync:
        Sync_MergeKingAward(curPlayer)
            
    return
 
def MergeKingOnDay(curPlayer):
    __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_Worship, 0)
    Sync_MergeKingAward(curPlayer)
    return
 
## OnLogin´¦Àí
def MergePKOnLogin(curPlayer):
    gameWorld = GameWorld.GetGameWorld()
    for idKey in [ShareDefine.Def_Notify_WorldKey_Merge_KingStartID, ShareDefine.Def_Notify_WorldKey_Merge_KingOverID]:
        __CheckResetPlayerMergeKingData(curPlayer, idKey, gameWorld.GetGameWorldDictByKey(idKey), False)
        
    Sync_MergeKingAward(curPlayer)
    return
 
def __GetMergeKingPDictValue(curPlayer, key, defaultVlaue=0):
    return curPlayer.NomalDictGetProperty(key, defaultVlaue, ChConfig.Def_PDictType_MergeKing)
 
def __SetMergeKingPDictValue(curPlayer, key, value):
    value = min(value, ChConfig.Def_UpperLimit_DWord)
    return PlayerControl.NomalDictSetProperty(curPlayer, key, value, ChConfig.Def_PDictType_MergeKing)
 
#//C1 08 Íæ¼ÒÖ´ÐÐĤ°Ý #tagPlayerMergeWorship
#
#struct    tagPlayerMergeWorship
#{
#    tagHead        Head;
#};
def Client_MergeKingWorship(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("Íæ¼Ò½øÐÐĤ°Ý!", playerID)
 
    state = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_Worship)
    
    if state:
        GameWorld.Log("    ½ñÈÕÒѾ­Ä¤°Ý¹ý!", playerID)
        return
    
    worshipInfo = ReadChConfig.GetEvalChConfig("MergeKing_WorshipAward")
    baseGongXun, multipleRateList = worshipInfo
    multiple = GameWorld.GetResultByRandomList(multipleRateList)
    giveGongXun = baseGongXun * multiple
    
    if multiple > 1:
        PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_412986", [multiple, giveGongXun])
    else:
        PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_155554", [giveGongXun])
    
    __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_Worship, 1)
    
    #PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_GongXun, giveGongXun, "Worship")
    
    GameWorld.Log("    Ä¤°Ý½±ÀøOK!multiple=%s,giveGongXun=%s" % (multiple, giveGongXun), playerID)
    Sync_MergeKingAward(curPlayer)
    return
 
#// C1 11 ¿ç·þÍõÕßÕù°ÔѺע #tagCMMergeKingSupport
#
#struct    tagCMMergeKingSupport
#{
#    tagHead        Head;
#    BYTE        SupportType;    // 0-Ѻע; 1-»ß¸
#    BYTE        GroupType;    // ×éÀàÐÍ£»Èç32Ç¿¡¢16Ç¿µÈ
#    BYTE        BattleIndex;    // ¶ÔÕ½×éË÷Òý£¬Ã¿ÖÖ×éÀàÐ͵ÄË÷Òý´Ó1¿ªÊ¼
#    BYTE        MoneyType;    // Ñº×¢µÄ»õ±ÒÀàÐÍ
#    BYTE        AccIDLen;
#    char        TagAccID[AccIDLen];    // Ö§³ÖµÄÄ¿±êÕ˺Å
#};
def Client_MergeKingSupport(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    
    supportType = clientData.SupportType
    groupType = clientData.GroupType
    battleIndex = clientData.BattleIndex
    moneyType = clientData.MoneyType
    tagAccID = clientData.TagAccID
    
    GameWorld.Log("¿ç·þÍõÕßÕù°ÔѺע SupportType=%s,GroupType=%s,BattleIndex=%s,MoneyType=%s,TagAccID=%s" 
                  % (supportType, groupType, battleIndex, moneyType, tagAccID), playerID)
    
    if supportType not in [0, 1]:
        return
    
    supportDict = ReadChConfig.GetEvalChConfig("MergeKing_Support")
    groupSupportDict = supportDict.get(groupType)
    
    if not groupSupportDict:
        GameWorld.ErrLog("    Õù°Ô¶ÔÕ½×éδÅäÖÃѺעÐÅÏ¢!groupType=%s" % groupType)
        return
    
    supportInfoList = groupSupportDict.get(moneyType)
    if not supportInfoList:
        GameWorld.ErrLog("    Õù°Ô¶ÔÕ½×éδÅäÖûõ±ÒÀàÐͶÔÓ¦µÄѺעÐÅÏ¢!groupType=%s,moneyType=%s" % (groupType, moneyType))
        return
    
    supportMoney, bribeMoney, score, unSupportScore = supportInfoList
    
    # Ñº×¢
    if supportType == 0:
        costMoney = supportMoney
        queryType = MergeKing_GSQType_Support
        
    # »ß¸Ѻע»ý·Ö
    elif supportType == 1:
        costMoney = bribeMoney
        queryType = MergeKing_GSQType_Bribe
        
    if costMoney <= 0:
        GameWorld.ErrLog("    ²»Ö§³Ö¸Ã»õ±ÒѺע/»ß¸!moneyType=%s,costMoney=%s" % (moneyType, costMoney))
        return
    
    if not PlayerControl.HaveMoney(curPlayer, moneyType, costMoney):
        GameWorld.Log("    »õ±Ò²»×ãѺע/»ß¸!moneyType=%s,costMoney=%s" % (moneyType, costMoney))
        return
 
    queryList = [queryType, groupType, battleIndex, moneyType, costMoney, tagAccID, score, unSupportScore]
    MergeKing_GameServerQuery(curPlayer, queryList)
    return
 
def MergeKing_GameServerQuery(curPlayer, queryList):
    queryListStr = str(queryList)
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, 'MergeKing', 
                                                              queryListStr, len(queryListStr))
    return
 
def MergeKing_GameServerQueryResult(curPlayer, resultInfo):
    resultType = resultInfo[0]
    resultParamList = resultInfo[1:]
    
    if resultType == MergeKing_GSQType_Support:
        return __DoLogic_GSQResult_Support(curPlayer, resultParamList)
        
    elif resultType == MergeKing_GSQType_Bribe:
        return __DoLogic_GSQResult_Bribe(curPlayer, resultParamList)
        
    elif resultType == MergeKing_GSQType_SupportAward:
        return __DoLogic_GSQResult_SupportAward(curPlayer, resultParamList)
        
    return
 
def __DoLogic_GSQResult_Support(curPlayer, resultParamList):
    moneyType, costMoney = resultParamList
    if not PlayerControl.PayMoney(curPlayer, moneyType, costMoney, ChConfig.Def_Cost_MergeKingSupport):
        return False
    return
 
def __DoLogic_GSQResult_Bribe(curPlayer, resultParamList):
    moneyType, costMoney = resultParamList
    if not PlayerControl.PayMoney(curPlayer, moneyType, costMoney, ChConfig.Def_Cost_MergeKingBribe):
        return False
    return
 
## Áìȡȫ·þÈÙÒ«½±Àø
def GetMergeKingAward_ServerHonour(curPlayer):
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("Íæ¼ÒÁìȡȫ·þÈÙÒ«½±Àø!", playerID)
    
    awardState = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_ServerHonourAward)
    
    if awardState:
        GameWorld.Log("    ÒÑÁìÈ¡¹ýÈ«·þÈÙÒ«½±Àø!", playerID)
        return
    
    honourAwardDict = ReadChConfig.GetEvalChConfig("MergeKing_ServerHonourAward")
    serverHonour = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_Merge_KingServerHonour)
    awardInfo = honourAwardDict.get(serverHonour, [])
    if not awardInfo:
        GameWorld.Log("    Ã»ÓиÃÈ«·þÈÙÒ«½±Àø!serverHonour=%s" % serverHonour, playerID)
        return
    
    needSpace, awardItemList = awardInfo
 
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_ServerHonourAward, 1)
 
    __GivePlayerAwardItem(curPlayer, awardItemList, "MergeKingServerHonour", {"serverHonour":serverHonour})
    
    GameWorld.Log("    Áìȡȫ·þÈÙÒ«½±ÀøOK!serverHonour=%s" % (serverHonour), playerID)
    Sync_MergeKingAward(curPlayer)
    return
 
## ÁìÈ¡½ú¼¶ÅÅÃû½±Àø
def GetMergeKingAward_Rank(curPlayer):
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("Íæ¼ÒÁìÈ¡½ú¼¶ÅÅÃû½±Àø!", playerID)
    
    rankAwardState = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_RankAward)
    
    if rankAwardState:
        GameWorld.Log("    ÒÑÁìÈ¡¹ý½ú¼¶ÅÅÃû½±Àø!", playerID)
        return
    
    rankAwardDict = ReadChConfig.GetEvalChConfig("MergeKing_RankAward")
    playerRank = PlayerControl.GetMergeWarRank(curPlayer)
    awardInfo = rankAwardDict.get(playerRank, [])
    if not awardInfo:
        GameWorld.Log("    Ã»Óиýú¼¶ÅÅÃû½±Àø!playerRank=%s" % playerRank, playerID)
        return
    
    needSpace, awardItemList = awardInfo
 
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_RankAward, 1)
 
    __GivePlayerAwardItem(curPlayer, awardItemList, "MergeKingRank", {"playerRank":playerRank})
    
    GameWorld.Log("    ÁìÈ¡½ú¼¶ÅÅÃû½±ÀøOK!playerRank=%s" % (playerRank), playerID)
    Sync_MergeKingAward(curPlayer)
    return
 
## ÁìÈ¡¾º²Â»ý·Ö½±Àø
def GetMergeKingAward_Support(curPlayer, index, tick):
    playerID = curPlayer.GetPlayerID()
    GameWorld.Log("Íæ¼ÒÁìÈ¡¾º²Â»ý·Ö½±Àø£º index=%s" % index, playerID)
    
    state = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_SupportAward)
    if state & pow(2, index):
        GameWorld.Log("    ÒÑÁìÈ¡¹ý¸Ã½±Àøindex=%s,state=%s" % (index, state), playerID)
        return
 
    if not GameWorld.CheckPlayerTick(curPlayer, ChConfig.TYPE_Player_Tick_MergeKingSupport, tick):
        GameWorld.Log("    ÁìÈ¡¾º²Â»ý·Ö½±Àø Áì½±ÇëÇóCDÖУ¡", playerID)
        return
    
    queryList = [MergeKing_GSQType_SupportAward, index]
    MergeKing_GameServerQuery(curPlayer, queryList)
    return
 
def __DoLogic_GSQResult_SupportAward(curPlayer, resultParamList):
    playerID = curPlayer.GetPlayerID()
    index, totalScore = resultParamList
    
    supportAwardList = ReadChConfig.GetEvalChConfig("MergeKing_SupportAward")
    
    if index < 0 or index > len(supportAwardList) - 1:
        GameWorld.Log("    ¾º²Â»ý·Ö½±ÀøË÷ÒýÔ½½ç index=%s" % (index), playerID)
        return
    
    awardInfo = supportAwardList[index]
    needScore, needSpace, awardItemList = awardInfo
 
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    if totalScore < needScore:
        GameWorld.Log("    ¾º²Â»ý·ÖÁì½±»ý·Ö²»×ã index=%s,needScore=%s,totalScore=%s" 
                      % (index, needScore, totalScore), playerID)
        return
    
    state = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_SupportAward)
    if state & pow(2, index):
        GameWorld.Log("    ¾º²Â»ý·ÖÁì½±ÒÑÁìÈ¡¹ý¸Ã½±Àøindex=%s,state=%s" % (index, state), playerID)
        return
    
    newState = state | pow(2, index)
    __SetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_SupportAward, newState)
 
    __GivePlayerAwardItem(curPlayer, awardItemList, "MergeKingSupport", {"index":index})
    
    curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_MergeKingSupport, 0)
    GameWorld.Log("    ¾º²Â»ý·ÖÁì½±OK!index=%s,state=%s,newState=%s" 
                  % (index, state, newState), playerID)
    Sync_MergeKingAward(curPlayer)
    return
 
def __GivePlayerAwardItem(curPlayer, awardItemList, drName, drDataDict={}):
    
    for itemID, itemCnt, isBind in awardItemList:
        
        if itemCnt <= 0 or itemID <= 0:
            continue
        
        packList = [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere]
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isBind, packList, True, 
                                     event=[drName, True, drDataDict])
        
    return
 
## Í¬²½¿ç·þÍõÕßÕù°Ô½±ÀøÏà¹Ø
def Sync_MergeKingAward(curPlayer):
    awardPack = ChPyNetSendPack.tagMCMergeKingAwardInfo()
    awardPack.Clear()
    awardPack.ServerHonour = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_Merge_KingServerHonour)
    awardPack.ServerHonourAward = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_ServerHonourAward)
    awardPack.RankAward = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_RankAward)
    awardPack.SupportAward = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_SupportAward)
    awardPack.WorshipState = __GetMergeKingPDictValue(curPlayer, ChConfig.Def_PDict_MergeKing_Worship)
    NetPackCommon.SendFakePack(curPlayer, awardPack)
    return