123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, NetPlayer, NetTeam, _crd, C2S_MATCH, C2S_MATCH_CANCEL, C2S_READY, C2S_KICK_OUT;
- function _reportPossibleCrUseOfNetPlayer(extras) {
- _reporterNs.report("NetPlayer", "./NetPlayer", _context.meta, extras);
- }
- _export("NetTeam", void 0);
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- }, function (_unresolved_2) {
- NetPlayer = _unresolved_2.NetPlayer;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "33caeCu1CZJPaCD2lrLn4Gv", "NetTeam", undefined);
- C2S_MATCH = 'c2s_match';
- C2S_MATCH_CANCEL = 'c2s_match_cancel';
- C2S_READY = 'c2s_ready';
- C2S_KICK_OUT = 'c2s_kick_out';
- /**网络队伍*/
- _export("NetTeam", NetTeam = class NetTeam {
- /**队伍是否能进*/
- get status() {
- return this._status;
- }
- /**队伍队长ID*/
- get HostId() {
- return this._hostId;
- }
- /**队伍进入口令*/
- get Password() {
- return this._password;
- }
- /**队伍上限*/
- get Limit() {
- return this._limit;
- }
- /**队伍标识id*/
- get Id() {
- return this._id;
- }
- /**是否在匹配中*/
- get inCollect() {
- return this._inCollect;
- }
- constructor(data, send) {
- /**队伍事件*/
- this.evt = chsdk.get_new_event();
- this._status = true;
- this._hostId = void 0;
- this._password = void 0;
- this._limit = void 0;
- this._id = void 0;
- this._inCollect = false;
- this._own_id = void 0;
- this._players = new Map();
- this._send = void 0;
- this._chat_msg = null;
- this._last_chat_time = 0;
- var team = data.teamData;
- var playerData = data.playerData;
- this._hostId = team.hostInfo;
- this._status = team.status;
- this._inCollect = team.inCollect;
- this._password = team.password;
- this._limit = team.limit;
- this._id = team.roomId;
- this._players.clear();
- var ps = Object.keys(playerData).map(key => ({
- key,
- data: playerData[key]
- }));
- for (var i = 0; i < ps.length; i++) this.addPlayer(ps[i]);
- this._send = send;
- }
- /**主机开始匹配*/
- match() {
- if (!this.isHost) return;
- this._send(C2S_MATCH);
- }
- /**主机退出匹配*/
- exit_match() {
- if (!this.isHost) return;
- this._send(C2S_MATCH_CANCEL);
- }
- /**主机踢出某个玩家出小队 */
- kick_out(arg) {
- if (!this.isHost) return;
- if (typeof arg === 'string') {
- this._send(C2S_KICK_OUT, arg);
- } else if (typeof arg === 'number') {
- var playerToKick = this.all.find(player => player.location === arg);
- if (playerToKick) this._send(C2S_KICK_OUT, playerToKick.Id); // 踢出找到的玩家
- }
- }
- /**主机踢出所有没有准备的玩家 */
- kick_out_no_readys() {
- if (!this.isHost) return;
- var list = this.notreadys;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**主机踢出所有不在线玩家*/
- kick_out_outlines() {
- if (!this.isHost) return;
- var list = this.outlines;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**主机踢出所有不在线或没有准备的玩家*/
- kick_out_badplayers() {
- if (!this.isHost) return;
- var list = this.badplayers;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**准备*/
- ready() {
- this._send(C2S_READY);
- }
- addPlayer(p, isevt) {
- if (isevt === void 0) {
- isevt = false;
- }
- var id = p.key;
- var pd = p.data;
- var player = this._players.get(id);
- if (!player) {
- player = new (_crd && NetPlayer === void 0 ? (_reportPossibleCrUseOfNetPlayer({
- error: Error()
- }), NetPlayer) : NetPlayer)(id);
- this._players.set(id, player);
- }
- player.init(pd);
- player.set_host(player.Id === this._hostId);
- if (player.isOwn) this._own_id = id;
- if (isevt) this.evt._emit('t_entry', id, player.location, player.nickName);
- }
- /**玩家离开*/
- removePlayer(id) {
- var p = this._players.get(id);
- if (p) {
- var _location = p.location;
- var nickName = p.nickName;
- this._players.delete(id);
- this.evt._emit('t_exit', id, _location, nickName);
- }
- }
- /**队伍解散*/
- closed() {
- this.evt._emit('t_closed');
- }
- updatePlayerStatus(id, online) {
- var p = this.getPlayer(id);
- if (p) {
- p.change_online(online);
- var _location2 = p.location;
- var nickName = p.nickName;
- this.evt._emit('t_online', id, online, _location2, nickName);
- }
- }
- updatePlayerReady(id, ready) {
- var p = this.getPlayer(id);
- if (p) {
- p.change_ready(ready);
- var _location3 = p.location;
- var nickName = p.nickName;
- this.evt._emit('t_ready', id, ready, _location3, nickName);
- }
- }
- match_start() {
- this._inCollect = true;
- this.evt._emit('t_matchStart');
- }
- match_cancel() {
- this._inCollect = false;
- this.evt._emit('t_matchCancel');
- }
- match_success() {
- this._inCollect = false;
- this.evt._emit('t_matchSuccess');
- var ps = this.getAllPlayer();
- for (var i = 0; i < ps.length; i++) {
- ps[i].change_ready(false);
- }
- }
- not_ready() {
- this.evt._emit('t_no_ready');
- }
- changeHost(id) {
- this._hostId = id;
- this._players.forEach((v, _) => {
- v.set_host(v.Id === this._hostId);
- });
- var p = this.getPlayer(this._hostId);
- this.evt._emit('t_host', id, p.location, p.nickName);
- }
- /*队伍里聊天,成功返回true,发送频率过快返回false*/
- chat(msg) {
- var now = chsdk.date.now();
- if (now - this._last_chat_time < 1000) return false;
- this._last_chat_time = now;
- this._chat_msg = msg;
- return true;
- }
- onChat(id, msg) {
- var p = this.getPlayer(id);
- this.evt._emit('t_chat', id, msg, p.location, p.nickName);
- }
- doSendChat(f) {
- f(this._chat_msg);
- this._chat_msg = null;
- }
- /**自己是否是主机*/
- get isHost() {
- return this._own_id === this._hostId;
- }
- /**自己的所有信息*/
- get own() {
- return this._players.get(this._own_id);
- }
- /**所有玩家*/
- get all() {
- return Array.from(this._players.values());
- }
- /**其它玩家信息*/
- get others() {
- return Array.from(this._players.values()).filter(player => !player.isOwn);
- ;
- }
- /**在线玩家信息*/
- get onlines() {
- return Array.from(this._players.values()).filter(player => player.online);
- ;
- }
- /**不在线玩家信息*/
- get outlines() {
- return Array.from(this._players.values()).filter(player => !player.online);
- ;
- }
- /**没有准备或不在线玩家*/
- get badplayers() {
- return Array.from(this._players.values()).filter(player => !player.ready || !player.online);
- ;
- }
- /**准备好的玩家信息*/
- get readys() {
- return Array.from(this._players.values()).filter(player => player.ready);
- ;
- }
- /**没有准备的玩家信息*/
- get notreadys() {
- return Array.from(this._players.values()).filter(player => !player.ready);
- ;
- }
- /**某个玩家的所有信息*/
- getPlayer(id) {
- return this._players.get(id);
- }
- /**所有玩家*/
- getAllPlayer() {
- return this.all;
- }
- /**将玩家按 location 放到一个数组中,并自定义数组长度*/
- getAllPlayersAtLocations(customLength) {
- var locationArray = Array(customLength).fill(null);
- this._players.forEach(player => {
- if (player.location >= 0 && player.location < customLength) locationArray[player.location] = player;
- });
- return locationArray;
- }
- /**获取除了某个id的所有玩家*/
- getExPlayer(id) {
- return Array.from(this._players.values()).filter(player => player.Id != id);
- ;
- }
- /**获在线或不在线的所有玩家*/
- getOnlinePlayer(isOnline) {
- return isOnline ? this.onlines : this.outlines;
- }
- /**获准备或没有准备的所有玩家*/
- getReadyPlayer(ready) {
- return ready ? this.readys : this.notreadys;
- }
- dispose() {
- this._send = null;
- this._players.forEach((v, _) => {
- v.dispose();
- });
- this._players.clear();
- }
- });
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=72bc24ff288b2b4316b5ddb0abd45b840383d6f0.js.map
|