KillAllMonsterSkill.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 weapon:WeaponBase;
  13. private startTime:number;
  14. /**
  15. * 使用技能
  16. * @param weapon
  17. */
  18. UseSkill(weapon:WeaponBase):void{
  19. this.weapon=weapon;
  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. let current:number=director.getCurrentTime();
  31. if(current-this.startTime>this.time){
  32. this.DispatchEvent(SkillBase.SKILL_COMPLETE);
  33. return;
  34. }
  35. let posType:number=GameController.single.FindAttackMonsterPosType;
  36. if(posType<0){
  37. SoundManager.single.StopSound("Weapon");
  38. SoundManager.single.StopSound("WeaponLeft");
  39. SoundManager.single.StopSound("WeaponRight");
  40. return;
  41. }
  42. if(current-this.lastTime>this.fireInterval){
  43. if(posType==0){
  44. this.weapon.fireKey=1;
  45. }else if(posType==1){
  46. this.weapon.fireKey=2;
  47. }else if(posType==2){
  48. this.weapon.fireKey=3;
  49. }
  50. this.weapon.MoveFirePosition();
  51. this.weapon.Fire(false);
  52. this.lastTime=current;
  53. }
  54. }
  55. /**
  56. * 销毁
  57. */
  58. Dispose():void{
  59. SoundManager.single.StopSound("Weapon");
  60. SoundManager.single.StopSound("WeaponLeft");
  61. SoundManager.single.StopSound("WeaponRight");
  62. }
  63. }