123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- 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) {
- "use strict";
- 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;
- 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); } }
- 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); }); }; }
- 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 }); }
- 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; }
- 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.'); }
- function _reportPossibleCrUseOfBaseExp(extras) {
- _reporterNs.report("BaseExp", "../core/base/BaseExp", _context.meta, extras);
- }
- function _reportPossibleCrUseOfautoBind(extras) {
- _reporterNs.report("autoBind", "../extend/AutoBind", _context.meta, extras);
- }
- function _reportPossibleCrUseOfConstants(extras) {
- _reporterNs.report("Constants", "../data/Constants", _context.meta, extras);
- }
- function _reportPossibleCrUseOfstateMgr(extras) {
- _reporterNs.report("stateMgr", "../core/manager/StateManager", _context.meta, extras);
- }
- function _reportPossibleCrUseOfuserIns(extras) {
- _reporterNs.report("userIns", "../data/UserData", _context.meta, extras);
- }
- function _reportPossibleCrUseOfITEM_TYPE(extras) {
- _reporterNs.report("ITEM_TYPE", "../utils/ResUtil", _context.meta, extras);
- }
- function _reportPossibleCrUseOfResUtil(extras) {
- _reporterNs.report("ResUtil", "../utils/ResUtil", _context.meta, extras);
- }
- function _reportPossibleCrUseOfPoolManager(extras) {
- _reporterNs.report("PoolManager", "../core/manager/PoolManager", _context.meta, extras);
- }
- function _reportPossibleCrUseOfbundleMgr(extras) {
- _reporterNs.report("bundleMgr", "../core/manager/BundleManager", _context.meta, extras);
- }
- function _reportPossibleCrUseOfUtils(extras) {
- _reporterNs.report("Utils", "../utils/Utils", _context.meta, extras);
- }
- function _reportPossibleCrUseOfuiMgr(extras) {
- _reporterNs.report("uiMgr", "../core/manager/UIManager", _context.meta, extras);
- }
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Node = _cc.Node;
- Label = _cc.Label;
- Vec3 = _cc.Vec3;
- UITransform = _cc.UITransform;
- Prefab = _cc.Prefab;
- tween = _cc.tween;
- }, function (_unresolved_2) {
- BaseExp = _unresolved_2.BaseExp;
- }, function (_unresolved_3) {
- autoBind = _unresolved_3.autoBind;
- }, function (_unresolved_4) {
- Constants = _unresolved_4.Constants;
- }, function (_unresolved_5) {
- stateMgr = _unresolved_5.stateMgr;
- }, function (_unresolved_6) {
- userIns = _unresolved_6.userIns;
- }, function (_unresolved_7) {
- ITEM_TYPE = _unresolved_7.ITEM_TYPE;
- ResUtil = _unresolved_7.ResUtil;
- }, function (_unresolved_8) {
- PoolManager = _unresolved_8.PoolManager;
- }, function (_unresolved_9) {
- bundleMgr = _unresolved_9.bundleMgr;
- }, function (_unresolved_10) {
- Utils = _unresolved_10.Utils;
- }, function (_unresolved_11) {
- uiMgr = _unresolved_11.uiMgr;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "27272ucZTlL27Dpvfou+OTG", "TossBoomerangUI", undefined);
- __checkObsolete__(['_decorator', 'Node', 'Label', 'EventTouch', 'Vec3', 'UITransform', 'Prefab', 'Size', 'tween', 'easing']);
- ({
- ccclass,
- property
- } = _decorator); //扔飞镖
- _export("TossBoomerangUI", TossBoomerangUI = (_dec = ccclass('TossBoomerangUI'), _dec2 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
- error: Error()
- }), autoBind) : autoBind)({
- type: Node,
- tooltip: "靶面"
- }), _dec3 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
- error: Error()
- }), autoBind) : autoBind)({
- type: Node,
- tooltip: "飞镖按钮"
- }), _dec4 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
- error: Error()
- }), autoBind) : autoBind)({
- type: Label,
- tooltip: "金币文本"
- }), _dec5 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
- error: Error()
- }), autoBind) : autoBind)({
- type: Label,
- tooltip: "钻石文本"
- }), _dec6 = (_crd && autoBind === void 0 ? (_reportPossibleCrUseOfautoBind({
- error: Error()
- }), autoBind) : autoBind)({
- type: Label,
- tooltip: "飞镖个数文本"
- }), _dec(_class = (_class2 = class TossBoomerangUI extends (_crd && BaseExp === void 0 ? (_reportPossibleCrUseOfBaseExp({
- error: Error()
- }), BaseExp) : BaseExp) {
- constructor() {
- super(...arguments);
- _initializerDefineProperty(this, "target_plate", _descriptor, this);
- _initializerDefineProperty(this, "shoot_btn", _descriptor2, this);
- _initializerDefineProperty(this, "gold_lable", _descriptor3, this);
- _initializerDefineProperty(this, "diamond_lable", _descriptor4, this);
- _initializerDefineProperty(this, "boomerang_num_lable", _descriptor5, this);
- //是否正在扔飞镖
- this.isBoomeranging = false;
- }
- start() {
- this.hasAnim = false;
- this.closeOnBlank = false; //注册动态变化值
- (_crd && stateMgr === void 0 ? (_reportPossibleCrUseOfstateMgr({
- error: Error()
- }), stateMgr) : stateMgr).registerUI((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).gold, this.gold_lable);
- (_crd && stateMgr === void 0 ? (_reportPossibleCrUseOfstateMgr({
- error: Error()
- }), stateMgr) : stateMgr).registerUI((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).diamond, this.diamond_lable);
- }
- show() {
- this.setBoomerang();
- }
- /**
- * 设置飞镖个数
- */
- setBoomerang() {
- if ((_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.boomerang > 0) {
- this.boomerang_num_lable.string = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.boomerang;
- } else {
- this.boomerang_num_lable.string = "Buy";
- }
- }
- /**
- * 购买飞镖
- */
- buyBoomerang() {
- (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
- error: Error()
- }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).popUIs.buyBoomerangUI);
- }
- /**
- * 扔飞镖数据
- */
- startToss() {
- var _this = this;
- return _asyncToGenerator(function* () {
- var _this$target_plate$ge;
- if (_this.isBoomeranging) return;
- if ((_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.boomerang <= 0) {
- _this.buyBoomerang();
- return;
- }
- _this.isBoomeranging = true;
- (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.boomerang -= 1;
- _this.setBoomerang(); //总的权重
- var totalWeight = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).boomerangTable.reduce((sum, item) => sum + item.weight, 0); //生成随机数(包含安全容错)
- var random = Math.min(Math.random() * totalWeight, totalWeight - 1e-6);
- var accumulatedWeight = 0;
- var selectedItem = null; //遍历查找命中的条目
- for (var item of (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).boomerangTable) {
- if (random < accumulatedWeight + item.weight) {
- selectedItem = item;
- break;
- }
- accumulatedWeight += item.weight;
- }
- if (!selectedItem) {
- selectedItem = (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).boomerangTable[0];
- } //加载飞镖预制体
- var ret = yield (_crd && bundleMgr === void 0 ? (_reportPossibleCrUseOfbundleMgr({
- error: Error()
- }), bundleMgr) : bundleMgr).loadAsset((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).bundleName.prefabs, "items/tossBoomerang", Prefab);
- var boomerang = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(ret, _this.target_plate.parent); //获取靶面尺寸(假设靶面锚点在中心)
- var targetSize = (_this$target_plate$ge = _this.target_plate.getComponent(UITransform)) == null ? void 0 : _this$target_plate$ge.contentSize; //生成随机角度(0-360度)
- var angle = Math.random() * Math.PI * 2; //根据权重计算偏移比例(权重越大,offsetRatio越小) 获取靶面中心的世界坐标
- var targetWorldPos = _this.target_plate.parent.getComponent(UITransform).convertToWorldSpaceAR(_this.target_plate.position); //转换为父节点坐标系下的坐标
- var targetCenter = _this.target_plate.parent.getComponent(UITransform).convertToNodeSpaceAR(targetWorldPos); //生成基于靶心坐标的随机偏移(权重越大越靠近中心)平方曲线增强中心聚集 缩小最大偏移范围
- var maxRadius = targetSize.width * 0.2;
- var offsetRatio = Math.pow(1 - selectedItem.weight / totalWeight, 2); //最终落点计算(以靶心为基准)
- var targetPos = new Vec3(targetCenter.x + Math.cos(angle) * maxRadius * offsetRatio, targetCenter.y + Math.sin(angle) * maxRadius * offsetRatio, 0);
- var targetUITransform = _this.target_plate.getComponent(UITransform);
- var radius = targetUITransform.contentSize.width / 2.0 * 1.5; // 半径取宽度的一半
- var randomAngle = Math.random() * Math.PI * 2; // 生成0-360度的随机角度
- //新起始点计算(靶面中心 + 半径 * 随机角度)
- var startPos = new Vec3(_this.target_plate.position.x + radius * Math.cos(randomAngle), _this.target_plate.position.y + radius * Math.sin(randomAngle), 0); //飞镖初始位置(从屏幕下方飞出)
- //let startPos: Vec3 = Utils.convertPosition(this.shoot_btn,this.target_plate.parent);
- boomerang.position = startPos.clone();
- var middePos = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
- error: Error()
- }), Utils) : Utils).randomUIPointGenerator(_this.target_plate, startPos, 200);
- var pos = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
- error: Error()
- }), Utils) : Utils).calculateParabolaCenter(startPos, targetPos);
- var controlPoint = new Vec3(middePos.x + pos.x, middePos.y, middePos.z); //贝塞尔轨迹计算
- var calculateTrajectory = (t, p0, p1, p2) => {
- var u = 1 - t;
- 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);
- };
- tween(boomerang).to(0.4, {}, {
- onUpdate: (_, ratio) => {
- //计算当前帧位置
- var currentPos = calculateTrajectory(ratio, startPos, controlPoint, targetPos); //更新位置和旋转
- boomerang.position = currentPos;
- boomerang.angle = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
- error: Error()
- }), Utils) : Utils).getAngle(currentPos, targetPos) - 90;
- },
- onComplete: () => {
- if (boomerang.parent) {
- setTimeout(() => {
- (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).putNode(boomerang);
- _this.handleReward(selectedItem);
- _this.isBoomeranging = false;
- }, 0.2);
- }
- }
- }).start();
- })();
- }
- /**
- * 奖励处理方法
- * @param item
- */
- handleReward(item) {
- var [type, amount] = item.quantity.split('_');
- switch (type) {
- case '1001':
- {
- //金币
- (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.gold += parseInt(amount);
- (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
- error: Error()
- }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {
- (_crd && ResUtil === void 0 ? (_reportPossibleCrUseOfResUtil({
- error: Error()
- }), ResUtil) : ResUtil).flyAnim((_crd && ITEM_TYPE === void 0 ? (_reportPossibleCrUseOfITEM_TYPE({
- error: Error()
- }), ITEM_TYPE) : ITEM_TYPE).Coin, this.shoot_btn, this.gold_lable.node, 5, 50, b => {});
- }]);
- }
- break;
- case '1002':
- {
- //钻石
- (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).data.diamond += parseInt(amount);
- (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
- error: Error()
- }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {
- (_crd && ResUtil === void 0 ? (_reportPossibleCrUseOfResUtil({
- error: Error()
- }), ResUtil) : ResUtil).flyAnim((_crd && ITEM_TYPE === void 0 ? (_reportPossibleCrUseOfITEM_TYPE({
- error: Error()
- }), ITEM_TYPE) : ITEM_TYPE).Diamond, this.shoot_btn, this.diamond_lable.node, 5, 50, b => {});
- }]);
- }
- break;
- default:
- {
- //武器解锁 获得显示武器栏
- var [gun_id, num] = item.quantity.split('_');
- (_crd && userIns === void 0 ? (_reportPossibleCrUseOfuserIns({
- error: Error()
- }), userIns) : userIns).unlockGun(gun_id);
- (_crd && uiMgr === void 0 ? (_reportPossibleCrUseOfuiMgr({
- error: Error()
- }), uiMgr) : uiMgr).show((_crd && Constants === void 0 ? (_reportPossibleCrUseOfConstants({
- error: Error()
- }), Constants) : Constants).popUIs.obtainUI, [item.id, () => {}]);
- }
- break;
- }
- }
- /**
- * 按钮点击事件
- * @param event 事件
- * @param param 参数
- */
- onBtnClicked(event, param) {
- super.onBtnClicked(event, param);
- var btnName = event.target.name;
- if (btnName === 'shoot_btn') {
- //扔飞镖的操作
- this.startToss();
- }
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "target_plate", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "shoot_btn", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "gold_lable", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "diamond_lable", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "boomerang_num_lable", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- })), _class2)) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=3bd48f79623dfcb34002b66c9435221cfa7d6f59.js.map
|