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
398
399
400
401
402
403
404
405
406
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerPrestigeSys
#
# @todo:¾ôλϵͳ/ÉÙÄê¾³½ç
# @author hxp
# @date 2017-7-21
# @version 1.0
#
# ÏêϸÃèÊö: ¾ôλϵͳ/ÉÙÄê¾³½ç
#
#-------------------------------------------------------------------------------
#"""Version = 2017-10-10 14:30"""
#-------------------------------------------------------------------------------
 
import ItemCommon
import GameFuncComm
import PlayerControl
import ChPyNetSendPack
import NetPackCommon
import IPY_GameWorld
import IpyGameDataPY
import ShareDefine
import GameWorld
import ChConfig
import PlayerSuccess
import ChEquip
import PlayerBillboard
import PlayerTongTianLing
import PassiveBuffEffMng
import EventShell
import DataRecordPack
import SkillCommon
 
import time
#------------------------------------------------------------------------------
 
 
def DoOfficialOpen(curPlayer):
    #¹¦ÄÜ¿ªÆô
#    curRealmLV = curPlayer.GetOfficialRank()
#    if not curRealmLV:
#        DoRealmLVUpLogic(curPlayer)
    return True
 
 
def OnLogin(curPlayer):
    SyncRealmFBState(curPlayer)
    UpdateRealmExp(curPlayer, False)
    NotifyRealmExpInfo(curPlayer)
    return
 
 
def GetRealmIpyData(realmLV): return IpyGameDataPY.GetIpyGameData("Realm", realmLV)
 
 
#// A5 24 ¿ªÆô¶É½Ù #tagCMOpenRealmFB
#
#struct    tagCMOpenRealmFB
#{
#    tagHead        Head;
#};
def OpenRealmFB(index, clientData, tick):
    return
 
def GetXXZLAward(curPlayer, taskID):
    ## ÁìÈ¡ÐÞÏÉ֮·½±Àø
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmXXZLAward)
    if awardState&pow(2, taskID):
        GameWorld.DebugLog("ÒÑÁìÈ¡¹ý¾³½çÐÞÏÉ֮·¸Ã½±Àø, taskID=%s" % taskID, curPlayer.GetPlayerID())
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("RealmXXZL", taskID)
    if not ipyData:
        return
    taskType = ipyData.GetTaskType()
    needValue = ipyData.GetNeedValue()
    curValue= 0
    
    #1. µÃµ½ XXX·¨±¦£¬ ËùÐèֵΪ·¨±¦ID
    if taskType == 1:
        magicWeaponID = needValue
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % magicWeaponID) >= 1:
            curValue = needValue
            
    #2. Í¨¹ØÌìÐÇËþX²ã
    elif taskType == 2:
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_SkyTowerFloor)
    
    #3. »÷ɱÊÀ½çBOSSXÖ»
    elif taskType == 3:
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Boss_KillCntTotal % ShareDefine.Def_Boss_Func_World)
        
    #4. »îÔ¾ÐÞÁ¶X´Î
    elif taskType == 4:
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCountTotal)
                
    #5. »÷ɱ¸öÈËBOSS£ºxxx£¬ËùÐè֮Ϊ¸öÈËboss±í¶ÔÓ¦Ïß·id
    elif taskType == 5:
        mapID = ChConfig.Def_FBMapID_PersonalBoss
        lineID = needValue
        if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID, False, [mapID]):
            curValue = needValue
            
    #6. Í¨¹Ø×ÚÃÅÊÔÁ¶x´Î
    elif taskType == 6:
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_EnterFbCntTotal % ChConfig.Def_FBMapID_MunekadoTrial)
        
    #7. »ñµÃXµãÁé¸ùµã
    elif taskType == 7:
        curValue = PlayerControl.GetTotalLingGenPoint(curPlayer)
        
    if curValue < needValue:
        GameWorld.DebugLog("¾³½çÐÞÏÉ֮·µ±Ç°ÈÎÎñËùÐèÖµ²»Âú×㣬ÎÞ·¨Áì½±, taskID=%s,taskType=%s,curValue=%s < %s" 
                           % (taskID, taskType, curValue, needValue), curPlayer.GetPlayerID())
        return
    
    awardItemList = ipyData.GetAwardItemList()
    if not ItemCommon.GiveAwardItem(curPlayer, awardItemList):
        return
    
    updAwardState = awardState|pow(2, taskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmXXZLAward, updAwardState)
    GameWorld.DebugLog("ÁìÈ¡¾³½çÐÞÏÉ֮·½±Àø, awardID=%s,updAwardState=%s" % (taskID, updAwardState), curPlayer.GetPlayerID())
    SyncRealmFBState(curPlayer)
    EventShell.EventRespons_RealmXXZLAward(curPlayer, taskID)
    return
 
def SyncRealmFBState(curPlayer):
    #֪ͨ¿Í»§¶Ë¶É½Ù¸±±¾ÊÇ·ñ¿ªÆô
    #if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Official):
    #    return
    sendPack = ChPyNetSendPack.tagMCSyncRealmInfo()
    sendPack.IsPass = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmFBIsOpen)
    sendPack.XXZLAwardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmXXZLAward)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
 
## ¼ÆËã¾ôλÊôÐÔ
#  @param curPlayer Íæ¼Ò
#  @param allAttrList ÊôÐÔÁбí
#  @return None
def CalcOfficialRankAttr(curPlayer):
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Official):
        return
 
    curRealmLV = curPlayer.GetOfficialRank()
    realmIpyData = GetRealmIpyData(curRealmLV)
    if not realmIpyData:
        return
   
    addAttrIDList, addAttrValueList = realmIpyData.GetAddAttrType(), realmIpyData.GetAddAttrNum()
    
    allAttrList = [{} for i in range(4)]
    for i, attrID in enumerate(addAttrIDList):
        PlayerControl.CalcAttrDict_Type(attrID, addAttrValueList[i], allAttrList)
        
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Prestige, allAttrList)
    return
 
 
## ÖØË¢ËùÓÐÊôÐÔ
#  @param curPlayer
#  @param isForceRefresh:Ç¿ÖÆË¢ÐÂÅÅÐаñ
#  @return Ö¸¶¨Êý¾Ý
def RefreshOfficialAttr(curPlayer):
    CalcOfficialRankAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
 
#// A5 23 ÌáÉý¾³½çµÈ¼¶ # tagCMRealmLVUp
#
#struct    tagCMRealmLVUp
#{
#    tagHead        Head;
#};
def DoRealmLVUp(index, clientData, tick):
    #Éý¼¶¾³½ç
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    curRealmLV = curPlayer.GetOfficialRank()
    realmIpyData = GetRealmIpyData(curRealmLV)
    if not realmIpyData:
        GameWorld.ErrLog("ûÓиþ³½çµÈ¼¶Êý¾Ý! Lv=%s" % curRealmLV)
        return
    if realmIpyData.GetBossID():
        canLvUp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmFBIsOpen) == 1
        if not canLvUp:
            GameWorld.DebugLog('    ¸±±¾Î´¹ý¹Ø£¬²»ÄÜÉý¼¶¾³½ç')
            return
    #µÈ¼¶ÅжÏ
    if curPlayer.GetLV() < realmIpyData.GetNeedLV():
        return
    #×°±¸ÅжÏ
    needEquip = realmIpyData.GetNeedEquip()
    if needEquip and len(needEquip) == 4:
        classLV, star, isSuite, color = needEquip
        equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
        for place in ChConfig.EquipPlace_Base:
            ipyData = IpyGameDataPY.GetIpyGameData('EquipPlaceIndexMap', classLV, place)
            if not ipyData:
                return
            gridIndex = ipyData.GetGridIndex()
            curEquip = equipPack.GetAt(gridIndex)
            if not ItemCommon.CheckItemCanUse(curEquip):
                return
            curPartStar = ChEquip.GetEquipPartStar(curPlayer, gridIndex)
            if curPartStar < star:
                return
            if isSuite and not curEquip.GetSuiteID():
                return
            if curEquip.GetItemColor() < color:
                return
    
    needItemID = realmIpyData.GetNeedItemID()
    needItemCount = realmIpyData.GetNeedItemCnt()
    # Ö§³Ö²»ÏûºÄÎïÆ·Éý¼¶
    if needItemID > 0 and needItemCount > 0:
        curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(needItemID, curPack, needItemCount)
        if not hasEnough:
            GameWorld.DebugLog("¶É½Ù¿ªÆô, ²ÄÁϲ»×ã! Lv=%s, needItemID=%s,needItemCount=%s" 
                               % (curRealmLV, needItemID, needItemCount))
            return
        #¿Û³ýÎïÆ·
        ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, needItemCount, True, "Realm")
    
    DoRealmLVUpLogic(curPlayer)
    return
 
# ÌáÉý1¼¶¾³½ç¼Óµã
def __DoRealmLVUpAddPoint(curPlayer):
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_AddPoint):
        # Î´¿ªÆôǰ²»¿É¼Óµã£¬ÒòΪDoAddPointOpen»áÒ»´ÎÐÔ²¹Æë£¬±ÜÃâÒâÍâÇé¿ö¶à¼ÓÁ˵ãÊý
        return
 
    curFreePoint = curPlayer.GetFreePoint()
    addPoint = IpyGameDataPY.GetFuncCfg("LVUPAddPoint", 3)
    if addPoint != 0:
        setFreePoint = curFreePoint + addPoint
        DataRecordPack.DR_Freepoint(curPlayer, "RealmLVUp", addPoint)
        curPlayer.SetFreePoint(setFreePoint)
 
    return
 
 
def DoRealmLVUpLogic(curPlayer, needSys=True):
    curRealmLV = curPlayer.GetOfficialRank()
    nextRealmLv = curRealmLV + 1
    GameWorld.DebugLog('    Éý¼¶¾³½çnextRealmLv=%s' % nextRealmLv)
    nextRealmIpyData = GetRealmIpyData(nextRealmLv)
    if not nextRealmIpyData:
        return
    
    curPlayer.SetOfficialRank(nextRealmLv)
    # ÌáÉý1¼¶¾³½ç¼Óµã
    __DoRealmLVUpAddPoint(curPlayer)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmFBIsOpen, 0)
    if needSys:
        addBuffID = nextRealmIpyData.GetBuffID()
        if addBuffID:
            PlayerControl.WorldNotify(0, 'BigRealmUpSuccess', [curPlayer.GetName(), curPlayer.GetID(), nextRealmLv, IpyGameDataPY.GetFuncCfg('RadioExpRealm')])
            msgStr = str(addBuffID)
            GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'RealmUpAddBuff', msgStr, len(msgStr))
        else:
            PlayerControl.WorldNotify(0, 'RealmUpSuccess', [curPlayer.GetName(), curPlayer.GetID(), nextRealmLv])
            
    if SkillCommon.GivePlayerSkillByJobSkill(curPlayer, nextRealmIpyData.GetLearnSkillIDInfo()):
        PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEffSet(curPlayer)
        
    addFreePoint = nextRealmIpyData.GetAddFreePoint()
    if addFreePoint:
        updFreePoint = curPlayer.GetFreePoint() + addFreePoint
        curPlayer.SetFreePoint(updFreePoint)
        GameWorld.DebugLog("    addFreePoint=%s,updFreePoint=%s" % (addFreePoint, updFreePoint))
        
    RefreshOfficialAttr(curPlayer)
    GameFuncComm.DoFuncOpenLogic(curPlayer)
    SyncRealmFBState(curPlayer)
    #¸üÐÂÐÞΪËÙÂÊ
    UpdateRealmExp(curPlayer, False, True)
    NotifyRealmExpInfo(curPlayer)
    #¾³½çÌáÉý³É¾Í
    PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_RealmlvUp, nextRealmLv)
    PlayerTongTianLing.AddTongTianTaskValue(curPlayer, ChConfig.TTLTaskType_RealmUp, 1)
    #¸üÐÂÅÅÐаñ
    PlayerBillboard.UpdateRealmBillboard(curPlayer)
    # ¼Ç¼¿ª·þ»î¶¯
    #OpenServerCampaign.UpdOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_RealmLV, nextRealmLv)
    EventShell.EventRespons_RealmUp(curPlayer, nextRealmLv)
    #Á÷Ïò
    DataRecordPack.DR_RealmLVUp(curPlayer, nextRealmLv)
    return True
 
 
def DologicDujieFBPass(curPlayer, realmLV, star):
    #¶É½Ùͨ¹ýºó´¦Àí
    realmIpyData = GetRealmIpyData(realmLV)
    if not realmIpyData:
        return
    #DoRealmLVUpLogic(curPlayer)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmFBIsOpen, 1)
    SyncRealmFBState(curPlayer)
    
    return
 
 
#// A5 21 ¾³½çÐÞΪ³ØÌáÈ¡ #tagCMTakeOutRealmExp
#
#struct    tagCMTakeOutRealmExp
#{
#    tagHead        Head;
#};
def OnTakeOutRealmExp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetID()
    curTotalRealmExp = UpdateRealmExp(curPlayer, False)
    if curTotalRealmExp <= 0:
        GameWorld.DebugLog('¾³½çÐÞΪ³ØÌáÈ¡ Ã»Óо­Ñé¿ÉÌáÈ¡', playerID)
        return
    playerControl = PlayerControl.PlayerControl(curPlayer)
    playerControl.AddExp(curTotalRealmExp)
    PlayerControl.NotifyCode(curPlayer, 'TakeOutRealmExp', [curTotalRealmExp])
    #
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, int(time.time()))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExp, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpPoint, 0)
 
    NotifyRealmExpInfo(curPlayer)
    return
 
 
def UpdateRealmExp(curPlayer, isNotify=True, isRealmLVUP=False):
    ##¸üо³½çÐÞΪ³Ø
    curRealmLV = curPlayer.GetOfficialRank()
    ipyData = GetRealmIpyData(curRealmLV)
    if not ipyData:
        return 0
    if not ipyData.GetExpRate():
        return 0
    curTime = int(time.time())
    beginTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBeginTime)
    if not beginTime:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, curTime)
        return 0
    if isRealmLVUP:
        ipyData = GetRealmIpyData(curRealmLV-1)
            
    curRealmExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExp)
    curRealmExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpPoint)
    curTotalExp = curRealmExpPoint * ChConfig.Def_PerPointValue + curRealmExp
    if curTotalExp >= ipyData.GetExpLimit():
        return curTotalExp
    
    passSeconds = curTime - beginTime
    if passSeconds <= 0:
        return curTotalExp
    perRealmExpTime = IpyGameDataPY.GetFuncCfg('RealmExpTime')
    curExpRate = ipyData.GetExpRate()
    #buffÔö¼ÓµÄ¶îÍâ¾­Ñé
    buffRemainTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)
    buffAddRate = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffAddRate)
    
    buffTime = min(buffRemainTime, passSeconds)
    
    addExp = buffTime /perRealmExpTime*(curExpRate*(ShareDefine.Def_MaxRateValue + buffAddRate)/ShareDefine.Def_MaxRateValue) + (passSeconds-buffTime)/perRealmExpTime*curExpRate
    #addExp = passSeconds / perRealmExpTime * curExpRate
    if addExp <= 0:
        return curTotalExp
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, curTime)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffRemainTime, buffRemainTime - buffTime)
    
    updTotalExp = min(curTotalExp + addExp, ipyData.GetExpLimit())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExp, updTotalExp % ChConfig.Def_PerPointValue)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpPoint, updTotalExp / ChConfig.Def_PerPointValue)
    #֪ͨ
    if isNotify:
        NotifyRealmExpInfo(curPlayer)
    return updTotalExp
 
def AddRealmExpBuffTime(curPlayer, addTime, addRate):
    ##Ôö¼Ó»áÁ鵤BUFFʱ¼ä
    UpdateRealmExp(curPlayer, False)
    
    remainTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffRemainTime, remainTime + addTime)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffAddRate, addRate)
    NotifyRealmExpInfo(curPlayer)
    return
 
def NotifyRealmExpInfo(curPlayer):
    ##֪ͨÐÞΪ³ØÐÅÏ¢
    sendPack = ChPyNetSendPack.tagMCRealmExpInfo()
    sendPack.BeginTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBeginTime)
    sendPack.BuffTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)
    sendPack.BuffAddRate = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffAddRate)
    sendPack.CurExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExp)
    sendPack.CurExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpPoint)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return