fix_weapon_costs.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import pandas as pd
  2. import json
  3. import os
  4. def fix_weapon_costs():
  5. # 读取JSON文件
  6. json_path = r'd:\CocosGame\Pong\assets\resources\data\weapons.json'
  7. try:
  8. # 读取JSON文件
  9. with open(json_path, 'r', encoding='utf-8') as f:
  10. json_data = json.load(f)
  11. print("=== 修复武器成本配置 ===")
  12. print()
  13. # 备份原文件
  14. backup_path = json_path + '.backup'
  15. with open(backup_path, 'w', encoding='utf-8') as f:
  16. json.dump(json_data, f, ensure_ascii=False, indent=2)
  17. print(f"已创建备份文件: {backup_path}")
  18. # 根据Excel数据定义的成本配置
  19. cost_configs = {
  20. 'pea_shooter': {
  21. 'baseCost': 5,
  22. 'shapeCosts': {
  23. 'I': 10, 'H-I': 10, 'L': 15, 'S': 20, 'D-T': 20,
  24. 'L2': 25, 'L3': 25, 'L4': 25, 'F-S': 25, 'T': 25
  25. }
  26. },
  27. 'sharp_carrot': {
  28. 'baseCost': 6,
  29. 'shapeCosts': {
  30. 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24,
  31. 'L2': 26, 'L3': 26, 'L4': 26, 'F-S': 26, 'T': 26
  32. }
  33. },
  34. 'saw_grass': {
  35. 'baseCost': 6,
  36. 'shapeCosts': {
  37. 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24,
  38. 'L2': 27, 'L3': 27, 'L4': 27, 'F-S': 27, 'T': 27
  39. }
  40. },
  41. 'watermelon_bomb': {
  42. 'baseCost': 10,
  43. 'shapeCosts': {
  44. 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40,
  45. 'L2': 28, 'L3': 28, 'L4': 28, 'F-S': 28, 'T': 28
  46. }
  47. },
  48. 'boomerang_plant': {
  49. 'baseCost': 6,
  50. 'shapeCosts': {
  51. 'I': 12, 'H-I': 12, 'L': 18, 'S': 24, 'D-T': 24,
  52. 'L2': 29, 'L3': 29, 'L4': 29, 'F-S': 29, 'T': 29
  53. }
  54. },
  55. 'hot_pepper': {
  56. 'baseCost': 10,
  57. 'shapeCosts': {
  58. 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40,
  59. 'L2': 30, 'L3': 30, 'L4': 30, 'F-S': 30, 'T': 30
  60. }
  61. },
  62. 'cactus_shotgun': {
  63. 'baseCost': 10,
  64. 'shapeCosts': {
  65. 'I': 20, 'H-I': 20, 'L': 30, 'S': 40, 'D-T': 40,
  66. 'L2': 31, 'L3': 31, 'L4': 31, 'F-S': 31, 'T': 31
  67. }
  68. },
  69. 'okra_missile': {
  70. 'baseCost': 15,
  71. 'shapeCosts': {
  72. 'I': 30, 'H-I': 30, 'L': 45, 'S': 60, 'D-T': 60,
  73. 'L2': 32, 'L3': 32, 'L4': 32, 'F-S': 32, 'T': 32
  74. }
  75. },
  76. 'mace_club': {
  77. 'baseCost': 8,
  78. 'shapeCosts': {
  79. 'I': 16, 'H-I': 16, 'L': 24, 'S': 32, 'D-T': 32,
  80. 'L2': 33, 'L3': 33, 'L4': 33, 'F-S': 33, 'T': 33
  81. }
  82. }
  83. }
  84. # 更新JSON配置
  85. updated_count = 0
  86. for i, weapon in enumerate(json_data['weapons']):
  87. weapon_id = weapon['id']
  88. weapon_name = weapon['name']
  89. if weapon_id in cost_configs:
  90. # 更新武器配置
  91. json_data['weapons'][i]['inGameCostConfig'] = cost_configs[weapon_id]
  92. updated_count += 1
  93. print(f"更新 {weapon_name} ({weapon_id}):")
  94. print(f" 基础成本: {cost_configs[weapon_id]['baseCost']}")
  95. print(f" 形状成本: {cost_configs[weapon_id]['shapeCosts']}")
  96. print()
  97. # 写入更新后的配置
  98. with open(json_path, 'w', encoding='utf-8') as f:
  99. json.dump(json_data, f, ensure_ascii=False, indent=2)
  100. print(f"\n✅ 成功更新武器配置文件: {json_path}")
  101. print(f"📋 更新了 {updated_count} 个武器的成本配置")
  102. # 验证更新结果
  103. print("\n=== 验证更新结果 ===")
  104. for weapon in json_data['weapons']:
  105. if 'inGameCostConfig' in weapon:
  106. print(f"{weapon['name']} ({weapon['id']}):")
  107. print(f" 基础成本: {weapon['inGameCostConfig']['baseCost']}")
  108. print(f" 形状成本数量: {len(weapon['inGameCostConfig']['shapeCosts'])} 种形状")
  109. print()
  110. except Exception as e:
  111. print(f"错误: {e}")
  112. import traceback
  113. traceback.print_exc()
  114. if __name__ == "__main__":
  115. fix_weapon_costs()