ChessThink.ts 22 KB

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