damage_calculation_analysis.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 武器伤害计算差异分析脚本
  5. 这个脚本分析了游戏中不同组件使用的伤害计算方法,
  6. 解释了为什么weapons.json中设置了固定伤害值,但游戏中显示的伤害会浮动。
  7. """
  8. import json
  9. import os
  10. def load_weapons_config():
  11. """加载武器配置文件"""
  12. weapons_path = r"d:\CocosGame\Pong\assets\resources\data\weapons.json"
  13. try:
  14. with open(weapons_path, 'r', encoding='utf-8') as f:
  15. return json.load(f)
  16. except Exception as e:
  17. print(f"无法加载武器配置: {e}")
  18. return None
  19. def analyze_damage_calculation_methods():
  20. """分析不同的伤害计算方法"""
  21. print("=" * 80)
  22. print("武器伤害计算差异分析")
  23. print("=" * 80)
  24. # 示例武器数据
  25. weapon_example = {
  26. "id": "weapon_001",
  27. "name": "基础武器",
  28. "rarity": "common",
  29. "stats": {
  30. "damage": 10
  31. },
  32. "upgradeConfig": {
  33. "levels": {
  34. "1": {"damage": 10, "cost": 0},
  35. "2": {"damage": 15, "cost": 100},
  36. "3": {"damage": 20, "cost": 200}
  37. }
  38. }
  39. }
  40. base_damage = weapon_example["stats"]["damage"]
  41. weapon_level = 2
  42. print(f"示例武器: {weapon_example['name']}")
  43. print(f"基础伤害: {base_damage}")
  44. print(f"武器等级: {weapon_level}")
  45. print(f"稀有度: {weapon_example['rarity']}")
  46. print()
  47. # 方法1: UpgradeController.calculateWeaponDamage (UI显示)
  48. print("方法1: UpgradeController.calculateWeaponDamage (升级界面UI显示)")
  49. print("- 优先使用手动配置的伤害值 (upgradeConfig.levels[level].damage)")
  50. print("- 如果没有手动配置,使用基于稀有度的计算公式")
  51. # 手动配置的伤害
  52. manual_damage = weapon_example["upgradeConfig"]["levels"][str(weapon_level)]["damage"]
  53. print(f"- 手动配置伤害 (等级{weapon_level}): {manual_damage}")
  54. # 稀有度计算 (后备方案)
  55. rarity_multipliers = {
  56. 'common': 0.15,
  57. 'uncommon': 0.18,
  58. 'rare': 0.20,
  59. 'epic': 0.25
  60. }
  61. damage_per_level = max(1, int(base_damage * rarity_multipliers.get(weapon_example['rarity'], 0.15)))
  62. rarity_calculated_damage = base_damage + (weapon_level - 1) * damage_per_level
  63. print(f"- 稀有度计算伤害 (后备): {rarity_calculated_damage}")
  64. print()
  65. # 方法2: WeaponInfo.getDamage (方块选择界面)
  66. print("方法2: WeaponInfo.getDamage (方块选择界面显示)")
  67. print("- 使用简单的线性增长: 每级增加10%基础伤害")
  68. level_multiplier = 1 + (weapon_level - 1) * 0.1
  69. weaponinfo_damage = int(base_damage * level_multiplier)
  70. print(f"- 计算结果: {weaponinfo_damage}")
  71. print()
  72. # 方法3: WeaponBullet.calculateRuntimeStats (实际战斗)
  73. print("方法3: WeaponBullet.calculateRuntimeStats (实际战斗伤害)")
  74. print("- 步骤1: 应用武器升级加成 (简单的+1每级)")
  75. bullet_base_damage = base_damage + (weapon_level - 1)
  76. print(f"- 升级后伤害: {bullet_base_damage}")
  77. print("- 步骤2: 应用稀有度伤害倍数")
  78. rarity_multipliers_bullet = {
  79. 'common': 1,
  80. 'uncommon': 1.5,
  81. 'rare': 4,
  82. 'epic': 8
  83. }
  84. rarity_multiplier = rarity_multipliers_bullet.get(weapon_example['rarity'], 1)
  85. bullet_final_damage = bullet_base_damage * rarity_multiplier
  86. print(f"- 稀有度倍数 ({weapon_example['rarity']}): {rarity_multiplier}x")
  87. print(f"- 最终基础伤害: {bullet_final_damage}")
  88. print("- 步骤3: 应用技能加成 (PersistentSkillManager)")
  89. print("- 技能加成会进一步修改最终伤害值")
  90. print()
  91. # 总结差异
  92. print("=" * 50)
  93. print("伤害计算结果对比:")
  94. print("=" * 50)
  95. print(f"升级界面显示 (UpgradeController): {manual_damage}")
  96. print(f"方块选择界面 (WeaponInfo): {weaponinfo_damage}")
  97. print(f"实际战斗伤害 (WeaponBullet): {bullet_final_damage} (+ 技能加成)")
  98. print()
  99. print("问题根源:")
  100. print("1. 不同组件使用了不同的伤害计算逻辑")
  101. print("2. UpgradeController 优先使用手动配置的伤害值")
  102. print("3. WeaponInfo 使用简单的百分比增长")
  103. print("4. WeaponBullet 使用复杂的多步骤计算 (升级+稀有度+技能)")
  104. print("5. 技能系统会动态修改最终伤害值")
  105. print()
  106. return {
  107. 'upgrade_ui': manual_damage,
  108. 'weapon_info': weaponinfo_damage,
  109. 'bullet_base': bullet_final_damage
  110. }
  111. def analyze_weapons_json():
  112. """分析weapons.json中的配置"""
  113. print("=" * 80)
  114. print("weapons.json 配置分析")
  115. print("=" * 80)
  116. weapons_config = load_weapons_config()
  117. if not weapons_config:
  118. return
  119. print(f"总武器数量: {len(weapons_config.get('weapons', []))}")
  120. print()
  121. for weapon in weapons_config.get('weapons', [])[:3]: # 只分析前3个武器
  122. print(f"武器: {weapon.get('name', 'Unknown')} (ID: {weapon.get('id', 'Unknown')})")
  123. print(f"- 基础伤害: {weapon.get('stats', {}).get('damage', 0)}")
  124. print(f"- 稀有度: {weapon.get('rarity', 'common')}")
  125. upgrade_config = weapon.get('upgradeConfig', {})
  126. if upgrade_config and 'levels' in upgrade_config:
  127. print("- 升级配置:")
  128. levels = upgrade_config['levels']
  129. for level, config in sorted(levels.items(), key=lambda x: int(x[0])):
  130. damage = config.get('damage', '未配置')
  131. cost = config.get('cost', '未配置')
  132. print(f" 等级 {level}: 伤害={damage}, 费用={cost}")
  133. else:
  134. print("- 无升级配置")
  135. print()
  136. def main():
  137. """主函数"""
  138. print("武器伤害浮动问题分析")
  139. print("问题: weapons.json中设置了固定伤害,但游戏中伤害显示浮动")
  140. print()
  141. # 分析配置文件
  142. analyze_weapons_json()
  143. # 分析计算方法差异
  144. results = analyze_damage_calculation_methods()
  145. print("=" * 80)
  146. print("解决方案建议:")
  147. print("=" * 80)
  148. print("1. 统一伤害计算逻辑:")
  149. print(" - 让所有组件都使用相同的伤害计算方法")
  150. print(" - 建议以 UpgradeController.calculateWeaponDamage 为标准")
  151. print()
  152. print("2. 明确伤害显示策略:")
  153. print(" - UI界面显示基础伤害 (不含技能加成)")
  154. print(" - 实际战斗使用完整计算 (含技能加成)")
  155. print()
  156. print("3. 完善配置文件:")
  157. print(" - 确保所有武器都有完整的 upgradeConfig.levels 配置")
  158. print(" - 或者移除手动配置,统一使用公式计算")
  159. print()
  160. print("4. 添加调试信息:")
  161. print(" - 在UI中显示伤害计算的详细信息")
  162. print(" - 区分显示基础伤害和最终伤害")
  163. if __name__ == "__main__":
  164. main()