SkillBase.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { _decorator, Component, Node, ModelComponent, Vec4, GraphicsComponent, Size, view, Color } from 'cc';
  2. import { EventDispatcher } from '../../../../engines/events/EventDispatcher';
  3. import { WeaponBase } from '../weapons/WeaponBase';
  4. const { ccclass, property } = _decorator;
  5. export class SkillBase extends EventDispatcher{
  6. public static SKILL_COMPLETE:string="SKILL_COMPLETE";
  7. config:any;
  8. data:any;
  9. weapon:WeaponBase;
  10. leftWeapon:ModelComponent;
  11. rightWeapon:ModelComponent;
  12. private color4:Vec4;
  13. private colorIndex:number=0;
  14. /**
  15. * 使用技能
  16. * @param weapon
  17. * @param data
  18. */
  19. UseSkill(weapon:WeaponBase,data?:any):void{
  20. this.weapon=weapon;
  21. this.data=data;
  22. if(this.weaponFlicker){
  23. this.color4=new Vec4(1,1,1,1)
  24. this.leftWeapon=this.weapon.leftWeapon.getComponentInChildren(ModelComponent);
  25. this.rightWeapon=this.weapon.rightWeapon.getComponentInChildren(ModelComponent);
  26. }
  27. }
  28. /**
  29. * 更新
  30. * @param dt
  31. */
  32. Update(dt:number):void{
  33. if(this.weaponFlicker){
  34. this.colorIndex+=0.1;
  35. let value:number=Math.sin(this.colorIndex);
  36. this.color4.w=value;
  37. this.leftWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  38. this.rightWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  39. }
  40. this.DrawingSkillState();
  41. }
  42. /**
  43. * 销毁
  44. */
  45. Dispose():void{
  46. if(this.weaponFlicker){
  47. this.color4.set(1,1,1,0);
  48. this.leftWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  49. this.rightWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  50. }
  51. this.opacityIndex=0;
  52. this.DrawingSkillState();
  53. this.weapon=null;
  54. this.data=null;
  55. }
  56. private opacityIndex:number=0;
  57. private DrawingSkillState():void{
  58. let a:number=Math.sin(this.opacityIndex)*255;
  59. let VisibleSize:Size=view.getVisibleSize();
  60. this.drawingBoard.clear(true);
  61. this.drawingBoard.fillColor=new Color(255,0,0,a);
  62. let w3:number=VisibleSize.width/3;
  63. let h4:number=VisibleSize.height/4;
  64. this.drawingBoard.moveTo(0,0);
  65. this.drawingBoard.lineTo(w3,0);
  66. this.drawingBoard.lineTo(0,h4);
  67. this.drawingBoard.fill();
  68. this.drawingBoard.moveTo(VisibleSize.width-w3,0);
  69. this.drawingBoard.lineTo(VisibleSize.width,0);
  70. this.drawingBoard.lineTo(VisibleSize.width,h4);
  71. this.drawingBoard.fill();
  72. this.drawingBoard.moveTo(0,VisibleSize.height);
  73. this.drawingBoard.lineTo(0,VisibleSize.height-h4);
  74. this.drawingBoard.lineTo(w3,VisibleSize.height);
  75. this.drawingBoard.fill();
  76. this.drawingBoard.moveTo(VisibleSize.width-w3,VisibleSize.height);
  77. this.drawingBoard.lineTo(VisibleSize.width,VisibleSize.height);
  78. this.drawingBoard.lineTo(VisibleSize.width,VisibleSize.height-h4);
  79. this.drawingBoard.fill();
  80. this.opacityIndex+=0.1;
  81. }
  82. protected get drawingBoard():GraphicsComponent{
  83. return this.data.drawingBoard;
  84. }
  85. /**
  86. * 射击间隔
  87. */
  88. get fireInterval():number{
  89. return this.config.fireInterval;
  90. }
  91. get damage():number{
  92. return this.config.damage;
  93. }
  94. get time():number{
  95. return this.config.time;
  96. }
  97. /**
  98. * 是否阻断玩家操作
  99. */
  100. get unController():boolean{
  101. return this.config.unController;
  102. }
  103. /**
  104. * 武器闪烁
  105. */
  106. get weaponFlicker():boolean{
  107. return this.config.weaponFlicker
  108. }
  109. /**
  110. * 界面闪烁
  111. */
  112. get viewFlicker():boolean{
  113. return this.config.viewFlicker;
  114. }
  115. /**
  116. * 无限子弹
  117. */
  118. get bullets():boolean{
  119. return true;
  120. }
  121. }