07c4522d3e8d15585922a238b5c4785bebda35a2.js 12 KB

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