AutomaticFifleWeapon.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { AnimationComponent } from "cc";
  2. import { WeaponBase } from "./WeaponBase";
  3. export default class AutomaticFifleWeapon extends WeaponBase
  4. {
  5. constructor(leftHand:AnimationComponent,rightHand:AnimationComponent){
  6. super(leftHand,rightHand);
  7. }
  8. Fire(bullet:boolean):void{
  9. super.Fire(bullet);
  10. if(this.fireKey==1){
  11. this.FireLeft();
  12. if(bullet){
  13. this.bulletCount--;
  14. }
  15. }else if(this.fireKey==3){
  16. this.FireRight();
  17. if(bullet){
  18. this.bulletCount--;
  19. }
  20. }else{
  21. this.FireLeft();
  22. if(this.bulletCount>1){
  23. this.FireRight();
  24. }
  25. if(bullet){
  26. this.bulletCount-=2;
  27. }
  28. }
  29. }
  30. private FireLeft():void{
  31. this.isLeftFire=true;
  32. this.leftHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  33. this.leftHand.play(this.weaponConfig.handFireAnimation);
  34. this.rightHand.crossFade("Idle",0.5);
  35. this.leftGunFire.play(this.weaponConfig.gunFireAnimation);
  36. }
  37. private FireRight():void{
  38. this.isLeftFire=false;
  39. this.rightHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  40. this.rightHand.play(this.weaponConfig.handFireAnimation);
  41. this.leftHand.crossFade("Idle",0.5);
  42. this.rightGunFire.play(this.weaponConfig.gunFireAnimation);
  43. }
  44. private FireCompleteHandler():void{
  45. this.isFire=false;
  46. if(this.isLeftFire){
  47. this.leftHand.crossFade("Idle",0.5);
  48. }else{
  49. this.rightHand.crossFade("Idle",0.5)
  50. }
  51. }
  52. }