AutomaticFifleWeapon.ts 2.5 KB

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