1c3614b3a2e4710764372e6a76dbe0058c9d9dab.js 11 KB

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