AutomaticFifleWeapon.ts 1.9 KB

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