import GlobalNode from "../../GlobalNode"; import { getGlobalNode } from "../BattleConst"; import { ObjData } from "./ObjData"; export class PatrolObj extends ObjData { private _patroltype: number = -1; /**0为入口 1为出口 */ get patrolType(): number { return this._patroltype; } private _patrolIndex: number = 0; get patrolIndex(): number { return this._patrolIndex; } /**对应出口的位置,只有入口才有有效值 */ private brotherIndex: number = -1; private _hited: string[] = []; initPatrolData($index: number, $type: number, $brotherIndex: number) { this.canSlide = false; //XXX 传送门不可下落,因为是成对出现的,下落有可能导致销毁 this._patroltype = $type; this._patrolIndex = $index; this.brotherIndex = $brotherIndex; } onCollisonToBall(collider: cc.Collider): void { super.onCollisonToBall(collider); if (this._patroltype == 0 && this.brotherIndex > -1 && !this._hited.includes(collider.node.uuid)) { this._hited.push(collider.node.uuid); let exitObj = this.map.objData.get(this.brotherIndex); this.map.battle.addToRoundClear(this); this.map.battle.addToRoundClear(exitObj); collider.enabled = false; //先关闭碰撞,等当前物理步进结束后,再设置位置 getGlobalNode().getComponent(GlobalNode).scheduleOnce(() => { collider.node.setPosition(exitObj.pixelPos.x, exitObj.pixelPos.y); collider.enabled = true; }, 0); } // else { // cc.warn('patrol cannot find exit') // } } clone(): PatrolObj { return this.cloneValue(new PatrolObj()); } protected cloneValue(target: PatrolObj): PatrolObj { super.cloneValue(target); target._patroltype = this._patroltype; target._patrolIndex = this._patrolIndex; target.brotherIndex = this.brotherIndex; return target; } }