72bc24ff288b2b4316b5ddb0abd45b840383d6f0.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, NetPlayer, NetTeam, _crd, C2S_MATCH, C2S_MATCH_CANCEL, C2S_READY, C2S_KICK_OUT;
  4. function _reportPossibleCrUseOfNetPlayer(extras) {
  5. _reporterNs.report("NetPlayer", "./NetPlayer", _context.meta, extras);
  6. }
  7. _export("NetTeam", void 0);
  8. return {
  9. setters: [function (_unresolved_) {
  10. _reporterNs = _unresolved_;
  11. }, function (_cc) {
  12. _cclegacy = _cc.cclegacy;
  13. }, function (_unresolved_2) {
  14. NetPlayer = _unresolved_2.NetPlayer;
  15. }],
  16. execute: function () {
  17. _crd = true;
  18. _cclegacy._RF.push({}, "33caeCu1CZJPaCD2lrLn4Gv", "NetTeam", undefined);
  19. C2S_MATCH = 'c2s_match';
  20. C2S_MATCH_CANCEL = 'c2s_match_cancel';
  21. C2S_READY = 'c2s_ready';
  22. C2S_KICK_OUT = 'c2s_kick_out';
  23. /**网络队伍*/
  24. _export("NetTeam", NetTeam = class NetTeam {
  25. /**队伍是否能进*/
  26. get status() {
  27. return this._status;
  28. }
  29. /**队伍队长ID*/
  30. get HostId() {
  31. return this._hostId;
  32. }
  33. /**队伍进入口令*/
  34. get Password() {
  35. return this._password;
  36. }
  37. /**队伍上限*/
  38. get Limit() {
  39. return this._limit;
  40. }
  41. /**队伍标识id*/
  42. get Id() {
  43. return this._id;
  44. }
  45. /**是否在匹配中*/
  46. get inCollect() {
  47. return this._inCollect;
  48. }
  49. constructor(data, send) {
  50. /**队伍事件*/
  51. this.evt = chsdk.get_new_event();
  52. this._status = true;
  53. this._hostId = void 0;
  54. this._password = void 0;
  55. this._limit = void 0;
  56. this._id = void 0;
  57. this._inCollect = false;
  58. this._own_id = void 0;
  59. this._players = new Map();
  60. this._send = void 0;
  61. this._chat_msg = null;
  62. this._last_chat_time = 0;
  63. var team = data.teamData;
  64. var playerData = data.playerData;
  65. this._hostId = team.hostInfo;
  66. this._status = team.status;
  67. this._inCollect = team.inCollect;
  68. this._password = team.password;
  69. this._limit = team.limit;
  70. this._id = team.roomId;
  71. this._players.clear();
  72. var ps = Object.keys(playerData).map(key => ({
  73. key,
  74. data: playerData[key]
  75. }));
  76. for (var i = 0; i < ps.length; i++) this.addPlayer(ps[i]);
  77. this._send = send;
  78. }
  79. /**主机开始匹配*/
  80. match() {
  81. if (!this.isHost) return;
  82. this._send(C2S_MATCH);
  83. }
  84. /**主机退出匹配*/
  85. exit_match() {
  86. if (!this.isHost) return;
  87. this._send(C2S_MATCH_CANCEL);
  88. }
  89. /**主机踢出某个玩家出小队 */
  90. kick_out(arg) {
  91. if (!this.isHost) return;
  92. if (typeof arg === 'string') {
  93. this._send(C2S_KICK_OUT, arg);
  94. } else if (typeof arg === 'number') {
  95. var playerToKick = this.all.find(player => player.location === arg);
  96. if (playerToKick) this._send(C2S_KICK_OUT, playerToKick.Id); // 踢出找到的玩家
  97. }
  98. }
  99. /**主机踢出所有没有准备的玩家 */
  100. kick_out_no_readys() {
  101. if (!this.isHost) return;
  102. var list = this.notreadys;
  103. for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
  104. }
  105. /**主机踢出所有不在线玩家*/
  106. kick_out_outlines() {
  107. if (!this.isHost) return;
  108. var list = this.outlines;
  109. for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
  110. }
  111. /**主机踢出所有不在线或没有准备的玩家*/
  112. kick_out_badplayers() {
  113. if (!this.isHost) return;
  114. var list = this.badplayers;
  115. for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
  116. }
  117. /**准备*/
  118. ready() {
  119. this._send(C2S_READY);
  120. }
  121. addPlayer(p, isevt) {
  122. if (isevt === void 0) {
  123. isevt = false;
  124. }
  125. var id = p.key;
  126. var pd = p.data;
  127. var player = this._players.get(id);
  128. if (!player) {
  129. player = new (_crd && NetPlayer === void 0 ? (_reportPossibleCrUseOfNetPlayer({
  130. error: Error()
  131. }), NetPlayer) : NetPlayer)(id);
  132. this._players.set(id, player);
  133. }
  134. player.init(pd);
  135. player.set_host(player.Id === this._hostId);
  136. if (player.isOwn) this._own_id = id;
  137. if (isevt) this.evt._emit('t_entry', id, player.location, player.nickName);
  138. }
  139. /**玩家离开*/
  140. removePlayer(id) {
  141. var p = this._players.get(id);
  142. if (p) {
  143. var _location = p.location;
  144. var nickName = p.nickName;
  145. this._players.delete(id);
  146. this.evt._emit('t_exit', id, _location, nickName);
  147. }
  148. }
  149. /**队伍解散*/
  150. closed() {
  151. this.evt._emit('t_closed');
  152. }
  153. updatePlayerStatus(id, online) {
  154. var p = this.getPlayer(id);
  155. if (p) {
  156. p.change_online(online);
  157. var _location2 = p.location;
  158. var nickName = p.nickName;
  159. this.evt._emit('t_online', id, online, _location2, nickName);
  160. }
  161. }
  162. updatePlayerReady(id, ready) {
  163. var p = this.getPlayer(id);
  164. if (p) {
  165. p.change_ready(ready);
  166. var _location3 = p.location;
  167. var nickName = p.nickName;
  168. this.evt._emit('t_ready', id, ready, _location3, nickName);
  169. }
  170. }
  171. match_start() {
  172. this._inCollect = true;
  173. this.evt._emit('t_matchStart');
  174. }
  175. match_cancel() {
  176. this._inCollect = false;
  177. this.evt._emit('t_matchCancel');
  178. }
  179. match_success() {
  180. this._inCollect = false;
  181. this.evt._emit('t_matchSuccess');
  182. var ps = this.getAllPlayer();
  183. for (var i = 0; i < ps.length; i++) {
  184. ps[i].change_ready(false);
  185. }
  186. }
  187. not_ready() {
  188. this.evt._emit('t_no_ready');
  189. }
  190. changeHost(id) {
  191. this._hostId = id;
  192. this._players.forEach((v, _) => {
  193. v.set_host(v.Id === this._hostId);
  194. });
  195. var p = this.getPlayer(this._hostId);
  196. this.evt._emit('t_host', id, p.location, p.nickName);
  197. }
  198. /*队伍里聊天,成功返回true,发送频率过快返回false*/
  199. chat(msg) {
  200. var now = chsdk.date.now();
  201. if (now - this._last_chat_time < 1000) return false;
  202. this._last_chat_time = now;
  203. this._chat_msg = msg;
  204. return true;
  205. }
  206. onChat(id, msg) {
  207. var p = this.getPlayer(id);
  208. this.evt._emit('t_chat', id, msg, p.location, p.nickName);
  209. }
  210. doSendChat(f) {
  211. f(this._chat_msg);
  212. this._chat_msg = null;
  213. }
  214. /**自己是否是主机*/
  215. get isHost() {
  216. return this._own_id === this._hostId;
  217. }
  218. /**自己的所有信息*/
  219. get own() {
  220. return this._players.get(this._own_id);
  221. }
  222. /**所有玩家*/
  223. get all() {
  224. return Array.from(this._players.values());
  225. }
  226. /**其它玩家信息*/
  227. get others() {
  228. return Array.from(this._players.values()).filter(player => !player.isOwn);
  229. ;
  230. }
  231. /**在线玩家信息*/
  232. get onlines() {
  233. return Array.from(this._players.values()).filter(player => player.online);
  234. ;
  235. }
  236. /**不在线玩家信息*/
  237. get outlines() {
  238. return Array.from(this._players.values()).filter(player => !player.online);
  239. ;
  240. }
  241. /**没有准备或不在线玩家*/
  242. get badplayers() {
  243. return Array.from(this._players.values()).filter(player => !player.ready || !player.online);
  244. ;
  245. }
  246. /**准备好的玩家信息*/
  247. get readys() {
  248. return Array.from(this._players.values()).filter(player => player.ready);
  249. ;
  250. }
  251. /**没有准备的玩家信息*/
  252. get notreadys() {
  253. return Array.from(this._players.values()).filter(player => !player.ready);
  254. ;
  255. }
  256. /**某个玩家的所有信息*/
  257. getPlayer(id) {
  258. return this._players.get(id);
  259. }
  260. /**所有玩家*/
  261. getAllPlayer() {
  262. return this.all;
  263. }
  264. /**将玩家按 location 放到一个数组中,并自定义数组长度*/
  265. getAllPlayersAtLocations(customLength) {
  266. var locationArray = Array(customLength).fill(null);
  267. this._players.forEach(player => {
  268. if (player.location >= 0 && player.location < customLength) locationArray[player.location] = player;
  269. });
  270. return locationArray;
  271. }
  272. /**获取除了某个id的所有玩家*/
  273. getExPlayer(id) {
  274. return Array.from(this._players.values()).filter(player => player.Id != id);
  275. ;
  276. }
  277. /**获在线或不在线的所有玩家*/
  278. getOnlinePlayer(isOnline) {
  279. return isOnline ? this.onlines : this.outlines;
  280. }
  281. /**获准备或没有准备的所有玩家*/
  282. getReadyPlayer(ready) {
  283. return ready ? this.readys : this.notreadys;
  284. }
  285. dispose() {
  286. this._send = null;
  287. this._players.forEach((v, _) => {
  288. v.dispose();
  289. });
  290. this._players.clear();
  291. }
  292. });
  293. _cclegacy._RF.pop();
  294. _crd = false;
  295. }
  296. };
  297. });
  298. //# sourceMappingURL=72bc24ff288b2b4316b5ddb0abd45b840383d6f0.js.map