import { _decorator, Component, Node, sp, tween, v3, Vec3 } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { Sound } from '../core/sound/Sound'; import { ConfigData } from '../data/ConfigData'; import { BattleData } from './BattleData'; import { HitData } from './HitData'; import { MissionData } from './MissionData'; import { Monster } from './Monster'; import { TakeAWalk, WalkDirection } from './TakeAWalk'; const { ccclass, property } = _decorator; @ccclass('LeaderSkillNode') export class LeaderSkillNode extends Component { @property({ type: sp.Skeleton, tooltip: "spine组件" }) spine: sp.Skeleton; @property({ type: sp.SkeletonData, tooltip: "爆炸特效" }) boom: sp.SkeletonData; @property({ type: ResourceLoader, tooltip: "资源加载组件" }) res: ResourceLoader; private target: Monster = null; private id: number = 0; private lv: number = 0; /**音效组件 */ private sound: Sound; start() { this.sound = this.getComponent(Sound); } public async setData(id: number, lv: number, monster: Monster) { this.id = id; this.target = monster; this.lv = lv - 1; if (this.id < 3) { tween(this.node).to( 0.2, { position: monster.node.position } ).call(this.tweenOver.bind(this)).start(); } else { let offest: Vec3; switch (monster.node.getComponent(TakeAWalk).direction) { case WalkDirection.down: offest = v3(0, -50, 0); this.spine.skeletonData = await this.res.load("spine/effect/fight_skill_dun_3", sp.SkeletonData); break; case WalkDirection.up: offest = v3(0, 50, 0); this.spine.skeletonData = await this.res.load("spine/effect/fight_skill_dun_1", sp.SkeletonData); break; case WalkDirection.right: offest = v3(50, 0, 0); this.spine.skeletonData = await this.res.load("spine/effect/fight_skill_dun_2", sp.SkeletonData); break; } let self = this; this.node.setPosition(monster.node.position.clone().add(offest)); this.spine.setAnimation(0, "in", false); this.spine.setCompleteListener(() => { self.spine.setAnimation(0, "idle", true); }); DataSystem.getData(BattleData)._obstruct = this.node; let commander = DataSystem.getData(BattleData).heros.get(5).id ? parseInt(DataSystem.getData(ConfigData)["general"][DataSystem.getData(BattleData).heros.get(5).id]["commander"]) : 0; this.scheduleOnce(() => { DataSystem.getData(BattleData)._obstruct = null; this.node.destroy(); }, parseFloat((DataSystem.getData(ConfigData)["skill"][110000 + this.id]["skillValue"].split(",")[this.lv])) * (1 + Math.pow(commander / 100, 1.9))); if (this.sound) { this.sound.play(); } } } private isDestroy = false; private tweenOver(): void { if (this.isDestroy) { return; } this.isDestroy = true; let self = this; this.node.setRotationFromEuler(v3(0, 0, 0)); this.spine.skeletonData = this.boom; this.spine.loop = false; this.spine.setAnimation(0, "animation", false); this.spine.setCompleteListener(() => { if (self.target.data) { let hit = new HitData(); hit.from = " 统帅技能"; hit.isSkill = true; if (self.target.data.isBoss) { let commander = DataSystem.getData(BattleData).heros.get(5).id ? parseInt(DataSystem.getData(ConfigData)["general"][DataSystem.getData(BattleData).heros.get(5).id]["commander"]) : 0; let bossHP = DataSystem.getData(ConfigData)["monster"][self.target.data.id]["hp"]; hit.hit = Math.floor(bossHP * (parseInt(DataSystem.getData(ConfigData)["skill"][110000 + self.id]["skillValue"].split(",")[self.lv]) * (1 + Math.pow(commander / 100, 1.9)) / 10000)); if (self.id == 2) { let buff = DataSystem.getData(ConfigData)["buff"][DataSystem.getData(ConfigData)["skill"][110000 + self.id]["extra"]]; self.target.data._addBuff.push(buff); } } else { hit.hit = 99999999; } self.target.data._hit.push(hit); } self.node.destroy(); }); if (this.sound && !DataSystem.getData(MissionData).isInPvp) { this.sound.play(); } } }