3bd48f79623dfcb34002b66c9435221cfa7d6f59.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Label, Vec3, UITransform, Prefab, tween, BaseExp, autoBind, Constants, stateMgr, userIns, ITEM_TYPE, ResUtil, PoolManager, bundleMgr, Utils, uiMgr, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _crd, ccclass, property, TossBoomerangUI;
  4. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  5. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  6. 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 }); }
  7. 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; }
  8. 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.'); }
  9. function _reportPossibleCrUseOfBaseExp(extras) {
  10. _reporterNs.report("BaseExp", "../core/base/BaseExp", _context.meta, extras);
  11. }
  12. function _reportPossibleCrUseOfautoBind(extras) {
  13. _reporterNs.report("autoBind", "../extend/AutoBind", _context.meta, extras);
  14. }
  15. function _reportPossibleCrUseOfConstants(extras) {
  16. _reporterNs.report("Constants", "../data/Constants", _context.meta, extras);
  17. }
  18. function _reportPossibleCrUseOfstateMgr(extras) {
  19. _reporterNs.report("stateMgr", "../core/manager/StateManager", _context.meta, extras);
  20. }
  21. function _reportPossibleCrUseOfuserIns(extras) {
  22. _reporterNs.report("userIns", "../data/UserData", _context.meta, extras);
  23. }
  24. function _reportPossibleCrUseOfITEM_TYPE(extras) {
  25. _reporterNs.report("ITEM_TYPE", "../utils/ResUtil", _context.meta, extras);
  26. }
  27. function _reportPossibleCrUseOfResUtil(extras) {
  28. _reporterNs.report("ResUtil", "../utils/ResUtil", _context.meta, extras);
  29. }
  30. function _reportPossibleCrUseOfPoolManager(extras) {
  31. _reporterNs.report("PoolManager", "../core/manager/PoolManager", _context.meta, extras);
  32. }
  33. function _reportPossibleCrUseOfbundleMgr(extras) {
  34. _reporterNs.report("bundleMgr", "../core/manager/BundleManager", _context.meta, extras);
  35. }
  36. function _reportPossibleCrUseOfUtils(extras) {
  37. _reporterNs.report("Utils", "../utils/Utils", _context.meta, extras);
  38. }
  39. function _reportPossibleCrUseOfuiMgr(extras) {
  40. _reporterNs.report("uiMgr", "../core/manager/UIManager", _context.meta, extras);
  41. }
  42. return {
  43. setters: [function (_unresolved_) {
  44. _reporterNs = _unresolved_;
  45. }, function (_cc) {
  46. _cclegacy = _cc.cclegacy;
  47. __checkObsolete__ = _cc.__checkObsolete__;
  48. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  49. _decorator = _cc._decorator;
  50. Node = _cc.Node;
  51. Label = _cc.Label;
  52. Vec3 = _cc.Vec3;
  53. UITransform = _cc.UITransform;
  54. Prefab = _cc.Prefab;
  55. tween = _cc.tween;
  56. }, function (_unresolved_2) {
  57. BaseExp = _unresolved_2.BaseExp;
  58. }, function (_unresolved_3) {
  59. autoBind = _unresolved_3.autoBind;
  60. }, function (_unresolved_4) {
  61. Constants = _unresolved_4.Constants;
  62. }, function (_unresolved_5) {
  63. stateMgr = _unresolved_5.stateMgr;
  64. }, function (_unresolved_6) {
  65. userIns = _unresolved_6.userIns;
  66. }, function (_unresolved_7) {
  67. ITEM_TYPE = _unresolved_7.ITEM_TYPE;
  68. ResUtil = _unresolved_7.ResUtil;
  69. }, function (_unresolved_8) {
  70. PoolManager = _unresolved_8.PoolManager;
  71. }, function (_unresolved_9) {
  72. bundleMgr = _unresolved_9.bundleMgr;
  73. }, function (_unresolved_10) {
  74. Utils = _unresolved_10.Utils;
  75. }, function (_unresolved_11) {
  76. uiMgr = _unresolved_11.uiMgr;
  77. }],
  78. execute: function () {
  79. _crd = true;
  80. _cclegacy._RF.push({}, "27272ucZTlL27Dpvfou+OTG", "TossBoomerangUI", undefined);
  81. __checkObsolete__(['_decorator', 'Node', 'Label', 'EventTouch', 'Vec3', 'UITransform', 'Prefab', 'Size', 'tween', 'easing']);
  82. ({
  83. ccclass,
  84. property
  85. } = _decorator); //扔飞镖
  86. _export("TossBoomerangUI", TossBoomerangUI = (_dec = ccclass('TossBoomerangUI'), _dec2 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  87. error: Error()
  88. }), autoBind) : autoBind)({
  89. type: Node,
  90. tooltip: "靶面"
  91. }), _dec3 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  92. error: Error()
  93. }), autoBind) : autoBind)({
  94. type: Node,
  95. tooltip: "飞镖按钮"
  96. }), _dec4 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  97. error: Error()
  98. }), autoBind) : autoBind)({
  99. type: Label,
  100. tooltip: "金币文本"
  101. }), _dec5 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  102. error: Error()
  103. }), autoBind) : autoBind)({
  104. type: Label,
  105. tooltip: "钻石文本"
  106. }), _dec6 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
  107. error: Error()
  108. }), autoBind) : autoBind)({
  109. type: Label,
  110. tooltip: "飞镖个数文本"
  111. }), _dec(_class = (_class2 = class TossBoomerangUI extends (_crd && BaseExp === void 0 ? (_reportPossibleCrUseOfBaseExp({
  112. error: Error()
  113. }), BaseExp) : BaseExp) {
  114. constructor() {
  115. super(...arguments);
  116. _initializerDefineProperty(this, "target_plate", _descriptor, this);
  117. _initializerDefineProperty(this, "shoot_btn", _descriptor2, this);
  118. _initializerDefineProperty(this, "gold_lable", _descriptor3, this);
  119. _initializerDefineProperty(this, "diamond_lable", _descriptor4, this);
  120. _initializerDefineProperty(this, "boomerang_num_lable", _descriptor5, this);
  121. //是否正在扔飞镖
  122. this.isBoomeranging = false;
  123. }
  124. start() {
  125. this.hasAnim = false;
  126. this.closeOnBlank = false; //注册动态变化值
  127. (_crd && stateMgr === void 0 ? (_reportPossibleCrUseOfstateMgr({
  128. error: Error()
  129. }), stateMgr) : stateMgr).registerUI((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  130. error: Error()
  131. }), Constants) : Constants).gold, this.gold_lable);
  132. (_crd && stateMgr === void 0 ? (_reportPossibleCrUseOfstateMgr({
  133. error: Error()
  134. }), stateMgr) : stateMgr).registerUI((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  135. error: Error()
  136. }), Constants) : Constants).diamond, this.diamond_lable);
  137. }
  138. show() {
  139. this.setBoomerang();
  140. }
  141. /**
  142. * 设置飞镖个数
  143. */
  144. setBoomerang() {
  145. if ((_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  146. error: Error()
  147. }), userIns) : userIns).data.boomerang > 0) {
  148. this.boomerang_num_lable.string = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  149. error: Error()
  150. }), userIns) : userIns).data.boomerang;
  151. } else {
  152. this.boomerang_num_lable.string = "Buy";
  153. }
  154. }
  155. /**
  156. * 购买飞镖
  157. */
  158. buyBoomerang() {
  159. (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  160. error: Error()
  161. }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  162. error: Error()
  163. }), Constants) : Constants).popUIs.buyBoomerangUI);
  164. }
  165. /**
  166. * 扔飞镖数据
  167. */
  168. startToss() {
  169. var _this = this;
  170. return _asyncToGenerator(function* () {
  171. var _this$target_plate$ge;
  172. if (_this.isBoomeranging) return;
  173. if ((_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  174. error: Error()
  175. }), userIns) : userIns).data.boomerang <= 0) {
  176. _this.buyBoomerang();
  177. return;
  178. }
  179. _this.isBoomeranging = true;
  180. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  181. error: Error()
  182. }), userIns) : userIns).data.boomerang -= 1;
  183. _this.setBoomerang(); //总的权重
  184. var totalWeight = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  185. error: Error()
  186. }), userIns) : userIns).boomerangTable.reduce((sum, item) => sum + item.weight, 0); //生成随机数(包含安全容错)
  187. var random = Math.min(Math.random() * totalWeight, totalWeight - 1e-6);
  188. var accumulatedWeight = 0;
  189. var selectedItem = null; //遍历查找命中的条目
  190. for (var item of (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  191. error: Error()
  192. }), userIns) : userIns).boomerangTable) {
  193. if (random < accumulatedWeight + item.weight) {
  194. selectedItem = item;
  195. break;
  196. }
  197. accumulatedWeight += item.weight;
  198. }
  199. if (!selectedItem) {
  200. selectedItem = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  201. error: Error()
  202. }), userIns) : userIns).boomerangTable[0];
  203. } //加载飞镖预制体
  204. var ret = yield (_crd && bundleMgr === void 0 ? (_reportPossibleCrUseOfbundleMgr({
  205. error: Error()
  206. }), bundleMgr) : bundleMgr).loadAsset((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  207. error: Error()
  208. }), Constants) : Constants).bundleName.prefabs, "items/tossBoomerang", Prefab);
  209. var boomerang = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  210. error: Error()
  211. }), PoolManager) : PoolManager).getNode(ret, _this.target_plate.parent); //获取靶面尺寸(假设靶面锚点在中心)
  212. var targetSize = (_this$target_plate$ge = _this.target_plate.getComponent(UITransform)) == null ? void 0 : _this$target_plate$ge.contentSize; //生成随机角度(0-360度)
  213. var angle = Math.random() * Math.PI * 2; //根据权重计算偏移比例(权重越大,offsetRatio越小) 获取靶面中心的世界坐标
  214. var targetWorldPos = _this.target_plate.parent.getComponent(UITransform).convertToWorldSpaceAR(_this.target_plate.position); //转换为父节点坐标系下的坐标
  215. var targetCenter = _this.target_plate.parent.getComponent(UITransform).convertToNodeSpaceAR(targetWorldPos); //生成基于靶心坐标的随机偏移(权重越大越靠近中心)平方曲线增强中心聚集 缩小最大偏移范围
  216. var maxRadius = targetSize.width * 0.2;
  217. var offsetRatio = Math.pow(1 - selectedItem.weight / totalWeight, 2); //最终落点计算(以靶心为基准)
  218. var targetPos = new Vec3(targetCenter.x + Math.cos(angle) * maxRadius * offsetRatio, targetCenter.y + Math.sin(angle) * maxRadius * offsetRatio, 0);
  219. var targetUITransform = _this.target_plate.getComponent(UITransform);
  220. var radius = targetUITransform.contentSize.width / 2.0 * 1.5; // 半径取宽度的一半
  221. var randomAngle = Math.random() * Math.PI * 2; // 生成0-360度的随机角度
  222. //新起始点计算(靶面中心 + 半径 * 随机角度)
  223. var startPos = new Vec3(_this.target_plate.position.x + radius * Math.cos(randomAngle), _this.target_plate.position.y + radius * Math.sin(randomAngle), 0); //飞镖初始位置(从屏幕下方飞出)
  224. //let startPos: Vec3 = Utils.convertPosition(this.shoot_btn,this.target_plate.parent);
  225. boomerang.position = startPos.clone();
  226. var middePos = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  227. error: Error()
  228. }), Utils) : Utils).randomUIPointGenerator(_this.target_plate, startPos, 200);
  229. var pos = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  230. error: Error()
  231. }), Utils) : Utils).calculateParabolaCenter(startPos, targetPos);
  232. var controlPoint = new Vec3(middePos.x + pos.x, middePos.y, middePos.z); //贝塞尔轨迹计算
  233. var calculateTrajectory = (t, p0, p1, p2) => {
  234. var u = 1 - t;
  235. return new Vec3(u * u * p0.x + 2 * u * t * p1.x + t * t * p2.x, u * u * p0.y + 2 * u * t * p1.y + t * t * p2.y, 0);
  236. };
  237. tween(boomerang).to(0.4, {}, {
  238. onUpdate: (_, ratio) => {
  239. //计算当前帧位置
  240. var currentPos = calculateTrajectory(ratio, startPos, controlPoint, targetPos); //更新位置和旋转
  241. boomerang.position = currentPos;
  242. boomerang.angle = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
  243. error: Error()
  244. }), Utils) : Utils).getAngle(currentPos, targetPos) - 90;
  245. },
  246. onComplete: () => {
  247. if (boomerang.parent) {
  248. setTimeout(() => {
  249. (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
  250. error: Error()
  251. }), PoolManager) : PoolManager).putNode(boomerang);
  252. _this.handleReward(selectedItem);
  253. _this.isBoomeranging = false;
  254. }, 0.2);
  255. }
  256. }
  257. }).start();
  258. })();
  259. }
  260. /**
  261. * 奖励处理方法
  262. * @param item
  263. */
  264. handleReward(item) {
  265. var [type, amount] = item.quantity.split('_');
  266. switch (type) {
  267. case '1001':
  268. {
  269. //金币
  270. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  271. error: Error()
  272. }), userIns) : userIns).data.gold += parseInt(amount);
  273. (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  274. error: Error()
  275. }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  276. error: Error()
  277. }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {
  278. (_crd && ResUtil === void 0 ? (_reportPossibleCrUseOfResUtil({
  279. error: Error()
  280. }), ResUtil) : ResUtil).flyAnim((_crd && ITEM_TYPE === void 0 ? (_reportPossibleCrUseOfITEM_TYPE({
  281. error: Error()
  282. }), ITEM_TYPE) : ITEM_TYPE).Coin, this.shoot_btn, this.gold_lable.node, 5, 50, b => {});
  283. }]);
  284. }
  285. break;
  286. case '1002':
  287. {
  288. //钻石
  289. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  290. error: Error()
  291. }), userIns) : userIns).data.diamond += parseInt(amount);
  292. (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  293. error: Error()
  294. }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  295. error: Error()
  296. }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {
  297. (_crd && ResUtil === void 0 ? (_reportPossibleCrUseOfResUtil({
  298. error: Error()
  299. }), ResUtil) : ResUtil).flyAnim((_crd && ITEM_TYPE === void 0 ? (_reportPossibleCrUseOfITEM_TYPE({
  300. error: Error()
  301. }), ITEM_TYPE) : ITEM_TYPE).Diamond, this.shoot_btn, this.diamond_lable.node, 5, 50, b => {});
  302. }]);
  303. }
  304. break;
  305. default:
  306. {
  307. //武器解锁 获得显示武器栏
  308. var [gun_id, num] = item.quantity.split('_');
  309. (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
  310. error: Error()
  311. }), userIns) : userIns).unlockGun(gun_id);
  312. (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
  313. error: Error()
  314. }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
  315. error: Error()
  316. }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {}]);
  317. }
  318. break;
  319. }
  320. }
  321. /**
  322. * 按钮点击事件
  323. * @param event 事件
  324. * @param param 参数
  325. */
  326. onBtnClicked(event, param) {
  327. super.onBtnClicked(event, param);
  328. var btnName = event.target.name;
  329. if (btnName === 'shoot_btn') {
  330. //扔飞镖的操作
  331. this.startToss();
  332. }
  333. }
  334. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "target_plate", [_dec2], {
  335. configurable: true,
  336. enumerable: true,
  337. writable: true,
  338. initializer: null
  339. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "shoot_btn", [_dec3], {
  340. configurable: true,
  341. enumerable: true,
  342. writable: true,
  343. initializer: null
  344. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "gold_lable", [_dec4], {
  345. configurable: true,
  346. enumerable: true,
  347. writable: true,
  348. initializer: null
  349. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "diamond_lable", [_dec5], {
  350. configurable: true,
  351. enumerable: true,
  352. writable: true,
  353. initializer: null
  354. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "boomerang_num_lable", [_dec6], {
  355. configurable: true,
  356. enumerable: true,
  357. writable: true,
  358. initializer: null
  359. })), _class2)) || _class));
  360. _cclegacy._RF.pop();
  361. _crd = false;
  362. }
  363. };
  364. });
  365. //# sourceMappingURL=3bd48f79623dfcb34002b66c9435221cfa7d6f59.js.map