cc865b0cad626cd4d72e49dc8528e7e6d444b5f5.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6", "__unresolved_7"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Vec3, tween, director, PoolManager, Game, uiMgr, Constants, Bullet1, GunBase, audioMgr, _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, Gun1;
  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 _reportPossibleCrUseOfuiMgr(extras) {
  14. _reporterNs.report("uiMgr", "../../core/manager/UIManager", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfConstants(extras) {
  17. _reporterNs.report("Constants", "../../data/Constants", _context.meta, extras);
  18. }
  19. function _reportPossibleCrUseOfGunfightShootUI(extras) {
  20. _reporterNs.report("GunfightShootUI", "../../ui/GunfightShootUI", _context.meta, extras);
  21. }
  22. function _reportPossibleCrUseOfBullet(extras) {
  23. _reporterNs.report("Bullet1", "./Bullet1", _context.meta, extras);
  24. }
  25. function _reportPossibleCrUseOfGunBase(extras) {
  26. _reporterNs.report("GunBase", "../base/GunBase", _context.meta, extras);
  27. }
  28. function _reportPossibleCrUseOfEnemy(extras) {
  29. _reporterNs.report("Enemy", "../../game/Enemy", _context.meta, extras);
  30. }
  31. function _reportPossibleCrUseOfPlayer(extras) {
  32. _reporterNs.report("Player", "../../game/Player", _context.meta, extras);
  33. }
  34. function _reportPossibleCrUseOfaudioMgr(extras) {
  35. _reporterNs.report("audioMgr", "../../core/manager/AudioManager", _context.meta, extras);
  36. }
  37. return {
  38. setters: [function (_unresolved_) {
  39. _reporterNs = _unresolved_;
  40. }, function (_cc) {
  41. _cclegacy = _cc.cclegacy;
  42. __checkObsolete__ = _cc.__checkObsolete__;
  43. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  44. _decorator = _cc._decorator;
  45. Node = _cc.Node;
  46. Vec3 = _cc.Vec3;
  47. tween = _cc.tween;
  48. director = _cc.director;
  49. }, function (_unresolved_2) {
  50. PoolManager = _unresolved_2.PoolManager;
  51. }, function (_unresolved_3) {
  52. Game = _unresolved_3.Game;
  53. }, function (_unresolved_4) {
  54. uiMgr = _unresolved_4.uiMgr;
  55. }, function (_unresolved_5) {
  56. Constants = _unresolved_5.Constants;
  57. }, function (_unresolved_6) {
  58. Bullet1 = _unresolved_6.Bullet1;
  59. }, function (_unresolved_7) {
  60. GunBase = _unresolved_7.GunBase;
  61. }, function (_unresolved_8) {
  62. audioMgr = _unresolved_8.audioMgr;
  63. }],
  64. execute: function () {
  65. _crd = true;
  66. _cclegacy._RF.push({}, "6984845eWhGy4N9LVXaCypl", "Gun1", undefined);
  67. __checkObsolete__(['_decorator', 'Node', 'Vec3', 'tween', 'director']);
  68. ({
  69. ccclass,
  70. property
  71. } = _decorator); //玩家所使用的枪 重狙枪 开一枪然后回缩镜头 (98K M24 AWM)
  72. _export("Gun1", Gun1 = (_dec = ccclass('Gun1'), _dec2 = property({
  73. type: Node,
  74. tooltip: "子弹节点"
  75. }), _dec3 = property({
  76. type: Node,
  77. tooltip: "烟雾特效"
  78. }), _dec4 = property({
  79. type: Node,
  80. tooltip: "开火特效节点"
  81. }), _dec(_class = (_class2 = class Gun1 extends (_crd && GunBase === void 0 ? (_reportPossibleCrUseOfGunBase({
  82. error: Error()
  83. }), GunBase) : GunBase) {
  84. constructor() {
  85. super(...arguments);
  86. _initializerDefineProperty(this, "bulletNode", _descriptor, this);
  87. _initializerDefineProperty(this, "impact", _descriptor2, this);
  88. _initializerDefineProperty(this, "fireEffect", _descriptor3, this);
  89. //枪的拥有者
  90. this.holder = null;
  91. //开枪结束回调
  92. this.endCb = null;
  93. //换弹匣的回调
  94. this.ammoCb = null;
  95. //触发间隔时间统计
  96. this.curTime = 0;
  97. //是否是第一次开火
  98. this.isFristShot = false;
  99. //所有的烟雾
  100. this.smokes = [];
  101. }
  102. onLoad() {
  103. this.bulletNode.active = false;
  104. this.impact.active = false;
  105. this.muzzleNode.active = false;
  106. }
  107. /**
  108. * 设置枪的数据
  109. * @param data 枪的数据
  110. * @param endCB 结束回调
  111. * @param ammoCb 换弹匣回调
  112. */
  113. init(data, holder, endCb, ammoCb) {
  114. this.data = data;
  115. this.shotBullets = 0;
  116. this.isFire = false;
  117. this.isFristShot = true;
  118. this.holder = holder;
  119. this.endCb = endCb;
  120. this.ammoCb = ammoCb;
  121. } //开火
  122. fire() {
  123. this.isFire = true;
  124. this.createBullet();
  125. this.playParticle(this.fireEffect);
  126. } //结束开火
  127. endFire() {
  128. var _this$endCb;
  129. this.isFire = false;
  130. (_this$endCb = this.endCb) == null || _this$endCb.call(this, this.data);
  131. this.recycle();
  132. }
  133. /**
  134. * 直接开抢射杀敌人
  135. */
  136. killEnemy(e) {
  137. if (e.isDead || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  138. error: Error()
  139. }), Game) : Game).I.isPause) {
  140. return;
  141. }
  142. var destPos = e.node.worldPosition.clone();
  143. var bullet = this.getBulleNode();
  144. bullet.init(this, true);
  145. tween(bullet.node).to(0.3, {
  146. worldPosition: destPos
  147. }).call(() => {
  148. bullet.isDead = true;
  149. (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  150. error: Error()
  151. }), PoolManager) : PoolManager).putNode(bullet.node); //直接打死 最大血量乘以2倍
  152. e.subHP(e.data.hp * 2, this.data);
  153. }).start();
  154. }
  155. /**
  156. * 展示子弹
  157. */
  158. createBullet() {
  159. if (!this.holder || this.holder.isDead || !this.isFire || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  160. error: Error()
  161. }), Game) : Game).I.isPause || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  162. error: Error()
  163. }), Game) : Game).I.isGameOver) {
  164. return;
  165. }
  166. (_crd && audioMgr === void 0 ? (_reportPossibleCrUseOfaudioMgr({
  167. error: Error()
  168. }), audioMgr) : audioMgr).playOneShot(this.data.gun_sound);
  169. this.getBulleNode();
  170. this.shotBullets++; //换弹夹的操作
  171. if (this.shotBullets >= this.data.magazine) {
  172. var _this$ammoCb;
  173. this.shotBullets = 0;
  174. (_this$ammoCb = this.ammoCb) == null || _this$ammoCb.call(this, this.data);
  175. }
  176. this.endFire();
  177. }
  178. /**
  179. * 初始化一个子弹
  180. * @param isGuaranteedHit 子弹是否必中(必中的时候targetNode不能为空)
  181. * @param targetNode 射击的目标对象
  182. * @returns 返回一颗子弹
  183. */
  184. getBulleNode(isGuaranteedHit, targetNode) {
  185. if (isGuaranteedHit === void 0) {
  186. isGuaranteedHit = true;
  187. }
  188. if (targetNode === void 0) {
  189. targetNode = null;
  190. }
  191. //从对象池获取子弹节点
  192. var bulletNode = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  193. error: Error()
  194. }), PoolManager) : PoolManager).getNode(this.bulletNode, director.getScene());
  195. var bullet = bulletNode.getComponent(_crd && Bullet1 === void 0 ? (_reportPossibleCrUseOfBullet({
  196. error: Error()
  197. }), Bullet1) : Bullet1);
  198. bullet.init(this);
  199. bulletNode.worldPosition = this.muzzleNode.worldPosition.clone(); //计算基准方向(瞄准目标或准星位置)
  200. var shootUI = (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  201. error: Error()
  202. }), uiMgr) : uiMgr).getPageComponent((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  203. error: Error()
  204. }), Constants) : Constants).popUIs.gunfightShootUI);
  205. var targetPos = targetNode ? targetNode.worldPosition : shootUI.getCrossHairPos();
  206. var baseDirection = Vec3.subtract(new Vec3(), targetPos, this.muzzleNode.worldPosition).normalize(); //最终弹道方向
  207. var finalDirection;
  208. if (isGuaranteedHit) {
  209. //100%必中(无偏移)
  210. finalDirection = baseDirection;
  211. } else {
  212. //非必中:在基准方向上添加小范围随机偏移
  213. var maxOffsetAngle = 5;
  214. var offsetX = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180;
  215. var offsetY = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180; //应用偏移(保持Z轴主要方向)
  216. finalDirection = new Vec3(baseDirection.x + offsetX, baseDirection.y + offsetY, baseDirection.z // 保持主要前进方向
  217. ).normalize();
  218. } //设置子弹方向
  219. bulletNode.forward = finalDirection;
  220. bullet.setBulletVector(finalDirection);
  221. return bullet;
  222. }
  223. /**
  224. * 回收烟雾
  225. */
  226. recycle() {
  227. this.smokes.forEach(e => {
  228. if (e && e.parent) {
  229. (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  230. error: Error()
  231. }), PoolManager) : PoolManager).putNode(e);
  232. }
  233. });
  234. this.smokes = [];
  235. }
  236. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "bulletNode", [_dec2], {
  237. configurable: true,
  238. enumerable: true,
  239. writable: true,
  240. initializer: function initializer() {
  241. return null;
  242. }
  243. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "impact", [_dec3], {
  244. configurable: true,
  245. enumerable: true,
  246. writable: true,
  247. initializer: function initializer() {
  248. return null;
  249. }
  250. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "fireEffect", [_dec4], {
  251. configurable: true,
  252. enumerable: true,
  253. writable: true,
  254. initializer: function initializer() {
  255. return null;
  256. }
  257. })), _class2)) || _class));
  258. _cclegacy._RF.pop();
  259. _crd = false;
  260. }
  261. };
  262. });
  263. //# sourceMappingURL=cc865b0cad626cd4d72e49dc8528e7e6d444b5f5.js.map