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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GM.Commands.NPCAttr
#
# @todo:Êä³öNPCÊôÐÔ
# @author hxp
# @date 2026-1-4
# @version 1.0
#
# ÏêϸÃèÊö: Êä³öNPCÊôÐÔ
#
#-------------------------------------------------------------------------------
#"""Version = 2026-1-4 11:00"""
#-------------------------------------------------------------------------------
 
import FBCommon
import GameWorld
import TurnAttack
import IpyGameDataPY
import NPCCommon
import ChConfig
import os
 
def OnExec(curPlayer, paramList):
    
    if not paramList:
        GameWorld.DebugAnswer(curPlayer, "Êä³ö¸±±¾ÊôÐÔ: NPCAttr mapID lineID")
        GameWorld.DebugAnswer(curPlayer, "Êä³öÖ÷Ïßboss: NPCAttr 2 Õ½ڠ¹Ø¿¨ID")
        GameWorld.DebugAnswer(curPlayer, "µ¼³öÖ÷ÏßÊôÐÔ: NPCAttr e main")
        return
    
    value = paramList[0]
    if value == "e":
        __exportNPCAttr(curPlayer, paramList)
        return
    
    GameWorld.DebugAnswer(curPlayer, "---------------------------")
    mapID = value
    if mapID in [ChConfig.Def_FBMapID_Main, ChConfig.Def_FBMapID_MainBoss]:
        chapterID = paramList[1] if len(paramList) > 1 else 1
        levelNum = paramList[2] if len(paramList) > 2 else 1
        levelIpyData = IpyGameDataPY.GetIpyGameData("MainLevel", chapterID, levelNum)
        if not levelIpyData:
            GameWorld.DebugAnswer(curPlayer, "²»´æÔÚ¸ÃÕ½ڹؿ¨! %s-%s" % (chapterID, levelNum))
            return
        lineupIDList = levelIpyData.GetBossLineupIDList() # Boss²¨ÕóÈÝIDÁÐ±í£¬Ð¡¶Ó1ÕóÈÝID|С¶Ó2ÕóÈÝID|...
        strongerLV = levelIpyData.GetNPCLV()
        difficulty = levelIpyData.GetDifficulty()
        GameWorld.DebugAnswer(curPlayer, "Ö÷ÏßÕ¹Ø: %s-%s" % (chapterID, levelNum))
    else:
        funcLineID = paramList[1] if len(paramList) > 1 else 0
        fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, funcLineID)
        if not fbLineIpyData:
            GameWorld.DebugAnswer(curPlayer, "²»´æÔڸø±±¾¹Ø¿¨! %s-%s" % (mapID, funcLineID))
            return
        lineupIDList = fbLineIpyData.GetLineupIDList()
        strongerLV = fbLineIpyData.GetNPCLV()
        difficulty = fbLineIpyData.GetDifficulty()
        GameWorld.DebugAnswer(curPlayer, "¸±±¾¹Ø¿¨: %s-%s" % (mapID, funcLineID))
        
    __printNPCLineupAttr(curPlayer, lineupIDList, strongerLV, difficulty)    
    return
 
def __exportNPCAttr(curPlayer, paramList):
    ## µ¼³öNPCÊôÐÔ£¬¹©²ß»®¼ì²é¶Ô±È
    mapID = paramList[1] if len(paramList) > 1 else "main"
    
    if mapID == "main":
        __exportMainLevelNPCAttr(curPlayer, mapID)
        
    return
 
def __printNPCLineupAttr(curPlayer, lineupIDList, npcLV, difficulty):
    GameWorld.DebugAnswer(curPlayer, "ÕóÈÝ:%s,LV:%s,ÄѶÈ:%s" % (lineupIDList, npcLV, difficulty))
    for lineupID in lineupIDList:
        lineupInfo = TurnAttack.GetNPCLineupInfo(lineupID, npcLV, difficulty, False)
        if not lineupInfo:
            continue
        heroDict = lineupInfo["Hero"]
        bossID = lineupInfo["BossID"] # ÎÞbossʱΪ0
        for posNum in range(1, 1 + 10):
            if str(posNum) not in heroDict:
                continue
            attrInfo = heroDict[str(posNum)]
            posNum = int(posNum)
            npcID = attrInfo["NPCID"]
            heroID = attrInfo["HeroID"]
            #realNPCLV = attrInfo["LV"]
            skillIDList = attrInfo["SkillIDList"]
            attrDict = attrInfo["AttrDict"]
            isBoss = 1 if bossID == npcID else 0
            attrDict2 = {}
            for attrID, value in attrDict.items():
                attrID = int(attrID)
                if not value:
                    continue
                attrDict2[attrID] = value
            
            npcData = NPCCommon.GetNPCDataPy(npcID)
            if not npcData:
                continue
            
            GameWorld.DebugAnswer(curPlayer, "----------")
            objName = GameWorld.CodeToGbk(npcData.GetNPCName())
            if heroID:
                objName += " Hero:%s" % heroID
            if npcID:
                objName += " NPC:%s" % npcID        
            objName = "P%s:%s" % (posNum, objName)
            
            GameWorld.DebugAnswer(curPlayer, "%s%s" % (objName, "¡¾Boss¡¿" if isBoss else ""))
            GameWorld.DebugAnswer(curPlayer, "¹¥:%s,·À:%s,HP:%s" 
                                  % (attrDict2.get(ChConfig.AttrID_Atk, 0), 
                                     attrDict2.get(ChConfig.AttrID_Def, 0), 
                                     attrDict2.get(ChConfig.AttrID_MaxHP, 0)))
            
            attrStr = ""
            attrIDList = attrDict2.keys()
            attrIDList.sort()
            for attrID in attrIDList:
                if attrID in [ChConfig.AttrID_Atk, ChConfig.AttrID_Def, ChConfig.AttrID_MaxHP]:
                    continue
                attrValue = attrDict2[attrID]
                if attrValue:
                    attrStr += "%s=%s£»" % (attrID, attrValue)
            GameWorld.DebugAnswer(curPlayer, "ÊôÐÔ:%s" % attrStr)
            GameWorld.DebugAnswer(curPlayer, "¼¼ÄÜ: %s,%s" % (len(skillIDList), skillIDList))
                
    return
 
def __exportMainLevelNPCAttr(curPlayer, mapID):
    fieldList = ["Õ½Ú", "¹Ø¿¨", "²¨", "ÕóÈÝID", "IsBoss", "NPCID", "HeroID", "LV", "SkillIDList"]
    valueList = []
    attrIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetMainLevelCount()):
        ipyData = ipyDataMgr.GetMainLevelByIndex(index)
        chapterID = ipyData.GetChapterID()
        levelNum = ipyData.GetLevelNum()
        npcLV = ipyData.GetNPCLV()
        difficulty = ipyData.GetDifficulty()
        waveLineupIDList = []
        for wave in range(1, 1 + 6):
            if not hasattr(ipyData, "GetWaveLineupIDList%s" % wave):
                break
            lineupIDList = getattr(ipyData, "GetWaveLineupIDList%s" % wave)()
            waveLineupIDList.append(lineupIDList)
        bossLineupIDList = ipyData.GetBossLineupIDList() # Boss²¨ÕóÈÝIDÁбí
        if bossLineupIDList:
            waveLineupIDList.append(bossLineupIDList) # bossµ±×ö×îºóÒ»²¨
            
        for wave, lineupIDList in enumerate(waveLineupIDList, 1):
            for lineupID in lineupIDList:
                lineupInfo = TurnAttack.GetNPCLineupInfo(lineupID, npcLV, difficulty, False)
                if not lineupInfo:
                    continue
                heroDict = lineupInfo["Hero"]
                bossID = lineupInfo["BossID"] # ÎÞbossʱΪ0
                for posNum, attrInfo in heroDict.items():
                    posNum = int(posNum)
                    npcID = attrInfo["NPCID"]
                    heroID = attrInfo["HeroID"]
                    realNPCLV = attrInfo["LV"]
                    skillIDList = attrInfo["SkillIDList"]
                    attrDict = attrInfo["AttrDict"]
                    isBoss = 1 if bossID == npcID else 0
                    attrDict2 = {}
                    for attrID, value in attrDict.items():
                        attrID = int(attrID)
                        if attrID not in attrIDList:
                            attrIDList.append(attrID)
                        attrDict2[attrID] = value
                    values = [chapterID, levelNum, wave, lineupID, isBoss, npcID, heroID, realNPCLV, skillIDList, attrDict2]
                    valueList.append(values)
                    
                    
    # °´Ë³ÐòÕûÀí´æÔÚµÄÊôÐÔ      
    attrIDList.sort()
    attrNameList = []
    for attrID in attrIDList:
        attrIpyData = IpyGameDataPY.GetIpyGameData("PlayerAttr", attrID)
        attrName = attrIpyData.GetParameter() if attrIpyData else "%s" % attrID
        attrNameList.append(attrName)
        
    fieldList += attrNameList # ×îÖÕ×Ö¶Î
    
    folderPath = os.path.join("C:\NPCAttr")
    if not os.path.exists(folderPath):
        os.makedirs(folderPath)
    exportFilePath = os.path.join(folderPath, "NPCAttrMapID_%s.txt" % (mapID))
    
    lineFormat = "%s" + "\t%s"*(len(fieldList) - 1)
    
    fp = open(exportFilePath, "w")
    fp.write("%s\n" % (lineFormat % tuple(fieldList)))
    for values in valueList:
        attrDict2 = values[-1]
        writeValues = values[:-1]
        for attrID in attrIDList:
            writeValues.append(attrDict2.get(attrID, 0))
        fp.write("%s\n" % (lineFormat % tuple(writeValues)))
    fp.close()
    GameWorld.DebugAnswer(curPlayer, "µ¼³ö:%s" % exportFilePath)
    return