BRTPPlayerView.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. var GamePlayer = require("GamePlayer");
  2. var Define = require("Define");
  3. var ProtocolGameServer = require("ProtocolGameServer");
  4. var BRTPSoundFun = require("BRTPSoundFun");
  5. var Global = require("Global");
  6. var UIHelper = require("UIHelper");
  7. import { CServerItem } from 'CServerItem'
  8. var voice = {
  9. localId: "",
  10. serverId: "",
  11. };
  12. cc.Class({
  13. extends: GamePlayer,
  14. //extends: cc.Component,
  15. properties: {
  16. sprHeadIcon:cc.Sprite,
  17. sprVipIcon:cc.Sprite, // VIP框
  18. btnHead:cc.Button,
  19. sprEmptyHeadIcon:cc.Sprite,
  20. labScoreWin:cc.Label,
  21. labScoreLose:cc.Label,
  22. labName:cc.Label,
  23. sprOffineFlag:cc.Sprite,
  24. sprScoreBg:cc.Sprite,
  25. spriteFrame:{
  26. default:null,
  27. type:cc.SpriteFrame
  28. },
  29. //牌的显示和操作
  30. cardNode: {
  31. default:null,
  32. type:cc.Node
  33. },
  34. goldPrefabArr: { //金豆预制数组
  35. default: [],
  36. type: [cc.Prefab]
  37. },
  38. iIndex:-1,
  39. _myScore:0,
  40. _chairID:-1,
  41. },
  42. // LIFE-CYCLE CALLBACKS:
  43. onLoad: function() {
  44. this.sprVipIcon.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  45. this.sprVipIcon.node.width = 120;
  46. this.sprVipIcon.node.height = 120;
  47. this.sprVipIcon.node.scale = 1;
  48. },
  49. init: function(index) {
  50. },
  51. resetCard:function()
  52. {
  53. this.node.getChildByName("scoreAni").active = false;
  54. this.node.getChildByName("bombOpenAniNode").active = false;
  55. this.node.getChildByName("bomb").active = false;
  56. },
  57. resetView: function() {
  58. this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").active = false;
  59. this.node.getChildByName("scoreAni").active = false;
  60. this.node.stopAllActions();
  61. },
  62. hideVoice: function() {
  63. this.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = false;
  64. },
  65. addScore: function(lScore,bAni)
  66. {
  67. this.node.getChildByName("addInfoNode").active = true;
  68. var pos = this.node.getChildByName("addInfoNode").getPosition();
  69. var goldNode = this.node.getChildByName("addInfoNode").getChildByName("goldNode");
  70. var posDe = goldNode.getPosition();
  71. var scoreNode = this.node.getChildByName("addInfoNode").getChildByName("scoreNode");
  72. if(bAni)
  73. {
  74. //音效
  75. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
  76. if (CServerItem.get().mGameServer.ServerType == 1) //金豆场金豆
  77. {
  78. var count_10w = parseInt(lScore/100000);
  79. var count_1w = parseInt((lScore-count_10w*100000)/10000);
  80. var count_1000 = parseInt((lScore-count_10w*100000-count_1w*10000)/1000);
  81. var count_100 = parseInt((lScore-count_10w*100000-count_1w*10000-count_1000*1000)/100);
  82. for(let i=0; i<count_10w;i++)
  83. {
  84. let gold = cc.instantiate(this.goldPrefabArr[4]);
  85. gold.parent = goldNode;
  86. gold.setPosition(cc.v2(-pos.x,-pos.y));
  87. let randx = Math.floor(Math.random() * 70);
  88. let randy = Math.floor(Math.random() * 50);
  89. let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
  90. gold.runAction(moveto);
  91. }
  92. for(let i=0; i<count_1w;i++)
  93. {
  94. let gold = cc.instantiate(this.goldPrefabArr[3]);
  95. gold.parent = goldNode;
  96. gold.setPosition(cc.v2(-pos.x,-pos.y));
  97. let randx = Math.floor(Math.random() * 70);
  98. let randy = Math.floor(Math.random() * 50);
  99. let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
  100. gold.runAction(moveto);
  101. }
  102. for(let i=0; i<count_1000;i++)
  103. {
  104. let gold = cc.instantiate(this.goldPrefabArr[2]);
  105. gold.parent = goldNode;
  106. gold.setPosition(cc.v2(-pos.x,-pos.y));
  107. let randx = Math.floor(Math.random() * 70);
  108. let randy = Math.floor(Math.random() * 50);
  109. let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
  110. gold.runAction(moveto);
  111. }
  112. for(let i=0; i<count_100;i++)
  113. {
  114. let gold = cc.instantiate(this.goldPrefabArr[1]);
  115. gold.parent = goldNode;
  116. gold.setPosition(cc.v2(-pos.x,-pos.y));
  117. let randx = Math.floor(Math.random() * 70);
  118. let randy = Math.floor(Math.random() * 50);
  119. let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
  120. gold.runAction(moveto);
  121. }
  122. }
  123. else
  124. {
  125. for(let i=0; i<lScore; i++)
  126. {
  127. var gold = cc.instantiate(this.goldPrefabArr[0]);
  128. gold.parent = goldNode;
  129. gold.setPosition(cc.v2(-pos.x,-pos.y));
  130. var randx = Math.floor(Math.random() * 70);
  131. var randy = Math.floor(Math.random() * 50);
  132. var moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
  133. gold.runAction(moveto);
  134. }
  135. }
  136. var isshow = CServerItem.get().mGameServer.ServerType != 1;
  137. this.node.runAction(cc.sequence(cc.delayTime(0.3), cc.callFunc(() => {
  138. scoreNode.getChildByName("score").getComponent(cc.Label).string = lScore;
  139. scoreNode.active = true;
  140. scoreNode.getChildByName("fen").active = isshow;
  141. }, this)));
  142. }
  143. else
  144. {
  145. if (CServerItem.get().mGameServer.ServerType == 1) //金豆场金豆
  146. {
  147. var count_10w = parseInt(lScore/100000);
  148. var count_1w = parseInt((lScore-count_10w*100000)/10000);
  149. var count_1000 = parseInt((lScore-count_10w*100000-count_1w*10000)/1000);
  150. var count_100 = parseInt((lScore-count_10w*100000-count_1w*10000-count_1000*1000)/100);
  151. for(let i=0; i<count_10w;i++)
  152. {
  153. let gold = cc.instantiate(this.goldPrefabArr[4]);
  154. gold.parent = goldNode;
  155. let randx = Math.floor(Math.random() * 70);
  156. let randy = Math.floor(Math.random() * 50);
  157. gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
  158. }
  159. for(let i=0; i<count_1w;i++)
  160. {
  161. let gold = cc.instantiate(this.goldPrefabArr[3]);
  162. gold.parent = goldNode;
  163. let randx = Math.floor(Math.random() * 70);
  164. let randy = Math.floor(Math.random() * 50);
  165. gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
  166. }
  167. for(let i=0; i<count_1000;i++)
  168. {
  169. let gold = cc.instantiate(this.goldPrefabArr[2]);
  170. gold.parent = goldNode;
  171. let randx = Math.floor(Math.random() * 70);
  172. let randy = Math.floor(Math.random() * 50);
  173. gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
  174. }
  175. for(let i=0; i<count_100;i++)
  176. {
  177. let gold = cc.instantiate(this.goldPrefabArr[1]);
  178. gold.parent = goldNode;
  179. let randx = Math.floor(Math.random() * 70);
  180. let randy = Math.floor(Math.random() * 50);
  181. gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
  182. }
  183. }
  184. else
  185. {
  186. for(let i=0; i<lScore; i++)
  187. {
  188. var gold = cc.instantiate(this.goldPrefabArr[0]);
  189. gold.parent = goldNode;
  190. var randx = Math.floor(Math.random() * 70);
  191. var randy = Math.floor(Math.random() * 50);
  192. gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
  193. }
  194. }
  195. var isshow = CServerItem.get().mGameServer.ServerType != 1;
  196. scoreNode.getChildByName("score").getComponent(cc.Label).string = lScore;
  197. scoreNode.active = true;
  198. scoreNode.getChildByName("fen").active = isshow;
  199. }
  200. },
  201. playerEnter: function() {
  202. this.labName.node.active = true;
  203. this.sprEmptyHeadIcon.node.active = false;
  204. this.sprHeadIcon.node.active = true;
  205. //百人场 不需要显示金豆,昵称
  206. this.btnHead.node.userID = this.getUserID();
  207. this.btnHead.node.gameID = this.getGameID();
  208. },
  209. playerLeave:function() {
  210. // this.node.active = false;
  211. // this.sprVipIcon.node.active = false;
  212. },
  213. upPlayerState: function() {
  214. this.setOffline(this.getUserStatus() == Define.US_OFFLINE);
  215. if (this.getUserStatus() == Define.US_OFFLINE) {
  216. //置灰
  217. // this.sprHeadIcon.node.color = cc.Color.GRAY;
  218. }
  219. else {
  220. //复原
  221. this.sprHeadIcon.node.color = cc.Color.WHITE;
  222. }
  223. },
  224. upPlayerInfo: function() {
  225. if (this.getNickName() != "") {
  226. var str = this.getNickName();
  227. this.labName.string = str;//Global.subStr(str);
  228. }
  229. if (CServerItem.get().mGameServer.ServerType == 1)
  230. {
  231. this.setScore(this.getUserScore());
  232. }
  233. // vip 头像框
  234. let vipID = this.getVIPLevel();
  235. let node = this.sprVipIcon;
  236. Global.print("upPlayerHead")
  237. if(vipID >= 4 && vipID <= 7) {
  238. // if(this.iIndex == 0) {
  239. node.getComponent(cc.Sprite).spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
  240. node.active = true;
  241. // }
  242. }else{
  243. node.active = false;
  244. }
  245. },
  246. setChairID: function(chairID){
  247. this._chairID = chairID
  248. },
  249. getChairID: function(){
  250. return this._chairID;
  251. },
  252. getnickName: function()
  253. {
  254. return this.labName.string
  255. },
  256. upPlayerHead: function() {
  257. var self=this;
  258. if (this.getHeadHttp() != "") {
  259. // 设置头像
  260. this.sprHeadIcon.getComponent("urlSpriteFrame").loadAvatar(this.getHeadHttp(),null, {width:100, height:100});
  261. } else {
  262. this.sprHeadIcon.spriteFrame = this.spriteFrame;
  263. this.sprHeadIcon.node.width = 100;
  264. this.sprHeadIcon.node.height = 100;
  265. }
  266. let vipID = this.getVIPLevel();
  267. if(vipID >= 4 && vipID <= 7) {
  268. this.sprVipIcon.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
  269. this.sprVipIcon.node.active = true;
  270. }else{
  271. this.sprVipIcon.node.active = false;
  272. }
  273. },
  274. getHeadIcon: function(ret) {
  275. if(ret)
  276. {
  277. return this.sprHeadIcon.spriteFrame;
  278. }
  279. if (this.getHeadHttp() != "") {
  280. return this.sprHeadIcon.spriteFrame;
  281. }
  282. return null;
  283. },
  284. showTalkState: function(data) {
  285. if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TALK_TYPE) {
  286. }
  287. if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD) {
  288. this.runPaoMaDeng(data.String);
  289. }
  290. if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_DEFINE) {
  291. var strArr = data.String.split(":",2);
  292. BRTPSoundFun.playEffectDefineString(strArr[0]);
  293. this.runPaoMaDeng(strArr[1]);
  294. }
  295. if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING) {
  296. this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").active = true;
  297. var cpgAni = this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").getComponent(sp.Skeleton);
  298. var aniName = data.String.substr(0,2);
  299. cpgAni.setAnimation(0,aniName,false);
  300. }
  301. },
  302. showVoice: function(data) {
  303. this.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = true;
  304. var self = this;
  305. var voice1 = this.node.getChildByName("ChatNode").getChildByName("VoiceNode").getChildByName("Voice1");
  306. var voice2 = this.node.getChildByName("ChatNode").getChildByName("VoiceNode").getChildByName("Voice2");
  307. voice1.active = false;
  308. voice2.active = false;
  309. var time = 0;
  310. var Voice1Visible = function() {
  311. voice1.active = true;
  312. voice1.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice1NoVisible)));
  313. }
  314. var Voice2Visible = function() {
  315. time += 0.6;
  316. voice2.active = true;
  317. voice2.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice2NoVisible)));
  318. }
  319. var Voice1NoVisible = function() {
  320. if (time > 5)
  321. {
  322. return;
  323. }
  324. voice1.active = false;
  325. voice1.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice1Visible)));
  326. }
  327. var Voice2NoVisible = function() {
  328. time += 0.6;
  329. if (time > 5)
  330. {
  331. self.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = false;
  332. }
  333. else
  334. {
  335. voice2.active = false;
  336. voice2.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice2Visible)));
  337. }
  338. }
  339. voice.serverId = data.SerVerID;
  340. voice1.runAction(cc.callFunc(Voice1Visible));
  341. voice2.runAction(cc.sequence(cc.delayTime(0.3),cc.callFunc(Voice2Visible)));
  342. },
  343. runPaoMaDeng: function(content) {
  344. var chatBubble = this.node.getChildByName("ChatNode").getChildByName("ChatBubble");
  345. chatBubble.active = true;
  346. chatBubble.opacity = 255;
  347. chatBubble.stopAllActions();
  348. var label = chatBubble.getChildByName("msg");
  349. label.active = true;
  350. label.getComponent(cc.Label).string = content;
  351. chatBubble.height = label.height + 33;
  352. var fadeOut = cc.sequence(cc.delayTime(4),cc.fadeOut(2.0));
  353. chatBubble.runAction(fadeOut);
  354. },
  355. setScore: function(score)
  356. {
  357. this._myScore = score;
  358. var ScoreImagic = this.node.getChildByName("PlayerInfo").getChildByName("ScoreImagic");
  359. var strScore = this.changeScore(Global.formatString2Score(score));
  360. ScoreImagic.getChildByName("Score").getComponent(cc.Label).string = strScore;
  361. },
  362. getScore: function() {
  363. return this._myScore;
  364. },
  365. addScoreAni: function(score)
  366. {
  367. if(score == 0){
  368. return;
  369. }
  370. var s = Math.abs(score);
  371. var strScore = this.changeScore(s);
  372. var scoreAni = this.node.getChildByName("scoreAni");
  373. if(score < 0)
  374. {
  375. scoreAni.getChildByName("scoreWinLabel").active = false;
  376. scoreAni.getChildByName("scoreLoseLabel").active = true;
  377. scoreAni.getChildByName("scoreLoseLabel").getChildByName("label").getComponent(cc.Label).string = "-"+strScore;
  378. }
  379. else if(score > 0)
  380. {
  381. scoreAni.getChildByName("scoreWinLabel").active = true;
  382. scoreAni.getChildByName("scoreLoseLabel").active = false;
  383. scoreAni.getChildByName("scoreWinLabel").getChildByName("label").getComponent(cc.Label).string = "+"+strScore;
  384. }
  385. scoreAni.active = true;
  386. scoreAni.getComponent(cc.Animation).play("showScoreAni");
  387. },
  388. setHost: function(isHost) {
  389. this.sprHostFlag.node.active = isHost;
  390. },
  391. setStatusHu: function(isHu) {
  392. this.node.getChildByName("Status_Hu").active = isHu;
  393. },
  394. setOffline: function(isOffline) {
  395. // this.sprOffineFlag.node.active = isOffline;
  396. },
  397. setReady: function(isReady) {
  398. this.sprReadyFlag.node.active = isReady;
  399. },
  400. resetSeatPos: function(pos) {
  401. this.node.getChildByName("PlayerHead").position = pos;
  402. },
  403. playMoveAction: function(pos) {
  404. var moveto = cc.moveTo(1,pos);
  405. this.node.getChildByName("PlayerHead").runAction(moveto);
  406. },
  407. startGameNoTime: function(pos) {
  408. this.node.getChildByName("PlayerHead").setPosition(pos);
  409. },
  410. playWinAni: function() {
  411. const aniNode = this.node.getChildByName("WinAni");
  412. if(aniNode) {
  413. aniNode.active = true;
  414. aniNode.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
  415. // aniNode.getComponent(sp.Skeleton).setTrackCompleteListener(
  416. // () => {
  417. // aniNode.active = false;
  418. // }
  419. // );
  420. }
  421. },
  422. changeScore (score,isEnglish) {
  423. var strScore = score.toString();
  424. if(score >= 100000000000) //千亿
  425. {
  426. strScore = strScore.slice(0,4);
  427. // strScore = parseInt(strScore) / 10;
  428. if(isEnglish)
  429. {
  430. strScore = strScore + "y"
  431. }
  432. else
  433. {
  434. strScore = strScore + "亿"
  435. }
  436. }
  437. else if(score >= 10000000000) //百亿
  438. {
  439. strScore = strScore.slice(0,3);
  440. // strScore = parseInt(strScore) / 10;
  441. if(isEnglish)
  442. {
  443. strScore = strScore + "y"
  444. }
  445. else
  446. {
  447. strScore = strScore + "亿"
  448. }
  449. }
  450. else if(score >= 1000000000) //十亿
  451. {
  452. strScore = strScore.slice(0,3);
  453. strScore = parseInt(strScore) / 10;
  454. if(isEnglish)
  455. {
  456. strScore = strScore + "y"
  457. }
  458. else
  459. {
  460. strScore = strScore + "亿"
  461. }
  462. }
  463. else if(score >= 100000000) //亿
  464. {
  465. strScore = strScore.slice(0,3);
  466. strScore = parseInt(strScore) / 100;
  467. if(isEnglish)
  468. {
  469. strScore = strScore + "y"
  470. }
  471. else
  472. {
  473. strScore = strScore + "亿"
  474. }
  475. }
  476. else if(score >= 10000000) //千万
  477. {
  478. strScore = strScore.slice(0,4);
  479. if(isEnglish)
  480. {
  481. strScore = strScore + "w"
  482. }
  483. else
  484. {
  485. strScore = strScore + "万"
  486. }
  487. }
  488. /*else if(score >= 1000000) //百万
  489. {
  490. strScore = strScore.slice(0,3);
  491. if(isEnglish)
  492. {
  493. strScore = strScore + "w"
  494. }
  495. else
  496. {
  497. strScore = strScore + "万"
  498. }
  499. }*/
  500. // else if(score >= 100000) //十万
  501. // {
  502. // strScore = strScore.slice(0,3);
  503. // strScore = parseInt(strScore) / 10;
  504. // if(isEnglish)
  505. // {
  506. // strScore = strScore + "w"
  507. // }
  508. // else
  509. // {
  510. // strScore = strScore + "万"
  511. // }
  512. // }
  513. else
  514. {
  515. strScore = parseFloat(score).toFixed(2);
  516. }
  517. return strScore;
  518. },
  519. });