| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 武器伤害计算差异分析脚本
- 这个脚本分析了游戏中不同组件使用的伤害计算方法,
- 解释了为什么weapons.json中设置了固定伤害值,但游戏中显示的伤害会浮动。
- """
- import json
- import os
- def load_weapons_config():
- """加载武器配置文件"""
- weapons_path = r"d:\CocosGame\Pong\assets\resources\data\weapons.json"
- try:
- with open(weapons_path, 'r', encoding='utf-8') as f:
- return json.load(f)
- except Exception as e:
- print(f"无法加载武器配置: {e}")
- return None
- def analyze_damage_calculation_methods():
- """分析不同的伤害计算方法"""
- print("=" * 80)
- print("武器伤害计算差异分析")
- print("=" * 80)
-
- # 示例武器数据
- weapon_example = {
- "id": "weapon_001",
- "name": "基础武器",
- "rarity": "common",
- "stats": {
- "damage": 10
- },
- "upgradeConfig": {
- "levels": {
- "1": {"damage": 10, "cost": 0},
- "2": {"damage": 15, "cost": 100},
- "3": {"damage": 20, "cost": 200}
- }
- }
- }
-
- base_damage = weapon_example["stats"]["damage"]
- weapon_level = 2
-
- print(f"示例武器: {weapon_example['name']}")
- print(f"基础伤害: {base_damage}")
- print(f"武器等级: {weapon_level}")
- print(f"稀有度: {weapon_example['rarity']}")
- print()
-
- # 方法1: UpgradeController.calculateWeaponDamage (UI显示)
- print("方法1: UpgradeController.calculateWeaponDamage (升级界面UI显示)")
- print("- 优先使用手动配置的伤害值 (upgradeConfig.levels[level].damage)")
- print("- 如果没有手动配置,使用基于稀有度的计算公式")
-
- # 手动配置的伤害
- manual_damage = weapon_example["upgradeConfig"]["levels"][str(weapon_level)]["damage"]
- print(f"- 手动配置伤害 (等级{weapon_level}): {manual_damage}")
-
- # 稀有度计算 (后备方案)
- rarity_multipliers = {
- 'common': 0.15,
- 'uncommon': 0.18,
- 'rare': 0.20,
- 'epic': 0.25
- }
- damage_per_level = max(1, int(base_damage * rarity_multipliers.get(weapon_example['rarity'], 0.15)))
- rarity_calculated_damage = base_damage + (weapon_level - 1) * damage_per_level
- print(f"- 稀有度计算伤害 (后备): {rarity_calculated_damage}")
- print()
-
- # 方法2: WeaponInfo.getDamage (方块选择界面)
- print("方法2: WeaponInfo.getDamage (方块选择界面显示)")
- print("- 使用简单的线性增长: 每级增加10%基础伤害")
- level_multiplier = 1 + (weapon_level - 1) * 0.1
- weaponinfo_damage = int(base_damage * level_multiplier)
- print(f"- 计算结果: {weaponinfo_damage}")
- print()
-
- # 方法3: WeaponBullet.calculateRuntimeStats (实际战斗)
- print("方法3: WeaponBullet.calculateRuntimeStats (实际战斗伤害)")
- print("- 步骤1: 应用武器升级加成 (简单的+1每级)")
- bullet_base_damage = base_damage + (weapon_level - 1)
- print(f"- 升级后伤害: {bullet_base_damage}")
-
- print("- 步骤2: 应用稀有度伤害倍数")
- rarity_multipliers_bullet = {
- 'common': 1,
- 'uncommon': 1.5,
- 'rare': 4,
- 'epic': 8
- }
- rarity_multiplier = rarity_multipliers_bullet.get(weapon_example['rarity'], 1)
- bullet_final_damage = bullet_base_damage * rarity_multiplier
- print(f"- 稀有度倍数 ({weapon_example['rarity']}): {rarity_multiplier}x")
- print(f"- 最终基础伤害: {bullet_final_damage}")
-
- print("- 步骤3: 应用技能加成 (PersistentSkillManager)")
- print("- 技能加成会进一步修改最终伤害值")
- print()
-
- # 总结差异
- print("=" * 50)
- print("伤害计算结果对比:")
- print("=" * 50)
- print(f"升级界面显示 (UpgradeController): {manual_damage}")
- print(f"方块选择界面 (WeaponInfo): {weaponinfo_damage}")
- print(f"实际战斗伤害 (WeaponBullet): {bullet_final_damage} (+ 技能加成)")
- print()
-
- print("问题根源:")
- print("1. 不同组件使用了不同的伤害计算逻辑")
- print("2. UpgradeController 优先使用手动配置的伤害值")
- print("3. WeaponInfo 使用简单的百分比增长")
- print("4. WeaponBullet 使用复杂的多步骤计算 (升级+稀有度+技能)")
- print("5. 技能系统会动态修改最终伤害值")
- print()
-
- return {
- 'upgrade_ui': manual_damage,
- 'weapon_info': weaponinfo_damage,
- 'bullet_base': bullet_final_damage
- }
- def analyze_weapons_json():
- """分析weapons.json中的配置"""
- print("=" * 80)
- print("weapons.json 配置分析")
- print("=" * 80)
-
- weapons_config = load_weapons_config()
- if not weapons_config:
- return
-
- print(f"总武器数量: {len(weapons_config.get('weapons', []))}")
- print()
-
- for weapon in weapons_config.get('weapons', [])[:3]: # 只分析前3个武器
- print(f"武器: {weapon.get('name', 'Unknown')} (ID: {weapon.get('id', 'Unknown')})")
- print(f"- 基础伤害: {weapon.get('stats', {}).get('damage', 0)}")
- print(f"- 稀有度: {weapon.get('rarity', 'common')}")
-
- upgrade_config = weapon.get('upgradeConfig', {})
- if upgrade_config and 'levels' in upgrade_config:
- print("- 升级配置:")
- levels = upgrade_config['levels']
- for level, config in sorted(levels.items(), key=lambda x: int(x[0])):
- damage = config.get('damage', '未配置')
- cost = config.get('cost', '未配置')
- print(f" 等级 {level}: 伤害={damage}, 费用={cost}")
- else:
- print("- 无升级配置")
- print()
- def main():
- """主函数"""
- print("武器伤害浮动问题分析")
- print("问题: weapons.json中设置了固定伤害,但游戏中伤害显示浮动")
- print()
-
- # 分析配置文件
- analyze_weapons_json()
-
- # 分析计算方法差异
- results = analyze_damage_calculation_methods()
-
- print("=" * 80)
- print("解决方案建议:")
- print("=" * 80)
- print("1. 统一伤害计算逻辑:")
- print(" - 让所有组件都使用相同的伤害计算方法")
- print(" - 建议以 UpgradeController.calculateWeaponDamage 为标准")
- print()
- print("2. 明确伤害显示策略:")
- print(" - UI界面显示基础伤害 (不含技能加成)")
- print(" - 实际战斗使用完整计算 (含技能加成)")
- print()
- print("3. 完善配置文件:")
- print(" - 确保所有武器都有完整的 upgradeConfig.levels 配置")
- print(" - 或者移除手动配置,统一使用公式计算")
- print()
- print("4. 添加调试信息:")
- print(" - 在UI中显示伤害计算的详细信息")
- print(" - 区分显示基础伤害和最终伤害")
- if __name__ == "__main__":
- main()
|