DefaultSkill.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { 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. export default class DefaultSkill extends SkillBase
  7. {
  8. private startTime:number;
  9. private lastTime:number=0;
  10. /**
  11. * 使用技能
  12. * @param weapon
  13. * @param data
  14. */
  15. UseSkill(weapon:WeaponBase,data?:any):void{
  16. super.UseSkill(weapon,data);
  17. this.weapon.fireKey=2;
  18. this.weapon.MoveFirePosition();
  19. this.startTime=director.getCurrentTime();
  20. }
  21. /**
  22. * 更新
  23. * @param dt
  24. */
  25. Update(dt:number):void{
  26. super.Update(dt);
  27. let current:number=director.getCurrentTime();
  28. if(current-this.startTime>this.time){
  29. this.DispatchEvent(SkillBase.SKILL_COMPLETE);
  30. return;
  31. }
  32. let posType:number=GameController.single.FindAttackMonsterPosType;
  33. if(posType<0){
  34. SoundManager.single.StopSound("Weapon");
  35. SoundManager.single.StopSound("WeaponLeft");
  36. SoundManager.single.StopSound("WeaponRight");
  37. return;
  38. }
  39. //自动攻击
  40. if(this.unController){
  41. if(current-this.lastTime>this.fireInterval){
  42. if(posType==0){
  43. this.weapon.fireKey=1;
  44. }else if(posType==1){
  45. this.weapon.fireKey=2;
  46. }else if(posType==2){
  47. this.weapon.fireKey=3;
  48. }
  49. this.weapon.MoveFirePosition();
  50. this.weapon.Fire(this.infiniteAmmo);
  51. this.lastTime=current;
  52. }
  53. }
  54. }
  55. /**
  56. * 销毁
  57. */
  58. Dispose():void{
  59. super.Dispose();
  60. SoundManager.single.StopSound("Weapon");
  61. SoundManager.single.StopSound("WeaponLeft");
  62. SoundManager.single.StopSound("WeaponRight");
  63. }
  64. // /**
  65. // * 是否阻断玩家操作
  66. // */
  67. // get unController():boolean{
  68. // return false;
  69. // }
  70. // /**
  71. // * 射击间隔
  72. // */
  73. // get fireInterval():number{
  74. // return 50;
  75. // }
  76. }