KillAllMonsterSkill.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Node, director } from 'cc';
  2. import { SoundManager } from '../../../../engines/sounds/SoundManager';
  3. import { GameController } from '../GameController';
  4. import { WeaponBase } from '../weapons/WeaponBase';
  5. import { SkillBase } from './SkillBase';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('KillAllMonsterSkill')
  8. export class KillAllMonsterSkill extends SkillBase {
  9. constructor(){
  10. super();
  11. }
  12. private startTime:number;
  13. /**
  14. * 使用技能
  15. * @param weapon
  16. * @param data
  17. */
  18. UseSkill(weapon:WeaponBase,data?:any):void{
  19. super.UseSkill(weapon,data);
  20. this.weapon.fireKey=2;
  21. this.weapon.MoveFirePosition();
  22. this.startTime=director.getCurrentTime();
  23. }
  24. private lastTime:number=0;
  25. /**
  26. * 更新
  27. * @param dt
  28. */
  29. Update(dt:number):void{
  30. super.Update(dt);
  31. let current:number=director.getCurrentTime();
  32. if(current-this.startTime>this.time){
  33. this.DispatchEvent(SkillBase.SKILL_COMPLETE);
  34. return;
  35. }
  36. let posType:number=GameController.single.FindAttackMonsterPosType;
  37. if(posType<0){
  38. SoundManager.single.StopSound("Weapon");
  39. SoundManager.single.StopSound("WeaponLeft");
  40. SoundManager.single.StopSound("WeaponRight");
  41. return;
  42. }
  43. if(current-this.lastTime>this.fireInterval){
  44. if(posType==0){
  45. this.weapon.fireKey=1;
  46. }else if(posType==1){
  47. this.weapon.fireKey=2;
  48. }else if(posType==2){
  49. this.weapon.fireKey=3;
  50. }
  51. this.weapon.MoveFirePosition();
  52. this.weapon.Fire(this.infiniteAmmo);
  53. this.lastTime=current;
  54. }
  55. }
  56. /**
  57. * 销毁
  58. */
  59. Dispose():void{
  60. super.Dispose();
  61. SoundManager.single.StopSound("Weapon");
  62. SoundManager.single.StopSound("WeaponLeft");
  63. SoundManager.single.StopSound("WeaponRight");
  64. }
  65. }