Gun12.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { _decorator, Node} from 'cc';
  2. import { PoolManager } from '../../core/manager/PoolManager';
  3. import { Game } from '../../game/Game';
  4. import { PlayerCamera } from '../../game/PlayerCamera';
  5. import { GunBase } from '../base/GunBase';
  6. import { Enemy } from '../../game/Enemy';
  7. import { Player } from '../../game/Player';
  8. const { ccclass, property } = _decorator;
  9. //1003 盾牌兵盾牌 不存在子弹
  10. @ccclass('Gun12')
  11. export class Gun12 extends GunBase {
  12. @property({type: Node,tooltip:"开盾特效节点"})
  13. shieldEffect: Node = null;
  14. //盾牌拥有者
  15. public holder: Player|Enemy = null;
  16. //开盾结束回调
  17. public endCb: Function = null!;
  18. //开盾回调结束
  19. public ammoCb: Function = null;
  20. //触发间隔时间统计
  21. private curTime: number = 0;
  22. //是否是第一次开盾
  23. private isFristShield: boolean = false;
  24. //所有的烟雾
  25. public smokes: Array<Node> = []!
  26. onLoad() {
  27. this.muzzleNode.active = false;
  28. }
  29. /**
  30. * 设置开盾的数据
  31. * @param data 开盾的数据
  32. * @param endCB 结束回调
  33. * @param ammoCb 换弹匣回调
  34. */
  35. public init(data: any,holder: any,endCb?: Function,ammoCb?: Function){
  36. this.data = data;
  37. this.shotBullets = 0;
  38. this.isFire = false;
  39. this.isFristShield = true;
  40. this.holder = holder;
  41. this.endCb = endCb;
  42. this.ammoCb = ammoCb;
  43. }
  44. //开火
  45. public fire() {
  46. this.isFire = true;
  47. this.createBullet();
  48. this.playParticle(this.shieldEffect);
  49. }
  50. //结束开火
  51. public endFire(){
  52. this.isFire = false;
  53. this.endCb?.(this.data);
  54. this.recycle();
  55. }
  56. /**
  57. * 展示子弹
  58. */
  59. public createBullet() {
  60. if(!this.holder
  61. ||this.holder.isDead
  62. ||!this.isFire
  63. ||Game.I.isPause
  64. ||Game.I.isGameOver){
  65. return;
  66. }
  67. //举盾操作
  68. this.raiseShield();
  69. this.endFire();
  70. }
  71. /**
  72. * 举盾操作
  73. * @param isGuaranteedHit 子弹是否必中(必中的时候targetNode不能为空)
  74. * @param targetNode 射击的目标对象
  75. * @returns 返回一颗子弹
  76. */
  77. public raiseShield(){
  78. }
  79. /**
  80. * 回收烟雾
  81. */
  82. public recycle(){
  83. this.smokes.forEach(e => {
  84. if(e && e.parent){
  85. PoolManager.putNode(e);
  86. }
  87. });
  88. this.smokes = [];
  89. }
  90. }