LeaderSkillNode.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { _decorator, Component, Node, sp, tween, v3, Vec3 } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  4. import { Sound } from '../core/sound/Sound';
  5. import { ConfigData } from '../data/ConfigData';
  6. import { BattleData } from './BattleData';
  7. import { HitData } from './HitData';
  8. import { MissionData } from './MissionData';
  9. import { Monster } from './Monster';
  10. import { TakeAWalk, WalkDirection } from './TakeAWalk';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('LeaderSkillNode')
  13. export class LeaderSkillNode extends Component {
  14. @property({ type: sp.Skeleton, tooltip: "spine组件" }) spine: sp.Skeleton;
  15. @property({ type: sp.SkeletonData, tooltip: "爆炸特效" }) boom: sp.SkeletonData;
  16. @property({ type: ResourceLoader, tooltip: "资源加载组件" }) res: ResourceLoader;
  17. private target: Monster = null;
  18. private id: number = 0;
  19. private lv: number = 0;
  20. /**音效组件 */
  21. private sound: Sound;
  22. start() {
  23. this.sound = this.getComponent(Sound);
  24. }
  25. public async setData(id: number, lv: number, monster: Monster) {
  26. this.id = id;
  27. this.target = monster;
  28. this.lv = lv - 1;
  29. if (this.id < 3) {
  30. tween(this.node).to(
  31. 0.2,
  32. { position: monster.node.position }
  33. ).call(this.tweenOver.bind(this)).start();
  34. } else {
  35. let offest: Vec3;
  36. switch (monster.node.getComponent(TakeAWalk).direction) {
  37. case WalkDirection.down:
  38. offest = v3(0, -50, 0);
  39. this.spine.skeletonData = await this.res.load<sp.SkeletonData>("spine/effect/fight_skill_dun_3", sp.SkeletonData);
  40. break;
  41. case WalkDirection.up:
  42. offest = v3(0, 50, 0);
  43. this.spine.skeletonData = await this.res.load<sp.SkeletonData>("spine/effect/fight_skill_dun_1", sp.SkeletonData);
  44. break;
  45. case WalkDirection.right:
  46. offest = v3(50, 0, 0);
  47. this.spine.skeletonData = await this.res.load<sp.SkeletonData>("spine/effect/fight_skill_dun_2", sp.SkeletonData);
  48. break;
  49. }
  50. let self = this;
  51. this.node.setPosition(monster.node.position.clone().add(offest));
  52. this.spine.setAnimation(0, "in", false);
  53. this.spine.setCompleteListener(() => {
  54. self.spine.setAnimation(0, "idle", true);
  55. });
  56. DataSystem.getData(BattleData)._obstruct = this.node;
  57. let commander = DataSystem.getData(BattleData).heros.get(5).id ? parseInt(DataSystem.getData(ConfigData)["general"][DataSystem.getData(BattleData).heros.get(5).id]["commander"]) : 0;
  58. this.scheduleOnce(() => {
  59. DataSystem.getData(BattleData)._obstruct = null;
  60. this.node.destroy();
  61. }, parseFloat((DataSystem.getData(ConfigData)["skill"][110000 + this.id]["skillValue"].split(",")[this.lv])) * (1 + Math.pow(commander / 100, 1.9)));
  62. if (this.sound) {
  63. this.sound.play();
  64. }
  65. }
  66. }
  67. private isDestroy = false;
  68. private tweenOver(): void {
  69. if (this.isDestroy) {
  70. return;
  71. }
  72. this.isDestroy = true;
  73. let self = this;
  74. this.node.setRotationFromEuler(v3(0, 0, 0));
  75. this.spine.skeletonData = this.boom;
  76. this.spine.loop = false;
  77. this.spine.setAnimation(0, "animation", false);
  78. this.spine.setCompleteListener(() => {
  79. if (self.target.data) {
  80. let hit = new HitData();
  81. hit.from = " 统帅技能";
  82. hit.isSkill = true;
  83. if (self.target.data.isBoss) {
  84. let commander = DataSystem.getData(BattleData).heros.get(5).id ? parseInt(DataSystem.getData(ConfigData)["general"][DataSystem.getData(BattleData).heros.get(5).id]["commander"]) : 0;
  85. let bossHP = DataSystem.getData(ConfigData)["monster"][self.target.data.id]["hp"];
  86. 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));
  87. if (self.id == 2) {
  88. let buff = DataSystem.getData(ConfigData)["buff"][DataSystem.getData(ConfigData)["skill"][110000 + self.id]["extra"]];
  89. self.target.data._addBuff.push(buff);
  90. }
  91. } else {
  92. hit.hit = 99999999;
  93. }
  94. self.target.data._hit.push(hit);
  95. }
  96. self.node.destroy();
  97. });
  98. if (this.sound && !DataSystem.getData(MissionData).isInPvp) {
  99. this.sound.play();
  100. }
  101. }
  102. }