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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PetControl
#
# @todo:³èÎï¿ØÖÆÆ÷
# @author hxp
# @date 2016-4-29
# @version 1.2
#
# @change: "2016-06-15 12:00" hxp Ôö¼Ó³èÎïÊØ»¤×´Ì¬
# @change: "2016-07-02 16:30" hxp ³èÎï¼Ì³ÐÖ÷ÈËÒÆ¶¯ËÙ¶È
#
# ÏêϸÃèÊö: ³èÎï¿ØÖÆÆ÷
#
#-------------------------------------------------------------------------------
#"""Version = 2016-07-02 16:30"""
#-------------------------------------------------------------------------------
#³èÎïC++½Ó¿Ú£º
#curPlayer.GetPetMgr -> IPY_RolePetMgr; 
#IPY_RolePetMgr.PetList_Find\GetFightPet\PetList_At -> IPY_RolePet;
#IPY_RolePet.GetRolePet -> tagIPY_RolePet(½á¹¹Ìå); 
#IPY_RolePet.GetPetData -> IPY_Pet;
#
#
#---------------------------------------------------------------------
import IPY_GameWorld
import ChConfig
import GameWorld
import BuffSkill
import SkillShell
import PlayerPet
import PlayerControl
import NPCCommon
import SkillCommon
import GameMap
import OperControlManager
import ShareDefine
 
import random
import copy
import math
import GameObj
import AICommon
import BaseAttack
import PassiveBuffEffMng
import ChNetSendPack
import IpyGameDataPY
import AttackCommon
#---------------------------------------------------------------------
 
DefPetRebornHPRate = 100  # ³èÎïËÀÍö¸´»îѪÁ¿°Ù·Ö±È
 
#---------------------------------------------------------------------
## ¼ì²é³èÎïÊÇ·ñ³öÕ½ÖÐ
#  @param curPlayer Íæ¼Ò¶ÔÏó
#  @param curPetID ³èÎïID
#  @return True or False ÊÇ·ñ³öÕ½ÖÐ
#  @remarks ¼ì²é³èÎïÊÇ·ñ³öÕ½ÖÐ
def CheckPetIsFight(curPlayer, curPetID):
    petMgr = curPlayer.GetPetMgr()
    #³öÕ½µÄ³èÎï¶ÔÏó
    fightPetObj = petMgr.GetFightPet()  
    
    if fightPetObj == None:
        return False
    
    if fightPetObj.GetRolePet().PetID == curPetID:
        return True
    
    return False
 
 
 
 
# ³èÎï¸úËæÈËÎïͬʱ¹¥»÷
def PetFight(curPlayer, tick):
    
    rolePet = curPlayer.GetPetMgr().GetFightPet()
    #ÎÞ³öÕ½³èÎï
    if rolePet == None:
        return
    rolePetControl = NPCCommon.NPCControl(rolePet)
    
    useSkillTagID = curPlayer.GetUseSkillTagID()
    useSkillTagType = curPlayer.GetUseSkillTagType()
    
    curTag = GameWorld.GetObj(useSkillTagID, useSkillTagType)
    if not curTag or GameObj.GetHP(curTag) <= 0:
        # Ã»ÓÐÖ÷Ä¿±ê¾Í´Ó³ðºÞÖÐÕÒ
        for i in range(curPlayer.GetAngryNPCCount()):
            curTag = curPlayer.GetAngryNPCByIndex(i)
            if not curTag or GameObj.GetHP(curTag) <= 0:
                continue
            
        # »¹Ã»ÓоʹÓÊÓÒ°ÖвéÕÒ
        if not curTag or GameObj.GetHP(curTag) <= 0:
            seePlayerCount = rolePet.GetInSightObjCount()
            for i in range(0, seePlayerCount):
                seeObj = rolePet.GetInSightObjByIndex(i)
                if seeObj == None:
                    continue
                seeObjID = seeObj.GetID()
                seeObjType = seeObj.GetGameObjType()
                # Ö»ÔÊÐíÖ÷¶¯¹¥»÷NPC£¬ÇÒÄ¿±êNPCÊÇÖ÷¶¯¹Ö
                if seeObjType != IPY_GameWorld.gotNPC:
                    continue
                seeObjDetail = GameWorld.GetObj(seeObjID, seeObjType)
                if not seeObjDetail:
                    continue
                if seeObjDetail.GetAtkType() == 1:
                    # 1Ϊ·ÇÖ÷¶¯¹Ö
                    continue
                if not AttackCommon.CheckCanAttackTag(rolePet, seeObjDetail):
                    continue
                relation = BaseAttack.GetTagRelation(rolePet, seeObjDetail, None, tick)[0]
                if relation != ChConfig.Type_Relation_Enemy:
                    continue
                curTag = seeObjDetail
                break
                
    if not curTag or GameObj.GetHP(curTag) <= 0:
        return
    
    #tagDist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
    tagDist = 0
    #---ÓÅÏÈÊͷż¼ÄÜ---
    if AICommon.DoAutoUseSkill(rolePet, curTag, tagDist, tick):
        return
    
    #---ÊÍ·ÅÆÕͨ¹¥»÷--- ±ß×߱߹¥»÷¾ÀÕýÒ»´ÎλÖÃ
    #if tagDist > rolePet.GetAtkDist():
    #    rolePetControl.MoveToObj_Detel(curTag)
    
    #ÆÕͨ¹¥»÷
    BaseAttack.Attack(rolePet, curTag, None, tick)
    return
 
 
#---------------------------------------------------------------------
##³öÕ½³èÎï¸úËæÒÆ¶¯
# @param curPlayer Íæ¼ÒʵÀý
# @param destPosX Òƶ¯Ä¿±êXµã
# @param destPosY Òƶ¯Ä¿±êYµã
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ³öÕ½³èÎï¸úËæÒÆ¶¯
def FightPetFollowMove(curPlayer, destPosX, destPosY):
    #Ö÷ÈËÔÚÕ½¶·ÖÐ, ³èÎï²»¸úËæÒÆ¶¯
 
    fightPet = curPlayer.GetPetMgr().GetFightPet()
    #ÎÞ³öÕ½³èÎï
    if fightPet == None:
        return
 
    petControl = NPCCommon.NPCControl(fightPet)
    movePosX, movePosY = petControl.GetMoveNearPos(destPosX, destPosY, 2)
    # Ö´ÐÐÒ»´ÎÖØÖÃλÖ㬱ÜÃâ¿ìËÙ·¢°üµ¼ÖÂÎÞ·¨Òƶ¯
    fightPet.ChangePos(movePosX, movePosY)
    
    #movePosX, movePosY = petControl.GetMoveNearPos(destPosX, destPosY, 1)
    PetMove(fightPet, movePosX, movePosY)
    return
 
 
def PetMove(fightPet, posX, posY):
    
    sendPack = ChNetSendPack.tagObjMove()
    
    sendPack.Clear()
    sendPack.ObjID = fightPet.GetID()
    sendPack.ObjType = IPY_GameWorld.gotNPC
    sendPack.MoveType = IPY_GameWorld.mtNormal
    sendPack.DestPosX = posX
    sendPack.DestPosY = posY
    sendPack.Speed = fightPet.GetSpeed()
    sendPack.StartPosX = fightPet.GetPosX()
    sendPack.StartPosY = fightPet.GetPosY()
    
    fightPet.NotifyAll(sendPack.GetBuffer(), sendPack.GetLength())
    return
#---------------------------------------------------------------------
##Çå³ý³öÕ½³èÎï³ðºÞ.
# @param curPlayer Íæ¼ÒʵÀý
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Çå³ý³öÕ½³èÎï³ðºÞ
def ClearFightPetAngry(curPlayer):
    fightPet = curPlayer.GetPetMgr().GetFightPet()
    #ÎÞ³öÕ½³èÎï
    if fightPet == None:
        return
 
    petControl = NPCCommon.NPCControl(fightPet)
    petControl.ClearNPCAngry()
    return
#---------------------------------------------------------------------
 
##»ñµÃ³èÎïµÄÓµÓÐÕß
# @param curPet ³èÎï
# @return ·µ»ØÖµ, ³èÎïÓµÓÐÕß(ʵÀý) or None
# @remarks »ñµÃ³èÎïµÄÓµÓÐÕß
def GetPetOwner(curPet):
    if curPet == None:
        return
    
    curPlayerID = curPet.GetRolePet().PlayerID  # ³èÎïÖ÷ÈËID
    
    if curPlayerID <= 0:
        return
    
    curObj = GameWorld.GetObj(curPlayerID, IPY_GameWorld.gotPlayer)
    
    #ÈËÎïÐèÒªÅжÏÊÇ·ñΪ¿Õ
    if curObj != None and curObj.IsEmpty():
        return
    
    return curObj
#---------------------------------------------------------------------
##ÊÇ·ñÊdzèÎï
# @param curObj ¶ÔÏó£¨NPC¡¢ÕÙ»½ÊÞ¡¢³èÎï¡¢Íæ¼ÒµÈ£©
# @return ÊÇ·ñ³èÎï
# @remarks Í¨¹ý´«ÈëµÄ¶ÔÏóÅжÏÊÇ·ñÊdzèÎï
def IsPet(curObj):
    curObjType = curObj.GetGameObjType()
    
    if curObjType != IPY_GameWorld.gotNPC:
        return False
    
    npcObjType = curObj.GetGameNPCObjType()
    
    if npcObjType == IPY_GameWorld.gnotPet:  # ³èÎï      
        return True
    
    return False
#---------------------------------------------------------------------    
##Çå¿Õ³èÎïÉíÉÏËùÓÐbuff
# @param curPet ³èÎï¶ÔÏó
# @return None
# @remarks Çå¿Õ³èÎïÉíÉÏËùÓÐbuff
def ClearPetBuff(curPet):
    buffRefreshList = NPCCommon.GetNPCBuffRefreshList(curPet, True)
    
    for buffState, canPileup in buffRefreshList:
        buffState.Clear()
    
    return
#---------------------------------------------------------------------    
##ÕÙ»½³èÎï
# @param curPet ³èÎï¶ÔÏó
# @param curPosX ³èÎï³öÉíµãλÖÃ
# @param curPosY ³èÎï³öÉíµãλÖÃ
# @return None
# @remarks ÕÙ»½³èÎ³õʼ»¯³èÎïËùÓÐÊôÐÔ(C++´¦Àí)
def SummonPet(curPet, curPosX, curPosY):
    #³öÏÖ(³öÕ½Âß¼­ÔÚC++, ½«Çå¿Õ³èÎïµÄÏà¹ØÐÅÏ¢)
    curPet.Summon(curPosX, curPosY)
    #¼Ç¼¸Ã³èÎï±»ÕÙ»Ø
    curPet.SetIsBattle(True)
    #³õʼ»¯³èÎï
    InitRolePet(curPet)
    PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPet)
    return
#---------------------------------------------------------------------
##³õʼ»¯³èÎïÊôÐÔ
# @param rolePet ³èÎïʵÀý
# @param canSyncClient ÊÇ·ñ֪ͨ¿Í»§¶Ë
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ³õʼ»¯³èÎïÊôÐÔ
def InitRolePet(rolePet, canSyncClient=True):
    #---³õʼ»¯Ê±ÖÓ---
    NPCCommon.InitNPC(rolePet)
    
    #---³õʼ»¯³ðºÞÁбí---
    npcAngry = rolePet.GetNPCAngry()
    if npcAngry.GetAngryCount() == 0:
        npcAngry.Init(ChConfig.Def_Pet_Angry_Count)
    else:
        npcAngry.Clear()
 
    #---³õʼ»¯³èÎïÊôÐÔ---
    petControl = NPCCommon.NPCControl(rolePet)
    petControl.RefreshNPCState(canSyncClient)
 
    #¼ÓÒ»¸ö·ÀÓù´ëÊ©, Èç¹û³èÎïѪΪ0, ²»¿ÉÕÙ»½³öÀ´, Ä¬ÈÏΪ³èÎïÕÙ»ØÊ±ºòµÄѪÁ¿
    if GameObj.GetHP(rolePet) <= 0:
        PetDead_ReStoreHP(rolePet, GameObj.GetMaxHP(rolePet))
        GameWorld.ErrLog('³èÎïÖØÉúѪÁ¿Îª0, PetID = %s' % (rolePet.GetRolePet().PetID))
 
    return
#---------------------------------------------------------------------
##ÕٻسöÕ½µÄ³èÎï
# @param curPlayer Íæ¼ÒʵÀý
# @return ²¼¶ûÖµ
# @remarks ÕٻسöÕ½µÄ³èÎï
def ReCallFightPet(curPlayer):
    rolePetMgr = curPlayer.GetPetMgr()
    #»ñµÃÕ½¶·µÄ³èÎï
    fightPet = rolePetMgr.GetFightPet()
    
    if fightPet == None:
        return False
    
    #Çå¿Õ³èÎïÉíÉϸ½¼ÓµÄbuff
    ClearPetBuff(fightPet)
    #¼Ç¼¸Ã³èÎï±»ÕÙ»Ø
    fightPet.SetIsBattle(False)
    #´ËËÀÍö½Ó¿Ú(C++½«ÖØÖÃËùÓÐÕ½¶·ÊôÐÔ, ÒªÔÚË¢Ò»´Î)
    NPCCommon.SetDeadEx(fightPet)
    #ˢгèÎïÊôÐÔ
    petControl = NPCCommon.NPCControl(fightPet)
    petControl.RefreshNPCState(canSyncClient=True)
    
    #³èÎïÊý¾ÝÎïÆ·×´Ì¬±ä¸ü
    petItemIndex = PlayerPet.GetPetObjItemIndex(fightPet)
    petItem = PlayerPet.GetPetDataItemByIndex(curPlayer, petItemIndex)
    if petItem:
        petItem.SetUserAttr(ShareDefine.Def_IudetPet_State, ShareDefine.Def_PetState_Null)
    
    petID = fightPet.GetRolePet().PetID
    npcID = fightPet.GetRolePet().NPCID
    rolePetMgr.PetList_SetFree(petID) # ÓÀºãÕٻغóĬÈÏ·ÅÉú, ×î¶àÖ»´æÔÚÒ»¸ö³öÕ½³èÎïʵÀý
    GameWorld.DebugLog("Ëæ´ÓÕٻغóĬÈÏ·ÅÉú, petID=%s, npcID=%s" % (petID, npcID))
    return True
#---------------------------------------------------------------------
## ÉèÖóèÎïËÀÍö
#  @param curPet ³èÎï¶ÔÏó
#  @return None
#  @remarks ÉèÖóèÎïËÀÍö
def SetPetDead(curPet):
    #---Ö´ÐÐËÀÍö³Í·£Âß¼­---
    
    #³èÎïÖ÷ÈË
    curPetOwner = GetPetOwner(curPet)
    if not curPetOwner:
        return
    ReCallFightPet(curPetOwner)
    return
 
#---------------------------------------------------------------------
##³èÎïËÀÍö»Ö¸´ÑªÁ¿
# @param index Íæ¼ÒË÷Òý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ³èÎïËÀÍö»Ö¸´ÑªÁ¿
def PetDead_ReStoreHP(curPet, maxHP):
    #ÉèÖóèÎﵱǰѪÁ¿ÎªÆäÉÏÏÞµÄ30%
    SetPetHP(curPet, int(maxHP * DefPetRebornHPRate / 100))
    return
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
##ÉèÖóèÎïHP
# @param rolePet Íæ¼Ò³èÎï
# @param Öµ
# @param canSyncClientÊÇ·ñ֪ͨ¿Í»§¶Ë
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ÉèÖóèÎïHP
def SetPetHP(rolePet, value, canSyncClient=True):
    GameObj.SetHP(rolePet, value, canSyncClient)
    
    if not canSyncClient:
        return
    
    #rolePet.Sync_RefreshProp(IPY_GameWorld.PetInfoRefresh_HP, value, True)
    return
#---------------------------------------------------------------------
##Ôö¼Ó³èÎïHP
# @param rolePet Íæ¼Ò³èÎï
# @param Öµ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼Ó³èÎïHP
def AddPetHP(rolePet, value):
    remainValue = min(GameObj.GetHP(rolePet) + value, GameObj.GetMaxHP(rolePet))
    SetPetHP(rolePet, remainValue)
    return
 
#---------------------------------------------------------------------
##ˢгèÎïµÄÊôÐÔ
# @param rolePet Íæ¼Ò³èÎï
# @param canSyncClient ÊÇ·ñ֪ͨ¿Í»§¶Ë(ĬÈÏΪTrue)
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Ë¢Ð³èÎïµÄÊôÐÔ
def RefurbishPetAttr(rolePet, canSyncClient=True):
    curPlayer = GetPetOwner(rolePet)
    if not curPlayer:
        return
    
    petDataItem = PlayerPet.GetPetDataItem(curPlayer, rolePet)
    if not petDataItem:
        return
    
    # ±ä¸üÐèҪͬ²½µÄÐÅÏ¢ÅäÖÃ, ¿Í»§¶ËÈ¡³èÎïÐÅϢȫ²¿ÒÔ³èÎïÎïÆ·Êý¾ÝΪ׼
    syncList = [
                [lambda petObj:petObj.GetMaxAtk(), IPY_GameWorld.PetInfoRefresh_PhysicAtk], #¹¥»÷
                #[lambda petObj:petObj.GetQualityLV(), IPY_GameWorld.PetInfoRefresh_QualityLV], #Æ·ÖÊ
                ]
    beforeValueList = []
    for syncInfo in syncList:
        beforeValueList.append(syncInfo[0](rolePet))
    
    #Ìí¼ÓBuffµ½³èÎïÉíÉÏ
    #AddPlayerPetSkillBuff(rolePet)
    
    #¼ÆËãBuff¶Ô»ù´¡ÊôÐÔµÄÓ°Ïì
    #SkillShell.CalcBuffer_NPCBaseEffect(rolePet)
    
    #³èÎï²»¿É±»¹¥»÷, ÃüÖÐÓë¹¥ËÙÖ±½Ó¼Ì³ÐÖ÷È˹¥»÷ÊôÐÔ£¬¹¥»÷È¡µÈ¼¶½×¼¶¼Ó³É
    rolePet.SetMinAtk(PlayerControl.GetPetMinAtk(curPlayer))
    rolePet.SetMaxAtk(PlayerControl.GetPetMaxAtk(curPlayer))
    rolePet.SetSkillAtkRate(PlayerControl.GetPetSkillAtkRate(curPlayer))
    GameObj.SetPetDamPer(rolePet, GameObj.GetPetDamPer(curPlayer))
    #rolePet.SetMAtkMin(curPlayer.GetMAtkMin())
    #rolePet.SetMAtkMax(curPlayer.GetMAtkMax())
    rolePet.SetHit(curPlayer.GetHit())
    rolePet.SetSpeed(curPlayer.GetSpeed())
    
    allAttrList = [{} for i in range(4)]
    #¼ÆËã¼¼ÄܶÔÕ½¶·ÊôÐÔµÄÓ°Ïì
    PlayerPet.CalcSkill_PetBattleEffect(curPlayer, rolePet, allAttrList)
    #¼ÆËãBuff¶ÔÕ½¶·ÊôÐÔµÄÓ°Ïì
    PlayerPet.CalcBuffer_PetBattleEffect(rolePet, allAttrList)
    
    GameWorld.DebugLog("RefurbishPetAttr ID=%s,npcID=%s,atk=%s,hit=%s,skillAtkRate=%s" 
                       % (rolePet.GetID(), rolePet.GetNPCID(), rolePet.GetMaxAtk(), rolePet.GetHit(), rolePet.GetSkillAtkRate()))
    
    #ÊÇ·ñÐèҪ֪ͨ¿Í»§¶ËÊôÐÔË¢ÐÂ
    if not canSyncClient:
        return
    
    #===========================================================================
    # for i, syncInfo in enumerate(syncList):
    #    nowValue = syncInfo[0](rolePet)
    #    if beforeValueList[i] != nowValue:
    #        rolePet.Sync_RefreshProp(syncInfo[1], nowValue, True)
    #        #GameWorld.DebugLog("Sync_RefreshProp i=%s,befValue=%s,nowValue=%s,type=%s" % (i, beforeValueList[i], nowValue, syncInfo[1]))
    #===========================================================================
    return
 
#---------------------------------------------------------------------
##Ìí¼Ó³èÎï¼¼ÄÜBuff
# @param rolePet ³èÎïʵÀý
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Ìí¼Ó³èÎï¼¼ÄÜBuff
#===============================================================================
# def AddPlayerPetSkillBuff(rolePet):
#    tick = GameWorld.GetGameWorld().GetTick()
#    #---ÏÈÇåµô---
#    passiveBuffManager = rolePet.GetPassiveBuf()
#    passiveBuffManager.Clear()
#    
#    #---ÔÚ¼ÓÉÏ---
#    rolePetSkillManager = rolePet.GetSkillManager()
#    
#    for i in range(0, rolePetSkillManager.GetSkillCount()):
#        learnSkill = rolePetSkillManager.GetSkillByIndex(i)
#        #Ö»Ìí¼Ó±»¶¯¼¼ÄÜ
#        if not SkillCommon.isPassiveBuffSkill(learnSkill):
#            continue
#        
#        #¼ÓÉÏbuff²»Ë¢ÐÂ״̬
#        BuffSkill.AddBuffNoRefreshState(rolePet, IPY_GameWorld.btPassiveBuf, learnSkill, tick)
#    
#    return
#===============================================================================
#---------------------------------------------------------------------
def DoLogic_PlayerPetLearnSkillList(rolePet, learnSkillList):
    #GameWorld.DebugLog("DoLogic_PlayerPetLearnSkillList----%s"%learnSkillList)
    gameData = GameWorld.GetGameData()
    
    rolePetSkillManager = rolePet.GetSkillManager()
    for leSkillID in learnSkillList:
        learnSkillData = gameData.GetSkillBySkillID(leSkillID)
        if not learnSkillData:
            GameWorld.ErrLog('PlayerPetLearnSkillList LeanrSkillID = %s, noFindInTable' % leSkillID)
            return
        rolePetSkillManager.LearnSkillByID(leSkillID)
        
    PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(rolePet)
    #rolePet.Sync_PetInfo()
    #rolePet.Sync_SkillList()     
    return
 
#---------------------------------------------------------------------
##¼ì²éµ±Ç°Ö¸¶¨³èÎïÊÇ·ñ¿É³öÕ½
# @param curPlayer Íæ¼ÒʵÀý
# @param curPetObj Ö¸¶¨³èÎïʵÀý
# @return BOOL ÊÇ·ñ¿É³öÕ½
# @remarks ¼ì²éµ±Ç°Ö¸¶¨³èÎïÊÇ·ñ¿É³öÕ½
def CheckPetCanFight(curPlayer, curPetObj):
    if not GetMapCanOutPet(curPlayer):
        #Pet_liubo_314885 ´ËµØÍ¼½ûÖ¹³èÎï
        #PlayerControl.NotifyCode(curPlayer, "Pet_liubo_314885")
        return False
    
    petData = curPetObj.GetPetData()
    
    #·À³ÁÃÔ
    if curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV) > ChConfig.Def_GameWallow_LV_First:
        PlayerControl.NotifyCode(curPlayer, "AvoidSink09")
        return False
    
    if GameObj.GetHP(curPlayer) <= 0:
        #ËÀÍö״̬ÎÞ·¨³öÕ½³èÎï
        return False
    
#    if curPlayer.GetLV() < petData.GetBringLV():
#        #Pet_hgg_442426 ¶Ô²»Æð,ÄúÉÐδµ½´ï¸Ã³èÎïµÄЯ´øµÈ¼¶.
#        PlayerControl.NotifyCode(curPlayer, "Pet_hgg_442426")
#        return False
#    
#    if curPetObj.GetLV() - curPlayer.GetLV() > ChConfig.Def_PetRoleGapLVMax:
#        #Pet_liubo_570355 ¶Ô²»Æð,Äú²»ÄܳöÕ½³¬¹ýÈËÎï5¼¶µÄ³èÎï!
#        PlayerControl.NotifyCode(curPlayer, "Pet_liubo_570355", [ChConfig.Def_PetRoleGapLVMax])
#        return False
    
    #---ÊÇ·ñÒÑÓгèÎï³öÕ½---
    #fightPetObj = curPlayer.GetPetMgr().GetFightPet()  # ³öÕ½µÄ³èÎï¶ÔÏó
    
    #if fightPetObj != None:
    #    #Pet_hgg_892377 ¶Ô²»Æð£¬ÄúÖ»ÄÜͬʱ³öÕ½Ò»Ö»³èÎÇëÏÈÕٻسöÕ½µÄ³èÎï!
    #    PlayerControl.NotifyCode(curPlayer, "Pet_hgg_892377")
    #    return False
    
    #GameWorld.Log('³èÎïѪÁ¿:%s£¬³èÎïID:%s'%(curPetStruct.HP,curPetStruct.PetID))
    return True
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
##Íæ¼ÒÀ뿪·þÎñÆ÷֪ͨ³èÎïÐÅÏ¢
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÀ뿪·þÎñÆ÷֪ͨ³èÎïÐÅÏ¢
def DoLogic_PetInfo_OnLeaveServer(curPlayer, tick):
    return
 
#---------------------------------------------------------------------
##Íæ¼ÒµÇ½֪ͨ³èÎïÐÅÏ¢
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒµÇ½֪ͨ³èÎïÐÅÏ¢
def DoLogic_PetInfo_OnLogin(curPlayer, tick):
   
    petMgr = curPlayer.GetPetMgr()
    if GameWorld.IsCrossServer():
        ''' 0435³èÎï³öÏÖ°üͬ²½µÄIDÊǸù¾Ý³èÎïµÄÁбíλÖÃÀ´µÄ£¬±ÈÈçÔÚµÚ2λ·¢µÄ¾ÍÊÇ2£¬¶øµØÍ¼µÄ¿ÉÄÜÊÇ1£¬»áµ¼ÖÂID²»Ò»ÖÂ
                            ËùÒÔ¿ç·þ·þÎñÆ÷µÇ¼ʱÏÈÇå³ý³öÕ½³èÎïÁÐ±í£¬È·±£µÇ¼µØÍ¼³É¹¦ºó¶¼ÊÇ´Ó1¿ªÊ¼µÄ¼´¿É
        '''
        petList = []
        for index in range(0, petMgr.PetList_Cnt()):
            rolePet = petMgr.PetList_At(index)
            petList.append(rolePet)
        for rolePet in petList:
            petMgr.PetList_SetFree(rolePet.GetRolePet().PetID)
    else:
        for index in range(0, petMgr.PetList_Cnt()):
            rolePet = petMgr.PetList_At(index)
            #ˢгèÎïÐÅÏ¢²¢Í¨Öª¿Í»§¶Ë
            __RefreshAndSyncPetInfo(rolePet)
            #×Ô¶¯³öÕ½³èÎï
            __AutoSummonPet_OnLogin(curPlayer, rolePet)
 
    return
#---------------------------------------------------------------------
##Íæ¼ÒÉÏÏß, ×Ô¶¯³öÕ½³èÎï
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÉÏÏß, ×Ô¶¯³öÕ½³èÎï
def __AutoSummonPet_OnLogin(curPlayer, rolePet):
    #ÊÇ·ñÓгöÕ½±êÖ¾
    if not rolePet.GetIsBattle():
        return
    
    if not GetMapCanOutPet(curPlayer):
        #´ËµØÍ¼½ûÖ¹³èÎï
        return
    #ÕÙ»½³èÎï³öÕ½
    resultPos = GameMap.GetEmptyPlaceInArea(curPlayer.GetPosX(), curPlayer.GetPosY(), ChConfig.Def_SummonAppearDist)
    
    SummonPet(rolePet, resultPos.GetPosX(), resultPos.GetPosY())
    return
 
#---------------------------------------------------------------------
##Íæ¼ÒÇл»µØÍ¼Í¨Öª³èÎïÐÅÏ¢.
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÇл»µØÍ¼Í¨Öª³èÎïÐÅÏ¢.
def Sync_PetInfo_ChangeMap(curPlayer, tick):
    petMgr = curPlayer.GetPetMgr()
    
    for index in range(0, petMgr.PetList_Cnt()):
        rolePet = petMgr.PetList_At(index)
        #ˢгèÎïÐÅÏ¢²¢Í¨Öª¿Í»§¶Ë
        __RefreshAndSyncPetInfo(rolePet)
 
    return
 
#---------------------------------------------------------------------
##Íæ¼ÒЯ´ø³èÎïµÇ½µØÍ¼
# @param curPlayer Íæ¼ÒʵÀý
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks 
def DoLogic_PetLoadMapOK(curPlayer):
    
    if GetMapCanOutPet(curPlayer):
        #´ËµØÍ¼³èÎï¿ÉÒÔÉÏ
        PlayerPet.AutoSummonPet(curPlayer)
        return
    
    #´ËµØÍ¼½ûÖ¹³èÎï, ÕٻسöÕ½µÄ³èÎï
    if not ReCallFightPet(curPlayer):
        return
    
    #Pet_liubo_314885 ´ËµØÍ¼½ûÖ¹³èÎï
    #PlayerControl.NotifyCode(curPlayer, "Pet_liubo_314885")
    return
 
def GetMapCanOutPet(curPlayer):
    ## ¼ì²é±¾µØÍ¼¿É·ñ³öÕ½³èÎ֧³Öǰ¶Ë×Ô¶¨Ò峡¾°
    customMapID = PlayerControl.GetCustomMapID(curPlayer)
    if customMapID:
        ipyMapData = IpyGameDataPY.GetIpyGameData("ChinMap", customMapID)
        canOutPet = True if ipyMapData and ipyMapData.GetCanOutPet() else False
    else:
        canOutPet = GameWorld.GetMap().GetMapCanOutPet()
    return canOutPet
 
#---------------------------------------------------------------------
## Ë¢Ð³èÎïÐÅÏ¢²¢Í¨Öª¿Í»§¶Ë
#  @param rolePet ³èÎïʵÀý
#  @return ÎÞ·µ»ØÖµ
#  @remarks Ë¢Ð³èÎïÐÅÏ¢²¢Í¨Öª¿Í»§¶Ë
def __RefreshAndSyncPetInfo(rolePet):
    #---ˢгèÎïÐÅÏ¢(²»Í¨Öª¿Í»§¶Ë)---
    InitRolePet(rolePet, False)
 
    return
 
#---------------------------------------------------------------------