ChessThink.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. import { _decorator, Component, Node, Label, Sprite, Animation, SpriteFrame, Texture2D, assetManager, ImageAsset, Slider, tween, Tween, Vec3 } from 'cc';
  2. import { ClientEvent } from '../../clientEvent';
  3. import { Constant } from '../../constant';
  4. import { fill } from '../../fill';
  5. import { fnt_count } from '../../fnt_count';
  6. import { GameMng } from '../../GameMng';
  7. import { ResMng } from '../../gcommon/ResMng';
  8. import { UIButton } from '../../gcommon/UIButton';
  9. import { UIManager } from '../../gcommon/UIManager';
  10. import { emote } from '../../Main/emote';
  11. import { msgManager } from '../../socket/msgManager';
  12. import { Tools } from '../../Tools';
  13. import { roomData } from '../../UserData/roomData';
  14. import { timeCountData } from '../../UserData/timeCountData';
  15. import ChessMng, { ChessType } from '../DiffSel/ChessMng';
  16. import UIDiffSel from '../DiffSel/UIDiffSel';
  17. import { waitJifen } from '../waitJifen';
  18. import GBoardChess from './GBoardChess';
  19. const { ccclass, property } = _decorator;
  20. @ccclass('ChessThink')
  21. export class ChessThink extends Component {
  22. @property(Node)
  23. self_head: Node = null;
  24. @property(Node)
  25. self_think: Node = null;
  26. @property(Node)
  27. self_think_bai: Node = null;
  28. @property(Node)
  29. self_name: Node = null;
  30. @property(Node)
  31. self_allTime: Node = null;//总剩余时间
  32. @property(Node)
  33. self_curCountTime: Node = null; //当前思考倒计时
  34. @property(Node)
  35. self_time_node: Node = null; //
  36. @property(Node)
  37. self_fnt_count: Node = null; //
  38. @property(Node)
  39. self_emote: Node = null; //
  40. @property(Node)
  41. self_head_btn: Node = null; //
  42. @property(Node)
  43. rival_head_btn: Node = null; //
  44. @property(Node)
  45. rival_emote: Node = null; //对手
  46. @property(Node)
  47. self_chat: Node = null; //
  48. @property(Node)
  49. rival_chat: Node = null; //对手
  50. @property(Node)
  51. rival_head: Node = null; //对手
  52. @property(Node)
  53. rival_think: Node = null; //对手
  54. @property(Node)
  55. rival_think_bai: Node = null; //对手
  56. @property(Node)
  57. rival_name: Node = null;
  58. @property(Node)
  59. rival_allTime: Node = null;//总剩余时间
  60. @property(Node)
  61. rival_curCountTime: Node = null; //当前思考倒计时
  62. @property(Node)
  63. rival_time_node: Node = null; //
  64. @property(Node)
  65. rival_ready_status_lab: Node = null; //对手准备状态信息
  66. @property(Node)
  67. btn_kick: Node = null; //踢出
  68. @property(Node)
  69. rival_offline: Node = null;
  70. @property(Node)
  71. rival_fnt_count: Node = null; //
  72. @property(Node)
  73. sf_rival_offline: Node = null; //对手离线
  74. @property(Node)
  75. rival_ready: Node = null; //对手准备
  76. @property(Node)
  77. ti_rival: Node = null; //踢出对手
  78. @property(Node)
  79. rival_dumiao_node: Node = null; //对手读秒
  80. @property(Node)
  81. rival_dumiao_lab: Node = null; //对手读秒
  82. @property(Node)
  83. self_dumiao_node: Node = null; //自己读秒
  84. @property(Node)
  85. self_dumiao_lab: Node = null; //自己读秒
  86. isThink:boolean = false;
  87. isPause:boolean = false;
  88. self_total_time:number = 0;
  89. self_every_step_time:number = 0;
  90. rival_total_time:number = 0;
  91. rival_every_step_time:number = 0;
  92. start() {
  93. //this.ti_rival.active = false;
  94. UIButton.BindClick(this.btn_kick,this.kickRival,this)
  95. UIButton.BindClick(this.self_head_btn,()=>{
  96. UIManager.addUserInfoViewPrefab(GameMng._userData)
  97. },this)
  98. UIButton.BindClick(this.rival_head_btn,()=>{
  99. if(GameMng._userData.room!=null&&GameMng._userData.room.rival!=null&&GameMng._userData.room.rival!=undefined){
  100. UIManager.addUserInfoViewPrefab(GameMng._userData.room.rival)
  101. }
  102. },this)
  103. ClientEvent.on(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  104. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.showRivalChat,this)
  105. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.showSelfChat,this)
  106. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_SELF_EMOTE,this.showSelfEmote,this)
  107. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_EMOTE,this.showRivalEmote,this)
  108. }
  109. onDestroy(){
  110. ClientEvent.off(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  111. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.showRivalChat,this)
  112. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.showSelfChat,this)
  113. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_SELF_EMOTE,this.showSelfEmote,this)
  114. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_EMOTE,this.showRivalEmote,this)
  115. this.unschedule(this.updateTime)
  116. }
  117. showSelfEmote(em_id:number){
  118. this.self_emote.active = true;
  119. this.self_emote.getComponent(emote).show(em_id)
  120. Tween.stopAllByTarget(this.self_emote)
  121. tween(this.self_emote).delay(2).call(()=>{
  122. this.self_emote.active = false;
  123. }).start()
  124. }
  125. showRivalEmote(em_id:number){
  126. this.rival_emote.active = true;
  127. this.rival_emote.getComponent(emote).show(em_id)
  128. Tween.stopAllByTarget(this.rival_emote)
  129. tween(this.rival_emote).delay(2).call(()=>{
  130. this.rival_emote.active = false;
  131. }).start()
  132. }
  133. showSelfChat(chat_str:string){
  134. this.self_chat.active = true;
  135. GameMng.add_chat_history(GameMng._userData.user_name+": "+chat_str)
  136. this.self_chat.getChildByName("Label").getComponent(Label).string = chat_str;
  137. tween(this.self_chat).delay(2).call(()=>{
  138. this.self_chat.active = false;
  139. }).start()
  140. }
  141. showRivalChat(chat_str:string){
  142. this.rival_chat.active = true;
  143. if(GameMng._userData.room.rival!=null){
  144. GameMng.add_chat_history(GameMng._userData.room.rival.user_name+": "+chat_str)
  145. }else{
  146. GameMng.add_chat_history("对手10001: "+chat_str)
  147. }
  148. this.rival_chat.getChildByName("Label").getComponent(Label).string = chat_str;
  149. tween(this.rival_chat).delay(2).call(()=>{
  150. this.rival_chat.active = false;
  151. }).start()
  152. }
  153. startThink(loacl_reset?:boolean,sever_reset?:boolean){
  154. var temp = new timeCountData()
  155. if(loacl_reset){
  156. if(GameMng._userData.room.time_count_data!=null&&GameMng._userData.room.time_count_data!=undefined){
  157. temp.self_total_time = GameMng._userData.room.time_count_data.self_total_time
  158. temp.self_every_step_time = temp.self_total_time>GameMng._userData.room.time_count_data.self_every_step_time?GameMng._userData.room.everysteptime:GameMng._userData.room.time_count_data.self_every_step_time
  159. temp.rival_total_time = GameMng._userData.room.time_count_data.rival_total_time
  160. temp.rival_every_step_time = temp.rival_total_time>GameMng._userData.room.time_count_data.rival_every_step_time?GameMng._userData.room.everysteptime:GameMng._userData.room.time_count_data.rival_every_step_time
  161. }else{
  162. temp.self_total_time = GameMng._userData.room.totaltime
  163. temp.self_every_step_time = GameMng._userData.room.everysteptime
  164. temp.rival_total_time = GameMng._userData.room.totaltime
  165. temp.rival_every_step_time = GameMng._userData.room.everysteptime
  166. }
  167. if(!sever_reset){
  168. }else{
  169. this.isPause = false;
  170. temp = GameMng._userData.room.time_count_data
  171. }
  172. }else{
  173. temp = GameMng._userData.room.time_count_data
  174. }
  175. this.self_total_time = temp.self_total_time
  176. this.self_every_step_time = temp.self_every_step_time
  177. this.rival_total_time = temp.rival_total_time
  178. this.rival_every_step_time = temp.rival_every_step_time
  179. if(sever_reset){
  180. this.updateTimeLab()
  181. }
  182. if(!this.isThink){
  183. this.isThink = true;
  184. this.isPause = false;
  185. this.unschedule(this.updateTime)
  186. this.schedule(this.updateTime,1)
  187. this.self_fnt_count.active = false;
  188. this.rival_fnt_count.active = false;
  189. this.self_time_node.active = true;
  190. this.rival_time_node.active = true;
  191. this.updateTime()
  192. }
  193. // if(!this.self_time_node.active){
  194. // }
  195. }
  196. stopThink(){
  197. this.isThink = false;
  198. this.isPause = true;
  199. this.unschedule(this.updateTime)
  200. this.self_time_node.active = false;
  201. this.rival_time_node.active = false;
  202. this.self_fnt_count.active = false;
  203. this.rival_fnt_count.active = false;
  204. this.stopAni()
  205. }
  206. stopAni(){
  207. this.self_think.getComponent(fill).stopAni();
  208. this.self_think_bai.getComponent(fill).stopAni();
  209. this.rival_think.getComponent(fill).stopAni();
  210. this.rival_think_bai.getComponent(fill).stopAni();
  211. }
  212. updateTime(){
  213. if(!GameMng._userData.room||this.isPause)return
  214. if(GBoardChess.instance.isStartGame&&GameMng._userData.room.time_count_data){
  215. this.updateTimeLab()
  216. if(GBoardChess.instance.who_round==1){
  217. this.self_think.active = true;
  218. this.self_think_bai.active = true;
  219. this.rival_think.active = false;
  220. this.rival_think_bai.active = false;
  221. this.self_total_time-=1;
  222. this.self_every_step_time-=1;
  223. if(this.self_total_time<0){
  224. this.self_total_time = 0;
  225. }
  226. if(this.self_every_step_time<0){
  227. this.self_every_step_time = 0;
  228. }
  229. }else{
  230. this.self_think.active = false;
  231. this.self_think_bai.active = false;
  232. this.rival_think.active = true;
  233. this.rival_think_bai.active = true;
  234. this.rival_total_time-=1;
  235. this.rival_every_step_time-=1;
  236. if(this.rival_total_time<0){
  237. this.rival_total_time = 0;
  238. }
  239. if(this.rival_every_step_time<0){
  240. this.rival_every_step_time = 0;
  241. }
  242. }
  243. }
  244. }
  245. updateLab(){
  246. }
  247. updateTimeLab(){
  248. this.self_allTime.getComponent(Label).string = Tools.ms_time(this.self_total_time)
  249. this.rival_allTime.getComponent(Label).string = Tools.ms_time(this.rival_total_time)
  250. this.self_curCountTime.getComponent(Label).string = Tools.ms_time(this.self_every_step_time)
  251. this.rival_curCountTime.getComponent(Label).string = Tools.ms_time(this.rival_every_step_time)
  252. this.self_dumiao_lab.getComponent(Label).string = Tools.ms_time(this.self_every_step_time)
  253. this.rival_dumiao_lab.getComponent(Label).string = Tools.ms_time(this.rival_every_step_time)
  254. var is_self_du_miao = GameMng._userData.room.time_count_data.self_countdown>0;
  255. var is_rival_du_miao = GameMng._userData.room.time_count_data.rival_countdown>0
  256. if(GBoardChess.instance.who_round==1){
  257. if(is_self_du_miao){ //说明有读秒要走
  258. this.self_dumiao_node.active = true;
  259. this.self_time_node.active = false;
  260. }
  261. }else{
  262. if(is_rival_du_miao){ //说明有读秒要走
  263. this.rival_dumiao_node.active = true;
  264. this.rival_time_node.active = false;
  265. }
  266. }
  267. let everysteptime = GameMng._userData.room.everysteptime;
  268. if(ChessMng.Instance.isJiFenRoom()){
  269. if(GBoardChess.instance.rund_number<6){
  270. everysteptime = 30
  271. }
  272. }
  273. let self_du_miao_time = everysteptime;
  274. let rival_du_miao_time = everysteptime;
  275. if(is_self_du_miao){ //说明有读秒要走
  276. self_du_miao_time = GameMng._userData.room.countdown;
  277. }
  278. if(is_rival_du_miao){ //说明有读秒要走
  279. rival_du_miao_time = GameMng._userData.room.countdown;
  280. }
  281. if(GBoardChess.instance.who_round==1){
  282. this.self_think_bai.getComponent(fill).startAni(this.self_every_step_time+self_du_miao_time*0.03,self_du_miao_time)
  283. this.self_think.getComponent(fill).startAni(this.self_every_step_time,self_du_miao_time)
  284. }else{
  285. this.rival_think_bai.getComponent(fill).startAni(this.rival_every_step_time+rival_du_miao_time*0.03,rival_du_miao_time)
  286. this.rival_think.getComponent(fill).startAni(this.rival_every_step_time,rival_du_miao_time)
  287. }
  288. if(GameMng._userData.room.time_count_data!=null){
  289. if(GameMng._userData.room.time_count_data.self_every_step_time<=0||GameMng._userData.room.time_count_data.rival_every_step_time<=0){
  290. this.isPause = true
  291. this.stopAni()
  292. }
  293. if(GameMng._userData.room.time_count_data.self_every_step_time>10||GBoardChess.instance.who_round==0){
  294. this.self_name.active = true;
  295. if(is_self_du_miao){
  296. this.self_dumiao_node.active = true;
  297. }else{
  298. this.self_time_node.active = true;
  299. }
  300. this.self_fnt_count.active = false;
  301. }else{
  302. this.self_time_node.active = false;
  303. this.self_dumiao_node.active = false;
  304. this.self_name.active = false;
  305. this.self_fnt_count.active = true;
  306. this.self_fnt_count.getComponent(fnt_count).show(this.self_every_step_time)
  307. }
  308. if(GameMng._userData.room.time_count_data.rival_every_step_time>10||GBoardChess.instance.who_round==1){
  309. this.rival_name.active = true;
  310. if(is_rival_du_miao){
  311. this.rival_dumiao_node.active = true;
  312. }else{
  313. this.rival_dumiao_node.active = false;
  314. this.rival_time_node.active = true;
  315. }
  316. this.rival_fnt_count.active = false;
  317. }else{
  318. this.rival_dumiao_node.active = false;
  319. this.rival_name.active = false;
  320. this.rival_time_node.active = false;
  321. this.rival_fnt_count.active = true;
  322. this.rival_fnt_count.getComponent(fnt_count).show(this.rival_every_step_time)
  323. }
  324. }
  325. }
  326. kickRival(){
  327. this.ti_rival.active = true;
  328. this.scheduleOnce(()=>{
  329. msgManager.kickRival()
  330. this.ti_rival.getComponent(Animation).stop()
  331. this.rival_head.active = false;
  332. this.rival_head.position = new Vec3(0,0,0)
  333. this.rival_head.angle = 0;
  334. },0.8)
  335. this.btn_kick.active = false;
  336. this.rival_name.active = false;
  337. this.rival_time_node.active = false;
  338. this.ti_rival.getComponent(Animation).play()
  339. }
  340. //对手加入房间
  341. onJoinRoom(room:roomData){
  342. GameMng.updateRoomData(room)
  343. this.StatusShow()
  344. UIManager.removeLoadingLayer()
  345. console.log("onJoinRoom",room)
  346. }
  347. setData(){
  348. }
  349. round_time_count(){
  350. if(GameMng._userData.room.time_count_data!=null){
  351. }
  352. }
  353. //等待状态显示
  354. StatusShow(){
  355. if(!GBoardChess.instance.isStartGame||ChessMng.Instance.chesstype==ChessType.renjiboyi){
  356. this.self_time_node.active = false;
  357. this.rival_time_node.active = false;
  358. this.self_think.active = false;
  359. this.rival_think.active = false;
  360. this.rival_offline.active = false;
  361. this.btn_kick.active = false;
  362. this.rival_ready_status_lab.active = false;
  363. this.sf_rival_offline.active = false;
  364. this.rival_ready.active = false;
  365. this.self_dumiao_node.active = false;
  366. }
  367. let self = this;
  368. if(ChessMng.Instance.chesstype==ChessType.renjiboyi){
  369. this.rival_head.active = true;
  370. this.rival_name.getComponent(Label).string = UIDiffSel.lvArr[UIDiffSel.selectIndex];
  371. ResMng.LoadAvatar(Tools.getAvatarByIndex(UIDiffSel.selectIndex+1),this.rival_head.getComponent(Sprite))
  372. }else{
  373. if(GameMng._userData.room!=null){
  374. console.log("GameMng._userData.room.wait_rival_status",GameMng._userData.room.wait_rival_startGame_status)
  375. //GameMng._userData.room.wait_rival_status===undefined||GameMng._userData.room.wait_rival_status===0||
  376. if(GameMng._userData.room.rival===null||GameMng._userData.room.rival===undefined){ //房间没有来人
  377. this.rival_head.active = false;
  378. this.rival_name.active = false;
  379. this.rival_head.getComponent(Sprite).spriteFrame = null;
  380. //this.rival_ready_status_lab.getComponent(Label).string = "暂无人员加入"
  381. if(ChessMng.Instance.isJiFenRoom()){
  382. if(GameMng._userData.room.wait_rival_startGame_status===1){
  383. if(ChessMng.Instance.isJiFenRoom()){
  384. GBoardChess.instance.wait_jifen.getComponent(waitJifen).recvReady(GameMng._userData.room)
  385. }
  386. this.rival_ready_status_lab.active = true;
  387. this.rival_ready_status_lab.getComponent(Label).string = "正在匹配..."
  388. }
  389. }
  390. }else{
  391. this.rival_head.active = true;
  392. this.rival_name.active = true;
  393. if(GameMng._userData.room.rival.user_avatar!=""){
  394. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head.getComponent(Sprite))
  395. }
  396. let rival_name = GameMng._userData.room.rival.user_name;
  397. if(ChessMng.Instance.isJiFenRoom()){
  398. rival_name = "["+ GameMng._userData.room.rival.integral_level_name +"] "+rival_name
  399. }
  400. this.rival_name.getComponent(Label).string =rival_name
  401. switch(GameMng._userData.room.wait_rival_startGame_status){
  402. case 0:case 1:{
  403. this.stopThink()
  404. this.rival_ready.active = false;
  405. //this.rival_ready_status_lab.getComponent(Label).string = "未准备"
  406. break;
  407. }
  408. case 2:{
  409. this.rival_ready.active = true;
  410. // this.rival_ready_status_lab.getComponent(Label).string = "已准备"
  411. break;
  412. }
  413. case 3:{
  414. this.rival_ready.active = false;
  415. break;
  416. }
  417. }
  418. if(GameMng._userData.room.ownerid===GameMng._userData.userid){ //说明我是房主
  419. if(GameMng._userData.room.wait_rival_startGame_status!=3){ //还没开局
  420. this.btn_kick.active = true;
  421. }
  422. }
  423. }
  424. if(GameMng._userData.room.rival!=null){
  425. this.rival_offline.active = false;
  426. if(GameMng._userData.room.rivalIsOffline==1){
  427. this.sf_rival_offline.active = true;
  428. //this.rival_offline.getComponent(Label).string = "离线"
  429. }else{
  430. this.sf_rival_offline.active = false;
  431. //this.rival_offline.getComponent(Label).string = "在线"
  432. }
  433. }
  434. }
  435. }
  436. let self_name = GameMng._userData.user_name;
  437. if(ChessMng.Instance.isJiFenRoom()){
  438. self_name = "["+ GameMng._userData.integral_level_name +"] "+self_name
  439. }
  440. this.self_name.getComponent(Label).string = self_name;
  441. if(this.self_head.getComponent(Sprite).spriteFrame ==null&&GameMng._userData.user_avatar!=""){
  442. Tools.loadWeiXinHead(GameMng._userData.user_avatar,this.self_head.getComponent(Sprite))
  443. }
  444. }
  445. update(deltaTime: number) {
  446. }
  447. }