hch
2018-09-20 a8d160566fcad719e98b6ac1ad6354fb6ddb1dc5
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerDogz
#
# @todo:ÉñÊÞϵͳ
# @author hxp
# @date 2018-08-20
# @version 1.0
#
# ÏêϸÃèÊö: ÉñÊÞϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2018-08-20 17:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ItemCommon
import ShareDefine
import PlayerControl
import ChPyNetSendPack
import NetPackCommon
import IPY_GameWorld
import IpyGameDataPY
import ChConfig
import ChEquip
import PassiveBuffEffMng
import SkillCommon
import SkillShell
 
'''
ÉñÊÞ±àºÅ: 1~20£¬ÉÏÏߺ󲻿ÉÐÞ¸Ä
ÉñÊÞ×°±¸Î»: 101~105 ÎïÆ·±íÖеÄ×°±¸Î»ÅäÖÃ
ÉñÊÞ×°±¸ÀàÐÍ£º119~123£¬²ß»®Ëµ´òËÀ²»»áÔÙ¼ÓÀàÐÍÁË£¬¹Ì¶¨5¸öÉñÊÞ×°±¸ÀàÐÍ
 
ÉñÊÞÎïÆ·±³°ü£¨ÀàÐÍ32,ÔÝ¿ª·Å100¸ñ£©£¬´æ·ÅÉñÊÞ×°±¸(ÀàÐÍ119~123)£¬¼°Ç¿»¯²ÄÁÏ£¨ÀàÐÍ70£©£¬
ÉñÊÞ×°±¸±³°ü£¨ÀàÐÍ33,ÔÝ¿ª·Å100¸ñ£©£¬ËùÓÐÉñÊÞ¹²Óã¬Ã¿Ö»ÉñÊÞ5¸ñ£¬(¸ñ×ÓË÷Òý/5)+1=¶ÔÓ¦ÉñÊÞ±àºÅ£¬(¸ñ×ÓË÷Òý%5)+100+1=¶ÔÓ¦ÉñÊÞ×°±¸Î»
'''
 
DogzEquipCount = 5 # ÉñÊÞ×°±¸Î»ÊýÁ¿£¬¹Ì¶¨5¸ö£¬²ß»®Ëµ´òËÀÒ²²»¸Ä
 
def GetDogzEquipPlaceIndex(equipPlace):
    ## »ñÈ¡ÉñÊÞ×°±¸Î»¶ÔÓ¦µÄË÷Òý
    return equipPlace - 1 - 100
 
def GetDogzEquipPackIndex(dogzID, equipPlaceIndex):
    ## »ñÈ¡ÉñÊÞ×°±¸ÔÚÉñÊÞ×°±¸±³°üÖеĹ̶¨Î»ÖÃË÷Òý
    return (dogzID - 1) * DogzEquipCount + equipPlaceIndex
 
def GetDogzIsHelpFight(curPlayer, dogzID):
    ## ÉñÊÞÊÇ·ñÖúս״̬
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzID - 1)
 
def SetDogzIsHelpFight(curPlayer, dogzID, isFight):
    ## ÉèÖÃÉñÊÞÊÇ·ñÖúս״̬
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzID - 1, 1 if isFight else 0)
    Sync_DogzHelpbattleState(curPlayer, dogzID, isFight)
    
    # ÉèÖóɹ¦ºó²ÅÄÜË¢¼¼ÄÜ
    PassiveBuffEffMng.PlayerDogzSkill(curPlayer)
    return
 
 
def OnPlayerLogin(curPlayer):
    
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount):
        Sync_DogzInfo(curPlayer)
        
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetDogzCount()):
        ipyData = ipyDataMgr.GetDogzByIndex(i)
        if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, i):
            Sync_DogzHelpbattleState(curPlayer, ipyData.GetDogzID(), 1)
            
    return
 
#// A5 C0 ÉñÊÞ´©´÷×°±¸ #tagCMDogzEquipItem
#
#struct    tagCMDogzEquipItem
#
#{
#    tagHead        Head;
#    BYTE        DogzID;    // ÉñÊÞID
#    BYTE        EquipIndex;    //ÉñÊÞ×°±¸ËùÔÚÉñÊÞ±³°üË÷Òý
#};
def OnDogzEquipItem(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    dogzID = clientData.DogzID
    equipIndex = clientData.EquipIndex
    
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)
    if not ipyData:
        return
    
    dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)
    curEquip = dogzItemPack.GetAt(equipIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        GameWorld.DebugLog("ÎïÆ·²»¿ÉÓÃ: equipIndex=%s" % equipIndex)
        return
    if not ItemCommon.GetIsDogzEquip(curEquip):
        GameWorld.DebugLog("·ÇÉñÊÞ×°±¸: equipIndex=%s" % equipIndex)
        return
    
    equipPlace = curEquip.GetEquipPlace()
    equipPlaceIndex = GetDogzEquipPlaceIndex(equipPlace)
    equipPlaceColorList = ipyData.GetEquipPlaceColorList()
    if equipPlaceIndex < 0 or equipPlaceIndex >= len(equipPlaceColorList):
        GameWorld.ErrLog("ÉñÊÞ×°±¸Î»Òì³£: equipPlace=%s,equipPlaceIndex=%s" % (equipPlace, equipPlaceIndex))
        return
    
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)
    equipPackIndex = GetDogzEquipPackIndex(dogzID, equipPlaceIndex)
    if equipPackIndex < 0 or equipPackIndex >= dogzEquipPack.GetCount():
        GameWorld.ErrLog("ÉñÊÞ×°±¸±³°üË÷ÒýÒì³£: dogzID=%s,equipPlace=%s,equipPackIndex=%s" % (dogzID, equipPlace, equipPackIndex))
        return
    
    equipColor = curEquip.GetItemColor()
    limitColor = equipPlaceColorList[equipPlaceIndex]
    if equipColor < limitColor:
        GameWorld.Log("ÉñÊÞ×°±¸Î»´©´÷ÑÕÉ«ÏÞÖÆ£ºdogzID=%s,equipPlaceIndex=%s,limitColor=%s > equipColor=%s" 
                      % (dogzID, equipPlaceIndex, limitColor, equipColor), playerID)
        return
    
    destEquip = dogzEquipPack.GetAt(equipPackIndex)
    isOK = ItemCommon.DoLogicSwitchItem(curPlayer, curEquip, destEquip, ShareDefine.rptDogzEquip)
    if not isOK:
        return
    
    # Öúս״̬»»×°ÐèҪˢÊôÐÔ
    if GetDogzIsHelpFight(curPlayer, dogzID):
        RefreshDogzAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
        
    return
 
 
#// A5 C1 ÉñÊÞжÏÂ×°±¸ #tagCMDogzUnEquipItem
#
#struct    tagCMDogzUnEquipItem
#
#{
#    tagHead        Head;
#    BYTE        DogzID;    // ÉñÊÞID
#    BYTE        EquipPlace;    //жϵÄ×°±¸Î», 0´ú±íжÏÂÈ«²¿
#};
def OnDogzUnEquipItem(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    dogzID = clientData.DogzID
    equipPlace = clientData.EquipPlace
    
    if equipPlace and equipPlace not in ShareDefine.DogzEquipPlace:
        GameWorld.DebugLog("·ÇÉñÊÞ×°±¸Î»£¬ÎÞ·¨Ð¶ÏÂ!equipPlace=%s" % equipPlace, playerID)
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)
    if not ipyData:
        return
    
    # Ð¶ÏÂÈ«²¿
    if equipPlace == 0:
        unEquipIndexList = [] # ÐèÒªÍÑϵÄÉñÊÞ×°±¸Ë÷Òý
        dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)
        equipPackCount = dogzEquipPack.GetCount()
        startIndex = (dogzID - 1) * DogzEquipCount
        for i in range(startIndex, startIndex + DogzEquipCount):
            if i < 0 or i >= equipPackCount:
                return
            curItem = dogzEquipPack.GetAt(i)            
            if not curItem.IsEmpty():
                unEquipIndexList.append(i)
                
        if not unEquipIndexList:
            GameWorld.DebugLog("ûÓд©´÷ÉñÊÞ×°±¸!dogzID=%s" % dogzID, playerID)
            return
        
        unEquipCount = len(unEquipIndexList)
        emptyIndexList = []
        
        dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)
        for i in xrange(dogzItemPack.GetCount()):
            curItem = dogzItemPack.GetAt(i)
            if curItem.IsEmpty():
                emptyIndexList.append(i)
                if len(emptyIndexList) >= unEquipCount:
                    break
                
        if len(emptyIndexList) < unEquipCount:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [ShareDefine.rptDogzItem])
            #GameWorld.DebugLog("ÉñÊÞ±³°ü¿Õ¸ñ²»×㣬ÎÞ·¨ÍÑÏÂËùÓÐ×°±¸")
            return
        
        for i in xrange(unEquipCount):
            ItemCommon.DoLogicSwitchItemEx(curPlayer, ShareDefine.rptDogzEquip, ShareDefine.rptDogzItem,
                                           unEquipIndexList[i], emptyIndexList[i])
            
    else:
        equipPackIndex = GetDogzEquipPackIndex(dogzID, GetDogzEquipPlaceIndex(equipPlace))
        emptyIndex = ItemCommon.GetEmptyIndexInPack(curPlayer, ShareDefine.rptDogzItem)
        
        if not ItemCommon.DoLogicSwitchItemEx(curPlayer, ShareDefine.rptDogzEquip, ShareDefine.rptDogzItem, equipPackIndex, emptyIndex):
            GameWorld.DebugLog("ÉñÊÞжÏÂ×°±¸Ê§°Ü: dogzID=%s,equipPlace=%s" % (dogzID, equipPlace), playerID)
            return
    
    # Öúս״̬»»×°ÐèҪˢÊôÐÔ
    if GetDogzIsHelpFight(curPlayer, dogzID):
        SetDogzIsHelpFight(curPlayer, dogzID, False) # ÒòΪÍÑÏÂÁË״̬£¬ËùÒÔ±ØÐëÉèÖÃΪ·ÇÖúս״̬
        RefreshDogzAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
        
    return
 
 
#// A5 C2 ÉñÊÞ±ä¸üÖúս״̬ #tagCMDogzBattleStateChange
#
#struct    tagCMDogzBattleStateChange
#
#{
#    tagHead        Head;
#    BYTE        DogzID;    // ÉñÊÞID
#    BYTE        BatteState;    //Öúս״̬£¬0-Õٻأ¬1-ÖúÕ½
#};
def OnDogzBattleStateChange(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    dogzID = clientData.DogzID
    batteState = clientData.BatteState
    
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)
    if not ipyData:
        return
    
    curState = GetDogzIsHelpFight(curPlayer, dogzID)
    if curState == batteState:
        GameWorld.DebugLog("ÉñÊÞÒѾ­ÊǸÃ״̬£¬ÎÞÐè±ä¸üÖúս״̬! dogzID=%s,batteState=%s,curState=%s" 
                           % (dogzID, batteState, curState), playerID)
        return
    
    # ±äΪÖúս״̬Ðè¼ì²éÉñÊÞ×°±¸ÊÇ·ñ´©Âú
    if batteState:
        helpbattleInitCount = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 1)[0]
        helpbattleBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)
        canHelpFightCount = helpbattleInitCount + helpbattleBuyCount
        
        curHelpFightCount = 0
        dogzCount = IpyGameDataPY.IPY_Data().GetDogzCount()
        for i in xrange(dogzCount):
            if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, i):
                curHelpFightCount += 1
                
        if curHelpFightCount >= canHelpFightCount:
            GameWorld.DebugLog("µ±Ç°ÉñÊÞÖúÕ½ÊýÒÑÂú£¬ÎÞ·¨ÖúÕ½!canHelpFightCount=%s <= curHelpFightCount=%s" 
                               % (canHelpFightCount, curHelpFightCount), playerID)
            return
        
        dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)
        equipPackCount = dogzEquipPack.GetCount()
        startIndex = (dogzID - 1) * DogzEquipCount
        for i in range(startIndex, startIndex + DogzEquipCount):
            if i < 0 or i >= equipPackCount:
                return
            curItem = dogzEquipPack.GetAt(i)            
            if curItem.IsEmpty():
                GameWorld.DebugLog("ÉñÊÞÓÐ×°±¸Î´´©´÷£¬ÎÞ·¨ÖúÕ½£¡dogzID=%s,packIndex=%s" % (dogzID, i), playerID)
                return
            
    isFight = True if batteState else False
    GameWorld.DebugLog("ÉñÊÞÖúս״̬±ä¸ü£¡dogzID=%s,isFight=%s" % (dogzID, isFight), playerID)
    SetDogzIsHelpFight(curPlayer, dogzID, isFight)
    RefreshDogzAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
 
#// A5 C3 ÉñÊÞ¹ºÂòÖúսλ #tagCMDogzBuyBatteCount
#
#struct    tagCMDogzBuyBatteCount
#
#{
#    tagHead        Head;
#};
def OnDogzBuyBatteCount(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    
    helpbattleInitCount, helpbattleMaxCount = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 1)
    helpbattleBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)
    curHelpFightCount = helpbattleInitCount + helpbattleBuyCount
    if curHelpFightCount >= helpbattleMaxCount:
        GameWorld.DebugLog("Òѳ¬¹ý×î´óÉñÊÞÖúÕ½Êý£¬ÎÞ·¨¹ºÂò£¡curHelpFightCount=%s,helpbattleMaxCount=%s" 
                           % (curHelpFightCount, helpbattleMaxCount), playerID)
        return
    
    needItemID = IpyGameDataPY.GetFuncCfg("DogzAssist", 2)
    needCountList = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 3)
    needCount = needCountList[-1] if helpbattleBuyCount >= len(needCountList) else needCountList[helpbattleBuyCount]
    
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, needItemID)
    if bindCnt + unBindCnt < needCount:
        GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλËùÐèµÀ¾ß²»×ã !needItemID=%s,needCount=%s" % (needItemID, needCount), playerID)
        return
    ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, needCount, "DogzBuyHelpFight")
    
    updBuyCount = helpbattleBuyCount + 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DogzBuyHelpbattleCount, updBuyCount)
    GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλ! updBuyCount=%s" % updBuyCount, playerID)
    
    Sync_DogzInfo(curPlayer)
    return
 
 
#// A5 C4 ÉñÊÞ×°±¸Ç¿»¯ #tagCMDogzEquipPlus
#
#struct    tagCMDogzEquipPlus
#
#{
#    tagHead        Head;
#    BYTE        EquipIndex;    //ÉñÊÞ×°±¸±³°üÖÐË÷Òý
#    BYTE        IndexCount;        //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýµÄÊýÁ¿
#    BYTE        IndexList[IndexCount];    //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýÁбí
#    BYTE        IndexUseCountList[IndexCount];    //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷Òý¶ÔӦʹÓøöÊýÁбí
#    BYTE        IsDouble;        //ÊÇ·ñË«±¶Ç¿»¯
#};
def OnDogzEquipPlus(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    equipIndex = clientData.EquipIndex
    indexList = clientData.IndexList
    indexUseCountList = clientData.IndexUseCountList
    isDouble = clientData.IsDouble
    GameWorld.DebugLog("ÉñÊÞ×°±¸Ç¿»¯: equipIndex=%s,indexList=%s,indexUseCountList=%s,isDouble=%s" 
                       % (equipIndex, indexList, indexUseCountList, isDouble), playerID)
    
    if len(indexList) != len(indexUseCountList):
        GameWorld.DebugLog("    Ö¸¶¨ÏûºÄµÄ¸öÊýÊý¾Ý³¤¶È´íÎó£¡")
        return
    
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)
    curEquip = dogzEquipPack.GetAt(equipIndex)
    if not ItemCommon.CheckItemCanUse(curEquip) or not ItemCommon.GetIsDogzEquip(curEquip):
        GameWorld.DebugLog("    ·ÇÉñÊÞ×°±¸£¬ÎÞ·¨Ç¿»¯£¡equipIndex=%s,itemID=%s" 
                           % (equipIndex, curEquip.GetItemTypeID()), playerID)
        return
    
    equipColor = curEquip.GetItemColor()
    colorPlusMaxLVDict = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 4) # {ÑÕÉ«:µÈ¼¶ÉÏÏÞ, ...}
    if equipColor not in colorPlusMaxLVDict:
        return
    maxPlusLV = colorPlusMaxLVDict[equipColor]
    
    equipPlace = curEquip.GetEquipPlace()
    curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)
    curPlusExpTotal = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1)
    if curPlusLV >= maxPlusLV:
        GameWorld.Log("ÉñÊÞ×°±¸ÒÑÂú¼¶, ÎÞ·¨Ç¿»¯£¡equipColor=%s,curPlusLV=%s,maxPlusLV=%s" % (equipColor, curPlusLV, maxPlusLV), playerID)
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("DogzEquipPlus", equipPlace, curPlusLV)
    if not ipyData:
        return
    lvUPTotalExp = ipyData.GetPlusLVUPTotalExp()
    if not lvUPTotalExp:
        GameWorld.Log("ÉñÊÞ×°±¸Éý¼¶ËùÐè×ܾ­ÑéΪ0, ÎÞ·¨Ç¿»¯£¡equipPlace=%s,curPlusLV=%s" % (equipPlace, curPlusLV), playerID)
        return
        
    costGoldTotal = 0
    addExpTotal = 0
    delItemList = []
    dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)
    dogzItemPackCount = dogzItemPack.GetCount()
    for i in indexList:
        if i < 0 or i >= dogzItemPackCount:
            GameWorld.ErrLog("ÉñÊÞ±³°üË÷Òý²»´æÔÚ£¬ÎÞ·¨Ç¿»¯£¡i=%s" % (i), playerID)
            return
        curItem = dogzItemPack.GetAt(i)
        if curItem.IsEmpty():
            GameWorld.ErrLog("ÉñÊÞ±³°üÎïÆ·Îª¿Õ£¬ÎÞ·¨Ç¿»¯£¡i=%s" % (i), playerID)
            return
        effect = ItemCommon.GetItemEffectByEffectID(curItem, ChConfig.Def_Effect_DogzEquipPlusExp)
        if not effect:
            GameWorld.ErrLog("ÉñÊÞ±³°üÎïÆ·ÎÞ¾­ÑéЧ¹û£¬ÎÞ·¨Ç¿»¯£¡i=%s,itemID=%s" % (i, curItem.GetItemTypeID()), playerID)
            return
        
        delCount = max(1, min(curItem.GetCount(), indexUseCountList[i]))
        baseExp = effect.GetEffectValue(0)
        doubleCostGold = effect.GetEffectValue(1)
        
        addExp = baseExp * delCount
        plusInfoCount = curItem.GetUserAttrCount(ShareDefine.Def_IudetDogzEquipPlus)
        if not plusInfoCount:
            if isDouble and doubleCostGold:
                addExp = (baseExp * 2 * delCount)
                costGoldTotal += doubleCostGold * delCount
            GameWorld.DebugLog("    Ç¿»¯: addExp=%s,delCount=%s,baseExp=%s,isDouble=%s,doubleCostGold=%s,costGoldTotal=%s" 
                               % (addExp, delCount, baseExp, isDouble, doubleCostGold, costGoldTotal), playerID)
        else:
            #plusLV = curItem.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)
            plusExpTotal = curItem.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1)
            addExp += plusExpTotal
            GameWorld.DebugLog("    Ç¿»¯: addExp=%s,delCount=%s,baseExp=%s,plusExpTotal=%s" % (addExp, delCount, baseExp, plusExpTotal), playerID)
        addExpTotal += addExp
        delItemList.append([curItem, delCount])
        
    if not delItemList:
        GameWorld.DebugLog("    Ã»ÓвÄÁÏ¿ÉÇ¿»¯£¡", playerID)
        return
    
    updPlusExpTotal = curPlusExpTotal + addExpTotal
    infoDict = {"updPlusExpTotal":updPlusExpTotal}
    
    if costGoldTotal:
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGoldTotal, 
                                      ChConfig.Def_Cost_DogzEquipPlus, infoDict):
            return
        
    for delItem, delCount in delItemList:
        ItemCommon.DelItem(curPlayer, delItem, delCount, False, ChConfig.ItemDel_DogzEquipPlus, infoDict)
        
    updPlusLV = curPlusLV
    doCount, maxDoCount = 0, maxPlusLV * 2
    while updPlusExpTotal >= lvUPTotalExp and updPlusLV < maxPlusLV and doCount < maxDoCount:
        doCount += 1
        nextLV = updPlusLV + 1
        nextLVIpyData = IpyGameDataPY.GetIpyGameDataNotLog("DogzEquipPlus", equipPlace, nextLV)
        if not nextLVIpyData:
            GameWorld.DebugLog("    Ã»ÓÐÏÂÒ»¼¶Êý¾Ý£¬²»ÄÜÉý¼¶£¡nextLV=%s" % (nextLV), playerID)
            break
        updPlusLV = nextLV
        lvUPTotalExp = nextLVIpyData.GetPlusLVUPTotalExp()
        GameWorld.DebugLog("    Éý¼¶: equipPlace=%s,maxPlusLV=%s,updPlusLV=%s,updPlusExpTotal=%s,lvUPTotalExp=%s" 
                           % (equipPlace, maxPlusLV, updPlusLV, updPlusExpTotal, lvUPTotalExp), playerID)
        
    isRefreshAtrr = False
    # Î´Ç¿»¯¹ý
    if not curPlusExpTotal:
        curEquip.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, updPlusLV)
        curEquip.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, updPlusExpTotal)
        isRefreshAtrr = (updPlusLV > 0)
    else:
        if curPlusLV != updPlusLV:
            isRefreshAtrr = True
            curEquip.UpdataUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0, updPlusLV)
        curEquip.UpdataUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1, updPlusExpTotal)
        
    GameWorld.DebugLog("    curPlus(LV=%s,EXP=%s),addExpTotal=%s,updPlus(LV=%s,EXP=%s)" 
                       % (curPlusLV, curPlusExpTotal, addExpTotal, updPlusLV, updPlusExpTotal), playerID)
    
    if isRefreshAtrr:
        RefreshDogzAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
        
    return
 
def GetDogzEquipPlusLVExpInfo(equipColor, equipPlace, totalExp):
    ## »ñÈ¡µ±Ç°ÉñÊÞ×°±¸×î¸ßÇ¿»¯µÈ¼¶µÄÇ¿»¯ÊìÁ·¶È
    retLV, retExp = 0, 0
    colorPlusMaxLVDict = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 4) # {ÑÕÉ«:µÈ¼¶ÉÏÏÞ, ...}
    if equipColor not in colorPlusMaxLVDict:
        return retLV, retExp
    maxPlusLV = colorPlusMaxLVDict[equipColor]
    for lv in xrange(maxPlusLV + 1):
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog("DogzEquipPlus", equipPlace, lv)
        if lv and not ipyData:
            break
        
        lvUPTotalExp = ipyData.GetPlusLVUPTotalExp()
        if not lvUPTotalExp:
            break
        
        if totalExp < lvUPTotalExp:
            return lv, totalExp
        retLV, retExp = lv, lvUPTotalExp
        
    return retLV, retExp
 
def RefreshDogzAttr(curPlayer):
    ## Ë¢ÐÂÉñÊÞÊôÐÔ
    
    fightPowerEx = 0
    allAttrList = [{} for _ in range(4)]
    
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)
    equipPackCount = dogzEquipPack.GetCount()
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for dogzIndex in xrange(ipyDataMgr.GetDogzCount()):
        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzIndex):
            continue
        
        ipyData = ipyDataMgr.GetDogzByIndex(dogzIndex)
        dogzID = ipyData.GetDogzID()
        #GameWorld.DebugLog("ÉñÊÞÊôÐÔ: dogzID=%s" % dogzID)
        
        # 1. »ù´¡ÊôÐÔ
        attrTypeList = ipyData.GetBaseAttrTypes()
        attrValueList = ipyData.GetBaseAttrValues()
        if attrTypeList and len(attrTypeList) == len(attrValueList):
            for attrIndex, baseAttrID in enumerate(attrTypeList):
                baseAttrValue = attrValueList[attrIndex]
                PlayerControl.CalcAttrDict_Type(baseAttrID, baseAttrValue, allAttrList)
                #GameWorld.DebugLog("    »ù´¡ÊôÐÔ: baseAttrID=%s,baseAttrValue=%s, %s" % (baseAttrID, baseAttrValue, allAttrList))
                
        # 2. ×°±¸ÊôÐÔ
        startIndex = (dogzID - 1) * DogzEquipCount
        for equipIndex in range(startIndex, startIndex + DogzEquipCount):
            if equipIndex < 0 or equipIndex >= equipPackCount:
                break
            curEquip = dogzEquipPack.GetAt(equipIndex)            
            if curEquip.IsEmpty():
                continue
            
            #itemID = curEquip.GetItemTypeID()
            # ×°±¸»ù´¡ÊôÐÔ
            for effIndex in xrange(curEquip.GetEffectCount()):
                curEffect = curEquip.GetEffectByIndex(effIndex)
                if not curEffect or not curEffect.GetEffectID():
                    break
                effID = curEffect.GetEffectID()
                if not effID or effID == ChConfig.Def_Effect_DogzEquipPlusExp:
                    continue
                effValue = curEffect.GetEffectValue(0)
                PlayerControl.CalcAttrDict_Type(effID, effValue, allAttrList)
                #GameWorld.DebugLog("    ×°±¸»ù´¡: itemID=%s,effID=%s,effValue=%s, %s" % (itemID, effID, effValue, allAttrList))
                
            # Ç¿»¯ÊôÐÔ
            curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)
            plusIpyData = IpyGameDataPY.GetIpyGameData("DogzEquipPlus", curEquip.GetEquipPlace(), curPlusLV)
            if plusIpyData:
                plusAttrTypeList = plusIpyData.GetPlusAttrTypes()
                plusAttrValueList = plusIpyData.GetPlusAttrValues()
                if plusAttrTypeList and len(plusAttrTypeList) == len(plusAttrValueList):
                    for plusIndex, plusAttrID in enumerate(plusAttrTypeList):
                        plusAttrValue = plusAttrValueList[plusIndex]
                        PlayerControl.CalcAttrDict_Type(plusAttrID, plusAttrValue, allAttrList)
                        #GameWorld.DebugLog("    ×°±¸Ç¿»¯: itemID=%s,plusAttrID=%s, plusAttrValue=%s, %s" % (itemID, plusAttrID, plusAttrValue, allAttrList))
                        
            # ´«ÆæÊôÐÔ
            ChEquip.CalcAttr_LegendAttr(curPlayer, curEquip, allAttrList)
            #GameWorld.DebugLog("    ×°±¸´«Ææ: itemID=%s,%s" % (itemID, allAttrList))
            
        # ¸½¼ÓÕ½Á¦
        fightPowerEx += ipyData.GetFightPowerEx()
        
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Dogz, allAttrList)
    curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_Dogz, fightPowerEx)
    
    # ¼¼ÄÜÊôÐÔ£¬´ÓDef_CalcAttrFunc_Dogz»ñÈ¡
    skillAttrList = CalcDogzBattleSkillAttr(curPlayer)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_HorseSkill, skillAttrList)
    return
 
# ÖúÕ½ÉñÊÞ¼¼ÄÜÊôÐÔ£¬±ØÐëÔÚ SetDogzIsHelpFightºóµ÷ÓÃ
def CalcDogzBattleSkillAttr(curPlayer):
    skillAttrList = [{} for _ in range(4)]
    skillManager = curPlayer.GetSkillManager()
 
    for i in range(0 , skillManager.GetSkillCount()):
        curSkill = skillManager.GetSkillByIndex(i)
        if not curSkill:
            continue
        
        if curSkill.GetFuncType() != ChConfig.Def_SkillFuncType_Dogz:
            continue
        
        if not SkillCommon.isPassiveAttr(curSkill):
            continue
        
        
        for effectIndex in xrange(curSkill.GetEffectCount()):
            curEffect = curSkill.GetEffect(effectIndex)
            SkillShell.CalcBuffEffAttr(curPlayer, curEffect, skillAttrList)
            
    
    #GameWorld.DebugLog("ÉñÊÞ¼¼ÄÜÊôÐÔ: skillFPEx=%s, %s" % ( skillFPEx, skillAttrList))
    return skillAttrList
 
 
def Sync_DogzInfo(curPlayer):
    ## Í¬²½ÉñÊÞÐÅÏ¢
    dogzInfoPack = ChPyNetSendPack.tagMCDogzInfo()
    dogzInfoPack.BuyHelpbattleCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)
    NetPackCommon.SendFakePack(curPlayer, dogzInfoPack)
    return
 
def Sync_DogzHelpbattleState(curPlayer, dogzID, batteState):
    ## Í¬²½ÉñÊÞÖúս״̬
    helpbattleState = ChPyNetSendPack.tagMCDogzHelpbattleState()
    helpbattleState.DogzID = dogzID
    helpbattleState.BatteState = 1 if batteState else 0
    NetPackCommon.SendFakePack(curPlayer, helpbattleState)
    return