a025321203cfe4d526aa288fae150433a1e08722.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, geometry, PhysicsSystem, RigidBody, PoolManager, Game, BulletBase, _dec, _class, _crd, ccclass, property, Bullet10;
  4. function _reportPossibleCrUseOfPoolManager(extras) {
  5. _reporterNs.report("PoolManager", "../../core/manager/PoolManager", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfGame(extras) {
  8. _reporterNs.report("Game", "../../game/Game", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfBulletBase(extras) {
  11. _reporterNs.report("BulletBase", "../base/BulletBase", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfGunBase(extras) {
  14. _reporterNs.report("GunBase", "../base/GunBase", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfGun(extras) {
  17. _reporterNs.report("Gun10", "./Gun10", _context.meta, extras);
  18. }
  19. return {
  20. setters: [function (_unresolved_) {
  21. _reporterNs = _unresolved_;
  22. }, function (_cc) {
  23. _cclegacy = _cc.cclegacy;
  24. __checkObsolete__ = _cc.__checkObsolete__;
  25. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  26. _decorator = _cc._decorator;
  27. geometry = _cc.geometry;
  28. PhysicsSystem = _cc.PhysicsSystem;
  29. RigidBody = _cc.RigidBody;
  30. }, function (_unresolved_2) {
  31. PoolManager = _unresolved_2.PoolManager;
  32. }, function (_unresolved_3) {
  33. Game = _unresolved_3.Game;
  34. }, function (_unresolved_4) {
  35. BulletBase = _unresolved_4.BulletBase;
  36. }],
  37. execute: function () {
  38. _crd = true;
  39. _cclegacy._RF.push({}, "d795a460dJCIanwcZSOLmLj", "Bullet10", undefined);
  40. __checkObsolete__(['_decorator', 'Vec3', 'Node', 'geometry', 'PhysicsSystem', 'PhysicsRayResult', 'RigidBody']);
  41. ({
  42. ccclass,
  43. property
  44. } = _decorator); //1001敌人所使用的枪大兵手枪 OR 1007将军手枪所用的子弹
  45. _export("Bullet10", Bullet10 = (_dec = ccclass('Bullet10'), _dec(_class = class Bullet10 extends (_crd && BulletBase === void 0 ? (_reportPossibleCrUseOfBulletBase({
  46. error: Error()
  47. }), BulletBase) : BulletBase) {
  48. constructor() {
  49. super(...arguments);
  50. //是否必死 必死的子弹不会回收 要自己控制
  51. this.isRemoveDead = false;
  52. //射击方向的位置
  53. this.vector = null;
  54. }
  55. /**
  56. * 初始化一个子弹
  57. */
  58. /**
  59. * 初始化一个子弹
  60. * @param gun 属于哪把枪
  61. * @param isRemoveDead 是否不受控制的子弹自己管理
  62. */
  63. init(gun, isRemoveDead) {
  64. if (isRemoveDead === void 0) {
  65. isRemoveDead = false;
  66. }
  67. this.gunBase = gun;
  68. this.isDead = false;
  69. this.isRemoveDead = isRemoveDead;
  70. }
  71. /**
  72. * 设置子弹开始位置和射击方向
  73. * @param v 射向的方向
  74. */
  75. setBulletVector(v) {
  76. var bulletSpeed = this.gunBase.data.bulletSpeed;
  77. this.vector = v.clone().multiplyScalar(bulletSpeed);
  78. this.node.forward = v;
  79. this.rayPreCheck(bulletSpeed / 60);
  80. }
  81. /**
  82. * 射击速度发生改变
  83. */
  84. speedChange() {
  85. var bulletSpeed = this.gunBase.data.bulletSpeed;
  86. if (this.vector) {
  87. this.vector = this.vector.normalize().multiplyScalar(bulletSpeed);
  88. }
  89. }
  90. /**
  91. * 实时帧更新
  92. */
  93. update(deltaTime) {
  94. if ((_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  95. error: Error()
  96. }), Game) : Game).I.isGameOver || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  97. error: Error()
  98. }), Game) : Game).I.isPause || this.isRemoveDead) {
  99. this.isDead = true;
  100. (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  101. error: Error()
  102. }), PoolManager) : PoolManager).putNode(this.node);
  103. return;
  104. }
  105. if (this.vector) {
  106. var moveDelta = this.vector.clone().multiplyScalar(deltaTime);
  107. this.node.worldPosition = this.node.worldPosition.add(moveDelta);
  108. this.rayPreCheck(moveDelta.length());
  109. }
  110. }
  111. /**
  112. * 检测射击
  113. * @param b
  114. * @param len 检测
  115. */
  116. rayPreCheck(len) {
  117. var p = this.node.worldPosition;
  118. var ray = geometry.Ray.create(p.x, p.y, p.z, this.vector.x, this.vector.y, this.vector.z);
  119. var phy = PhysicsSystem.instance;
  120. var isHit = phy.raycast(ray, 0xffffff, len);
  121. if (isHit && phy.raycastResults.length > 0) {
  122. var result = phy.raycastResults[0];
  123. this.addImpact(result);
  124. if (result.collider.getComponent(RigidBody)) {
  125. result.collider.getComponent(RigidBody).applyForce(this.vector, result.hitPoint);
  126. }
  127. var name = result.collider.node.name;
  128. if (name == (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  129. error: Error()
  130. }), Game) : Game).I.player.head.name) {
  131. //敌人打玩家爆头
  132. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  133. error: Error()
  134. }), Game) : Game).I.player.subHP(this.gunBase.data.attack, this.gunBase.data);
  135. } else if (name == (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  136. error: Error()
  137. }), Game) : Game).I.player.body.name) {
  138. //敌人打玩家身体
  139. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  140. error: Error()
  141. }), Game) : Game).I.player.subHP(this.gunBase.data.attack, this.gunBase.data);
  142. } //自动回收了子弹
  143. this.autoRecycle();
  144. }
  145. }
  146. /**
  147. * 加入射击中的效果
  148. * @param e 碰撞到的结果
  149. */
  150. addImpact(e) {
  151. var impact = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  152. error: Error()
  153. }), PoolManager) : PoolManager).getNode(this.gunBase.impact);
  154. impact.worldPosition = e.hitPoint.add(e.hitNormal.multiplyScalar(0.01));
  155. impact.forward = e.hitNormal.multiplyScalar(-1);
  156. impact.scale = this.node.scale;
  157. impact.setParent(e.collider.node, true);
  158. }
  159. }) || _class));
  160. _cclegacy._RF.pop();
  161. _crd = false;
  162. }
  163. };
  164. });
  165. //# sourceMappingURL=a025321203cfe4d526aa288fae150433a1e08722.js.map