4939d0aafb7a933a612fcaa12691e0b0a210a5ff.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6", "__unresolved_7", "__unresolved_8", "__unresolved_9", "__unresolved_10", "__unresolved_11"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Quat, math, Camera, sys, Vec3, Label, geometry, ProgressBar, tween, easing, Tween, UIOpacity, Game, BaseExp, autoBind, Constants, uiMgr, userIns, MsgHints, List, Utils, TaskEnemyItem, BulletMagazine, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _crd, ccclass, property, clamp, toRadian, GunfightShootUI;
  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 _reportPossibleCrUseOfBaseExp(extras) {
  11. _reporterNs.report("BaseExp", "../core/base/BaseExp", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfautoBind(extras) {
  14. _reporterNs.report("autoBind", "../extend/AutoBind", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfConstants(extras) {
  17. _reporterNs.report("Constants", "../data/Constants", _context.meta, extras);
  18. }
  19. function _reportPossibleCrUseOfuiMgr(extras) {
  20. _reporterNs.report("uiMgr", "../core/manager/UIManager", _context.meta, extras);
  21. }
  22. function _reportPossibleCrUseOfuserIns(extras) {
  23. _reporterNs.report("userIns", "../data/UserData", _context.meta, extras);
  24. }
  25. function _reportPossibleCrUseOfMsgHints(extras) {
  26. _reporterNs.report("MsgHints", "../utils/MsgHints", _context.meta, extras);
  27. }
  28. function _reportPossibleCrUseOfList(extras) {
  29. _reporterNs.report("List", "../third/List", _context.meta, extras);
  30. }
  31. function _reportPossibleCrUseOfUtils(extras) {
  32. _reporterNs.report("Utils", "../utils/Utils", _context.meta, extras);
  33. }
  34. function _reportPossibleCrUseOfTaskEnemyItem(extras) {
  35. _reporterNs.report("TaskEnemyItem", "../items/item/TaskEnemyItem", _context.meta, extras);
  36. }
  37. function _reportPossibleCrUseOfBulletMagazine(extras) {
  38. _reporterNs.report("BulletMagazine", "../game/BulletMagazine", _context.meta, extras);
  39. }
  40. return {
  41. setters: [function (_unresolved_) {
  42. _reporterNs = _unresolved_;
  43. }, function (_cc) {
  44. _cclegacy = _cc.cclegacy;
  45. __checkObsolete__ = _cc.__checkObsolete__;
  46. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  47. _decorator = _cc._decorator;
  48. Node = _cc.Node;
  49. Quat = _cc.Quat;
  50. math = _cc.math;
  51. Camera = _cc.Camera;
  52. sys = _cc.sys;
  53. Vec3 = _cc.Vec3;
  54. Label = _cc.Label;
  55. geometry = _cc.geometry;
  56. ProgressBar = _cc.ProgressBar;
  57. tween = _cc.tween;
  58. easing = _cc.easing;
  59. Tween = _cc.Tween;
  60. UIOpacity = _cc.UIOpacity;
  61. }, function (_unresolved_2) {
  62. Game = _unresolved_2.Game;
  63. }, function (_unresolved_3) {
  64. BaseExp = _unresolved_3.BaseExp;
  65. }, function (_unresolved_4) {
  66. autoBind = _unresolved_4.autoBind;
  67. }, function (_unresolved_5) {
  68. Constants = _unresolved_5.Constants;
  69. }, function (_unresolved_6) {
  70. uiMgr = _unresolved_6.uiMgr;
  71. }, function (_unresolved_7) {
  72. userIns = _unresolved_7.userIns;
  73. }, function (_unresolved_8) {
  74. MsgHints = _unresolved_8.default;
  75. }, function (_unresolved_9) {
  76. List = _unresolved_9.default;
  77. }, function (_unresolved_10) {
  78. Utils = _unresolved_10.Utils;
  79. }, function (_unresolved_11) {
  80. TaskEnemyItem = _unresolved_11.TaskEnemyItem;
  81. }, function (_unresolved_12) {
  82. BulletMagazine = _unresolved_12.BulletMagazine;
  83. }],
  84. execute: function () {
  85. _crd = true;
  86. _cclegacy._RF.push({}, "c368esIoplOL4AhvWUUyNzo", "GunfightShootUI", undefined);
  87. __checkObsolete__(['_decorator', 'EventTouch', 'Node', 'Quat', 'math', 'Camera', 'sys', 'Vec3', 'Label', 'geometry', 'ProgressBar', 'tween', 'easing', 'Tween', 'UIOpacity', 'game', 'PhysicsSystem', 'PhysicsRayResult']);
  88. ({
  89. ccclass,
  90. property
  91. } = _decorator);
  92. ({
  93. clamp,
  94. toRadian
  95. } = math);
  96. _export("GunfightShootUI", GunfightShootUI = (_dec = ccclass('GunfightShootUI'), _dec2 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  97. error: Error()
  98. }), autoBind) : autoBind)({
  99. type: Node,
  100. tooltip: "轮盘节点"
  101. }), _dec3 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  102. error: Error()
  103. }), autoBind) : autoBind)({
  104. type: Node,
  105. tooltip: "标准贴图"
  106. }), _dec4 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  107. error: Error()
  108. }), autoBind) : autoBind)({
  109. type: Node,
  110. tooltip: "准心"
  111. }), _dec5 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  112. error: Error()
  113. }), autoBind) : autoBind)({
  114. type: ProgressBar,
  115. tooltip: "步枪子弹进度条"
  116. }), _dec6 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  117. error: Error()
  118. }), autoBind) : autoBind)({
  119. type: Label,
  120. tooltip: "步枪子弹数文本"
  121. }), _dec7 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  122. error: Error()
  123. }), autoBind) : autoBind)({
  124. type: _crd && BulletMagazine === void 0 ? (_reportPossibleCrUseOfBulletMagazine({
  125. error: Error()
  126. }), BulletMagazine) : BulletMagazine,
  127. tooltip: "步枪子弹列表"
  128. }), _dec8 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  129. error: Error()
  130. }), autoBind) : autoBind)({
  131. type: _crd && BulletMagazine === void 0 ? (_reportPossibleCrUseOfBulletMagazine({
  132. error: Error()
  133. }), BulletMagazine) : BulletMagazine,
  134. tooltip: "狙击枪子弹列表"
  135. }), _dec9 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  136. error: Error()
  137. }), autoBind) : autoBind)({
  138. type: Node,
  139. tooltip: "步枪显示子弹的总的节点"
  140. }), _dec10 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  141. error: Error()
  142. }), autoBind) : autoBind)({
  143. type: _crd && List === void 0 ? (_reportPossibleCrUseOfList({
  144. error: Error()
  145. }), List) : List,
  146. tooltip: "敌人任务列表"
  147. }), _dec11 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  148. error: Error()
  149. }), autoBind) : autoBind)({
  150. type: ProgressBar,
  151. tooltip: "玩家生命进度条"
  152. }), _dec12 = property({
  153. type: [Node],
  154. tooltip: "要隐藏的所有按钮"
  155. }), _dec13 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  156. error: Error()
  157. }), autoBind) : autoBind)({
  158. type: ProgressBar,
  159. tooltip: "换弹夹时间进度条"
  160. }), _dec14 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  161. error: Error()
  162. }), autoBind) : autoBind)({
  163. type: Node,
  164. tooltip: "玩家受到伤害呼吸闪烁"
  165. }), _dec15 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  166. error: Error()
  167. }), autoBind) : autoBind)({
  168. type: Label,
  169. tooltip: "玩家枪的名字"
  170. }), _dec(_class = (_class2 = class GunfightShootUI extends (_crd && BaseExp === void 0 ? (_reportPossibleCrUseOfBaseExp({
  171. error: Error()
  172. }), BaseExp) : BaseExp) {
  173. constructor() {
  174. super(...arguments);
  175. _initializerDefineProperty(this, "wheel", _descriptor, this);
  176. _initializerDefineProperty(this, "scopeOverlay", _descriptor2, this);
  177. _initializerDefineProperty(this, "crossHair", _descriptor3, this);
  178. _initializerDefineProperty(this, "rifle_bullet_progressBar", _descriptor4, this);
  179. _initializerDefineProperty(this, "rifle_bullet_num_label", _descriptor5, this);
  180. _initializerDefineProperty(this, "rifle_bullets_scrollView", _descriptor6, this);
  181. _initializerDefineProperty(this, "snipe_bullets_scrollView", _descriptor7, this);
  182. _initializerDefineProperty(this, "rifle_bullets_bg", _descriptor8, this);
  183. _initializerDefineProperty(this, "task_scrollView", _descriptor9, this);
  184. _initializerDefineProperty(this, "hpProgressBar", _descriptor10, this);
  185. _initializerDefineProperty(this, "hiddeNodes", _descriptor11, this);
  186. _initializerDefineProperty(this, "reloadProgressBar", _descriptor12, this);
  187. _initializerDefineProperty(this, "injury_blood", _descriptor13, this);
  188. _initializerDefineProperty(this, "gun_name_label", _descriptor14, this);
  189. /** 子弹飞行距离 */
  190. this.bulletDistance = 800;
  191. /** 当前相机绕 X 轴的旋转角度 */
  192. this.currentXRotation = 0;
  193. /** 当前相机绕 Y 轴的旋转角度 */
  194. this.currentYRotation = 0;
  195. /** 左右旋转角度的最大限制值 */
  196. this.maxHorizontalAngle = 40;
  197. /** 上下旋转角度的最大限制值 */
  198. this.maxVerticalAngle = 40;
  199. /** 相机的原始视野值 */
  200. this.originalFov = void 0;
  201. /** 玩家节点的初始旋转四元数 */
  202. this.initialPlayerRotation = new Quat();
  203. /** 相机节点的初始旋转四元数 */
  204. this.initialCameraRotation = new Quat();
  205. /**相机旋转的灵敏度 值越大移动越快 灵敏度越高*/
  206. this.sensitivity = 0.5;
  207. /** 相机放大后的目标视野值 */
  208. this.targetFov = void 0;
  209. /** 标记相机是否正在进行放大操作 */
  210. this.isZoomingIn = false;
  211. /** 标记相机是否正在进行缩小操作 */
  212. this.isZoomingOut = false;
  213. /** 相机视野放大的速度 */
  214. this.zoomSpeed = 0;
  215. /** 期望的缩放时间,单位为秒 */
  216. this.zoomDuration = 0.2;
  217. /** 记录镜头开始放大的时间 */
  218. this.zoomStartTime = 0;
  219. /** 标记是否在2秒内完成放大 */
  220. this.zoomValid = false;
  221. /** 标记是否开镜 */
  222. this._isScopeOpen = false;
  223. /**镜头的位置*/
  224. this.wheelPos = Vec3.ZERO;
  225. //任务数据
  226. this.taskDatas = [];
  227. //是否正在被击中
  228. this.isHurtRun = false;
  229. }
  230. get isScopeOpen() {
  231. return this._isScopeOpen;
  232. }
  233. set isScopeOpen(value) {
  234. this.gunDataUI();
  235. if (this._isScopeOpen !== value) {
  236. this._isScopeOpen = value;
  237. if (value) {
  238. this.openScope();
  239. } else {
  240. this.closeScope();
  241. }
  242. }
  243. }
  244. start() {
  245. this.hasAnim = false;
  246. this.closeOnBlank = false;
  247. this.injury_blood.active = false;
  248. this.reloadProgressBar.node.active = false;
  249. if (!(_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  250. error: Error()
  251. }), Constants) : Constants).isDebug) {
  252. this.hiddeNodes.forEach(e => e.active = false);
  253. }
  254. this.wheelPos = this.wheel.position.clone(); //记录摄像机原始视野
  255. this.originalFov = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  256. error: Error()
  257. }), Game) : Game).I.camera.getComponent(Camera).fov; //录初始旋转角度
  258. this.initialPlayerRotation = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  259. error: Error()
  260. }), Game) : Game).I.player.node.rotation.clone();
  261. this.initialCameraRotation = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  262. error: Error()
  263. }), Game) : Game).I.camera.node.rotation.clone(); //监听当前节点触摸事件
  264. this.node.on(Node.EventType.TOUCH_START, this.onNodeTouchMove, this);
  265. this.node.on(Node.EventType.TOUCH_MOVE, this.onNodeTouchMove, this);
  266. this.node.on(Node.EventType.TOUCH_END, this.onCustomNodeTouchEnd, this);
  267. this.node.on(Node.EventType.TOUCH_CANCEL, this.onCustomNodeTouchEnd, this); //监听轮盘点击事件 监听轮盘的触摸开始事件,当触摸开始时调用 onWheelClick 方法
  268. this.wheel.on(Node.EventType.TOUCH_START, this.onWheelClick, this);
  269. this.wheel.on(Node.EventType.TOUCH_END, this.onWheelRelease, this);
  270. this.wheel.on(Node.EventType.TOUCH_CANCEL, this.onWheelRelease, this);
  271. }
  272. show() {
  273. this.loadTaskData();
  274. }
  275. /**
  276. * 加载数据
  277. */
  278. loadTaskData() {
  279. var data = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  280. error: Error()
  281. }), userIns) : userIns).getCurLevelData();
  282. if (!data) return;
  283. this.taskDatas = []; //拆分并处理每个敌人配置
  284. data.dispose.split('|').forEach(item => {
  285. var [enemyId, count] = item.split('_').map(Number);
  286. var enemyData = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  287. error: Error()
  288. }), Utils) : Utils).clone((_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  289. error: Error()
  290. }), userIns) : userIns).enemyTable).find(e => e.id === enemyId);
  291. enemyData.count = count;
  292. enemyData.killCount = 0;
  293. this.taskDatas.push(enemyData);
  294. });
  295. if (this.taskDatas.length <= 0) return;
  296. this.task_scrollView.numItems = this.taskDatas.length; //加载子弹的数据
  297. this.gunDataUI();
  298. }
  299. /**
  300. * 设置枪的数据
  301. */
  302. gunDataUI() {
  303. var gData = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  304. error: Error()
  305. }), Game) : Game).I.player.pData;
  306. if (!gData) return;
  307. this.crossHair.active = true; //准心
  308. if (gData.type == 2) {
  309. //步枪
  310. this.scopeOverlay.active = false; //标准贴图
  311. } else {
  312. this.scopeOverlay.active = true; //标准贴图
  313. }
  314. this.gun_name_label.string = gData.name_lang;
  315. var isSnipeGun = gData.type == 1; //换弹夹进度条
  316. var isMagazine = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  317. error: Error()
  318. }), Game) : Game).I.player.isReloadMagazine;
  319. if (isMagazine) {
  320. this.rifle_bullets_bg.active = false;
  321. this.snipe_bullets_scrollView.node.active = false;
  322. } else {
  323. //步枪子弹视图
  324. this.rifle_bullets_bg.active = !isSnipeGun; //狙击子弹视图列表
  325. this.snipe_bullets_scrollView.node.active = isSnipeGun;
  326. if (isSnipeGun) {
  327. this.snipe_bullets_scrollView.magazineNum = gData.magazine;
  328. } else {
  329. this.rifle_bullets_scrollView.magazineNum = gData.magazine; //子弹进度条
  330. var s_bullet = gData.magazine - (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  331. error: Error()
  332. }), Game) : Game).I.player.gun.shotBullets;
  333. this.rifle_bullet_progressBar.progress = s_bullet / gData.magazine;
  334. this.rifle_bullet_num_label.string = s_bullet + "/" + gData.magazine;
  335. }
  336. }
  337. }
  338. /**
  339. * 更换弹夹动画
  340. * @param time 换弹时间 单位秒
  341. * @param complete 完成回调
  342. */
  343. reloadMagazineing(time, complete) {
  344. if (time <= 0) {
  345. complete == null || complete();
  346. } else {
  347. this.reloadProgressBar.node.active = true;
  348. this.reloadProgressBar.progress = 1;
  349. this.rifle_bullets_bg.active = false;
  350. this.snipe_bullets_scrollView.node.active = false; //创建定时器动画
  351. tween(this.reloadProgressBar).to(time, {
  352. progress: 0
  353. }, {
  354. easing: easing.linear,
  355. onStart: () => {
  356. tween(this.reloadProgressBar).stop();
  357. },
  358. onComplete: () => {
  359. this.reloadProgressBar.node.active = false;
  360. complete == null || complete();
  361. }
  362. }).start();
  363. }
  364. }
  365. /**
  366. * 任务数据
  367. * @param item item节点
  368. * @param idx 数据下标
  369. */
  370. setTaskItemData(item, idx) {
  371. item.getComponent(_crd && TaskEnemyItem === void 0 ? (_reportPossibleCrUseOfTaskEnemyItem({
  372. error: Error()
  373. }), TaskEnemyItem) : TaskEnemyItem).init(this.taskDatas[idx]);
  374. }
  375. /**
  376. * 根据切换枪的stability设置镜头的稳定性
  377. */
  378. crossHairStability() {
  379. var gData = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  380. error: Error()
  381. }), Game) : Game).I.player.pData;
  382. if (!gData) return;
  383. this.gunDataUI();
  384. this.wheel.position = this.wheelPos; //参数映射优化(假设stability范围0-1) 振幅稳定性越低振幅越大 频率稳定性越低抖动越快
  385. var amplitude = 20 * (1 - gData.stability / 1000);
  386. var elapsed = 0; //基础抖动持续时间
  387. var duration = 0.4;
  388. var updateShake = deltaTime => {
  389. elapsed += deltaTime; //双轴随机偏移
  390. var offsetX = amplitude * (Math.random() - 0.5) * Math.max(1 - elapsed / duration, 0);
  391. var offsetY = amplitude * (Math.random() - 0.5) * Math.max(1 - elapsed / duration, 0);
  392. this.wheel.position = new Vec3(this.wheelPos.x + offsetX, this.wheelPos.y + offsetY, this.wheelPos.z); //自动结束
  393. if (elapsed >= duration) {
  394. this.wheel.position = this.wheelPos;
  395. this.unschedule(updateShake);
  396. }
  397. };
  398. this.unschedule(updateShake); // 使用游戏时间而非系统时间
  399. this.schedule(updateShake, 0.02); // 每0.02秒更新(约50FPS)
  400. }
  401. /**
  402. * 屏幕触摸事件
  403. * 触摸移动时,根据触摸的位置计算旋转角度,并应用到节点上
  404. * @param event
  405. */
  406. onNodeTouchMove(event) {
  407. var delta = event.getDelta(); //计算旋转角度
  408. this.currentYRotation -= delta.x * this.sensitivity;
  409. this.currentXRotation -= delta.y * this.sensitivity; //分别限制左右和上下旋转角度
  410. this.currentYRotation = clamp(this.currentYRotation, -this.maxHorizontalAngle, this.maxHorizontalAngle);
  411. this.currentXRotation = clamp(this.currentXRotation, -this.maxVerticalAngle, this.maxVerticalAngle); //计算水平和垂直旋转的四元数
  412. var yQuat = new Quat();
  413. Quat.fromEuler(yQuat, 0, this.currentYRotation, 0);
  414. var xQuat = new Quat();
  415. Quat.fromEuler(xQuat, +this.currentXRotation, 0, 0); //合并旋转
  416. var finalQuat = new Quat();
  417. Quat.multiply(finalQuat, yQuat, xQuat); //将最终旋转与初始摄像机旋转合并
  418. Quat.multiply(finalQuat, this.initialPlayerRotation, finalQuat); //应用旋转到摄像机
  419. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  420. error: Error()
  421. }), Game) : Game).I.player.node.rotation = finalQuat;
  422. }
  423. /**
  424. * 触摸结束
  425. * 触摸结束时 触摸结束处理方法
  426. */
  427. onCustomNodeTouchEnd() {//触摸结束,可添加其他逻辑
  428. }
  429. /**
  430. * 开始慢慢放大视野
  431. */
  432. onWheelClick() {
  433. this.isScopeOpen = true;
  434. }
  435. /**
  436. * 恢复原始视野
  437. */
  438. onWheelRelease() {
  439. if (!this.zoomValid) {
  440. this.isScopeOpen = false;
  441. return;
  442. }
  443. this.scheduleOnce(() => {
  444. //检查是否在秒内完成放大 已经在update里开镜完成时调用 Game.I.player.shoot();
  445. this.isScopeOpen = false;
  446. }, 0.2);
  447. }
  448. /**
  449. * 开始开镜
  450. */
  451. openScope() {
  452. //从枪械数据获取参数
  453. var gData = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  454. error: Error()
  455. }), Game) : Game).I.player.pData;
  456. if (!gData) return;
  457. var isRifle = this.isRifleGun(); //是步枪直接连续开火
  458. if (isRifle) {
  459. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  460. error: Error()
  461. }), Game) : Game).I.player.shoot();
  462. }
  463. this.isZoomingIn = true; //将 zoomingSpeed 转换为持续时间(450对应1.2秒)
  464. this.zoomDuration = 72 / gData.zoomingSpeed; //使用枪械类型决定视口倍数
  465. var zoomMultiplier = isRifle ? 1 / gData.rifleZoom : // 步枪使用 rifleZoom
  466. 1 / gData.scopeZoom; // 狙击枪使用 scopeZoom
  467. this.targetFov = this.originalFov * zoomMultiplier; //保持原有速度计算逻辑
  468. var fovDifference = this.originalFov - this.targetFov;
  469. this.zoomSpeed = fovDifference / this.zoomDuration;
  470. this.zoomStartTime = sys.now();
  471. } // 在 closeScope 方法中保持相同持续时间
  472. closeScope() {
  473. this.isZoomingIn = false;
  474. this.isZoomingOut = true;
  475. var fovDifference = this.originalFov - this.targetFov; //使用相同 zoomDuration 保证缩镜速度一致
  476. this.zoomSpeed = fovDifference / this.zoomDuration;
  477. }
  478. /**
  479. * 是否是步枪
  480. */
  481. isRifleGun() {
  482. var gData = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  483. error: Error()
  484. }), Game) : Game).I.player.pData;
  485. if (!gData) return false;
  486. return gData.id == '100014' || gData.id == '100015';
  487. }
  488. /**
  489. * 计算从枪口出发,沿准心射线方向的点
  490. * @param isBulletEndPos 是否获得子弹的终点
  491. */
  492. getCrossHairPos() {
  493. //获取屏幕准心位置(世界坐标)
  494. var worldPos = this.crossHair.worldPosition.clone();
  495. var camera2D = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  496. error: Error()
  497. }), Game) : Game).I.canvas.getChildByName('Camera2D').getComponent(Camera);
  498. var screenPos = camera2D.worldToScreen(worldPos); //校准补偿准心的偏移量
  499. screenPos.x -= 0;
  500. screenPos.y += 20; //从摄像机发射通过准心的射线
  501. var ray = new geometry.Ray();
  502. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  503. error: Error()
  504. }), Game) : Game).I.camera.screenPointToRay(screenPos.x, screenPos.y, ray); //获取枪口位置
  505. var muzzlePos = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  506. error: Error()
  507. }), Game) : Game).I.player.gun.muzzleNode.worldPosition;
  508. return new Vec3(muzzlePos.x + ray.d.x * this.bulletDistance, muzzlePos.y + ray.d.y * this.bulletDistance, muzzlePos.z + ray.d.z * this.bulletDistance);
  509. }
  510. /**
  511. * 玩家血量低于30%一直闪烁、打一枪的时候闪一下
  512. * @param progress 血量进度
  513. * @returns
  514. */
  515. playerHurtTwinkle(progress) {
  516. this.hpProgressBar.progress = progress;
  517. var isRepeat = progress <= 0.3;
  518. if (this.isHurtRun) return;
  519. this.isHurtRun = true;
  520. this.injury_blood.active = true; //audioMgr.play(Constants.audios.pop_up_sound);
  521. Tween.stopAllByTarget(this.injury_blood);
  522. var op = this.injury_blood.getComponent(UIOpacity);
  523. op.opacity = 255;
  524. tween(op).to(0.2, {
  525. opacity: 0
  526. }).call(() => {
  527. this.isHurtRun = false;
  528. this.injury_blood.active = false;
  529. }).repeat(isRepeat ? 100000 : 1).start();
  530. }
  531. /**
  532. * 点击事件
  533. * @param event 事件
  534. * @param customEventData 数据
  535. */
  536. onBtnClicked(event, customEventData) {
  537. super.onBtnClicked(event, customEventData);
  538. var btnName = event.target.name;
  539. if (btnName === 'pause_btn') {
  540. // 暂停页面
  541. (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  542. error: Error()
  543. }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  544. error: Error()
  545. }), Constants) : Constants).popUIs.pauseUI);
  546. } else if (btnName === 'shot_btn') {
  547. //射击
  548. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  549. error: Error()
  550. }), Game) : Game).I.player.shoot();
  551. } else if (btnName === 'cut_gun_btn') {
  552. //切枪
  553. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  554. error: Error()
  555. }), Game) : Game).I.player.randomCutGun();
  556. } else if (btnName === 'clean_btn') {
  557. //重新加载数据
  558. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  559. error: Error()
  560. }), userIns) : userIns).removeData();
  561. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  562. error: Error()
  563. }), Game) : Game).I.player.pData = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  564. error: Error()
  565. }), userIns) : userIns).getCurUseGun();
  566. (_crd && MsgHints === void 0 ? (_reportPossibleCrUseOfMsgHints({
  567. error: Error()
  568. }), MsgHints) : MsgHints).show('重新加载数据完成');
  569. } else if (btnName === 'adds_btn') {
  570. //解锁全部枪数据
  571. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  572. error: Error()
  573. }), userIns) : userIns).unlockAllGuns();
  574. (_crd && MsgHints === void 0 ? (_reportPossibleCrUseOfMsgHints({
  575. error: Error()
  576. }), MsgHints) : MsgHints).show('已经解锁全部枪数据');
  577. }
  578. }
  579. /**
  580. * 每帧更新,处理视野渐变和检查 2 秒时间限制
  581. * @param deltaTime - 上一帧到当前帧的时间间隔
  582. */
  583. update(deltaTime) {
  584. if (this.isZoomingIn) {
  585. var currentFov = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  586. error: Error()
  587. }), Game) : Game).I.camera.fov;
  588. if (currentFov > this.targetFov) {
  589. var newFov = currentFov - this.zoomSpeed * deltaTime;
  590. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  591. error: Error()
  592. }), Game) : Game).I.camera.fov = Math.max(newFov, this.targetFov);
  593. } else {
  594. //检查是否在2秒内完成放大
  595. var elapsedTime = (sys.now() - this.zoomStartTime) / 1000;
  596. if (elapsedTime <= 1.5) {
  597. this.zoomValid = true;
  598. }
  599. this.isZoomingIn = false;
  600. }
  601. } else if (this.isZoomingOut) {
  602. var _currentFov = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  603. error: Error()
  604. }), Game) : Game).I.camera.fov;
  605. if (_currentFov < this.originalFov) {
  606. var _newFov = _currentFov + this.zoomSpeed * deltaTime;
  607. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  608. error: Error()
  609. }), Game) : Game).I.camera.fov = Math.min(_newFov, this.originalFov);
  610. } else {
  611. this.isZoomingOut = false;
  612. this.zoomValid = false; //非步枪开镜结束开火
  613. if (!this.isRifleGun()) {
  614. (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  615. error: Error()
  616. }), Game) : Game).I.player.shoot();
  617. }
  618. }
  619. }
  620. }
  621. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "wheel", [_dec2], {
  622. configurable: true,
  623. enumerable: true,
  624. writable: true,
  625. initializer: null
  626. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "scopeOverlay", [_dec3], {
  627. configurable: true,
  628. enumerable: true,
  629. writable: true,
  630. initializer: null
  631. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "crossHair", [_dec4], {
  632. configurable: true,
  633. enumerable: true,
  634. writable: true,
  635. initializer: null
  636. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "rifle_bullet_progressBar", [_dec5], {
  637. configurable: true,
  638. enumerable: true,
  639. writable: true,
  640. initializer: null
  641. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "rifle_bullet_num_label", [_dec6], {
  642. configurable: true,
  643. enumerable: true,
  644. writable: true,
  645. initializer: null
  646. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "rifle_bullets_scrollView", [_dec7], {
  647. configurable: true,
  648. enumerable: true,
  649. writable: true,
  650. initializer: null
  651. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "snipe_bullets_scrollView", [_dec8], {
  652. configurable: true,
  653. enumerable: true,
  654. writable: true,
  655. initializer: null
  656. }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "rifle_bullets_bg", [_dec9], {
  657. configurable: true,
  658. enumerable: true,
  659. writable: true,
  660. initializer: null
  661. }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "task_scrollView", [_dec10], {
  662. configurable: true,
  663. enumerable: true,
  664. writable: true,
  665. initializer: null
  666. }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "hpProgressBar", [_dec11], {
  667. configurable: true,
  668. enumerable: true,
  669. writable: true,
  670. initializer: null
  671. }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "hiddeNodes", [_dec12], {
  672. configurable: true,
  673. enumerable: true,
  674. writable: true,
  675. initializer: function initializer() {
  676. return [];
  677. }
  678. }), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "reloadProgressBar", [_dec13], {
  679. configurable: true,
  680. enumerable: true,
  681. writable: true,
  682. initializer: null
  683. }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "injury_blood", [_dec14], {
  684. configurable: true,
  685. enumerable: true,
  686. writable: true,
  687. initializer: null
  688. }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "gun_name_label", [_dec15], {
  689. configurable: true,
  690. enumerable: true,
  691. writable: true,
  692. initializer: null
  693. })), _class2)) || _class));
  694. _cclegacy._RF.pop();
  695. _crd = false;
  696. }
  697. };
  698. });
  699. //# sourceMappingURL=4939d0aafb7a933a612fcaa12691e0b0a210a5ff.js.map