瀏覽代碼

完成weaponInfor的添加

181404010226 4 月之前
父節點
當前提交
afe7dfdc06

+ 8 - 8
assets/Scenes/GameLevel.scene

@@ -19062,7 +19062,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 96.87109375,
+      "width": 65.3359375,
       "height": 54.4
     },
     "_anchorPoint": {
@@ -19092,7 +19092,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "BATTLE",
+    "_string": "战  斗",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 24,
@@ -19522,7 +19522,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 72.015625,
+      "width": 65.3359375,
       "height": 54.4
     },
     "_anchorPoint": {
@@ -19552,7 +19552,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "SHOP",
+    "_string": "商  店",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 24,
@@ -20093,7 +20093,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 124.01171875,
+      "width": 65.3359375,
       "height": 54.4
     },
     "_anchorPoint": {
@@ -20123,7 +20123,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "UPGRADE",
+    "_string": "升  级",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 24,
@@ -20662,7 +20662,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 73.328125,
+      "width": 65.3359375,
       "height": 54.4
     },
     "_anchorPoint": {
@@ -20692,7 +20692,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "SKILL",
+    "_string": "技  能",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 24,

二進制
assets/resources/data/excel/方块武器配置/~$方块武器配置表.xlsx


+ 12 - 0
assets/resources/data/excel/方块武器配置/~$方块武器配置表.xlsx.meta

@@ -0,0 +1,12 @@
+{
+  "ver": "1.0.0",
+  "importer": "*",
+  "imported": true,
+  "uuid": "29bb78ca-4aae-41d3-a6cf-d035988bf6c2",
+  "files": [
+    ".json",
+    ".xlsx"
+  ],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 12
assets/resources/data/weapons.json

@@ -45,7 +45,7 @@
           "returnToOrigin": false
         },
         "visual": {
-          "bulletPrefab": "bullets/Pea_ShooterBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -165,7 +165,7 @@
           "maxRange": 800
         },
         "visual": {
-          "bulletPrefab": "bullets/Sharp_CarrotBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "Animation/WeaponTx/tx0001/tx0001",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -293,7 +293,7 @@
           "returnToOrigin": false
         },
         "visual": {
-          "bulletPrefab": "bullets/Saw_GrassBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -413,7 +413,7 @@
           "returnToOrigin": false
         },
         "visual": {
-          "bulletPrefab": "bullets/Watermelon_BombBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0007/tx0007",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -532,7 +532,7 @@
           "returnDelay": 1.0
         },
         "visual": {
-          "bulletPrefab": "bullets/Boomerang_PlantBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -650,7 +650,7 @@
           "returnToOrigin": false
         },
         "visual": {
-          "bulletPrefab": "bullets/Hot_PepperBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -736,10 +736,10 @@
         "bulletSpeed": 30
       },
       "bulletConfig": {
-        "count": {
-          "type": "spread",
-          "amount": 5,
-          "spreadAngle": 30,
+         "count": {
+          "type": "single",
+          "amount": 1,
+          "spreadAngle": 0,
           "burstCount": 1,
           "burstDelay": 0
         },
@@ -769,7 +769,7 @@
           "maxRange": 400
         },
         "visual": {
-          "bulletPrefab": "bullets/Cactus_ShotgunBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"
@@ -889,7 +889,7 @@
           "returnToOrigin": false
         },
         "visual": {
-          "bulletPrefab": "bullets/Okra_MissileBullet",
+          "bulletPrefab": "Pellet",
           "hitEffect": "Animation/WeaponTx/tx0002/tx0002",
           "trailEffect": "True",
           "muzzleFlash": "Animation/WeaponTx/tx0002/tx0002"

+ 77 - 1
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -2,8 +2,9 @@ import { _decorator, Component, Node, Button, Label, find, EventTouch, Vec2, Vec
 import { LevelSessionManager } from '../../Core/LevelSessionManager';
 import { BallController } from '../BallController';
 import { BlockManager } from '../BlockManager';
-
+import { ConfigManager } from '../../Core/ConfigManager';
 import { BlockTag } from './BlockTag';
+import { WeaponInfo } from './WeaponInfo';
 import { SkillManager } from '../SkillSelection/SkillManager';
 
 import EventBus, { GameEvents } from '../../Core/EventBus';
@@ -833,6 +834,75 @@ export class GameBlockSelection extends Component {
         }
     }
     
+    /**
+     * 为方块的武器节点添加武器信息组件
+     * @param block 方块节点
+     */
+    private attachWeaponInfoToBlock(block: Node): void {
+        console.log(`[GameBlockSelection] 添加武器信息`);
+        try {
+            // 查找方块中的Weapon节点
+            const weaponNode = this.findWeaponNodeInBlock(block);
+            if (!weaponNode) {
+                console.warn(`[GameBlockSelection] 方块 ${block.name} 中未找到Weapon节点,无法添加武器信息组件`);
+                return;
+            }
+            
+            // 检查是否已经有WeaponInfo组件
+            let weaponInfo = weaponNode.getComponent(WeaponInfo);
+            if (weaponInfo) {
+                console.log(`[GameBlockSelection] 武器节点 ${weaponNode.name} 已有WeaponInfo组件,跳过添加`);
+                return;
+            }
+            
+            // 添加WeaponInfo组件
+            weaponInfo = weaponNode.addComponent(WeaponInfo);
+            
+            // 获取方块的武器配置
+            const weaponConfig = this.blockManager.getBlockWeaponConfig(block);
+            if (weaponConfig) {
+                // 设置武器配置到WeaponInfo组件
+                weaponInfo.setWeaponConfig(weaponConfig);
+                console.log(`[GameBlockSelection] 成功为武器节点 ${weaponNode.name} 添加武器信息组件,武器: ${weaponConfig.name}`);
+            } else {
+                console.warn(`[GameBlockSelection] 方块 ${block.name} 没有武器配置,无法设置武器信息`);
+                // 移除刚添加的组件
+                weaponNode.removeComponent(WeaponInfo);
+            }
+        } catch (error) {
+            console.error(`[GameBlockSelection] 为方块 ${block.name} 添加武器信息组件时发生错误:`, error);
+        }
+    }
+    
+    /**
+     * 在方块中查找Weapon节点
+     * @param block 方块节点
+     * @returns Weapon节点,如果未找到返回null
+     */
+    private findWeaponNodeInBlock(block: Node): Node | null {
+        if (!block || !block.isValid) {
+            return null;
+        }
+        
+        // 递归查找名为"Weapon"的子节点
+        const findWeaponRecursive = (node: Node): Node | null => {
+            if (node.name === 'Weapon') {
+                return node;
+            }
+            
+            for (let i = 0; i < node.children.length; i++) {
+                const result = findWeaponRecursive(node.children[i]);
+                if (result) {
+                    return result;
+                }
+            }
+            
+            return null;
+        };
+        
+        return findWeaponRecursive(block);
+    }
+    
     // 处理成功放置
     private async handleSuccessfulPlacement(startLocation: string) {
         try {
@@ -851,6 +921,9 @@ export class GameBlockSelection extends Component {
                 // 立即将方块移动到PlacedBlocks节点下,不等游戏开始
                 this.blockManager.moveBlockToPlacedBlocks(this.currentDragBlock);
                 
+                // 为武器节点添加武器信息组件
+                this.attachWeaponInfoToBlock(this.currentDragBlock);
+                
                 // 如果游戏已开始,添加锁定视觉提示
                 if (this.blockManager.gameStarted) {
                     this.blockManager.addLockedVisualHint(this.currentDragBlock);
@@ -882,6 +955,9 @@ export class GameBlockSelection extends Component {
                     // 立即将方块移动到PlacedBlocks节点下,不等游戏开始
                     this.blockManager.moveBlockToPlacedBlocks(this.currentDragBlock);
                     
+                    // 为武器节点添加武器信息组件
+                    this.attachWeaponInfoToBlock(this.currentDragBlock);
+                    
                     // 如果游戏已开始,添加锁定视觉提示
                     if (this.blockManager.gameStarted) {
                         this.blockManager.addLockedVisualHint(this.currentDragBlock);

+ 410 - 0
assets/scripts/CombatSystem/BlockSelection/WeaponInfo.ts

@@ -0,0 +1,410 @@
+import { _decorator, Component, Node } from 'cc';
+import { WeaponConfig } from '../../Core/ConfigManager';
+const { ccclass, property } = _decorator;
+
+/**
+ * 武器信息组件
+ * 用于存储和管理挂载到武器节点上的武器配置信息
+ */
+@ccclass('WeaponInfo')
+export class WeaponInfo extends Component {
+    
+    // 编辑器面板可见属性
+    @property({ displayName: "武器ID", readonly: true })
+    public weaponId: string = "";
+    
+    @property({ displayName: "武器名称", readonly: true })
+    public weaponName: string = "";
+    
+    @property({ displayName: "武器等级", readonly: true })
+    public weaponLevel: number = 1;
+    
+    @property({ displayName: "武器伤害", readonly: true })
+    public weaponDamage: number = 0;
+    
+    @property({ displayName: "射速", readonly: true })
+    public fireRate: number = 0;
+    
+    @property({ displayName: "射程", readonly: true })
+    public range: number = 0;
+    
+    @property({ displayName: "是否激活", readonly: true })
+    public activeStatus: boolean = false;
+    
+    @property({ displayName: "总伤害", readonly: true })
+    public totalDamage: number = 0;
+    
+    @property({ displayName: "击杀数", readonly: true })
+    public killCount: number = 0;
+    
+    // 武器配置数据
+    private _weaponConfig: WeaponConfig | null = null;
+    
+    // 武器等级(用于升级系统)
+    private _weaponLevel: number = 1;
+    
+    // 武器是否已激活(用于战斗状态管理)
+    private _isActive: boolean = false;
+    
+    // 武器最后开火时间(用于冷却计算)
+    private _lastFireTime: number = 0;
+    
+    // 武器当前弹药数(如果适用)
+    private _currentAmmo: number = -1; // -1表示无限弹药
+    
+    // 武器累计伤害统计
+    private _totalDamageDealt: number = 0;
+    
+    // 武器击杀数统计
+    private _killCount: number = 0;
+    
+    /**
+     * 设置武器配置
+     * @param config 武器配置数据
+     */
+    public setWeaponConfig(config: WeaponConfig): void {
+        this._weaponConfig = config;
+        this._weaponLevel = 1;
+        this._isActive = true;
+        this._lastFireTime = 0;
+        this._totalDamageDealt = 0;
+        this._killCount = 0;
+        
+        // 更新编辑器面板可见属性
+        this.weaponId = config.id;
+        this.weaponName = config.name;
+        this.weaponLevel = this._weaponLevel;
+        this.weaponDamage = this.getDamage();
+        this.fireRate = config.stats.fireRate;
+        this.range = config.stats.range;
+        this.activeStatus = this._isActive;
+        this.totalDamage = this._totalDamageDealt;
+        this.killCount = this._killCount;
+        
+        // 如果武器配置中有弹药限制,设置初始弹药数
+        if (config.bulletConfig && config.bulletConfig.count) {
+            // 这里可以根据具体需求设置弹药数,目前设为无限
+            this._currentAmmo = -1;
+        }
+        
+        console.log(`[WeaponInfo] 武器配置已设置: ${config.name} (${config.id})`);
+    }
+    
+    /**
+     * 获取武器配置
+     * @returns 武器配置数据
+     */
+    public getWeaponConfig(): WeaponConfig | null {
+        return this._weaponConfig;
+    }
+    
+    /**
+     * 获取武器ID
+     * @returns 武器ID
+     */
+    public getWeaponId(): string | null {
+        return this._weaponConfig ? this._weaponConfig.id : null;
+    }
+    
+    /**
+     * 获取武器名称
+     * @returns 武器名称
+     */
+    public getWeaponName(): string | null {
+        return this._weaponConfig ? this._weaponConfig.name : null;
+    }
+    
+    /**
+     * 获取武器类型
+     * @returns 武器类型
+     */
+    public getWeaponType(): string | null {
+        return this._weaponConfig ? this._weaponConfig.type : null;
+    }
+    
+    /**
+     * 获取武器稀有度
+     * @returns 武器稀有度
+     */
+    public getWeaponRarity(): string | null {
+        return this._weaponConfig ? (this._weaponConfig.rarity || 'common') : null;
+    }
+    
+    /**
+     * 设置武器等级
+     * @param level 武器等级
+     */
+    public setWeaponLevel(level: number): void {
+        if (level < 1) {
+            console.warn(`[WeaponInfo] 武器等级不能小于1,当前设置: ${level}`);
+            return;
+        }
+        
+        const maxLevel = this._weaponConfig?.upgradeConfig?.maxLevel || 10;
+        if (level > maxLevel) {
+            console.warn(`[WeaponInfo] 武器等级不能超过最大等级 ${maxLevel},当前设置: ${level}`);
+            return;
+        }
+        
+        this._weaponLevel = level;
+        
+        // 更新编辑器面板可见属性
+        this.weaponLevel = this._weaponLevel;
+        this.weaponDamage = this.getDamage();
+        
+        console.log(`[WeaponInfo] 武器等级已设置为: ${level}`);
+    }
+    
+    /**
+     * 获取武器等级
+     * @returns 武器等级
+     */
+    public getWeaponLevel(): number {
+        return this._weaponLevel;
+    }
+    
+    /**
+     * 获取武器最大等级
+     * @returns 武器最大等级
+     */
+    public getMaxWeaponLevel(): number {
+        return this._weaponConfig?.upgradeConfig?.maxLevel || 10;
+    }
+    
+    /**
+     * 设置武器激活状态
+     * @param active 是否激活
+     */
+    public setActive(active: boolean): void {
+        this._isActive = active;
+        
+        // 更新编辑器面板可见属性
+        this.activeStatus = this._isActive;
+        
+        console.log(`[WeaponInfo] 武器激活状态已设置为: ${active}`);
+    }
+    
+    /**
+     * 获取武器激活状态
+     * @returns 是否激活
+     */
+    public isActive(): boolean {
+        return this._isActive;
+    }
+    
+    /**
+     * 检查武器是否可以开火(基于冷却时间)
+     * @returns 是否可以开火
+     */
+    public canFire(): boolean {
+        if (!this._isActive || !this._weaponConfig) {
+            return false;
+        }
+        
+        const currentTime = Date.now() / 1000; // 转换为秒
+        const fireRate = this._weaponConfig.stats.fireRate || 1.0;
+        const cooldown = 1.0 / fireRate; // 计算冷却时间
+        
+        return (currentTime - this._lastFireTime) >= cooldown;
+    }
+    
+    /**
+     * 记录开火时间
+     */
+    public recordFireTime(): void {
+        this._lastFireTime = Date.now() / 1000;
+    }
+    
+    /**
+     * 获取武器伤害值(考虑等级加成)
+     * @returns 武器伤害值
+     */
+    public getDamage(): number {
+        if (!this._weaponConfig) {
+            return 0;
+        }
+        
+        const baseDamage = this._weaponConfig.stats.damage || 0;
+        
+        // 根据等级计算伤害加成(简单的线性增长)
+        // 每级增加10%的基础伤害
+        const levelMultiplier = 1 + (this._weaponLevel - 1) * 0.1;
+        const finalDamage = Math.floor(baseDamage * levelMultiplier);
+        
+        return finalDamage;
+    }
+    
+    /**
+     * 获取武器射程
+     * @returns 武器射程
+     */
+    public getRange(): number {
+        return this._weaponConfig?.stats.range || 0;
+    }
+    
+    /**
+     * 获取武器射速
+     * @returns 武器射速
+     */
+    public getFireRate(): number {
+        return this._weaponConfig?.stats.fireRate || 1.0;
+    }
+    
+    /**
+     * 获取子弹速度
+     * @returns 子弹速度
+     */
+    public getBulletSpeed(): number {
+        return this._weaponConfig?.stats.bulletSpeed || 100;
+    }
+    
+    /**
+     * 获取武器精度
+     * @returns 武器精度
+     */
+    public getAccuracy(): number {
+        return this._weaponConfig?.stats.accuracy || 1.0;
+    }
+    
+    /**
+     * 添加伤害统计
+     * @param damage 造成的伤害
+     */
+    public addDamageDealt(damage: number): void {
+        this._totalDamageDealt += damage;
+        
+        // 更新编辑器面板可见属性
+        this.totalDamage = this._totalDamageDealt;
+        
+        console.log(`[WeaponInfo] 累计伤害增加 ${damage},总伤害: ${this._totalDamageDealt}`);
+    }
+    
+    /**
+     * 获取总伤害统计
+     * @returns 总伤害
+     */
+    public getTotalDamageDealt(): number {
+        return this._totalDamageDealt;
+    }
+    
+    /**
+     * 增加击杀数
+     */
+    public addKill(): void {
+        this._killCount++;
+        
+        // 更新编辑器面板可见属性
+        this.killCount = this._killCount;
+        
+        console.log(`[WeaponInfo] 击杀数增加,当前击杀数: ${this._killCount}`);
+    }
+    
+    /**
+     * 获取击杀数
+     * @returns 击杀数
+     */
+    public getKillCount(): number {
+        return this._killCount;
+    }
+    
+    /**
+     * 重置统计数据
+     */
+    public resetStats(): void {
+        this._totalDamageDealt = 0;
+        this._killCount = 0;
+        this._lastFireTime = 0;
+        
+        // 更新编辑器面板可见属性
+        this.totalDamage = this._totalDamageDealt;
+        this.killCount = this._killCount;
+        
+        console.log(`[WeaponInfo] 武器统计数据已重置`);
+    }
+    
+    /**
+     * 获取武器升级所需费用
+     * @param targetLevel 目标等级
+     * @returns 升级费用,如果无法升级返回-1
+     */
+    public getUpgradeCost(targetLevel?: number): number {
+        if (!this._weaponConfig || !this._weaponConfig.upgradeConfig) {
+            return -1;
+        }
+        
+        const level = targetLevel || (this._weaponLevel + 1);
+        const levelConfig = this._weaponConfig.upgradeConfig.levels?.[level.toString()];
+        
+        return levelConfig?.cost || -1;
+    }
+    
+    /**
+     * 检查是否可以升级
+     * @returns 是否可以升级
+     */
+    public canUpgrade(): boolean {
+        if (!this._weaponConfig || !this._weaponConfig.upgradeConfig) {
+            return false;
+        }
+        
+        const maxLevel = this._weaponConfig.upgradeConfig.maxLevel || 10;
+        return this._weaponLevel < maxLevel;
+    }
+    
+    /**
+     * 升级武器
+     * @returns 是否升级成功
+     */
+    public upgrade(): boolean {
+        if (!this.canUpgrade()) {
+            return false;
+        }
+        
+        this._weaponLevel++;
+        
+        // 更新编辑器面板可见属性
+        this.weaponLevel = this._weaponLevel;
+        this.weaponDamage = this.getDamage();
+        
+        console.log(`[WeaponInfo] 武器 ${this.getWeaponName()} 升级到等级 ${this._weaponLevel}`);
+        return true;
+    }
+    
+    /**
+     * 更新所有编辑器面板可见属性
+     * 用于确保编辑器中显示的信息与内部状态同步
+     */
+    private updateEditorProperties(): void {
+        if (this._weaponConfig) {
+            this.weaponId = this._weaponConfig.id;
+            this.weaponName = this._weaponConfig.name;
+            this.fireRate = this._weaponConfig.stats.fireRate;
+            this.range = this._weaponConfig.stats.range;
+        }
+        
+        this.weaponLevel = this._weaponLevel;
+        this.weaponDamage = this.getDamage();
+        this.activeStatus = this._isActive;
+        this.totalDamage = this._totalDamageDealt;
+        this.killCount = this._killCount;
+    }
+    
+    /**
+     * 获取武器信息摘要
+     * @returns 武器信息字符串
+     */
+    public getWeaponSummary(): string {
+        if (!this._weaponConfig) {
+            return '无武器配置';
+        }
+        
+        return `${this._weaponConfig.name} (Lv.${this._weaponLevel}) - 伤害:${this.getDamage()} 射速:${this.getFireRate()} 射程:${this.getRange()}`;
+    }
+    
+    /**
+     * 组件销毁时清理
+     */
+    onDestroy(): void {
+        this._weaponConfig = null;
+    }
+}

+ 9 - 0
assets/scripts/CombatSystem/BlockSelection/WeaponInfo.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "cf6641dd-49bb-4b97-a0be-c092f5e51fb7",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 0 - 6
assets/scripts/CombatSystem/BulletEffects/BulletCount.ts

@@ -287,16 +287,10 @@ export class BulletCount extends Component {
         }
         // 获取多重射击技能等级
         const multiShotSkillLevel = skillManager.getSkillLevel('multi_shots');
-        console.log("技能等级",multiShotSkillLevel);
         if (multiShotSkillLevel <= 0) {
             return originalConfig; // 技能等级为0,返回原配置
         }
-        // // 检查是否为单发武器(amount = 1 且 type = 'single')
         const bulletCountConfig = originalConfig.bulletConfig.count;
-        // const isSingleShotWeapon = bulletCountConfig.type === 'single' && bulletCountConfig.amount === 1;
-        // if (!isSingleShotWeapon) {
-        //     return originalConfig; // 多发武器不受影响,返回原配置
-        // }
         // 计算多重射击几率
         const baseMultiShotChance = 0; // 基础几率为0
         const multiShotChance = SkillManager.calculateMultiShotChance(baseMultiShotChance, multiShotSkillLevel);