import pandas as pd import json import os def fix_weapon_costs(): # 读取JSON文件 json_path = r'd:\CocosGame\Pong\assets\resources\data\weapons.json' try: # 读取JSON文件 with open(json_path, 'r', encoding='utf-8') as f: json_data = json.load(f) print("=== 修复武器成本配置 ===") print() # 备份原文件 backup_path = json_path + '.backup' with open(backup_path, 'w', encoding='utf-8') as f: json.dump(json_data, f, ensure_ascii=False, indent=2) print(f"已创建备份文件: {backup_path}") # 根据Excel数据定义的成本配置 cost_configs = { 'pea_shooter': { 'baseCost': 5, 'shapeCosts': { 'I': 10, 'H-I': 10, 'L': 15, 'S': 20, 'D-T': 20, 'L2': 25, 'L3': 25, 'L4': 25, 'F-S': 25, 'T': 25 } }, 'sharp_carrot': { 'baseCost': 6, 'shapeCosts': { 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24, 'L2': 26, 'L3': 26, 'L4': 26, 'F-S': 26, 'T': 26 } }, 'saw_grass': { 'baseCost': 6, 'shapeCosts': { 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24, 'L2': 27, 'L3': 27, 'L4': 27, 'F-S': 27, 'T': 27 } }, 'watermelon_bomb': { 'baseCost': 10, 'shapeCosts': { 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40, 'L2': 28, 'L3': 28, 'L4': 28, 'F-S': 28, 'T': 28 } }, 'boomerang_plant': { 'baseCost': 6, 'shapeCosts': { 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24, 'L2': 29, 'L3': 29, 'L4': 29, 'F-S': 29, 'T': 29 } }, 'hot_pepper': { 'baseCost': 10, 'shapeCosts': { 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40, 'L2': 30, 'L3': 30, 'L4': 30, 'F-S': 30, 'T': 30 } }, 'cactus_shotgun': { 'baseCost': 10, 'shapeCosts': { 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40, 'L2': 31, 'L3': 31, 'L4': 31, 'F-S': 31, 'T': 31 } }, 'okra_missile': { 'baseCost': 15, 'shapeCosts': { 'I': 30, 'H-I': 30, 'L': 45, 'S': 60, 'D-T': 60, 'L2': 32, 'L3': 32, 'L4': 32, 'F-S': 32, 'T': 32 } }, 'mace_club': { 'baseCost': 8, 'shapeCosts': { 'I': 16, 'H-I': 16, 'L': 24, 'S': 32, 'D-T': 32, 'L2': 33, 'L3': 33, 'L4': 33, 'F-S': 33, 'T': 33 } } } # 更新JSON配置 updated_count = 0 for i, weapon in enumerate(json_data['weapons']): weapon_id = weapon['id'] weapon_name = weapon['name'] if weapon_id in cost_configs: # 更新武器配置 json_data['weapons'][i]['inGameCostConfig'] = cost_configs[weapon_id] updated_count += 1 print(f"更新 {weapon_name} ({weapon_id}):") print(f" 基础成本: {cost_configs[weapon_id]['baseCost']}") print(f" 形状成本: {cost_configs[weapon_id]['shapeCosts']}") print() # 写入更新后的配置 with open(json_path, 'w', encoding='utf-8') as f: json.dump(json_data, f, ensure_ascii=False, indent=2) print(f"\n✅ 成功更新武器配置文件: {json_path}") print(f"📋 更新了 {updated_count} 个武器的成本配置") # 验证更新结果 print("\n=== 验证更新结果 ===") for weapon in json_data['weapons']: if 'inGameCostConfig' in weapon: print(f"{weapon['name']} ({weapon['id']}):") print(f" 基础成本: {weapon['inGameCostConfig']['baseCost']}") print(f" 形状成本数量: {len(weapon['inGameCostConfig']['shapeCosts'])} 种形状") print() except Exception as e: print(f"错误: {e}") import traceback traceback.print_exc() if __name__ == "__main__": fix_weapon_costs()