| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GM.Commands.Pet  | 
| #  | 
| # @todo:³èÎï  | 
| # @author hxp  | 
| # @date 2021-07-02  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ³èÎï  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-07-02 19:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import ChConfig  | 
| import GameWorld  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ShareDefine  | 
| import PetControl  | 
| import PlayerPet  | 
| import OpenFunc  | 
|   | 
|   | 
| def __Help(curPlayer, petNumNameDict):  | 
|     GameWorld.DebugAnswer(curPlayer, "------------------")  | 
|     GameWorld.DebugAnswer(curPlayer, "ÖØÖÃÁé³è: Pet 0 [¿ÉÑ¡µÚ¼¸Ö»]")  | 
|     GameWorld.DebugAnswer(curPlayer, "¼¤»îËùÓÐ: Pet 99 [¿ÉÑ¡ÊÇ·ñÂú½×]")  | 
|     GameWorld.DebugAnswer(curPlayer, "¼¤»îÖ¸¶¨: Pet µÚ¼¸Ö» ½×¼¶")  | 
|     GameWorld.DebugAnswer(curPlayer, "ÅàÑøÁé³è: Pet ÅàÑøÀàÐÍ µÈ½× µ¤Êý")  | 
|     GameWorld.DebugAnswer(curPlayer, "×¢£ºÖØÖÃÁé³èÐèÖØµÇ")  | 
|       | 
|     petNumList = petNumNameDict.keys()  | 
|     petNameNumInfo = ""  | 
|     for i, petNum in enumerate(petNumList, 1):  | 
|         petNameNumInfo += "%s-%s£»" % (petNumNameDict[petNum], petNum)  | 
|         if petNum % 3 == 0 or i == len(petNumList):  | 
|             GameWorld.DebugAnswer(curPlayer, petNameNumInfo)  | 
|             petNameNumInfo = ""  | 
|               | 
|     return  | 
|   | 
| ## GMÃüÁîÖ´ÐÐÈë¿Ú  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param msgList ²ÎÊýÁÐ±í  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def OnExec(curPlayer, msgList):  | 
|       | 
|     petNumNameDict = {}  | 
|     petNPCIDNumDict = {}  | 
|     ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|     for index in xrange(ipyDataMgr.GetPetInfoCount()):  | 
|         ipyData = ipyDataMgr.GetPetInfoByIndex(index)  | 
|         needItemID = ipyData.GetUnLockNeedItemID()  | 
|         curItem = GameWorld.GetGameData().GetItemByTypeID(needItemID)  | 
|         if not curItem:  | 
|             continue  | 
|         itemName = curItem.GetName()  | 
|         petName = itemName.replace("Áé³è£º", "")  | 
|         petNum = index + 1  | 
|           | 
|         petNPCID = ipyData.GetID()  | 
|         petNPCIDNumDict[petNPCID] = petNum  | 
|         petNumNameDict[petNum] = petName  | 
|     petNumList = sorted(petNumNameDict.keys())  | 
|       | 
|     if not msgList:  | 
|         __Help(curPlayer, petNumNameDict)  | 
|         return  | 
|       | 
|           | 
|     # ÖØÖÃÁé³è  | 
|     if msgList[0] == 0:  | 
|         clearNumList = msgList[1:] if len(msgList) > 1 else None  | 
|         clearOKList = __ClearPet(curPlayer, petNPCIDNumDict, clearNumList)  | 
|           | 
|         for trainType in xrange(1, PlayerPet.GetPetTrainTypes() + 1):  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PetTrainLV % trainType, 1)  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PetTrainItemCount % trainType, 0)  | 
|               | 
|         GameWorld.DebugAnswer(curPlayer, "ÖØÖÃÁé³è±àºÅ:%s" % sorted(clearOKList))  | 
|           | 
|     # ¼¤»îËùÓÐ  | 
|     elif msgList[0] == 99:  | 
|         isFullLV = msgList[1] if len(msgList) > 1 else None  | 
|         classLV = 999 if isFullLV else None  | 
|         OpenFunc.DoGMOpenFunc(curPlayer, ShareDefine.GameFuncID_Pet)  | 
|         activeOKList = []  | 
|         petNumList = petNPCIDNumDict.values()  | 
|         for i, petNum in enumerate(petNumList):  | 
|             index = msgList[0]  | 
|             refresh = i >= (len(petNumList) - 1)  | 
|             if PlayerPet.DoPetActivate(curPlayer, petNum, classLV, refresh=refresh):  | 
|                 activeOKList.append(petNum)  | 
|                   | 
|         GameWorld.DebugAnswer(curPlayer, "¼¤»îÁé³è±àºÅ:%s" % sorted(activeOKList))  | 
|           | 
|     # ¼¤»îÖ¸¶¨  | 
|     elif len(msgList) == 2:  | 
|         petNum = msgList[0]  | 
|         classLV = msgList[1]  | 
|         OpenFunc.DoGMOpenFunc(curPlayer, ShareDefine.GameFuncID_Pet)  | 
|         if PlayerPet.DoPetActivate(curPlayer, petNum, classLV):  | 
|             GameWorld.DebugAnswer(curPlayer, "¼¤»îÁé³è: %s(%s), %s½×" % (petNumNameDict.get(petNum, petNum), petNum, classLV))  | 
|               | 
|     # ÅàÑøÁé³è  | 
|     elif len(msgList) == 3:  | 
|         trainType, trainLV, eatItemCount = msgList  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PetTrainLV % trainType, trainLV)  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PetTrainItemCount % trainType, eatItemCount)  | 
|           | 
|     else:  | 
|         __Help(curPlayer, petNumNameDict)  | 
|         return  | 
|       | 
|     PlayerPet.RefreshPetItemAddAttr(curPlayer, True)  | 
|     PlayerPet.OnPlayerPetLogin(curPlayer)  | 
|     return  | 
|   | 
| def __ClearPet(curPlayer, petNPCIDNumDict, clearNumList=None):  | 
|       | 
|     clearOKList = []  | 
|     #»ñµÃÕ½¶·µÄ³èÎï  | 
|     fightPetNPCID = 0  | 
|     curPetMgr = curPlayer.GetPetMgr()  | 
|     fightPet = curPetMgr.GetFightPet()  | 
|     if fightPet != None:  | 
|         fightPetNPCID = fightPet.GetRolePet().NPCID  | 
|           | 
|     fightPetNum = petNPCIDNumDict.get(fightPetNPCID)  | 
|     #---Èç¹ûÓгöÕ½ÖеijèÎïÐèÒªÏÈÕÙ»Ø---  | 
|     if not clearNumList or fightPetNum in clearNumList:  | 
|         PetControl.ReCallFightPet(curPlayer)  | 
|           | 
|     #»ñµÃÍæ¼Ò³èÎïÐÅÏ¢  | 
|     petList = []  | 
|     petListCount = curPetMgr.PetList_Cnt()          | 
|     for i in range(petListCount):  | 
|         pet = curPetMgr.PetList_At(i)  | 
|         petNPCID = pet.GetRolePet().NPCID  | 
|         petNum = petNPCIDNumDict.get(petNPCID)  | 
|         if not clearNumList or petNum in clearNumList:  | 
|             petList.append(pet)  | 
|               | 
|     for pet in petList:  | 
|         curPetMgr.PetList_SetFree(pet.GetRolePet().PetID)  | 
|           | 
|     # ³èÎïÊý¾ÝÎïÆ·±³°üÇå³ý  | 
|     petPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptPet)  | 
|     for i in range(petPack.GetCount())[::-1]:  | 
|         petItem = petPack.GetAt(i)  | 
|           | 
|         if not petItem or petItem.IsEmpty():  | 
|             continue  | 
|           | 
|         petNPCID = petItem.GetUserAttr(ShareDefine.Def_IudetPet_NPCID)  | 
|         petNum = petNPCIDNumDict.get(petNPCID)  | 
|         if not clearNumList or petNum in clearNumList:  | 
|             petItem.Clear()  | 
|             clearOKList.append(petNum)  | 
|               | 
|     return clearOKList  |