System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) { "use strict"; var _reporterNs, _cclegacy, ch_util, ch_pvp, _crd; 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: 可选字符串,指示错误信息(如果有)。 */ async setSceneData(extend) { const check = chsdk.check_req_time('setSceneData'); if (check) return check; const body = { extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({ error: Error() }), ch_util) : ch_util).stringify(extend) }; const ret = await chsdk.makePostTokenRequest(chsdk.getUrl(this._set_url), body); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); } else { chsdk.log.log(`PVP擂台数据上报成功`); if (!this._own) { await 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排行榜名次 */ async startMatch(uid) { const check = chsdk.check_req_time('startMatch'); if (check) return null; const ret = await chsdk.makePostTokenRequest(chsdk.getUrl(this._match_url), { uid: uid ? uid.toString() : '' }); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { const 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 }; } } /**从一条记录开始匹配,用于复仇*/ async startMatchRecord(pd) { const check = chsdk.check_req_time('startMatch'); if (check) return null; let pp = await this.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 分数变动 */ async finish(otherUid, status, ext, serverData, pvpId) { const check = chsdk.check_req_time('finish'); if (check) return null; const 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 }; const ret = await chsdk.makePostTokenRequest(chsdk.getUrl(this._finish_url), body); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { const data = ret.data.data; chsdk.log.log(`pvp结果数据上报成功,结算:`, data); return data; } } /**获取自己的pvp擂台数据*/ async getOwn() { if (!this._own) await this.getRecords(3, false); return this._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 自己信息 */ async getRecords(typeId = 1, cache = true) { if (cache) { const data = this.get_cache_records(); if (data) return data; } const check = chsdk.check_req_time('getRecords'); if (check) return null; const ret = await chsdk.makePostTokenRequest(chsdk.getUrl(this._record_url), { typeId: typeId }); if (ret.code != chsdk.code.success) { chsdk.log.warn(ret); return null; } else { let data = ret.data.data; if (data.own) { const 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 (let i = 0; i < data.list.length; i++) { const 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); } this._own = data.own; this._cache_records = data; this._cache_time = chsdk.date.now(); return data; } } /** * 获取pvp排位分值榜单 * @returns */ async getRank() { const d = await 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 分享显示图片 */ async sharePvp(player, extend, title, imageUrl) { 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() { const query = chsdk.getQuery(); if (!query) return null; const message = query.message; if (!message) return null; const 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