123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, NetBase, NetPlayer, NetRoom, _crd;
- function _reportPossibleCrUseOfNetBase(extras) {
- _reporterNs.report("NetBase", "./NetBase", _context.meta, extras);
- }
- function _reportPossibleCrUseOfNetPlayer(extras) {
- _reporterNs.report("NetPlayer", "./NetPlayer", _context.meta, extras);
- }
- _export("NetRoom", void 0);
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- }, function (_unresolved_2) {
- NetBase = _unresolved_2.NetBase;
- }, function (_unresolved_3) {
- NetPlayer = _unresolved_3.NetPlayer;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "577dcgqDHFNgZms65V5Rprz", "NetRoom", undefined);
- /**网络房间*/
- _export("NetRoom", NetRoom = class NetRoom extends (_crd && NetBase === void 0 ? (_reportPossibleCrUseOfNetBase({
- error: Error()
- }), NetBase) : NetBase) {
- /**游戏主机ID*/
- get HostId() {
- return this._hostId;
- }
- /**游戏是否关闭*/
- get cloosed() {
- return !this._status;
- }
- //
- constructor(roomData, playerData) {
- super(roomData.roomId);
- this.evt = chsdk.get_new_event();
- this._hostId = void 0;
- this._status = true;
- this._own_id = void 0;
- this._players = new Map();
- //
- this._waitSends_mode0 = [];
- this._waitSends_mode1 = [];
- this._waitSends_mode2 = [];
- this._results = [];
- this._chat_msg = null;
- this._last_chat_time = 0;
- this._status = roomData.status;
- this._hostId = roomData.hostInfo;
- let ps = Object.keys(playerData).map(key => ({
- key,
- data: playerData[key]
- }));
- for (let i = 0; i < ps.length; i++) this.addPlayer(ps[i]);
- this._players.forEach((v, _) => {
- v.set_host(v.Id === this._hostId, this.isHost);
- });
- this.initValue(roomData.gameData);
- }
- addPlayer(p) {
- const id = p.key;
- const pd = p.data;
- let 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);
- if (player.isOwn) this._own_id = id;
- }
- updatePlayerStatus(id, online) {
- const p = this.getPlayer(id);
- if (p) {
- p.change_online(online);
- const location = p.location;
- const nickName = p.nickName;
- this.evt._emit('r_online', id, online, location, nickName);
- }
- }
- changeHost(id) {
- this._hostId = id;
- this._players.forEach((v, _) => {
- v.set_host(v.Id === this._hostId, this.isHost);
- });
- const p = this.getPlayer(this._hostId);
- this.evt._emit('r_host', id, p.location, p.nickName);
- }
- /**自己是否是主机*/
- get isHost() {
- return this._own_id === this._hostId;
- }
- /**自己的所有信息*/
- get own() {
- return this._players.get(this._own_id);
- }
- /**其它玩家信息*/
- get others() {
- return Array.from(this._players.values()).filter(player => !player.isOwn);
- }
- /**所有ai信息*/
- get ais() {
- return Array.from(this._players.values()).filter(player => player.isAI);
- }
- /**所有玩家*/
- get all() {
- return this.getAllPlayer();
- }
- /**在线玩家信息*/
- get onlines() {
- return Array.from(this._players.values()).filter(player => player.online);
- }
- /**不在线玩家信息*/
- get outlines() {
- return Array.from(this._players.values()).filter(player => !player.online);
- }
- /**所有玩家*/
- getAllPlayer() {
- return Array.from(this._players.values());
- }
- /**将玩家按 location 放到一个数组中,并自定义数组长度*/
- getAllPlayersAtLocations(customLength) {
- const locationArray = Array(customLength).fill(null);
- this._players.forEach(player => {
- if (player.location >= 0 && player.location < customLength) locationArray[player.location] = player;
- });
- return locationArray;
- }
- /**中某个玩家的所有信息*/
- getPlayer(id) {
- return this._players.get(id);
- }
- /**获取除了某个id的所有玩家*/
- getExPlayer(id) {
- return Array.from(this._players.values()).filter(player => player.Id != id);
- }
- /**获在线或不在线的所有玩家*/
- getOnlinePlayer(isOnline) {
- return isOnline ? this.onlines : this.outlines;
- }
- /**是否有AI权限*/
- canAiPlayer(player) {
- if (!this._status) return false;
- if (!this.isHost) return false;
- if (!player || !player.isAI) return false;
- return true;
- }
- /**是否有AI权限Id,返回可以控制的player*/
- canAiPlayerId(id) {
- if (!this._status) return null;
- if (!this.isHost) return null;
- const player = this._players.get(id);
- if (!player) return null;
- if (!player.isAI) return null;
- return player;
- }
- /**是否拥有权限(包括,自己和自己是主机时的ai)*/
- hasPermission(player) {
- return player.isOwn || this.canAiPlayer(player);
- }
- /**创建obj数据*/
- creatObj(data) {
- var _super$getValue;
- if (!this._status) return;
- if (!this.isHost) return;
- let oid = (_super$getValue = super.getValue('oid')) != null ? _super$getValue : 0;
- oid++;
- const key = 'obj_' + oid;
- super.setValue('oid', oid);
- super.setValueDirty('oid', oid);
- super.setValue(key, data);
- super.setValueDirty(key, data);
- this.evt._emit('r_obj', key, data);
- return key;
- }
- /**删除obj数据*/
- getObj(key) {
- return super.getValue(key);
- }
- /**不建议经常更改obj */
- changeObj(key, data) {
- if (!this.isHost) return;
- let old = super.getValue(key);
- if (old) {
- super.setValue(key, data);
- super.setValueDirty(key, data);
- this.evt._emit('r_obj', key, data, old);
- }
- } //
- deleteObj(key) {
- if (!this.isHost) return;
- super.setValue(key, null);
- super.setValueDirty(key, null);
- }
- /**修改某个键的值*/
- setValue(key, data) {
- if (!this._status) return;
- if (!this.isHost) return; //不是主机没有权限
- let old = super.getValue(key);
- if (old) {
- if (typeof data === "object") {//old = JSON.parse(JSON.stringify(old));
- } else if (data === old) {
- return;
- }
- }
- super.setValue(key, data);
- super.setValueDirty(key, data);
- this.evt._emit(key, data, old);
- }
- /**获取数据的值*/
- getValue(key) {
- return super.getValue(key);
- }
- server_change(data) {
- if (!this._status) return;
- if (this.isHost) return;
- Object.keys(data).forEach(key => {
- this.change(key, data[key]);
- });
- }
- change(key, data) {
- const old = super.getValue(key);
- super.setValue(key, data);
- if (typeof data !== "object" && data === old) return;
- if (key === 'oid') {
- return;
- } else if (key.startsWith('obj_')) {
- this.evt._emit('r_obj', key, data, old);
- } else {
- this.evt._emit(key, data, old);
- }
- }
- /**
- * 游戏结算数据
- *
- * @returns {Array} results - 包含游戏结算信息的数组。
- * 每个元素表示一个玩家的结算数据,结构如下:
- *
- * - Id: {string} 玩家唯一标识符
- * - AddScore: {number} 本局游戏中增加的星星数
- * - IsFinish: {boolean} 游戏是否已完成
- * - Rank: {number} 玩家在当前游戏中的排名
- * - Score: {number} 玩家在最后星星数
- * - TotalRank: {number} 玩家的总排名
- * - Level: {Object} 玩家当前等级的信息
- * - LowerRank: {number} 当前段位的等级
- * - Rank: {number} 段位
- * - Star: {number} 当前段位的等级的星级
- * - UserData: {Object} 玩家个人信息
- * - gid: {string} 游戏全局唯一标识符
- * - head: {string} 玩家头像的 URL
- * - hid: {number} 玩家省份id
- * - ip: {string} 玩家 IP 地址
- * - loginTime: {number} 玩家登录时间的时间戳
- * - nickName: {string} 玩家昵称
- * - openId: {string} 玩家在平台上的唯一标识符
- * - option: {string} 玩家选择的选项或设置
- * - pf: {string} 平台信息
- * - registerTime: {number} 玩家注册时间的时间戳
- * - userId: {number} 玩家在系统中的用户 ID
- * - province: {string} 玩家所在的省份
- * - Elements: {Array} 包含其他玩家的结算数据
- * - Rank: {number} 其他玩家的排名
- * - Level: {Object} 其他玩家的等级信息
- * - LowerRank: {number} 其他玩家当前段位的等级
- * - Rank: {number} 其他玩家的段位
- * - Star: {number} 其他玩家段位的等级的星级
- * - UserData: {Object} 其他玩家的个人信息(与上面的 UserData 结构相同)
- */
- get results() {
- return this._results;
- }
- /**获取自己本局获得星星*/
- get own_results_addScore() {
- const rs = this.results;
- if (!rs) return 0;
- for (let i = 0; i < rs.length; i++) {
- if (rs[i].Id === this._own_id) {
- return rs[i].AddScore;
- }
- }
- return 0;
- }
- closed(data) {
- this._status = false;
- this._results.length = 0;
- const ps = Object.keys(data).map(key => ({
- key,
- data: data[key]
- }));
- for (let i = 0; i < ps.length; i++) {
- const key = ps[i].key;
- const user = ps[i].data;
- user.Id = key;
- const player = this.getPlayer(key);
- player.set_level(user.Level, user.Rank, user.Score, user.TotalRank);
- user.UserData = {
- gid: player.gid,
- head: player.head,
- hid: player.hid,
- ip: player.ip,
- loginTime: player.loginTime,
- nickName: player.nickName,
- openId: player.openId,
- option: player.option,
- pf: player.pf,
- registerTime: player.registerTime,
- userId: player.userId,
- province: player.province
- };
- const elements = user.Elements;
- if (elements) {
- for (let i = 0; i < elements.length; i++) {
- var _chsdk$provinceCode2N;
- const o = elements[i];
- o.nickName = o.nickName || '玩家' + o.userId;
- o.hid = Number.parseInt(o.hid);
- o.loginTime = Number.parseInt(o.loginTime);
- o.registerTime = Number.parseInt(o.registerTime);
- o.userId = Number.parseInt(o.userId);
- o.province = (_chsdk$provinceCode2N = chsdk.provinceCode2Name(o.hid)) != null ? _chsdk$provinceCode2N : '其它';
- }
- }
- this._results.push(user);
- }
- ;
- if (this._results.length > 1) {
- this._results.sort((a, b) => {
- if (a.Rank === 0 && b.Rank === 0) {
- return 0;
- } else if (a.Rank === 0) {
- return 1;
- } else if (b.Rank === 0) {
- return -1;
- } else {
- return a.Rank - b.Rank;
- }
- });
- } //
- this.evt._emit('r_closed');
- }
- finish(pid, rank) {
- const player = this.getPlayer(pid);
- if (!player) return;
- player.setFinish(rank);
- this.evt._emit('r_finish', pid, rank);
- }
- /**向房间所有玩家发消息*/
- sendEvt(key, ...data) {
- if (!this._status) return;
- this._waitSends_mode0.push({
- type: key,
- data: data
- });
- }
- /**向房间主机发消息*/
- sendToHost(key, ...data) {
- if (!this._status) return;
- this._waitSends_mode1.push({
- type: key,
- data: data
- });
- }
- /**向房间其它玩家*/
- sendToOther(key, ...data) {
- if (!this._status) return;
- this._waitSends_mode2.push({
- type: key,
- data: data
- });
- }
- /**处理发送事件*/
- doSendMode(f) {
- f(this._waitSends_mode0, this._waitSends_mode1, this._waitSends_mode2);
- this._waitSends_mode0.length = 0;
- this._waitSends_mode1.length = 0;
- this._waitSends_mode2.length = 0;
- }
- /**房间里聊天 ,成功返回true,发送频率过快返回false*/
- chat(msg) {
- const 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) {
- const p = this.getPlayer(id);
- this.evt._emit('r_chat', id, msg, p.location, p.nickName);
- }
- doSendChat(f) {
- f(this._chat_msg);
- this._chat_msg = null;
- } //
- _onEvt(key, data) {
- this.evt._emit(key, ...data);
- } //
- dispose() {
- super.dispose();
- this._players.forEach((v, _) => {
- v.dispose();
- });
- this._players.clear();
- this._status = false;
- this.evt.clearAll();
- }
- });
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=3f8dff31feda7b51e2d0428361dac48e18834ed8.js.map
|