import BaseEvent from "../fight/evnet/base/BaseEvent"; import FSprite from "../fight/object/FSprite"; /** * 地刺 */ const { ccclass, property } = cc._decorator; interface ThornSprite { isAtk: boolean, sprite: FSprite } @ccclass export default class JG0108 extends BaseEvent { @property({ displayName: '数值(怪物id)' }) public monsterId = 1001; @property({ displayName: '地刺出现间隔时间' }) public interval = 2; @property({ type: sp.Skeleton, displayName: '地刺动画' }) public spine: sp.Skeleton = null; private isAtk = false; private isPause = false; //当前处于碰撞区域的对象 private spriteList: Array = []; start() { this.run(); } update(dt) { if (!this.ff.lockCamera) { if (!this.ff.lockCamera != this.isPause) { this.isPause = true; if (this.spine) { this.spine.paused = true; } return } } else { if (!this.ff.lockCamera != this.isPause) { this.isPause = false; if (this.spine) { this.spine.paused = false; } } } if (this.isAtk) { this.spriteList.forEach(element => { this.rmHP(element); }); } } private rmHP(thornSprite: ThornSprite) { if (thornSprite.isAtk) { return; } if (thornSprite.sprite.hp <= 0) { return; } thornSprite.isAtk = true; let main = this.ff.main; let attrData = main.sManage.getMonsterData(this.monsterId); thornSprite.sprite.bAtkjs(attrData); } private run() { this.spriteList.forEach(element => { element.isAtk = false; }); if (!this.interval) { this.isAtk = true; } else { cc.tween(this).sequence( cc.delayTime(this.interval), cc.callFunc(() => { this.playAtk(); }) ).start() } } private playAtk() { this.isAtk = true; this.spine.setAnimation(0, 'atk', false); this.spine.setCompleteListener(() => { this.isAtk = false; this.spine.setCompleteListener(null); this.spine.setAnimation(0, 'idle', true); this.run() }); } onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) { if (other.node.group == 'A') { let obj = other.node.getComponent(FSprite); this.ff = obj.ff; this.pushSprite(obj); } } onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) { if (other.node.group == 'A') { let obj = other.node.getComponent(FSprite); this.removeSprite(obj); } } private pushSprite(sprite: FSprite) { for (let i = 0; i < this.spriteList.length; i++) { const element = this.spriteList[i]; if (element.sprite == sprite) { return } } this.spriteList.push({ isAtk: false, sprite: sprite }) } private removeSprite(sprite: FSprite) { for (let i = 0; i < this.spriteList.length; i++) { const element = this.spriteList[i]; if (element.sprite == sprite) { this.spriteList.splice(i, 1); break } } } }