import { _decorator, Collider2D, Component, Node, Vec3, v3 } from 'cc'; import { zidanScript } from './zidanScript'; const { ccclass, property } = _decorator; @ccclass('atgSkill') export class atgSkill extends Component { zidanCore:zidanScript = null; moveDir: Vec3 = v3(0, 1, 0); //子弹上携带的数字 zidanTakeNumber = 1; /** 子弹归属:player=主角发射(不应触发主角吃子弹),enemy=门/敌方发射(会被主角消化) */ owner: 'player' | 'enemy' = 'enemy'; // 防止“从某个门生成的子弹”立刻再次与该门碰撞,造成递归触发卡死 ignoreDoorUuid: string | null = null; ignoreContactFrames: number = 0; /** 主角阶段:已进入“待回收”队列,避免与主角/墙 AABB 多帧重叠时重复计入 hitZhujue */ queuedForPlayerHit: boolean = false; /** 由哪一扇门生成(同门再次碰撞时永久忽略,防止倍率门指数递归) */ generatedByDoorUuid: string | null = null; /** 同一颗子弹对同一扇门只处理一次(用于屏蔽物理重复 BEGIN_CONTACT / 多碰撞体回调) */ processedDoorUuids: Record = {}; /** 正在回收/已回收进对象池:忽略所有碰撞回调(防止回调队列重复触发) */ isRecycling: boolean = false; isDie: boolean = false; start() { } setIsDie(isDie: boolean) { this.isDie = isDie } getIsDie() { return this.isDie } setSkillData(zidanCore: zidanScript, zidanTakeNumber=1){ this.zidanCore = zidanCore; // 从对象池取出时重置一次性状态 this.isDie = false this.zidanTakeNumber = zidanTakeNumber this.owner = 'enemy'; this.queuedForPlayerHit = false; this.ignoreDoorUuid = null; this.ignoreContactFrames = 0; this.generatedByDoorUuid = null; this.processedDoorUuids = {}; this.isRecycling = false; // const col = this.getComponent(Collider2D); // if (col) col.enabled = true; } setMoveDir(dir: Vec3) { // 防御:避免外部复用同一个 Vec3 被意外改写 this.moveDir = dir.clone(); } setIgnoreDoor(doorNode: Node, frames: number = 12) { this.ignoreDoorUuid = doorNode?.uuid ?? null; this.ignoreContactFrames = frames; this.generatedByDoorUuid = doorNode?.uuid ?? null; } //移除子弹 removeZidan(){ if (!this.zidanCore) { console.log('zidanCore is null'); return; }; this.isRecycling = true; // const col = this.getComponent(Collider2D); // if (col) col.enabled = false; this.zidanCore.putZidan(this.node); } }