3992b8f5aeffb73132ac910c2ae7b76d02a98b94.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, NetBase, NetPlayer, _crd;
  4. function _reportPossibleCrUseOfNetBase(extras) {
  5. _reporterNs.report("NetBase", "./NetBase", _context.meta, extras);
  6. }
  7. _export("NetPlayer", void 0);
  8. return {
  9. setters: [function (_unresolved_) {
  10. _reporterNs = _unresolved_;
  11. }, function (_cc) {
  12. _cclegacy = _cc.cclegacy;
  13. }, function (_unresolved_2) {
  14. NetBase = _unresolved_2.NetBase;
  15. }],
  16. execute: function () {
  17. _crd = true;
  18. _cclegacy._RF.push({}, "6fc05FzfGNCnJsa3eEcsw94", "NetPlayer", undefined);
  19. /**网络玩家*/
  20. _export("NetPlayer", NetPlayer = class NetPlayer extends (_crd && NetBase === void 0 ? (_reportPossibleCrUseOfNetBase({
  21. error: Error()
  22. }), NetBase) : NetBase) {
  23. constructor(...args) {
  24. super(...args);
  25. this.evt = chsdk.get_new_event();
  26. this._location = 0;
  27. this._online = true;
  28. this._ready = false;
  29. this._score = 0;
  30. this._rank = 0;
  31. this._totalRank = 0;
  32. this._ishost = true;
  33. this._userData = void 0;
  34. this._rankInfo = void 0;
  35. this._canAI = false;
  36. this._finsh_tag = false;
  37. }
  38. get score() {
  39. return this._score;
  40. }
  41. get rank() {
  42. return this._rank;
  43. }
  44. get totalRank() {
  45. return this._totalRank;
  46. }
  47. /**房间位置0开头*/
  48. get location() {
  49. return this._location;
  50. }
  51. get gid() {
  52. return this._userData.gid;
  53. }
  54. get head() {
  55. return this._userData.head;
  56. }
  57. get hid() {
  58. return this._userData.hid;
  59. }
  60. get province() {
  61. var _chsdk$provinceCode2N;
  62. return (_chsdk$provinceCode2N = chsdk.provinceCode2Name(this._userData.hid)) != null ? _chsdk$provinceCode2N : '其它';
  63. }
  64. get ip() {
  65. return this._userData.ip;
  66. }
  67. get loginTime() {
  68. return this._userData.loginTime;
  69. }
  70. get nickName() {
  71. return this._userData.nickName || '玩家' + this._userData.userId;
  72. }
  73. get openId() {
  74. return this._userData.openId;
  75. }
  76. get option() {
  77. return this._userData.option;
  78. }
  79. get pf() {
  80. return this._userData.pf;
  81. }
  82. get userId() {
  83. return this._userData.userId;
  84. }
  85. get registerTime() {
  86. return this._userData.registerTime;
  87. }
  88. /**是否是主机*/
  89. get isHost() {
  90. return this._ishost;
  91. }
  92. /**是否准备*/
  93. get ready() {
  94. return this._ready;
  95. }
  96. /**是否在线*/
  97. get online() {
  98. return this._online;
  99. }
  100. /**是否能开启匹配*/
  101. get canMatch() {
  102. return this.online && this.ready;
  103. }
  104. /**段位信息*/
  105. get level() {
  106. return this._rankInfo;
  107. }
  108. /**是否是当前玩家自己 */
  109. get isOwn() {
  110. return chsdk.get_uid() === this.userId;
  111. }
  112. /**是否是AI */
  113. get isAI() {
  114. return this._userData.userId < 8888;
  115. }
  116. /**是否有控制当前AI权限*/
  117. get canAI() {
  118. return this._canAI;
  119. }
  120. /**是否有此玩家数据权限*/
  121. get isPermission() {
  122. return this.isOwn || this._canAI;
  123. }
  124. init(pd) {
  125. var _pd$status;
  126. this._location = pd.location;
  127. this._online = (_pd$status = pd.status) != null ? _pd$status : true;
  128. this._ready = pd.teamReady;
  129. this._score = pd.score;
  130. this._rank = pd.rank;
  131. this._totalRank = pd.TotalRank;
  132. this._userData = pd.userData;
  133. this._userData.hid = Number.parseInt(pd.userData.hid);
  134. this._userData.loginTime = Number.parseInt(pd.userData.loginTime);
  135. this._userData.registerTime = Number.parseInt(pd.userData.registerTime);
  136. this._userData.userId = Number.parseInt(pd.userData.userId);
  137. this._rankInfo = pd.userRank;
  138. if (pd.gameData) this.initValue(pd.gameData);
  139. }
  140. set_level(level, rank, score, totalRank) {
  141. this._rankInfo = level;
  142. this._rank = rank;
  143. this._totalRank = totalRank;
  144. this._score = score;
  145. }
  146. set_host(isHost, ownHost) {
  147. this._ishost = isHost;
  148. this._canAI = this.isAI && ownHost;
  149. }
  150. change_online(ol) {
  151. this._online = ol;
  152. this.evt._emit('online', this._online);
  153. }
  154. change_ready(ready) {
  155. this._ready = ready;
  156. this.evt._emit('ready', this._ready);
  157. }
  158. /**修改某个键的值*/
  159. setValue(key, data) {
  160. if (!this.isPermission) return;
  161. let old = super.getValue(key);
  162. if (old) {
  163. if (typeof old === "object") {//old = JSON.parse(JSON.stringify(old));
  164. } else if (data === old) {
  165. return;
  166. }
  167. }
  168. super.setValue(key, data);
  169. super.setValueDirty(key, data);
  170. this.evt._emit(key, data, old);
  171. }
  172. /**获取数据的值*/
  173. getValue(key) {
  174. return super.getValue(key);
  175. } //服务器发送过来的数据
  176. server_change(data) {
  177. if (this.isPermission) return;
  178. Object.keys(data).forEach(key => {
  179. const old = super.getValue(key);
  180. super.setValue(key, data[key]);
  181. this.evt._emit(key, data[key], old);
  182. });
  183. }
  184. setFinish(rank) {
  185. this._rank = rank;
  186. this.evt._emit('finish', this._rank);
  187. }
  188. /**玩家完成游戏 不是自己或主机没有权限*/
  189. finishGame() {
  190. if (!this.isPermission) return;
  191. this._finsh_tag = true;
  192. }
  193. doFinishGame(f) {
  194. if (this._finsh_tag) f(this.Id);
  195. this._finsh_tag = false;
  196. }
  197. dispose() {
  198. super.dispose();
  199. this.evt.clearAll();
  200. }
  201. });
  202. _cclegacy._RF.pop();
  203. _crd = false;
  204. }
  205. };
  206. });
  207. //# sourceMappingURL=3992b8f5aeffb73132ac910c2ae7b76d02a98b94.js.map