hxp
2022-02-21 0c27822ef5e6c67782ed143a4ff03ecfbdfda1fb
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Pet.py
@@ -18,11 +18,30 @@
import ChConfig
import GameWorld
import PlayerControl
import IpyGameDataPY
import ShareDefine
import PetControl
import PlayerPet
import PetClear
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 当前玩家
@@ -31,29 +50,117 @@
#  @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:
        GameWorld.DebugAnswer(curPlayer, "重置所有灵宠: Pet 0")
        GameWorld.DebugAnswer(curPlayer, "设置培养灵宠: Pet 培养类型 等阶 丹数")
        __Help(curPlayer, petNumNameDict)
        return
    
    # 重置灵宠
    if msgList[0] == 0:
        if len(msgList) > 1 and msgList[1] == 1:
            PetClear.OnExec(curPlayer, [])
        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)
    #---如果有出战中的宠物需要先召回---
    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