26e25cadbecaf935d6c63422d2afe63a6d143ea6.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Vec3, director, PoolManager, Game, GunBase, Bullet14, Utils, _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, Gun14;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfPoolManager(extras) {
  8. _reporterNs.report("PoolManager", "../../core/manager/PoolManager", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfGame(extras) {
  11. _reporterNs.report("Game", "../../game/Game", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfGunBase(extras) {
  14. _reporterNs.report("GunBase", "../base/GunBase", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfBullet(extras) {
  17. _reporterNs.report("Bullet14", "./Bullet14", _context.meta, extras);
  18. }
  19. function _reportPossibleCrUseOfUtils(extras) {
  20. _reporterNs.report("Utils", "../../utils/Utils", _context.meta, extras);
  21. }
  22. function _reportPossibleCrUseOfEnemy(extras) {
  23. _reporterNs.report("Enemy", "../../game/Enemy", _context.meta, extras);
  24. }
  25. function _reportPossibleCrUseOfPlayer(extras) {
  26. _reporterNs.report("Player", "../../game/Player", _context.meta, extras);
  27. }
  28. return {
  29. setters: [function (_unresolved_) {
  30. _reporterNs = _unresolved_;
  31. }, function (_cc) {
  32. _cclegacy = _cc.cclegacy;
  33. __checkObsolete__ = _cc.__checkObsolete__;
  34. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  35. _decorator = _cc._decorator;
  36. Node = _cc.Node;
  37. Vec3 = _cc.Vec3;
  38. director = _cc.director;
  39. }, function (_unresolved_2) {
  40. PoolManager = _unresolved_2.PoolManager;
  41. }, function (_unresolved_3) {
  42. Game = _unresolved_3.Game;
  43. }, function (_unresolved_4) {
  44. GunBase = _unresolved_4.GunBase;
  45. }, function (_unresolved_5) {
  46. Bullet14 = _unresolved_5.Bullet14;
  47. }, function (_unresolved_6) {
  48. Utils = _unresolved_6.Utils;
  49. }],
  50. execute: function () {
  51. _crd = true;
  52. _cclegacy._RF.push({}, "0d7bfOMJexIJ7DSg3dmO0p5", "Gun14", undefined);
  53. __checkObsolete__(['_decorator', 'Node', 'Vec3', 'director']);
  54. ({
  55. ccclass,
  56. property
  57. } = _decorator); //1006 坦克
  58. _export("Gun14", Gun14 = (_dec = ccclass('Gun14'), _dec2 = property({
  59. type: Node,
  60. tooltip: "子弹节点"
  61. }), _dec3 = property({
  62. type: Node,
  63. tooltip: "烟雾特效"
  64. }), _dec4 = property({
  65. type: Node,
  66. tooltip: "开火特效节点"
  67. }), _dec(_class = (_class2 = class Gun14 extends (_crd && GunBase === void 0 ? (_reportPossibleCrUseOfGunBase({
  68. error: Error()
  69. }), GunBase) : GunBase) {
  70. constructor() {
  71. super(...arguments);
  72. _initializerDefineProperty(this, "bulletNode", _descriptor, this);
  73. _initializerDefineProperty(this, "impact", _descriptor2, this);
  74. _initializerDefineProperty(this, "fireEffect", _descriptor3, this);
  75. this.isCb = false;
  76. //枪的拥有者
  77. this.enemy = null;
  78. //开枪结束回调
  79. this.endCb = null;
  80. //换弹匣的回调
  81. this.ammoCb = null;
  82. //触发间隔时间统计
  83. this.curTime = 0;
  84. //是否是第一次开火
  85. this.isFristShot = false;
  86. //所有的烟雾
  87. this.smokes = [];
  88. //是否是第一次激活开枪
  89. this.isFristShoot = false;
  90. //为了戳开子弹产生的时间间隔统计
  91. this.diff = 0;
  92. //随机延迟的时间
  93. this.r_delay = 0;
  94. //继续正常统计时间
  95. this.isGo = true;
  96. }
  97. onLoad() {
  98. this.bulletNode.active = false;
  99. this.impact.active = false;
  100. this.muzzleNode.active = false;
  101. }
  102. /**
  103. * 设置枪的数据
  104. * @param data 枪的数据
  105. * @param endCB 结束回调
  106. * @param ammoCb 换弹匣回调
  107. */
  108. init(data, enemy, endCb, ammoCb) {
  109. this.data = data;
  110. this.curTime = 0;
  111. this.isFire = false;
  112. this.isFristShot = true;
  113. this.enemy = enemy;
  114. this.endCb = endCb;
  115. this.ammoCb = ammoCb;
  116. this.node.eulerAngles = new Vec3(0, 180, 0);
  117. } //开火
  118. fire() {
  119. this.isFire = true;
  120. this.playParticle(this.fireEffect);
  121. } //结束开火
  122. endFire() {
  123. var _this$endCb;
  124. this.isFire = false;
  125. (_this$endCb = this.endCb) == null || _this$endCb.call(this, this.data);
  126. this.recycle();
  127. }
  128. /**
  129. * 展示子弹
  130. */
  131. createBullet() {
  132. if (!this.getNextAllow()) return;
  133. var delay = 0.1;
  134. for (var i = 0; i < this.data.bullet_number; i++) {
  135. this.scheduleOnce(k => {
  136. delay += (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  137. error: Error()
  138. }), Utils) : Utils).getRandomFloat(0, 0.2);
  139. if (!this.getNextAllow()) return; //获取射击的精准度
  140. var isHit = this.enemy.calculateIsHit(); //创建子弹
  141. this.getBulleNode(isHit);
  142. }, delay * i);
  143. }
  144. }
  145. /**
  146. * 初始化一个子弹
  147. * @param isGuaranteedHit 子弹是否必中(必中的时候targetNode不能为空)
  148. * @param targetNode 射击的目标对象
  149. * @returns 返回一颗子弹
  150. */
  151. getBulleNode(isGuaranteedHit) {
  152. if (isGuaranteedHit === void 0) {
  153. isGuaranteedHit = true;
  154. }
  155. //从对象池获取子弹节点
  156. var bulletNode = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  157. error: Error()
  158. }), PoolManager) : PoolManager).getNode(this.bulletNode, director.getScene());
  159. var bullet = bulletNode.getComponent(_crd && Bullet14 === void 0 ? (_reportPossibleCrUseOfBullet({
  160. error: Error()
  161. }), Bullet14) : Bullet14);
  162. bullet.init(this);
  163. bulletNode.setWorldPosition(this.muzzleNode.worldPosition);
  164. var playPos = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  165. error: Error()
  166. }), Game) : Game).I.player.head.worldPosition.clone();
  167. var baseDirection = Vec3.subtract(new Vec3(), playPos, this.muzzleNode.worldPosition).normalize(); //最终弹道方向
  168. var finalDirection;
  169. if (isGuaranteedHit) {
  170. //100%必中(无偏移)
  171. finalDirection = baseDirection;
  172. } else {
  173. //非必中:在基准方向上添加小范围随机偏移
  174. var maxOffsetAngle = 5;
  175. var offsetX = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180;
  176. var offsetY = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180; //应用偏移(保持Z轴主要方向)
  177. finalDirection = new Vec3(baseDirection.x + offsetX, baseDirection.y + offsetY, baseDirection.z // 保持主要前进方向
  178. ).normalize();
  179. } //设置子弹方向
  180. bulletNode.forward = finalDirection;
  181. bullet.setBulletVector(finalDirection);
  182. return bullet;
  183. } //激活调用 持续开火
  184. update(dt) {
  185. if (!this.getNextAllow()) return; //每几秒攻击一次
  186. var m = this.data.atk_speed; //不是第一次激活 有延迟间隔
  187. if (!this.isFristShoot) {
  188. m = this.isFristShoot ? 0 : m;
  189. if (this.diff >= this.r_delay && !this.isGo) {
  190. this.diff += dt;
  191. this.isGo = true;
  192. return;
  193. } else {
  194. this.curTime += dt;
  195. }
  196. } else {
  197. //第一次激活 就直接开枪不延迟
  198. m = this.isFristShoot ? 0 : m;
  199. } //在随机延迟的时间间隔里 发射一颗子弹
  200. if (this.curTime >= m - this.r_delay) {
  201. if (this.isFire) {
  202. this.isFristShoot = false;
  203. this.r_delay = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  204. error: Error()
  205. }), Utils) : Utils).getRandomFloat(0, 0.12);
  206. this.diff = 0;
  207. this.isGo = false; //audioMgr.playOneShot(this.data.gun_sound);
  208. //播放射击帧动画
  209. //this.playShootAnim();
  210. this.createBullet();
  211. this.curTime = 0;
  212. this.isCb = false;
  213. } else {
  214. if (!this.isFire && !this.isCb) {
  215. var _this$endCb2;
  216. this.isFire = false;
  217. (_this$endCb2 = this.endCb) == null || _this$endCb2.call(this, this.data.type);
  218. this.isCb = true;
  219. }
  220. }
  221. }
  222. }
  223. /**
  224. * 是否可以允许操作
  225. */
  226. getNextAllow() {
  227. var player = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  228. error: Error()
  229. }), Game) : Game).I.player;
  230. if (!player || player.isDead || !this.isFire || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  231. error: Error()
  232. }), Game) : Game).I.isPause || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  233. error: Error()
  234. }), Game) : Game).I.isGameOver) {
  235. return false;
  236. }
  237. return true;
  238. }
  239. /**
  240. * 回收烟雾
  241. */
  242. recycle() {
  243. this.smokes.forEach(e => {
  244. if (e && e.parent) {
  245. (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  246. error: Error()
  247. }), PoolManager) : PoolManager).putNode(e);
  248. }
  249. });
  250. this.smokes = [];
  251. }
  252. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "bulletNode", [_dec2], {
  253. configurable: true,
  254. enumerable: true,
  255. writable: true,
  256. initializer: function initializer() {
  257. return null;
  258. }
  259. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "impact", [_dec3], {
  260. configurable: true,
  261. enumerable: true,
  262. writable: true,
  263. initializer: function initializer() {
  264. return null;
  265. }
  266. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "fireEffect", [_dec4], {
  267. configurable: true,
  268. enumerable: true,
  269. writable: true,
  270. initializer: function initializer() {
  271. return null;
  272. }
  273. })), _class2)) || _class));
  274. _cclegacy._RF.pop();
  275. _crd = false;
  276. }
  277. };
  278. });
  279. //# sourceMappingURL=26e25cadbecaf935d6c63422d2afe63a6d143ea6.js.map