hxp
2022-02-21 0c27822ef5e6c67782ed143a4ff03ecfbdfda1fb
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
#!/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