SkillBase.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. if(this.leftWeapon.isValid){
  49. this.leftWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  50. }
  51. if(this.rightWeapon.isValid){
  52. this.rightWeapon.sharedMaterial.setProperty('rimColor',this.color4);
  53. }
  54. }
  55. this.opacityIndex=0;
  56. this.DrawingSkillState();
  57. this.weapon=null;
  58. this.data=null;
  59. }
  60. private opacityIndex:number=0;
  61. private DrawingSkillState():void{
  62. let a:number=Math.sin(this.opacityIndex)*255;
  63. let VisibleSize:Size=view.getVisibleSize();
  64. this.drawingBoard.clear(true);
  65. this.drawingBoard.fillColor=new Color(255,0,0,a);
  66. let w3:number=VisibleSize.width/3;
  67. let h4:number=VisibleSize.height/4;
  68. this.drawingBoard.moveTo(0,0);
  69. this.drawingBoard.lineTo(w3,0);
  70. this.drawingBoard.lineTo(0,h4);
  71. this.drawingBoard.fill();
  72. this.drawingBoard.moveTo(VisibleSize.width-w3,0);
  73. this.drawingBoard.lineTo(VisibleSize.width,0);
  74. this.drawingBoard.lineTo(VisibleSize.width,h4);
  75. this.drawingBoard.fill();
  76. this.drawingBoard.moveTo(0,VisibleSize.height);
  77. this.drawingBoard.lineTo(0,VisibleSize.height-h4);
  78. this.drawingBoard.lineTo(w3,VisibleSize.height);
  79. this.drawingBoard.fill();
  80. this.drawingBoard.moveTo(VisibleSize.width-w3,VisibleSize.height);
  81. this.drawingBoard.lineTo(VisibleSize.width,VisibleSize.height);
  82. this.drawingBoard.lineTo(VisibleSize.width,VisibleSize.height-h4);
  83. this.drawingBoard.fill();
  84. this.opacityIndex+=0.1;
  85. }
  86. protected get drawingBoard():GraphicsComponent{
  87. return this.data.drawingBoard;
  88. }
  89. /**
  90. * 射击间隔
  91. */
  92. get fireInterval():number{
  93. return this.config.fireInterval;
  94. }
  95. get damage():number{
  96. return this.config.damage;
  97. }
  98. get time():number{
  99. return this.config.time;
  100. }
  101. /**
  102. * 是否阻断玩家操作
  103. */
  104. get unController():boolean{
  105. return this.config.unController==1;
  106. }
  107. /**
  108. * 武器闪烁
  109. */
  110. get weaponFlicker():boolean{
  111. return this.config.weaponFlicker==1;
  112. }
  113. /**
  114. * 界面闪烁
  115. */
  116. get viewFlicker():boolean{
  117. return this.config.viewFlicker==1;
  118. }
  119. /**
  120. * 无限子弹
  121. */
  122. get infiniteAmmo():boolean{
  123. return this.config.infiniteAmmo==1;
  124. }
  125. }