KillAllMonsterSkill.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. return;
  38. }
  39. if(current-this.lastTime>this.fireInterval){
  40. if(posType==0){
  41. this.weapon.fireKey=1;
  42. }else if(posType==1){
  43. this.weapon.fireKey=2;
  44. }else if(posType==2){
  45. this.weapon.fireKey=3;
  46. }
  47. this.weapon.MoveFirePosition();
  48. this.weapon.Fire(false);
  49. this.lastTime=current;
  50. }
  51. }
  52. /**
  53. * 销毁
  54. */
  55. Dispose():void{
  56. SoundManager.single.StopSound("Weapon");
  57. SoundManager.single.StopSound("WeaponLeft");
  58. SoundManager.single.StopSound("WeaponRight");
  59. }
  60. }