| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- import pandas as pd
- import json
- import os
- def load_enemies_json():
- """加载敌人配置JSON文件"""
- json_path = 'd:/CocosGame/Pong/assets/resources/data/enemies.json'
- with open(json_path, 'r', encoding='utf-8') as f:
- return json.load(f)
- def create_enemies_excel():
- """创建敌人配置Excel表格"""
- data = load_enemies_json()
- enemies = data['enemies']
-
- # 1. 敌人基础配置表
- enemies_basic = []
- for enemy in enemies:
- enemies_basic.append({
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '敌人类型': enemy['type'],
- '稀有度': enemy['rarity'],
- '权重': enemy['weight'],
- '生命值': enemy['stats']['health'],
- '移动速度': enemy['stats']['speed'],
- '攻击力': enemy['stats']['damage'],
- '攻击范围': enemy['stats']['attackRange'],
- '攻击速度': enemy['stats']['attackSpeed'],
- '防御力': enemy['stats']['defense'],
- '金币奖励': enemy['stats']['coinReward']
- })
-
- # 2. 战斗配置表
- combat_configs = []
- for enemy in enemies:
- combat = enemy['combat']
- combat_config = {
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '攻击类型': combat['attackType'],
- '攻击延迟': combat['attackDelay'],
- '攻击冷却': combat['attackCooldown'],
- '可格挡': combat['canBlock'],
- '格挡几率': combat['blockChance']
- }
-
- # 添加可选字段
- if 'weaponType' in combat:
- combat_config['武器类型'] = combat['weaponType']
- if 'projectileType' in combat:
- combat_config['投射物类型'] = combat['projectileType']
- if 'projectileSpeed' in combat:
- combat_config['投射物速度'] = combat['projectileSpeed']
-
- combat_configs.append(combat_config)
-
- # 3. 移动配置表
- movement_configs = []
- for enemy in enemies:
- movement = enemy['movement']
- movement_config = {
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '移动类型': movement['type'],
- '移动模式': movement['pattern'],
- '速度变化': movement['speedVariation']
- }
-
- # 添加可选字段
- if 'swayAmplitude' in movement:
- movement_config['摆动幅度'] = movement['swayAmplitude']
- if 'swayFrequency' in movement:
- movement_config['摆动频率'] = movement['swayFrequency']
-
- movement_configs.append(movement_config)
-
- # 4. 视觉配置表
- visual_configs = []
- for enemy in enemies:
- visual = enemy['visualConfig']
- visual_config = {
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '精灵预制体': visual['spritePrefab'],
- '缩放比例': visual['scale'],
- '水平翻转': visual['flipX'],
- '待机动画': visual['animations']['idle'],
- '行走动画': visual['animations']['walk'],
- '攻击动画': visual['animations']['attack'],
- '死亡动画': visual['animations']['dead']
- }
-
- # 添加可选字段
- if 'weapon' in visual:
- visual_config['武器道具'] = visual['weapon']
- if 'armor' in visual:
- visual_config['护甲道具'] = visual['armor']
- if 'prop' in visual:
- visual_config['特殊道具'] = visual['prop']
-
- visual_configs.append(visual_config)
-
- # 5. 音频配置表
- audio_configs = []
- for enemy in enemies:
- audio = enemy['audioConfig']
- audio_config = {
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '行走音效': audio['walkSound'],
- '攻击音效': audio['attackSound'],
- '死亡音效': audio['deathSound']
- }
-
- # 添加可选字段
- if 'hurtSound' in audio:
- audio_config['受伤音效'] = audio['hurtSound']
- if 'blockSound' in audio:
- audio_config['格挡音效'] = audio['blockSound']
- if 'stealthSound' in audio:
- audio_config['隐身音效'] = audio['stealthSound']
- if 'armorBreakSound' in audio:
- audio_config['护甲破碎音效'] = audio['armorBreakSound']
- if 'fuseSound' in audio:
- audio_config['引信音效'] = audio['fuseSound']
- if 'summonSound' in audio:
- audio_config['召唤音效'] = audio['summonSound']
- if 'laserSound' in audio:
- audio_config['激光音效'] = audio['laserSound']
-
- audio_configs.append(audio_config)
-
- # 6. 特殊能力配置表
- abilities_configs = []
- for enemy in enemies:
- abilities = enemy['specialAbilities']
- for ability in abilities:
- abilities_configs.append({
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '特殊能力': ability
- })
-
- # 7. BOSS配置表
- boss_configs = []
- for enemy in enemies:
- if enemy['type'] == 'boss' and 'bossConfig' in enemy:
- boss = enemy['bossConfig']
- boss_config = {
- '敌人ID': enemy['id'],
- '敌人名称': enemy['name'],
- '阶段数': boss['phases'],
- '阶段血量阈值': boss['phaseHealthThreshold']
- }
-
- # 添加可选字段
- if 'enrageBonus' in boss:
- enrage = boss['enrageBonus']
- boss_config['狂暴速度加成'] = enrage.get('speed', 1.0)
- boss_config['狂暴伤害加成'] = enrage.get('damage', 1.0)
- boss_config['狂暴攻速加成'] = enrage.get('attackSpeed', 1.0)
-
- if 'summonAbility' in boss:
- summon = boss['summonAbility']
- boss_config['召唤单位类型'] = summon['minionType']
- boss_config['召唤数量'] = summon['summonCount']
- boss_config['召唤冷却'] = summon['summonCooldown']
-
- if 'laserAbility' in boss:
- laser = boss['laserAbility']
- boss_config['激光伤害'] = laser['damage']
- boss_config['激光射程'] = laser['range']
- boss_config['激光充能时间'] = laser['chargeTime']
- boss_config['激光冷却时间'] = laser['cooldown']
-
- boss_configs.append(boss_config)
-
- # 8. 生成权重配置表
- spawn_weights = []
- for rarity, weight in data['spawnWeights'].items():
- spawn_weights.append({
- '稀有度': rarity,
- '生成权重': weight
- })
-
- # 9. 波次进度配置表
- wave_progression = []
- for wave_type, enemy_list in data['waveProgression'].items():
- for enemy_id in enemy_list:
- wave_progression.append({
- '波次类型': wave_type,
- '敌人ID': enemy_id
- })
-
- # 10. 敌人名称映射表
- name_mapping = []
- if 'nameToIdMapping' in data:
- for name, enemy_id in data['nameToIdMapping'].items():
- name_mapping.append({
- '中文名称': name,
- '英文ID': enemy_id
- })
-
- # 创建Excel文件
- output_path = 'd:/CocosGame/Pong/assets/resources/data/excel/敌人配置表.xlsx'
- with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
- # 写入各个工作表
- pd.DataFrame(enemies_basic).to_excel(writer, sheet_name='敌人基础配置', index=False)
- pd.DataFrame(combat_configs).to_excel(writer, sheet_name='战斗配置', index=False)
- pd.DataFrame(movement_configs).to_excel(writer, sheet_name='移动配置', index=False)
- pd.DataFrame(visual_configs).to_excel(writer, sheet_name='视觉配置', index=False)
- pd.DataFrame(audio_configs).to_excel(writer, sheet_name='音频配置', index=False)
- pd.DataFrame(abilities_configs).to_excel(writer, sheet_name='特殊能力配置', index=False)
- pd.DataFrame(boss_configs).to_excel(writer, sheet_name='BOSS配置', index=False)
- pd.DataFrame(spawn_weights).to_excel(writer, sheet_name='生成权重配置', index=False)
- pd.DataFrame(wave_progression).to_excel(writer, sheet_name='波次进度配置', index=False)
- pd.DataFrame(name_mapping).to_excel(writer, sheet_name='敌人名称映射', index=False)
-
- # 为每个工作表添加中文注释(第二行)
- workbook = writer.book
-
- # 敌人基础配置注释
- ws1 = workbook['敌人基础配置']
- ws1.insert_rows(2)
- comments1 = ['唯一标识符', '显示名称', '敌人分类', '稀有程度', '生成权重值', '生命点数', '移动速度', '攻击伤害', '攻击距离', '攻击频率', '防御数值', '击杀奖励']
- for i, comment in enumerate(comments1, 1):
- ws1.cell(row=2, column=i, value=comment)
-
- # 战斗配置注释
- ws2 = workbook['战斗配置']
- ws2.insert_rows(2)
- comments2 = ['唯一标识符', '显示名称', '攻击方式', '攻击前摇', '攻击间隔', '是否可格挡', '格挡成功率', '武器种类', '投射物类型', '投射物飞行速度']
- for i, comment in enumerate(comments2, 1):
- if i <= len(ws2[1]):
- ws2.cell(row=2, column=i, value=comment)
-
- # 移动配置注释
- ws3 = workbook['移动配置']
- ws3.insert_rows(2)
- comments3 = ['唯一标识符', '显示名称', '移动方式', '移动轨迹', '速度随机变化', '左右摆动范围', '摆动周期频率']
- for i, comment in enumerate(comments3, 1):
- if i <= len(ws3[1]):
- ws3.cell(row=2, column=i, value=comment)
-
- # 视觉配置注释
- ws4 = workbook['视觉配置']
- ws4.insert_rows(2)
- comments4 = ['唯一标识符', '显示名称', 'Spine动画资源路径', '显示缩放倍数', '是否水平镜像', '待机状态动画', '移动状态动画', '攻击状态动画', '死亡状态动画', '武器道具路径', '护甲道具路径', '特殊道具路径']
- for i, comment in enumerate(comments4, 1):
- if i <= len(ws4[1]):
- ws4.cell(row=2, column=i, value=comment)
-
- # 音频配置注释
- ws5 = workbook['音频配置']
- ws5.insert_rows(2)
- comments5 = ['唯一标识符', '显示名称', '移动时音效', '攻击时音效', '死亡时音效', '受伤时音效', '格挡时音效', '隐身时音效', '护甲破碎音效', '引信燃烧音效', '召唤时音效', '激光发射音效']
- for i, comment in enumerate(comments5, 1):
- if i <= len(ws5[1]):
- ws5.cell(row=2, column=i, value=comment)
-
- # 特殊能力配置注释
- ws6 = workbook['特殊能力配置']
- ws6.insert_rows(2)
- comments6 = ['唯一标识符', '显示名称', '特殊技能名称']
- for i, comment in enumerate(comments6, 1):
- ws6.cell(row=2, column=i, value=comment)
-
- # BOSS配置注释
- ws7 = workbook['BOSS配置']
- ws7.insert_rows(2)
- comments7 = ['唯一标识符', '显示名称', '战斗阶段总数', '进入下阶段血量比例', '狂暴状态速度倍数', '狂暴状态伤害倍数', '狂暴状态攻速倍数', '召唤的单位类型', '单次召唤数量', '召唤技能冷却时间', '激光攻击伤害', '激光攻击射程', '激光充能准备时间', '激光技能冷却时间']
- for i, comment in enumerate(comments7, 1):
- if i <= len(ws7[1]):
- ws7.cell(row=2, column=i, value=comment)
-
- # 生成权重配置注释
- ws8 = workbook['生成权重配置']
- ws8.insert_rows(2)
- comments8 = ['稀有度等级', '随机生成权重值']
- for i, comment in enumerate(comments8, 1):
- ws8.cell(row=2, column=i, value=comment)
-
- # 波次进度配置注释
- ws9 = workbook['波次进度配置']
- ws9.insert_rows(2)
- comments9 = ['游戏阶段类型', '该阶段出现的敌人ID']
- for i, comment in enumerate(comments9, 1):
- ws9.cell(row=2, column=i, value=comment)
-
- # 敌人名称映射注释
- ws10 = workbook['敌人名称映射']
- ws10.insert_rows(2)
- comments10 = ['关卡配置中使用的中文名称', '对应的英文敌人ID']
- for i, comment in enumerate(comments10, 1):
- ws10.cell(row=2, column=i, value=comment)
-
- print(f"敌人配置Excel表格已生成完成!")
- print(f"文件位置: {output_path}")
- print(f"包含工作表: 敌人基础配置、战斗配置、移动配置、视觉配置、音频配置、特殊能力配置、BOSS配置、生成权重配置、波次进度配置、敌人名称映射")
- def main():
- """主函数"""
- try:
- print("开始生成敌人配置Excel表格...")
- create_enemies_excel()
- print("所有表格生成完成!")
- except Exception as e:
- print(f"生成过程中出现错误: {e}")
- import traceback
- traceback.print_exc()
- if __name__ == "__main__":
- main()
|