skillManger.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import DataObj from "../../configData/DataObj";
  2. import GameConfig from "../../configData/GameConfig";
  3. import monsterManger from "../monster/monsterManger";
  4. import towerManger from "./towerManger";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class skillManger extends cc.Component {
  8. @property(cc.Sprite)
  9. private tapQuan: cc.Sprite = null;
  10. public static instance: skillManger = null;
  11. public myDataObj: DataObj = null;
  12. private yunshiArr: cc.Node[] = [];
  13. private yunshiPosArr: cc.Vec3[] = [];
  14. /**燃烧半径 */
  15. private lenthR = 0;
  16. protected onLoad() {
  17. skillManger.instance = this;
  18. this.myDataObj = new DataObj();
  19. }
  20. /** 陨石创建*/
  21. public yunshiBuild(loca: cc.Vec2) {
  22. this.myDataObj.writeSkill_Config(60);
  23. let num = this.myDataObj.SkillData.parameter_1;
  24. if (towerManger.instance.talantData[20].length > 0) {
  25. num += towerManger.instance.talantData[20][0];
  26. }
  27. this.lenthR = this.myDataObj.getArr(this.myDataObj.SkillData.parameter_2)[1];
  28. if (towerManger.instance.talantData[22].length > 0) {
  29. this.lenthR *=1+ towerManger.instance.talantData[22][1];
  30. }
  31. let lethShow = this.lenthR - 20;
  32. this.yunshiArr = [];
  33. this.yunshiPosArr = [];
  34. let self = this;
  35. cc.resources.load("skill/yunshi", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  36. for (let i = 0; i < num; i++) {
  37. let suijix = Math.floor((-lethShow + 2 * lethShow * Math.random()) / 20) * 20;
  38. let yyLenth = Math.sqrt(lethShow * lethShow - suijix * suijix);
  39. let suijiY = Math.floor((-yyLenth + 2 * yyLenth * Math.random()) / 20) * 20;
  40. if (i == 0) {
  41. suijix = 0;
  42. }
  43. let mynode = new cc.Node();
  44. let spr = mynode.addComponent(cc.Sprite);
  45. spr.spriteFrame = myspriteFrame;
  46. mynode.setPosition(cc.v2(loca.x + suijix, 550));
  47. mynode.setAnchorPoint(cc.v2(0.5, 0));
  48. self.node.addChild(mynode, 1009);
  49. if (i == 0) {
  50. self.yunshiPosArr.push(cc.v3(loca));
  51. mynode.scale = 0.8;
  52. }
  53. else {
  54. mynode.scale = 0.4;
  55. self.yunshiPosArr.push(cc.v3(loca).add(cc.v3(suijix, suijiY)));
  56. }
  57. self.yunshiArr.push(mynode);
  58. }
  59. self.yunshiAct();
  60. });
  61. }
  62. /**陨石掉落动画 */
  63. private yunshiAct() {
  64. for (let i = 0; i < this.yunshiArr.length; i++) {
  65. const element = this.yunshiArr[i];
  66. let tt = 0.1 + Math.random() / 2;
  67. if (i == 0) {
  68. tt = 0;
  69. }
  70. let leth = 550 - this.yunshiPosArr[i].y;
  71. cc.tween(element)
  72. .delay(tt)
  73. .to(leth / Number(this.myDataObj.SkillData.parameter_5), { position: this.yunshiPosArr[i] })
  74. .call(() => {
  75. let hurt = this.myDataObj.getRanm(1, this.myDataObj.SkillData.parameter_3);
  76. if (towerManger.instance.talantData[24].length > 0) {
  77. hurt *= 1+ towerManger.instance.talantData[20][1]+towerManger.instance.talantData[22][0] + towerManger.instance.talantData[24][0];
  78. }
  79. else
  80. {
  81. if (towerManger.instance.talantData[22].length > 0) {
  82. hurt *= 1 + towerManger.instance.talantData[20][1]+towerManger.instance.talantData[22][0];
  83. }
  84. else
  85. {
  86. if (towerManger.instance.talantData[20].length > 0) {
  87. hurt *= 1 + towerManger.instance.talantData[20][1];
  88. }
  89. }
  90. }
  91. let lethR = this.myDataObj.getArr(this.myDataObj.SkillData.parameter_2)[0];
  92. if (towerManger.instance.talantData[22].length > 0) {
  93. lethR *= 1+ towerManger.instance.talantData[22][1];
  94. }
  95. this.hurtMonster(this.yunshiPosArr[i], hurt, lethR);
  96. if (i == this.yunshiArr.length - 1) {
  97. if (towerManger.instance.talantData[23].length > 0) {
  98. this.schedule(this.burningHurt24, 1, towerManger.instance.talantData[23][1]-1, 0);
  99. this.burningHurtAction();
  100. }
  101. else
  102. {
  103. if (towerManger.instance.talantData[21].length > 0) {
  104. this.schedule(this.burningHurt22, 1, towerManger.instance.talantData[21][1]-1, 0);
  105. this.burningHurtAction();
  106. }
  107. }
  108. }
  109. })
  110. .removeSelf()
  111. .start();
  112. }
  113. this.yunshiQuan(cc.v2(this.yunshiPosArr[0]));
  114. }
  115. /**燃烧陷阱 */
  116. private burningHurt22() {
  117. this.hurtMonster(this.yunshiPosArr[0], towerManger.instance.talantData[21][0], this.lenthR);
  118. }
  119. /**燃烧陷阱 */
  120. private burningHurt24() {
  121. this.hurtMonster(this.yunshiPosArr[0], towerManger.instance.talantData[23][0], this.lenthR);
  122. }
  123. /**燃烧陷阱动画 */
  124. private burningHurtAction() {
  125. }
  126. /**陨石掉落伤害 */
  127. private hurtMonster(pos: cc.Vec3, attack: number, sqrt: number) {
  128. let monarr = monsterManger.instance.GetMonsterArr();
  129. for (let k = 0; k < monarr.length; k++) {
  130. const minster = monarr[k];
  131. let monPos = minster.node.getPosition();
  132. if (monPos.sub(cc.v2(pos)).mag() < sqrt) {
  133. minster.hpDown(attack);
  134. }
  135. }
  136. }
  137. /**陨石圈 */
  138. public yunshiQuan(poss: cc.Vec2) {
  139. this.tapQuan.node.opacity = 255;
  140. this.tapQuan.node.setPosition(poss);
  141. this.tapQuan.node.setContentSize(this.lenthR * 2, this.lenthR * 2);
  142. this.tapQuan.node.stopAllActions();
  143. cc.tween(this.tapQuan.node)
  144. .to(0.3, { opacity: 100 })
  145. .to(0.3, { opacity: 255 })
  146. .to(0.3, { opacity: 100 })
  147. .to(0.6, { opacity: 255 })
  148. .to(0.3, { opacity: 0 })
  149. .start();
  150. }
  151. }