create_enemies_excel.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import pandas as pd
  2. import json
  3. import os
  4. def load_enemies_json():
  5. """加载敌人配置JSON文件"""
  6. json_path = 'd:/CocosGame/Pong/assets/resources/data/enemies.json'
  7. with open(json_path, 'r', encoding='utf-8') as f:
  8. return json.load(f)
  9. def create_enemies_excel():
  10. """创建敌人配置Excel表格"""
  11. data = load_enemies_json()
  12. enemies = data['enemies']
  13. # 1. 敌人基础配置表
  14. enemies_basic = []
  15. for enemy in enemies:
  16. enemies_basic.append({
  17. '敌人ID': enemy['id'],
  18. '敌人名称': enemy['name'],
  19. '敌人类型': enemy['type'],
  20. '稀有度': enemy['rarity'],
  21. '权重': enemy['weight'],
  22. '生命值': enemy['stats']['health'],
  23. '移动速度': enemy['stats']['speed'],
  24. '攻击力': enemy['stats']['damage'],
  25. '攻击范围': enemy['stats']['attackRange'],
  26. '攻击速度': enemy['stats']['attackSpeed'],
  27. '防御力': enemy['stats']['defense'],
  28. '金币奖励': enemy['stats']['coinReward']
  29. })
  30. # 2. 战斗配置表
  31. combat_configs = []
  32. for enemy in enemies:
  33. combat = enemy['combat']
  34. combat_config = {
  35. '敌人ID': enemy['id'],
  36. '敌人名称': enemy['name'],
  37. '攻击类型': combat['attackType'],
  38. '攻击延迟': combat['attackDelay'],
  39. '攻击冷却': combat['attackCooldown'],
  40. '可格挡': combat['canBlock'],
  41. '格挡几率': combat['blockChance']
  42. }
  43. # 添加可选字段
  44. if 'weaponType' in combat:
  45. combat_config['武器类型'] = combat['weaponType']
  46. if 'projectileType' in combat:
  47. combat_config['投射物类型'] = combat['projectileType']
  48. if 'projectileSpeed' in combat:
  49. combat_config['投射物速度'] = combat['projectileSpeed']
  50. combat_configs.append(combat_config)
  51. # 3. 移动配置表
  52. movement_configs = []
  53. for enemy in enemies:
  54. movement = enemy['movement']
  55. movement_config = {
  56. '敌人ID': enemy['id'],
  57. '敌人名称': enemy['name'],
  58. '移动类型': movement['type'],
  59. '移动模式': movement['pattern'],
  60. '速度变化': movement['speedVariation']
  61. }
  62. # 添加可选字段
  63. if 'swayAmplitude' in movement:
  64. movement_config['摆动幅度'] = movement['swayAmplitude']
  65. if 'swayFrequency' in movement:
  66. movement_config['摆动频率'] = movement['swayFrequency']
  67. movement_configs.append(movement_config)
  68. # 4. 视觉配置表
  69. visual_configs = []
  70. for enemy in enemies:
  71. visual = enemy['visualConfig']
  72. visual_config = {
  73. '敌人ID': enemy['id'],
  74. '敌人名称': enemy['name'],
  75. '精灵预制体': visual['spritePrefab'],
  76. '缩放比例': visual['scale'],
  77. '水平翻转': visual['flipX'],
  78. '待机动画': visual['animations']['idle'],
  79. '行走动画': visual['animations']['walk'],
  80. '攻击动画': visual['animations']['attack'],
  81. '死亡动画': visual['animations']['dead']
  82. }
  83. # 添加可选字段
  84. if 'weapon' in visual:
  85. visual_config['武器道具'] = visual['weapon']
  86. if 'armor' in visual:
  87. visual_config['护甲道具'] = visual['armor']
  88. if 'prop' in visual:
  89. visual_config['特殊道具'] = visual['prop']
  90. visual_configs.append(visual_config)
  91. # 5. 音频配置表
  92. audio_configs = []
  93. for enemy in enemies:
  94. audio = enemy['audioConfig']
  95. audio_config = {
  96. '敌人ID': enemy['id'],
  97. '敌人名称': enemy['name'],
  98. '行走音效': audio['walkSound'],
  99. '攻击音效': audio['attackSound'],
  100. '死亡音效': audio['deathSound']
  101. }
  102. # 添加可选字段
  103. if 'hurtSound' in audio:
  104. audio_config['受伤音效'] = audio['hurtSound']
  105. if 'blockSound' in audio:
  106. audio_config['格挡音效'] = audio['blockSound']
  107. if 'stealthSound' in audio:
  108. audio_config['隐身音效'] = audio['stealthSound']
  109. if 'armorBreakSound' in audio:
  110. audio_config['护甲破碎音效'] = audio['armorBreakSound']
  111. if 'fuseSound' in audio:
  112. audio_config['引信音效'] = audio['fuseSound']
  113. if 'summonSound' in audio:
  114. audio_config['召唤音效'] = audio['summonSound']
  115. if 'laserSound' in audio:
  116. audio_config['激光音效'] = audio['laserSound']
  117. audio_configs.append(audio_config)
  118. # 6. 特殊能力配置表
  119. abilities_configs = []
  120. for enemy in enemies:
  121. abilities = enemy['specialAbilities']
  122. for ability in abilities:
  123. abilities_configs.append({
  124. '敌人ID': enemy['id'],
  125. '敌人名称': enemy['name'],
  126. '特殊能力': ability
  127. })
  128. # 7. BOSS配置表
  129. boss_configs = []
  130. for enemy in enemies:
  131. if enemy['type'] == 'boss' and 'bossConfig' in enemy:
  132. boss = enemy['bossConfig']
  133. boss_config = {
  134. '敌人ID': enemy['id'],
  135. '敌人名称': enemy['name'],
  136. '阶段数': boss['phases'],
  137. '阶段血量阈值': boss['phaseHealthThreshold']
  138. }
  139. # 添加可选字段
  140. if 'enrageBonus' in boss:
  141. enrage = boss['enrageBonus']
  142. boss_config['狂暴速度加成'] = enrage.get('speed', 1.0)
  143. boss_config['狂暴伤害加成'] = enrage.get('damage', 1.0)
  144. boss_config['狂暴攻速加成'] = enrage.get('attackSpeed', 1.0)
  145. if 'summonAbility' in boss:
  146. summon = boss['summonAbility']
  147. boss_config['召唤单位类型'] = summon['minionType']
  148. boss_config['召唤数量'] = summon['summonCount']
  149. boss_config['召唤冷却'] = summon['summonCooldown']
  150. if 'laserAbility' in boss:
  151. laser = boss['laserAbility']
  152. boss_config['激光伤害'] = laser['damage']
  153. boss_config['激光射程'] = laser['range']
  154. boss_config['激光充能时间'] = laser['chargeTime']
  155. boss_config['激光冷却时间'] = laser['cooldown']
  156. boss_configs.append(boss_config)
  157. # 8. 生成权重配置表
  158. spawn_weights = []
  159. for rarity, weight in data['spawnWeights'].items():
  160. spawn_weights.append({
  161. '稀有度': rarity,
  162. '生成权重': weight
  163. })
  164. # 9. 波次进度配置表
  165. wave_progression = []
  166. for wave_type, enemy_list in data['waveProgression'].items():
  167. for enemy_id in enemy_list:
  168. wave_progression.append({
  169. '波次类型': wave_type,
  170. '敌人ID': enemy_id
  171. })
  172. # 10. 敌人名称映射表
  173. name_mapping = []
  174. if 'nameToIdMapping' in data:
  175. for name, enemy_id in data['nameToIdMapping'].items():
  176. name_mapping.append({
  177. '中文名称': name,
  178. '英文ID': enemy_id
  179. })
  180. # 创建Excel文件
  181. output_path = 'd:/CocosGame/Pong/assets/resources/data/excel/敌人配置表.xlsx'
  182. with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
  183. # 写入各个工作表
  184. pd.DataFrame(enemies_basic).to_excel(writer, sheet_name='敌人基础配置', index=False)
  185. pd.DataFrame(combat_configs).to_excel(writer, sheet_name='战斗配置', index=False)
  186. pd.DataFrame(movement_configs).to_excel(writer, sheet_name='移动配置', index=False)
  187. pd.DataFrame(visual_configs).to_excel(writer, sheet_name='视觉配置', index=False)
  188. pd.DataFrame(audio_configs).to_excel(writer, sheet_name='音频配置', index=False)
  189. pd.DataFrame(abilities_configs).to_excel(writer, sheet_name='特殊能力配置', index=False)
  190. pd.DataFrame(boss_configs).to_excel(writer, sheet_name='BOSS配置', index=False)
  191. pd.DataFrame(spawn_weights).to_excel(writer, sheet_name='生成权重配置', index=False)
  192. pd.DataFrame(wave_progression).to_excel(writer, sheet_name='波次进度配置', index=False)
  193. pd.DataFrame(name_mapping).to_excel(writer, sheet_name='敌人名称映射', index=False)
  194. # 为每个工作表添加中文注释(第二行)
  195. workbook = writer.book
  196. # 敌人基础配置注释
  197. ws1 = workbook['敌人基础配置']
  198. ws1.insert_rows(2)
  199. comments1 = ['唯一标识符', '显示名称', '敌人分类', '稀有程度', '生成权重值', '生命点数', '移动速度', '攻击伤害', '攻击距离', '攻击频率', '防御数值', '击杀奖励']
  200. for i, comment in enumerate(comments1, 1):
  201. ws1.cell(row=2, column=i, value=comment)
  202. # 战斗配置注释
  203. ws2 = workbook['战斗配置']
  204. ws2.insert_rows(2)
  205. comments2 = ['唯一标识符', '显示名称', '攻击方式', '攻击前摇', '攻击间隔', '是否可格挡', '格挡成功率', '武器种类', '投射物类型', '投射物飞行速度']
  206. for i, comment in enumerate(comments2, 1):
  207. if i <= len(ws2[1]):
  208. ws2.cell(row=2, column=i, value=comment)
  209. # 移动配置注释
  210. ws3 = workbook['移动配置']
  211. ws3.insert_rows(2)
  212. comments3 = ['唯一标识符', '显示名称', '移动方式', '移动轨迹', '速度随机变化', '左右摆动范围', '摆动周期频率']
  213. for i, comment in enumerate(comments3, 1):
  214. if i <= len(ws3[1]):
  215. ws3.cell(row=2, column=i, value=comment)
  216. # 视觉配置注释
  217. ws4 = workbook['视觉配置']
  218. ws4.insert_rows(2)
  219. comments4 = ['唯一标识符', '显示名称', 'Spine动画资源路径', '显示缩放倍数', '是否水平镜像', '待机状态动画', '移动状态动画', '攻击状态动画', '死亡状态动画', '武器道具路径', '护甲道具路径', '特殊道具路径']
  220. for i, comment in enumerate(comments4, 1):
  221. if i <= len(ws4[1]):
  222. ws4.cell(row=2, column=i, value=comment)
  223. # 音频配置注释
  224. ws5 = workbook['音频配置']
  225. ws5.insert_rows(2)
  226. comments5 = ['唯一标识符', '显示名称', '移动时音效', '攻击时音效', '死亡时音效', '受伤时音效', '格挡时音效', '隐身时音效', '护甲破碎音效', '引信燃烧音效', '召唤时音效', '激光发射音效']
  227. for i, comment in enumerate(comments5, 1):
  228. if i <= len(ws5[1]):
  229. ws5.cell(row=2, column=i, value=comment)
  230. # 特殊能力配置注释
  231. ws6 = workbook['特殊能力配置']
  232. ws6.insert_rows(2)
  233. comments6 = ['唯一标识符', '显示名称', '特殊技能名称']
  234. for i, comment in enumerate(comments6, 1):
  235. ws6.cell(row=2, column=i, value=comment)
  236. # BOSS配置注释
  237. ws7 = workbook['BOSS配置']
  238. ws7.insert_rows(2)
  239. comments7 = ['唯一标识符', '显示名称', '战斗阶段总数', '进入下阶段血量比例', '狂暴状态速度倍数', '狂暴状态伤害倍数', '狂暴状态攻速倍数', '召唤的单位类型', '单次召唤数量', '召唤技能冷却时间', '激光攻击伤害', '激光攻击射程', '激光充能准备时间', '激光技能冷却时间']
  240. for i, comment in enumerate(comments7, 1):
  241. if i <= len(ws7[1]):
  242. ws7.cell(row=2, column=i, value=comment)
  243. # 生成权重配置注释
  244. ws8 = workbook['生成权重配置']
  245. ws8.insert_rows(2)
  246. comments8 = ['稀有度等级', '随机生成权重值']
  247. for i, comment in enumerate(comments8, 1):
  248. ws8.cell(row=2, column=i, value=comment)
  249. # 波次进度配置注释
  250. ws9 = workbook['波次进度配置']
  251. ws9.insert_rows(2)
  252. comments9 = ['游戏阶段类型', '该阶段出现的敌人ID']
  253. for i, comment in enumerate(comments9, 1):
  254. ws9.cell(row=2, column=i, value=comment)
  255. # 敌人名称映射注释
  256. ws10 = workbook['敌人名称映射']
  257. ws10.insert_rows(2)
  258. comments10 = ['关卡配置中使用的中文名称', '对应的英文敌人ID']
  259. for i, comment in enumerate(comments10, 1):
  260. ws10.cell(row=2, column=i, value=comment)
  261. print(f"敌人配置Excel表格已生成完成!")
  262. print(f"文件位置: {output_path}")
  263. print(f"包含工作表: 敌人基础配置、战斗配置、移动配置、视觉配置、音频配置、特殊能力配置、BOSS配置、生成权重配置、波次进度配置、敌人名称映射")
  264. def main():
  265. """主函数"""
  266. try:
  267. print("开始生成敌人配置Excel表格...")
  268. create_enemies_excel()
  269. print("所有表格生成完成!")
  270. except Exception as e:
  271. print(f"生成过程中出现错误: {e}")
  272. import traceback
  273. traceback.print_exc()
  274. if __name__ == "__main__":
  275. main()