xdh
2019-03-02 0f297a5b66b91751d8342624db871efeca7ed94e
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
407
408
409
410
411
412
413
414
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerGodWeapon
#
# @todo:Éñ±ø
# @author alee
# @date 2017-07-20
# @version 1.0
#
# ÏêϸÃèÊö: Éñ±ø
#
#---------------------------------------------------------------------
#"""Version = 2017-07-20 16:00"""
#---------------------------------------------------------------------
 
import GameWorld
import EventShell
import ChConfig
import PlayerControl
import ItemCommon
import IPY_GameWorld
import ChPyNetSendPack
import NetPackCommon
import PlayerSuccess
import ShareDefine
import SkillShell
import DataRecordPack
import GameFuncComm
import SkillCommon
import BuffSkill
import PlayerWeekParty
#import EventReport
import IpyGameDataPY
import PassiveBuffEffMng
import OpenServerCampaign
 
import random
 
Def_GodWeaponType_HP = 1  # ÉúÃüÉñ±øÀàÐÍ
Def_GodWeaponType_Atk = 2  # ¹¥»÷Éñ±øÀàÐÍ
Def_GodWeaponType_SuperHit = 3  # ±©»÷Éñ±øÀàÐÍ
Def_GodWeaponType_Def = 4  # »¤¶ÜÉñ±øÀàÐÍ
 
## ÉñÆ÷¹¦ÄܵǼ´¦Àí
#  @param curPlayer Íæ¼Ò
#  @return None
def OnLogin(curPlayer):
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):
        return
    Sync_GodWeaponLVInfo(curPlayer)
    
    return
 
def SetGodWeaponLV(curPlayer, weaponType, lv):
    ## ÉèÖÃÉñ±øµÈ¼¶£¬Í¬²½ÉèÖó¡¾°Éñ±øµÈ¼¶
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % weaponType, lv)
            
    totalLV = GetGodWeaponTotalLV(curPlayer)
    # ¿ª·þ»î¶¯Êý¾Ý
    OpenServerCampaign.UpdOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_GodWeaponLV, totalLV)
    PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_GodWeapon, totalLV, False, True)
    return
 
def GetGodWeaponTotalLV(curPlayer):
    ##»ñÈ¡Éñ±ø×ܵȼ¶
    totalLV = 0
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType()
    for gwType in xrange(1, maxType + 1):
        totalLV += curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % gwType)
    return totalLV
 
## ÉñÆ÷¿ªÆô
#  @return: ÊÇ·ñ¼¤»î³É¹¦
def DoGodWeaponOpen(curPlayer):
    # Ä¬Èϼ¤»î1¼¶µÄÀàÐÍ
    for i in IpyGameDataPY.GetFuncEvalCfg('GodWeaponActive'):
        SetGodWeaponLV(curPlayer, i, 1)
        PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, 1, [i])
    Sync_GodWeaponLVInfo(curPlayer)
    return True
 
 
## Ë¢ÐÂÉñ±øÊôÐÔ
def RefreshGodWeaponAttr(curPlayer):
    CalcGodWeaponAttr(curPlayer)
    # ²»Á¢¼´Ë¢ÐÂ
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
## ¼ÆËãÊôÐÔ
#  @param curPlayer Íæ¼Ò
#  @param allAttrList ÊôÐÔÁбí
#  @return None
def CalcGodWeaponAttr(curPlayer):
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):
        return
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType()
 
    fightPowerEx = 0  # ¶îÍâÔö¼ÓµÄÕ½Á¦
    allAttrList = [{} for i in range(4)]
    for gwType in xrange(1, maxType + 1):
        # ÒòΪÉñ±ø½âËøÌõ¼þ×öÁ˵÷Õû£¬ÓÉ֮ǰµÄ0~1½×½âËø¸ÄΪÓÉǰÖÃÉñ±øÀàÐ͵ȼ¶½âËø£¬Ä¬ÈϽâËøºóΪ1½×
        # Îª¼æÈÝÀϺţ¬Ë¢ÊôÐÔʱֻҪÅжϵȼ¶ÊÇ·ñ´óÓÚ0£¬²»¹ÜÊÇ·ñ½âËø£¬ÐºŽâËøÓÉÉñ±øÉý¼¶µÄʱºò½øÐнâËø
        attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % gwType)
        if not attrLV:
            continue
        godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', gwType, attrLV)
        if not godWeaponData:
            continue
        attrTypeList, attrValueList =  godWeaponData.GetAttrType(), godWeaponData.GetAttrNum()
        for i, attrID in enumerate(attrTypeList):
            PlayerControl.CalcAttrDict_Type(attrID, attrValueList[i], allAttrList)
        
        fightPowerEx += IpyGameDataPY.GetFuncEvalCfg('MagicExterior').get(str(gwType), 0)
        #ÌØÐ§µÈ¼¶ÊôÐÔÕ½Á¦
        godWeaponEffectData = IpyGameDataPY.InterpolationSearch("GodWeaponEffect", "Level", attrLV, {"GWType":gwType})
        if godWeaponEffectData:
            for attrID, attrValue in godWeaponEffectData.GetAttr().items():
                PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
            fightPowerEx += godWeaponEffectData.GetFightPower()
        
        
    # ¸½¼ÓÕ½Á¦
    curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_GodWeapon, fightPowerEx)
    GameWorld.DebugLog("Éñ±øÊôÐÔ£º%s" % allAttrList)
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_GodWeapon, allAttrList)   
    return
 
#---------------------------------------------------------------------------------------------------
#// A5 56 Éñ±ø¼¤»î #tagCMGodWeaponActivate
#
#struct    tagCMGodWeaponActivate
#{
#    tagHead        Head;
#    DWORD        WeaponType;    // Éñ±øÀàÐÍ
#};
def OnGodWeaponActivate(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    weaponType = clientData.WeaponType
 
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % weaponType):
        GameWorld.DebugLog("ÒѾ­½âËøµÄÉñ±ø!weaponType=%s" % weaponType)
        return
    
    # Âú×ãÍæ¼ÒµÈ¼¶»òÕßǰÖÃÉñ±øµÈ¼¶¿É½âËø
    if __GWCheckPlayerLV(curPlayer, weaponType) or __GWCheckOtherGWLV(curPlayer, weaponType):
            
        SetGodWeaponLV(curPlayer, weaponType, 1)
        RefreshGodWeaponAttr(curPlayer)
        GameWorld.DebugLog("½âËøÉñ±ø: weaponType=%s" % weaponType)
        Sync_GodWeaponLVInfo(curPlayer, weaponType)
    return
 
# Éñ±ø¼¤»îÐè2´ÎÅжϵȼ¶ {2:100, 4:100}
def __GWCheckPlayerLV(curPlayer, weaponType):
    godWeaponUnlockDict = IpyGameDataPY.GetFuncEvalCfg("GodWeaponActive", 3, {})
    if str(weaponType) not in godWeaponUnlockDict:
        GameWorld.DebugLog("¸ÃÉñ±ø²»ÄܽâËø!weaponType=%s" % weaponType)
        return False
    return curPlayer.GetLV() >= godWeaponUnlockDict[str(weaponType)]
 
# Éñ±ø¼¤»îÐèÅжÏǰÖÃÉñ±øµÈ¼¶
def __GWCheckOtherGWLV(curPlayer, weaponType):
    godWeaponUnlockDict = IpyGameDataPY.GetFuncEvalCfg("GodWeaponActive", 2, {})
    if str(weaponType) not in godWeaponUnlockDict:
        GameWorld.DebugLog("¸ÃÉñ±ø²»ÄܽâËø!weaponType=%s" % weaponType)
        return False
    conditionList = godWeaponUnlockDict[str(weaponType)]
    
    for needType, needLV in conditionList:
        needTypeLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % needType)
        if needTypeLV < needLV:
            GameWorld.DebugLog("ËùÐèǰÖÃÉñ±øµÈ¼¶²»×㣬ÎÞ·¨½âËø£¡weaponType=%s,needType=%s,needLV=%s > needTypeLV(%s)" 
                               % (weaponType, needType, needLV, needTypeLV))
            return False
        
    return True
 
#===============================================================================
#// A5 55 Éñ±øÉý¼¶ #tagCMGodWeaponPlus
#
#struct    tagCMGodWeaponPlus
#{
#    tagHead        Head;
#    DWORD        WeaponType;    // Éñ±øÀàÐÍ
#    DWORD        ItemID;        //ÏûºÄµÄÎïÆ·ID
#    BYTE        ItemCount;        //ÏûºÄ¸öÊý£¬Ä¬ÈÏ1
#    BYTE        IsAutoBuy;        //ÊÇ·ñ×Ô¶¯¹ºÂò£¬Ä¬ÈÏ0
#};
#===============================================================================
def OnPlusGodWeapon(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    weaponType = clientData.WeaponType
    useItemID = clientData.ItemID
    useItemCount = max(1, clientData.ItemCount)
    isAutoBuy = clientData.IsAutoBuy
    
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):
        #µÈ¼¶²»×ã
        return
    
    #1.ÅжϱíÖÐÓÐû´ËÀàÐÍ£¬2.ÊÇ·ñÂú¼¶£¬3.ÅжÏÊÇ·ñÓÐÎïÆ·
    attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % weaponType)
    if not attrLV and Def_GodWeaponType_SuperHit != weaponType:
        GameWorld.DebugLog("Éñ±øÎ´½âËø£¬ÎÞ·¨Éý¼¶£¡weaponType=%s,attrLV=%s" % (weaponType, attrLV))
        return
      
    beforeAttrLV = attrLV   # ÓÃÓÚÌáʾ
    godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV)
    if not godWeaponData:
        GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV))
        return
    
    totalExp = godWeaponData.GetExp()
    if totalExp == 0:
        #Âú¼¶
        return
    
    #ÑéÖ¤ÊÇ·ñÖ¸¶¨µÄÎïÆ·ID
    if useItemID not in IpyGameDataPY.GetFuncEvalCfg("GodWeapon%s"%weaponType):
        return
    
    itemData = GameWorld.GetGameData().GetItemByTypeID(useItemID)
    if not itemData:
        return
    effect = ItemCommon.GetItemEffectByEffectID(itemData, ChConfig.Def_Item_Eff_GodWeaponExp)
    if not effect:
        GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓо­ÑéÖµ'%useItemID)
        return
    itemExp = effect.GetEffectValue(0)
    if not itemExp:
        GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓо­ÑéÖµ'%useItemID)
        return
    
    goldExpTotal = 0
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, useItemID, useItemCount)
    lackCount = max(0, useItemCount - (bindCnt + unBindCnt))
    if lackCount > 0:
        if not isAutoBuy:
            GameWorld.DebugLog("Éñ±øÉý¼¶ÏûºÄ²»×ã!useItemID=%s,useItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCount=%s" 
                               % (useItemID, useItemCount, bindCnt, unBindCnt, lackCount))
            return
        godMagicExpDict = IpyGameDataPY.GetFuncEvalCfg("GodMagicExp", 1, {})
        if str(weaponType) not in godMagicExpDict:
            return
        costGold, goldExp = godMagicExpDict[str(weaponType)]
        lackCost = costGold * lackCount
        goldExpTotal = goldExp * lackCount
        #lackCost = ItemCommon.GetAutoBuyItemNeedGold({useItemID:lackCount})
        if lackCost <= 0:
            return
        
        infoDict = {ChConfig.Def_Cost_Reason_SonKey:useItemID, "lackCount":lackCount}
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, lackCost,
                                      ChConfig.Def_Cost_GodWeapon, infoDict, lackCount):
            return
        
    delUseItemCount = useItemCount - lackCount
    # ¿Û³ýÏûºÄ
    if delUseItemCount:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delUseItemCount, ChConfig.ItemDel_GodWeapon)
        
    addTotalExp = itemExp * delUseItemCount + goldExpTotal
    befExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % weaponType)
    curExp = befExp + addTotalExp
    GameWorld.DebugLog("Ö´ÐÐÉñ±øÉý¼¶: weaponType=%s,beforeAttrLV=%s,befExp=%s,addTotalExp=%s(%s*%s+%s),curExp=%s" 
                       % (weaponType, beforeAttrLV, befExp, addTotalExp, itemExp, delUseItemCount, goldExpTotal, curExp))
    
    isLVUP = False
    
    # °²È«ÎªÖ÷²»ÓÃwhile
    for _ in xrange(100):
        if curExp < totalExp:
            break
        godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV+1)
        if not godWeaponData:
            GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV))
            break
        
        GameWorld.DebugLog("    Éñ±øÉý¼¶: attrLV=%s,needExp=%s" % (attrLV, totalExp))
        curExp = curExp - totalExp
        attrLV += 1
        isLVUP = True
        GodWeaponLVUP(curPlayer, godWeaponData, attrLV)
        
        totalExp = godWeaponData.GetExp()
        if totalExp == 0:
            curExp = 0
            #Âú¼¶
            break
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponExp % weaponType, curExp)
    if isLVUP:
        SetGodWeaponLV(curPlayer, weaponType, attrLV)
        GameWorld.DebugLog("Éñ±øÉý¼¶½á¹û: attrLV=%s,curExp=%s" % (attrLV, curExp))
        RefreshGodWeaponAttr(curPlayer)
        #xÉñÆ÷´ïµ½X¼¶³É¾Í
        PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, attrLV, [weaponType])
        if beforeAttrLV == 0:
            # ½â·â֪ͨ
            sysMark = IpyGameDataPY.GetFuncEvalCfg('GodWeaponSys', 1, {}).get(weaponType, 'GetGodWeapon')
            PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), weaponType])
            
        #{1:[100,200,300,400],2:[100,200,300,400],3:[100,200,300,400]}
        #=======================================================================
        # notifyDict = IpyGameDataPY.GetFuncEvalCfg('GodLv', 1, {})
        # if weaponType in notifyDict:
        #    for notifyLV in notifyDict[weaponType]:
        #        if beforeAttrLV < notifyLV and attrLV >= notifyLV:
        #            PlayerControl.WorldNotify(0, 'GodWeaponLv', [curPlayer.GetName(), weaponType, notifyLV])
        #=======================================================================
                
        # Éñ±øÌØÐ§¼¤»î¹ã²¥
        godWeaponEffectData = IpyGameDataPY.GetIpyGameDataByCondition('GodWeaponEffect', {'GWType':weaponType, "Level":attrLV}, False, False)
        if godWeaponEffectData:
            PlayerControl.WorldNotify(0, godWeaponEffectData.GetNotifyCode(), [curPlayer.GetName(), attrLV])
        
        totalExp = godWeaponData.GetExp()
        
        
    Sync_GodWeaponLVInfo(curPlayer, weaponType)
    #ÈÎÎñ
    EventShell.EventRespons_PlusGodWeapon(curPlayer)
    return
 
#Éñ±øÉý¼¶´¥·¢ÆäËû¹¦ÄÜ£º¼¼ÄÜ
def GodWeaponLVUP(curPlayer, godWeaponData, attrLV):
    skillID = godWeaponData.GetSkillID()
    
    if skillID:
        if __GiveGodWeaponSkill(curPlayer, skillID):
            sysMark = godWeaponData.GetSysMark()
            if sysMark:
                PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), attrLV, skillID])
            return skillID
    return
    
 
 
 
## Í¬²½ÉñÆ÷µÈ¼¶
#  @param curPlayer
#  @param godWeaponId ÉñÆ÷ID
#  @return None
def Sync_GodWeaponLVInfo(curPlayer, godWeaponID=0):
    sendPack = ChPyNetSendPack.tagMCGodWeaponLVList()
    sendPack.Clear()
        
    sendPack.WeaponInfoList = []
 
    if godWeaponID <= 0:
#        weaponStateStr = bin(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponState))[::-1][:-2]
#        for i in range(0, len(weaponStateStr)):
#            if weaponStateStr[i] == '0':
#                #ÕÒ³ö¼¤»îµÄÉñ±ø
#                continue
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType()
        for i in xrange(1, maxType + 1):
            weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo()
            weaponInfo.Clear()
            weaponInfo.WeaponType = i
            weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % i)
            weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % i)
            sendPack.WeaponInfoList.append(weaponInfo)
    else:
        weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo()
        weaponInfo.Clear()
        weaponInfo.WeaponType = godWeaponID
        weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % godWeaponID)
        weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % godWeaponID)
        sendPack.WeaponInfoList.append(weaponInfo)
    
    sendPack.WeaponNum = len(sendPack.WeaponInfoList)
    NetPackCommon.SendFakePack(curPlayer, sendPack)  
    return
 
 
 
def __GiveGodWeaponSkill(curPlayer, skillResId):
    # ÉñÆ÷ѧϰ¼¼ÄÜ
    skillManager = curPlayer.GetSkillManager()
    if skillManager.FindSkillBySkillTypeID(skillResId):
        GameWorld.DebugLog("godSkill() have learned skill(%s)" % skillResId)
        return
    
    skillData = GameWorld.GetGameData().FindSkillByType(skillResId, 1)
    if skillData == None:
        GameWorld.DebugLog("godSkill() hasn't find skill(%s)" % skillResId)
        return
    if not SkillShell.CheckLearnSkillCondition(curPlayer, skillData):
        GameWorld.DebugLog("godSkill() learn skill(%s) condition isn't enough" % skillResId)
        return
    
    skillManager.LVUpSkillBySkillTypeID(skillResId)
    #PlayerControl.NotifyCode(curPlayer, "Skill_andyshao_31379", [skillResId])
    GameWorld.DebugLog("godSkill() skill(%s) success!" % skillResId)
    DataRecordPack.DR_LearnORUPSkill(curPlayer, skillResId, 0)
    
    #if SkillCommon.isPassiveSkill(skillData):
    #    buffType = SkillCommon.GetBuffType(skillData)
    #    BuffSkill.DoAddBuff(curPlayer, buffType, skillData, GameWorld.GetGameWorld().GetTick(), [], curPlayer)
    PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, skillResId)
    PlayerControl.PlayerControl(curPlayer).RefreshSkillFightPowerEx(skillResId, 0)
    return True