System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) { "use strict"; var _reporterNs, _cclegacy, ch_util, ch_pvp, _crd; 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 _reportPossibleCrUseOfch_util(extras) { _reporterNs.report("ch_util", "../ch_util", _context.meta, extras); } return { setters: [function (_unresolved_) { _reporterNs = _unresolved_; }, function (_cc) { _cclegacy = _cc.cclegacy; }, function (_unresolved_2) { ch_util = _unresolved_2.default; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "8b658c6Uk1Jq4HkHx1ctH2P", "ch_pvp", undefined); /** * pvp扩展玩法 基于 chsdk */ ch_pvp = class ch_pvp { constructor() { this._set_url = '/user/setPvpSceneData'; this._match_url = '/user/startPvpMatch'; this._finish_url = '/user/pvpFinishAction'; this._record_url = '/user/pvpChallengeRecord'; this._own = void 0; // this._cache_records = null; this._cache_time = void 0; } static getInstance() { if (!this._instance) this._instance = new ch_pvp(); return this._instance; } /** * 设置自己的 PVP 擂台数据 * 该方法用于更新当前用户在 PVP 擂台上的数据。数据将根据传入的 extend 参数进行更新, * 并返回一个包含操作状态和可能错误信息的 Promise。 * @param extend - 一个pvp擂台数据对象,包含要更新的具体数据。 * @returns 一个 Promise,解析为一个包含以下属性的对象: * - code: 操作的结果状态。0 表示成功,其他值表示不同的错误类型。 * - err: 可选字符串,指示错误信息(如果有)。 */ setSceneData(extend) { var _this = this; return _asyncToGenerator(function* () { var check = chsdk.check_req_time('setSceneData'); if (check) return check; var body = { extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).stringify(extend) }; var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this._set_url), body); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); } else { chsdk.log.log("PVP\u64C2\u53F0\u6570\u636E\u4E0A\u62A5\u6210\u529F"); if (!_this._own) { yield _this.getOwn(); } else { _this._own.extends = extend; } } return ret; })(); } /** * 开始匹配 * @param uid (可选)具体好友的uid,默为空 * @returns null 匹配失败 * * pvp_data extends PVP 擂台数据 * other 台主信息 * own 自己的信息 * head:头像, nickName:名字, uid:id, hid:省id, province:省名, pvp:pvp排位分值, rank:pvp排行榜名次 */ startMatch(uid) { var _this2 = this; return _asyncToGenerator(function* () { var check = chsdk.check_req_time('startMatch'); if (check) return null; var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this2._match_url), { uid: uid ? uid.toString() : '' }); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { var data = ret.data.data; data.other.uid = Number.parseInt(data.other.uid); data.other.hid = Number.parseInt(data.other.hid); data.other.province = chsdk.provinceCode2Name(data.other.hid); data.own.uid = Number.parseInt(data.own.uid); data.own.hid = Number.parseInt(data.own.hid); data.own.province = chsdk.provinceCode2Name(data.own.hid); return { extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).parse(data.extends), other: data.other, own: data.own }; } })(); } /**从一条记录开始匹配,用于复仇*/ startMatchRecord(pd) { var _this3 = this; return _asyncToGenerator(function* () { var check = chsdk.check_req_time('startMatch'); if (check) return null; var pp = yield _this3.startMatch(pd.other.uid); if (!pp) return null; pp.extends = pd.extends; pp.pvpId = pd.pvpId; return pp; })(); } /** * 完成pvp上报 * @param otherUid 对方uid * @param status 0:挑战失败 1:挑战胜利 * @param ext PVP 擂台数据 * @param serverData 服务器处理排行数据,订阅消息 * ..ownValue 增减自己排位分值 * ..otherValue 增减对方排位分值 * ..msg 自定义的订阅消息 * @param pvpId 复仇id * @returns 对战结果 * other 对方的排名和分数变化 * own 自己的排名和分数变化 * curRank 当前排名(变动后) curScore 当前分数(变动后) rank 名数变动 score 分数变动 */ finish(otherUid, status, ext, serverData, pvpId) { var _this4 = this; return _asyncToGenerator(function* () { var check = chsdk.check_req_time('finish'); if (check) return null; var body = { otherUid: otherUid.toString(), status: status, extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).stringify(ext), serverData: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).stringify(serverData), pvpId: pvpId }; var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this4._finish_url), body); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { var data = ret.data.data; chsdk.log.log("pvp\u7ED3\u679C\u6570\u636E\u4E0A\u62A5\u6210\u529F,\u7ED3\u7B97:", data); return data; } })(); } /**获取自己的pvp擂台数据*/ getOwn() { var _this5 = this; return _asyncToGenerator(function* () { if (!_this5._own) yield _this5.getRecords(3, false); return _this5._own; })(); } get_cache_records() { if (chsdk.date.now() - this._cache_time > 6e4) return null; return this._cache_records; } /** * 获取pvp对战记录 * @param type 0:全部纪录 1:被挑战的记录信息(默认) 2:挑战别人的记录 3:不需要纪录 * @param cache 默认为true,优先缓存拿数据,缓存存在一分钟 * @returns own:自己的PVP 擂台数据 * list:交互纪录 * extends PVP 擂台数据 * reward 奖励惩罚排位分值,由于serverData中得来 * type 0:自己的数据 1:被挑战的记录信息 2:挑战别人的记录 * status 0:挑战失败 1:挑战胜利 2:复仇成功 * time 时间 * pvpId pvp复仇id * other 对方信息 * own 自己信息 */ getRecords(typeId, cache) { var _this6 = this; return _asyncToGenerator(function* () { if (typeId === void 0) { typeId = 1; } if (cache === void 0) { cache = true; } if (cache) { var data = _this6.get_cache_records(); if (data) return data; } var check = chsdk.check_req_time('getRecords'); if (check) return null; var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this6._record_url), { typeId: typeId }); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { var _data = ret.data.data; if (_data.own) { var d = _data.own; d.extends = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).parse(d.extends); d.own.uid = Number.parseInt(d.own.uid); d.own.hid = Number.parseInt(d.own.hid); d.own.province = chsdk.provinceCode2Name(d.own.hid); } else { _data.own = null; } _data.list || (_data.list = []); for (var i = 0; i < _data.list.length; i++) { var _d = _data.list[i]; _d.extends = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).parse(_d.extends); _d.own.uid = Number.parseInt(_d.own.uid); _d.own.hid = Number.parseInt(_d.own.hid); _d.own.province = chsdk.provinceCode2Name(_d.own.hid); _d.other.uid = Number.parseInt(_d.other.uid); _d.other.hid = Number.parseInt(_d.other.hid); _d.other.province = chsdk.provinceCode2Name(_d.other.hid); } _this6._own = _data.own; _this6._cache_records = _data; _this6._cache_time = chsdk.date.now(); return _data; } })(); } /** * 获取pvp排位分值榜单 * @returns */ getRank() { return _asyncToGenerator(function* () { var d = yield chsdk.loadRankData('pvp', 1, 100, true); return { list: d.data.list, ower: d.data.own }; })(); } /** * 分享pvp数据,邀请对战 * @param player 玩家自己信息 * @param extend (可选)pvp关卡等数据 * @param title 分享显示标题 * @param imageUrl 分享显示图片 */ sharePvp(player, extend, title, imageUrl) { return _asyncToGenerator(function* () { chsdk.shareAppMessage(title, '', imageUrl, (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).stringify({ type: 'pvp', player: player, extends: extend })); })(); } /** *获取从好友分享的pvp数据进入游戏的数据 */ getSharePvpExtends() { var query = chsdk.getQuery(); if (!query) return null; var message = query.message; if (!message) return null; var data = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).parse(message); if (!data) return null; if (data.type != 'pvp') return null; query.message = null; return { player: data.player, extend: data.extends }; } }; // ch_pvp._instance = void 0; _export("default", ch_pvp.getInstance()); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=0f8c19fc5c7f0402a178675e61ebcbe3435fabc7.js.map