0f8c19fc5c7f0402a178675e61ebcbe3435fabc7.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, ch_util, ch_pvp, _crd;
  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 _reportPossibleCrUseOfch_util(extras) {
  7. _reporterNs.report("ch_util", "../ch_util", _context.meta, extras);
  8. }
  9. return {
  10. setters: [function (_unresolved_) {
  11. _reporterNs = _unresolved_;
  12. }, function (_cc) {
  13. _cclegacy = _cc.cclegacy;
  14. }, function (_unresolved_2) {
  15. ch_util = _unresolved_2.default;
  16. }],
  17. execute: function () {
  18. _crd = true;
  19. _cclegacy._RF.push({}, "8b658c6Uk1Jq4HkHx1ctH2P", "ch_pvp", undefined);
  20. /**
  21. * pvp扩展玩法 基于 chsdk
  22. */
  23. ch_pvp = class ch_pvp {
  24. constructor() {
  25. this._set_url = '/user/setPvpSceneData';
  26. this._match_url = '/user/startPvpMatch';
  27. this._finish_url = '/user/pvpFinishAction';
  28. this._record_url = '/user/pvpChallengeRecord';
  29. this._own = void 0;
  30. //
  31. this._cache_records = null;
  32. this._cache_time = void 0;
  33. }
  34. static getInstance() {
  35. if (!this._instance) this._instance = new ch_pvp();
  36. return this._instance;
  37. }
  38. /**
  39. * 设置自己的 PVP 擂台数据
  40. * 该方法用于更新当前用户在 PVP 擂台上的数据。数据将根据传入的 extend 参数进行更新,
  41. * 并返回一个包含操作状态和可能错误信息的 Promise。
  42. * @param extend - 一个pvp擂台数据对象,包含要更新的具体数据。
  43. * @returns 一个 Promise,解析为一个包含以下属性的对象:
  44. * - code: 操作的结果状态。0 表示成功,其他值表示不同的错误类型。
  45. * - err: 可选字符串,指示错误信息(如果有)。
  46. */
  47. setSceneData(extend) {
  48. var _this = this;
  49. return _asyncToGenerator(function* () {
  50. var check = chsdk.check_req_time('setSceneData');
  51. if (check) return check;
  52. var body = {
  53. extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  54. error: Error()
  55. }), ch_util) : ch_util).stringify(extend)
  56. };
  57. var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this._set_url), body);
  58. if (ret.code != chsdk.code.success) {
  59. chsdk.log.warn(ret);
  60. } else {
  61. chsdk.log.log("PVP\u64C2\u53F0\u6570\u636E\u4E0A\u62A5\u6210\u529F");
  62. if (!_this._own) {
  63. yield _this.getOwn();
  64. } else {
  65. _this._own.extends = extend;
  66. }
  67. }
  68. return ret;
  69. })();
  70. }
  71. /**
  72. * 开始匹配
  73. * @param uid (可选)具体好友的uid,默为空
  74. * @returns null 匹配失败
  75. *
  76. * pvp_data<T>
  77. extends PVP 擂台数据
  78. * other 台主信息
  79. * own 自己的信息
  80. * head:头像, nickName:名字, uid:id, hid:省id, province:省名, pvp:pvp排位分值, rank:pvp排行榜名次
  81. */
  82. startMatch(uid) {
  83. var _this2 = this;
  84. return _asyncToGenerator(function* () {
  85. var check = chsdk.check_req_time('startMatch');
  86. if (check) return null;
  87. var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this2._match_url), {
  88. uid: uid ? uid.toString() : ''
  89. });
  90. if (ret.code != chsdk.code.success) {
  91. chsdk.log.warn(ret);
  92. return null;
  93. } else {
  94. var data = ret.data.data;
  95. data.other.uid = Number.parseInt(data.other.uid);
  96. data.other.hid = Number.parseInt(data.other.hid);
  97. data.other.province = chsdk.provinceCode2Name(data.other.hid);
  98. data.own.uid = Number.parseInt(data.own.uid);
  99. data.own.hid = Number.parseInt(data.own.hid);
  100. data.own.province = chsdk.provinceCode2Name(data.own.hid);
  101. return {
  102. extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  103. error: Error()
  104. }), ch_util) : ch_util).parse(data.extends),
  105. other: data.other,
  106. own: data.own
  107. };
  108. }
  109. })();
  110. }
  111. /**从一条记录开始匹配,用于复仇*/
  112. startMatchRecord(pd) {
  113. var _this3 = this;
  114. return _asyncToGenerator(function* () {
  115. var check = chsdk.check_req_time('startMatch');
  116. if (check) return null;
  117. var pp = yield _this3.startMatch(pd.other.uid);
  118. if (!pp) return null;
  119. pp.extends = pd.extends;
  120. pp.pvpId = pd.pvpId;
  121. return pp;
  122. })();
  123. }
  124. /**
  125. * 完成pvp上报
  126. * @param otherUid 对方uid
  127. * @param status 0:挑战失败 1:挑战胜利
  128. * @param ext PVP 擂台数据
  129. * @param serverData 服务器处理排行数据,订阅消息
  130. * ..ownValue 增减自己排位分值
  131. * ..otherValue 增减对方排位分值
  132. * ..msg 自定义的订阅消息
  133. * @param pvpId 复仇id
  134. * @returns 对战结果
  135. * other 对方的排名和分数变化
  136. * own 自己的排名和分数变化
  137. * curRank 当前排名(变动后)
  138. curScore 当前分数(变动后)
  139. rank 名数变动
  140. score 分数变动
  141. */
  142. finish(otherUid, status, ext, serverData, pvpId) {
  143. var _this4 = this;
  144. return _asyncToGenerator(function* () {
  145. var check = chsdk.check_req_time('finish');
  146. if (check) return null;
  147. var body = {
  148. otherUid: otherUid.toString(),
  149. status: status,
  150. extends: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  151. error: Error()
  152. }), ch_util) : ch_util).stringify(ext),
  153. serverData: (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  154. error: Error()
  155. }), ch_util) : ch_util).stringify(serverData),
  156. pvpId: pvpId
  157. };
  158. var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this4._finish_url), body);
  159. if (ret.code != chsdk.code.success) {
  160. chsdk.log.warn(ret);
  161. return null;
  162. } else {
  163. var data = ret.data.data;
  164. chsdk.log.log("pvp\u7ED3\u679C\u6570\u636E\u4E0A\u62A5\u6210\u529F,\u7ED3\u7B97:", data);
  165. return data;
  166. }
  167. })();
  168. }
  169. /**获取自己的pvp擂台数据*/
  170. getOwn() {
  171. var _this5 = this;
  172. return _asyncToGenerator(function* () {
  173. if (!_this5._own) yield _this5.getRecords(3, false);
  174. return _this5._own;
  175. })();
  176. }
  177. get_cache_records() {
  178. if (chsdk.date.now() - this._cache_time > 6e4) return null;
  179. return this._cache_records;
  180. }
  181. /**
  182. * 获取pvp对战记录
  183. * @param type 0:全部纪录 1:被挑战的记录信息(默认) 2:挑战别人的记录 3:不需要纪录
  184. * @param cache 默认为true,优先缓存拿数据,缓存存在一分钟
  185. * @returns own:自己的PVP 擂台数据
  186. * list:交互纪录
  187. * extends PVP 擂台数据
  188. * reward 奖励惩罚排位分值,由于serverData中得来
  189. * type 0:自己的数据 1:被挑战的记录信息 2:挑战别人的记录
  190. * status 0:挑战失败 1:挑战胜利 2:复仇成功
  191. * time 时间
  192. * pvpId pvp复仇id
  193. * other 对方信息
  194. * own 自己信息
  195. */
  196. getRecords(typeId, cache) {
  197. var _this6 = this;
  198. return _asyncToGenerator(function* () {
  199. if (typeId === void 0) {
  200. typeId = 1;
  201. }
  202. if (cache === void 0) {
  203. cache = true;
  204. }
  205. if (cache) {
  206. var data = _this6.get_cache_records();
  207. if (data) return data;
  208. }
  209. var check = chsdk.check_req_time('getRecords');
  210. if (check) return null;
  211. var ret = yield chsdk.makePostTokenRequest(chsdk.getUrl(_this6._record_url), {
  212. typeId: typeId
  213. });
  214. if (ret.code != chsdk.code.success) {
  215. chsdk.log.warn(ret);
  216. return null;
  217. } else {
  218. var _data = ret.data.data;
  219. if (_data.own) {
  220. var d = _data.own;
  221. d.extends = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  222. error: Error()
  223. }), ch_util) : ch_util).parse(d.extends);
  224. d.own.uid = Number.parseInt(d.own.uid);
  225. d.own.hid = Number.parseInt(d.own.hid);
  226. d.own.province = chsdk.provinceCode2Name(d.own.hid);
  227. } else {
  228. _data.own = null;
  229. }
  230. _data.list || (_data.list = []);
  231. for (var i = 0; i < _data.list.length; i++) {
  232. var _d = _data.list[i];
  233. _d.extends = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  234. error: Error()
  235. }), ch_util) : ch_util).parse(_d.extends);
  236. _d.own.uid = Number.parseInt(_d.own.uid);
  237. _d.own.hid = Number.parseInt(_d.own.hid);
  238. _d.own.province = chsdk.provinceCode2Name(_d.own.hid);
  239. _d.other.uid = Number.parseInt(_d.other.uid);
  240. _d.other.hid = Number.parseInt(_d.other.hid);
  241. _d.other.province = chsdk.provinceCode2Name(_d.other.hid);
  242. }
  243. _this6._own = _data.own;
  244. _this6._cache_records = _data;
  245. _this6._cache_time = chsdk.date.now();
  246. return _data;
  247. }
  248. })();
  249. }
  250. /**
  251. * 获取pvp排位分值榜单
  252. * @returns
  253. */
  254. getRank() {
  255. return _asyncToGenerator(function* () {
  256. var d = yield chsdk.loadRankData('pvp', 1, 100, true);
  257. return {
  258. list: d.data.list,
  259. ower: d.data.own
  260. };
  261. })();
  262. }
  263. /**
  264. * 分享pvp数据,邀请对战
  265. * @param player 玩家自己信息
  266. * @param extend (可选)pvp关卡等数据
  267. * @param title 分享显示标题
  268. * @param imageUrl 分享显示图片
  269. */
  270. sharePvp(player, extend, title, imageUrl) {
  271. return _asyncToGenerator(function* () {
  272. chsdk.shareAppMessage(title, '', imageUrl, (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  273. error: Error()
  274. }), ch_util) : ch_util).stringify({
  275. type: 'pvp',
  276. player: player,
  277. extends: extend
  278. }));
  279. })();
  280. }
  281. /**
  282. *获取从好友分享的pvp数据进入游戏的数据
  283. */
  284. getSharePvpExtends() {
  285. var query = chsdk.getQuery();
  286. if (!query) return null;
  287. var message = query.message;
  288. if (!message) return null;
  289. var data = (_crd && ch_util === void 0 ? (_reportPossibleCrUseOfch_util({
  290. error: Error()
  291. }), ch_util) : ch_util).parse(message);
  292. if (!data) return null;
  293. if (data.type != 'pvp') return null;
  294. query.message = null;
  295. return {
  296. player: data.player,
  297. extend: data.extends
  298. };
  299. }
  300. }; //
  301. ch_pvp._instance = void 0;
  302. _export("default", ch_pvp.getInstance());
  303. _cclegacy._RF.pop();
  304. _crd = false;
  305. }
  306. };
  307. });
  308. //# sourceMappingURL=0f8c19fc5c7f0402a178675e61ebcbe3435fabc7.js.map