import CMath from "../../../../util/CMath"; import BObject from "../../bullet/BObject"; import FSprite, { SpriteActionType } from "../FSprite"; import SkillBase from "./SkillBase"; /** * 散弹 */ const { ccclass, property } = cc._decorator; @ccclass export default class SkillShotgun extends SkillBase { @property({ displayName: '每次发射方向数' }) public count = 10; @property({ displayName: '每方向旋转弧度' }) public rotate = 0.2; @property({ displayName: '每个方向多少颗子弹' }) public bcount = 3; @property({ displayName: '每个子弹间隔时间' }) public btime = 0.2; @property({ type: cc.Prefab, displayName: '子弹' }) public mBullet: cc.Prefab = null; /** * 释放技能 */ public exe(target: FSprite,callback:()=>void) { this.time = new Date().getTime(); // this.sprite.setDir({ x: 0, y: 0 }); //-----播放开始动画 let bNode = cc.instantiate(this.mBullet) let bobject = bNode.getComponent(BObject) let sf = bobject.mStartEffect bobject.distance = this.range let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX let y = this.sprite.mAtkSite.worldY let pos = cc.v2(x, y); let sfNode = cc.instantiate(sf) sfNode.angle = this.sprite.wAngle sfNode.setPosition(pos); sfNode.parent = this.sprite.node let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton) startSpine.setCompleteListener(() => { startSpine.setCompleteListener(null); sfNode.destroy() callback() }); if(startSpine.findAnimation('skill')){ startSpine.setAnimation(0, 'skill', false); }else{ startSpine.setAnimation(0, 'atk', false); } //----开始动画播放结束 this.sprite.playAction(SpriteActionType.atk, false, () => { // this.AI.walk(this.range); this.sprite.playAction(SpriteActionType.stand,true) }); let tp = target.node.getPosition(); for (let i = 0; i < this.count; i++) { this.fire(i, tp); } } public fire(index, tp: cc.Vec2) { this.fireBullet(index, tp); } private fireBullet(index, p2) { for (let i = 0; i < this.bcount; i++) { cc.tween(this).sequence( cc.delayTime(i * this.btime), cc.callFunc(() => { this.fireBulletByTime(index, p2); }) ).start(); } } private fireBulletByTime(index, p2) { let node = cc.instantiate(this.mBullet); node.group = 'bullet' let sprite = this.sprite let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX let y = sprite.node.y + sprite.mAtkSite.worldY let pos = cc.v2(x, y); node.setPosition(pos); let bObject = node.getComponent(BObject); bObject.setSprite(this.sprite); bObject.speed = this.speed; bObject.distance = this.range node.parent = this.sprite.map.mSprites; let p1 = node.getPosition(); let angle = CMath.getAngle(p1, p2); let cur = index - Math.floor(this.count / 2); angle += cur * this.rotate; bObject._skillData = this._skillData bObject.fireAngle(angle); } }