CachetaPlayer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. var GamePlayer = require("GamePlayer");
  2. var Define = require("Define");
  3. var Global = require("Global");
  4. var UIHelper = require("UIHelper");
  5. import { CServerItem } from 'CServerItem'
  6. import ScenceManager from 'HNScenceManager'
  7. var BaseDefine = require("BaseDefine");
  8. var SoundFun = require("CachetaSoundFun");
  9. var GameProtocol = require("CachetaGameProtocol");
  10. var ProtocolGameServer = require("ProtocolGameServer")
  11. cc.Class({
  12. extends: GamePlayer,
  13. //extends: cc.Component,
  14. editor: {
  15. menu: 'Game/Cacheta/GamePlayer'
  16. },
  17. properties: {
  18. sprHeadIcon:cc.Sprite, //头像
  19. sprVipIcon:cc.Sprite, // VIP框
  20. btnHead:cc.Button,
  21. btnGift:cc.Button,
  22. sprEmptyHeadIcon:cc.Sprite,
  23. labScore:cc.Label, //分数
  24. labName:cc.Label, //昵称
  25. infoNode: cc.Node,
  26. cardsNode: cc.Node,
  27. huAniNode: cc.Node,
  28. OffineFlag:cc.Node, //离线标记
  29. TrusteeFlag: cc.Node,
  30. readyNode:cc.Node,
  31. labScoreW:cc.Label,
  32. labScoreL:cc.Label,
  33. iIndex:-1,
  34. _CurGameScene:null,
  35. _myScore:0,
  36. },
  37. // LIFE-CYCLE CALLBACKS:
  38. onLoad: function() {
  39. this.handCardPos = [
  40. cc.v2(-500,-440),
  41. cc.v2(-750,120),
  42. cc.v2(-177,447),
  43. cc.v2(750,120)];
  44. this.endCardPos = [
  45. cc.v2(-500,-440),
  46. cc.v2(-750,120),
  47. cc.v2(-200,400),
  48. cc.v2(750,120)];
  49. this.endCoinPos = [
  50. cc.v2(-478,-323),
  51. cc.v2(-574,0),
  52. cc.v2(0,181),
  53. cc.v2(574,7)];
  54. this.beizeOutMidPos = [
  55. cc.v2(0,0),
  56. cc.v2(0,555),
  57. cc.v2(555,555),
  58. cc.v2(0,555)];
  59. this.beizePickMidPos = [
  60. cc.v2(555,555),
  61. cc.v2(0,555),
  62. cc.v2(555,555),
  63. cc.v2(0,555)];
  64. this._isGameEnd = false;
  65. this._tenCardPosX = 724;
  66. this.infoNode.active = false;
  67. this.huAniNode.active = false;
  68. this.needPlayScoreAni = false;
  69. this.trusteeState = 0;
  70. // this.sprVipIcon.node.width = 118;
  71. // this.sprVipIcon.node.height = 118;
  72. this.sprVipIcon.node.scale = 0.25;
  73. this.myHandCards = [];
  74. this.hideHandCard();
  75. },
  76. init: function(index) {
  77. },
  78. playerEnter: function(){
  79. Global.print("用户playerEnter")
  80. this.node.getChildByName("PlayerHead").active = true;
  81. // this.sprEmptyHeadIcon.node.active = false;
  82. this.sprHeadIcon.node.active = true;
  83. this.btnHead.node.userID = this.getUserID();
  84. this.btnHead.node.gameID = this.getGameID();
  85. this.btnGift.node.userID = this.getUserID();
  86. this.btnGift.node.gameID = this.getGameID();
  87. this.node.active = true;
  88. this.infoNode.active = true;
  89. this.needPlayScoreAni = false;
  90. this.changeTrusteeState(0);
  91. this.setScore(this.getUserScore());
  92. // this.trusteeState = 0;
  93. this.hideWinLoseAni();
  94. this.hideHuAni();
  95. this.hideTimeNode();
  96. this.node.getChildByName("AndroidTip").active = (this.getAndroidTip()==1 && BaseDefine.LOCALTEST);
  97. },
  98. playerLeave:function() {
  99. this.labName.string = "";
  100. this.sprEmptyHeadIcon.node.active = true;
  101. this.sprHeadIcon.node.active = false;
  102. this.infoNode.active = false;
  103. this.node.getChildByName("AndroidTip").active = false;
  104. this.hideTimeNode();
  105. this.upPlayerInfo();
  106. this.upPlayerHead();
  107. this.upPlayerState();
  108. this.showWarning(false);
  109. Global.print("用户离开了")
  110. this.sprVipIcon.node.active = false;
  111. this.node.active = false;
  112. },
  113. upPlayer:function(show)
  114. {
  115. this.upPlayerInfo();
  116. this.upPlayerHead();
  117. this.node.active = show;
  118. },
  119. upPlayerState: function() {
  120. this.setOffline(this.getUserStatus() == Define.US_OFFLINE);
  121. },
  122. upPlayerInfo: function() {
  123. if (this.getNickName() != "") {
  124. var str = this.getNickName();
  125. let len = 6;
  126. this.labName.string = Global.subStr(str,len);
  127. }
  128. // this.setScore(this.getUserScore());
  129. },
  130. setNameLabelActive:function(show){
  131. this.infoNode.active = show;
  132. },
  133. setVIPActive:function(show){
  134. this.sprVipIcon.node.active = show;
  135. },
  136. getnickName: function()
  137. {
  138. return this.labName.string
  139. },
  140. upPlayerHead: function() {
  141. if (this.getHeadHttp() != "") {
  142. // 设置头像
  143. this.sprHeadIcon.getComponent("urlSpriteFrame").loadAvatar(this.getHeadHttp(),null, {width:100, height:100});
  144. } else {
  145. this.sprHeadIcon.spriteFrame = this.spriteFrame;
  146. this.sprHeadIcon.node.width = 100;
  147. this.sprHeadIcon.node.height = 100;
  148. }
  149. this.sprHeadIcon.node.active = true;
  150. let vipID = this.getVIPLevel();
  151. if(vipID >= 4 && vipID <= 7) {
  152. this.sprVipIcon.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
  153. this.sprVipIcon.node.active = true;
  154. }else{
  155. this.sprVipIcon.node.active = false;
  156. }
  157. },
  158. getHeadSpriteFrame() {
  159. return this.sprHeadIcon.spriteFrame;
  160. },
  161. getVIPSpriteFrame() {
  162. return this.sprVipIcon.spriteFrame;
  163. },
  164. //游戏结束,隐藏VIP框
  165. hideVIP() {
  166. this.sprVipIcon.node.active = false;
  167. },
  168. getHeadIcon: function(ret) {
  169. if(ret)
  170. {
  171. return this.sprHeadIcon.spriteFrame;
  172. }
  173. if (this.getHeadHttp() != "") {
  174. return this.sprHeadIcon.spriteFrame;
  175. }
  176. return null;
  177. },
  178. getIndex: function() {
  179. return this.iIndex;
  180. },
  181. setScore: function(score) {
  182. this._myScore = score;
  183. var strScore = this.changeScore(Global.formatString2Score(score));
  184. this.labScore.string = strScore;
  185. },
  186. getScore: function() {
  187. return this._myScore;
  188. },
  189. setOffline: function(isOffline) {
  190. this.OffineFlag.active = isOffline;
  191. if (isOffline) {
  192. //置灰
  193. this.sprHeadIcon.node.color = cc.Color.GRAY;
  194. }
  195. else {
  196. //复原
  197. this.sprHeadIcon.node.color = cc.Color.WHITE;
  198. }
  199. },
  200. setEndGameState(bbb) {
  201. this.needPlayScoreAni = bbb;
  202. },
  203. getEndGameState() {
  204. return this.needPlayScoreAni;
  205. },
  206. setEndGameScore(score) {
  207. this.needPlayScore = score;
  208. },
  209. getEndGameScore() {
  210. return this.needPlayScore;
  211. },
  212. changeTrusteeState(state) {
  213. this.trusteeState = state;
  214. this.TrusteeFlag.active = state;
  215. this.labName.node.active = !state;
  216. },
  217. showWarning: function(isReady) {
  218. if(this.readyNode.active == isReady) return;
  219. this.readyNode.active = isReady;
  220. if(isReady) {
  221. SoundFun.playEffectEX(SoundFun.WARNING);
  222. let ani = this.readyNode.getComponent(sp.Skeleton);
  223. ani.clearTracks();
  224. ani.setAnimation(0, "a1", false);
  225. ani.addAnimation(0, "a1", false);
  226. ani.addAnimation(0, "a1", false);
  227. ani.addAnimation(0, "a2", true);
  228. }
  229. },
  230. playTimeAction: function(SystemLeftTime,UserLeftTime){
  231. this.node.getChildByName("TimeNode").active = true;
  232. this.node.getChildByName("TimeNode").getComponent("CachetaTimePointer").playTimeAction(SystemLeftTime,UserLeftTime,this.iIndex==0);
  233. },
  234. hideTimeNode:function(){
  235. this.node.getChildByName("TimeNode").active = false;
  236. this.node.getChildByName("TimeNode").getComponent("CachetaTimePointer").stopTimeSchedule();
  237. },
  238. showHuAni() {
  239. this.huAniNode.active = true;
  240. let ani = this.huAniNode.getComponent(sp.Skeleton);
  241. ani.clearTracks();
  242. ani.setAnimation(0, "a1", false);
  243. },
  244. hideHuAni() {
  245. this.huAniNode.active = false;
  246. },
  247. hideWinLoseAni() {
  248. this.node.getChildByName("ani").active = false;
  249. this.node.getChildByName("scoreAni").active = false;
  250. },
  251. playWinOrLoseAni(bWin, addScore) {
  252. let aniNode = this.node.getChildByName("ani");
  253. aniNode.active = true;
  254. let scoreNode = this.node.getChildByName("scoreAni");
  255. let ani = aniNode.getComponent(sp.Skeleton);
  256. ani.clearTracks();
  257. if(bWin) {
  258. ani.setAnimation(0, "b1", false);
  259. ani.addAnimation(0, "b2", true);
  260. scoreNode.getChildByName("winNode").active = true;
  261. scoreNode.getChildByName("loseNode").active = false;
  262. this.labScoreW.string = Global.formatString2Score('+'+addScore);
  263. }else{
  264. ani.setAnimation(0, "b3", false);
  265. ani.addAnimation(0, "b4", true);
  266. scoreNode.getChildByName("winNode").active = false;
  267. scoreNode.getChildByName("loseNode").active = true;
  268. this.labScoreL.string = Global.formatString2Score(addScore);
  269. }
  270. scoreNode.active = true;
  271. scoreNode.getComponent(cc.Animation).play("showScoreAni");
  272. this.setScore(this.getUserScore());
  273. },
  274. playLiuJuAni() {
  275. let aniNode = this.node.getChildByName("ani");
  276. aniNode.active = true;
  277. let scoreNode = this.node.getChildByName("scoreAni");
  278. let ani = aniNode.getComponent(sp.Skeleton);
  279. ani.clearTracks();
  280. ani.setAnimation(0, "b3", false);
  281. ani.addAnimation(0, "b4", true);
  282. scoreNode.getChildByName("winNode").active = true;
  283. scoreNode.getChildByName("loseNode").active = false;
  284. this.labScoreW.string = '+0.00';
  285. scoreNode.active = true;
  286. scoreNode.getComponent(cc.Animation).play("showScoreAni");
  287. },
  288. start () {
  289. },
  290. showTalkState: function(data){
  291. if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TALK_TYPE){
  292. }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD){
  293. }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_DEFINE){
  294. }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING)
  295. {
  296. if(data.String == ""){
  297. return;
  298. }
  299. let memeIdx = data.String;
  300. if(memeIdx <=0 || memeIdx >= 13){
  301. return;
  302. }
  303. this.node.getChildByName("GameMeme").active = true;
  304. var Ani = this.node.getChildByName("GameMeme").getComponent(sp.Skeleton);
  305. Ani.setAnimation(0,"a"+memeIdx,false);
  306. }
  307. },
  308. rePlayHandCardShow() {
  309. if(this.iIndex <= 0) return;
  310. this.cardsNode.active = true;
  311. for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
  312. this.cardsNode.children[i].position = this.handCardPos[this.iIndex];
  313. this.cardsNode.children[i].scale = 0.6;
  314. this.cardsNode.children[i].angle = 0;
  315. this.cardsNode.children[i].getComponent("CachetaCard").setId(0,0);
  316. this.cardsNode.children[i].active = true;
  317. }
  318. },
  319. getEndCoinPos() {
  320. return this.endCoinPos[this.iIndex];
  321. },
  322. getHandCardPos() {
  323. return this.handCardPos[this.iIndex];
  324. },
  325. getEndCardPos() {
  326. return this.endCardPos[this.iIndex];
  327. },
  328. hideHandCard() {
  329. if(!this.cardsNode) return;
  330. for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
  331. this.cardsNode.children[i].x = -160;
  332. this.cardsNode.children[i].y = 38;
  333. this.cardsNode.children[i].scale = 0.8;
  334. if(this.cardsNode.children[i].is3DNode) {
  335. this.cardsNode.children[i].eulerAngles = cc.v3(0,0,0);
  336. }else{
  337. this.cardsNode.children[i].angle = 0;
  338. }
  339. this.cardsNode.children[i].color = cc.color(255,255,255);
  340. this.cardsNode.children[i].getComponent("CachetaCard").setId(0,0);
  341. this.cardsNode.children[i].active = false;
  342. }
  343. this.cardsNode.active = true;
  344. this.huAniNode.active = false;
  345. this.myHandCards.splice(0);
  346. },
  347. resetHandCardPos() {
  348. if(!this.cardsNode) return;
  349. this.cardsNode.active = true;
  350. for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
  351. this.cardsNode.children[i].x = -160;
  352. this.cardsNode.children[i].y = 38;
  353. this.cardsNode.children[i].scale = 0.8;
  354. if(this.cardsNode.children[i].is3DNode) {
  355. this.cardsNode.children[i].eulerAngles = cc.v3(0,0,0);
  356. }else{
  357. this.cardsNode.children[i].angle = 0;
  358. }
  359. // this.cardsNode.children[i].angle = 0;
  360. // this.cardsNode.children[i].zIndex = 10-i;
  361. // this.cardsNode.children[i].active = false//i > 0;
  362. }
  363. },
  364. pickLixoToMyHandCard(cardData, callback, endCall) {
  365. if(this.iIndex > 0) return;
  366. let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
  367. if(card) {
  368. card.getComponent("CachetaCard").setId(cardData, 0);
  369. card.active = true;
  370. card.position = cc.v2(167, 5);
  371. card.scale = 0.8;
  372. card.zIndex = 100;
  373. if(callback) {
  374. callback();
  375. }
  376. let endPos = cc.v2(this._tenCardPosX, -480);
  377. let midPos = this.beizePickMidPos[this.iIndex];
  378. let moveTime = 0.5;
  379. var opts1 = Object.create(null);
  380. opts1.progress = (start, end, current, t)=> {
  381. current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
  382. current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
  383. return current;
  384. }
  385. card.stopAllActions();
  386. cc.tween(card)
  387. .parallel(
  388. cc.tween().to(moveTime, {position: endPos}, opts1),
  389. cc.tween().to(moveTime, {scale: 1.2})
  390. )
  391. .call(()=>{
  392. if(endCall) {
  393. endCall();
  394. }
  395. })
  396. .start()
  397. }
  398. },
  399. pickMonteToMyHandCard(cardData, magicCards, callback) {
  400. if(this.iIndex > 0) return;
  401. let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
  402. if(card) {
  403. card.getComponent("CachetaCard").setId(0,0);
  404. card.active = true;
  405. card.position = cc.v2(-160, 5);
  406. card.scale = 0.8;
  407. card.zIndex = 100;
  408. let endPos = cc.v2(this._tenCardPosX, -480);
  409. let midPos = this.beizePickMidPos[this.iIndex];
  410. let moveTime = 0.5;
  411. var opts1 = Object.create(null);
  412. opts1.progress = (start, end, current, t)=> {
  413. current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
  414. current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
  415. return current;
  416. }
  417. card.stopAllActions();
  418. cc.tween(card)
  419. .parallel(
  420. cc.tween().to(moveTime, {position: endPos}, opts1),
  421. cc.tween().to(moveTime, {scale: 1.2})
  422. )
  423. .to(0.2, {eulerAngles: cc.v3(0,90,0)})
  424. .call(()=>{
  425. card.getComponent("CachetaCard").setId(cardData, magicCards);
  426. })
  427. .to(0.2, {eulerAngles: cc.v3(0,0,0)})
  428. .call(()=>{
  429. if(callback) {
  430. callback();
  431. }
  432. })
  433. .start()
  434. }
  435. },
  436. pickOneCardToHandCard(isDark, cardData, callback, endCall) {
  437. if(this.iIndex <= 0) return;
  438. let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
  439. if(card) {
  440. card.active = true;
  441. card.scale = 0.8;
  442. card.zIndex = 100;
  443. card.position = cc.v2(-160, 5);
  444. let cardd = 0;
  445. if(!isDark) {
  446. card.x = 167;
  447. cardd = cardData;
  448. if(callback) {
  449. callback();
  450. }
  451. }
  452. card.getComponent("CachetaCard").setId(cardd,0);
  453. let endPos = this.handCardPos[this.iIndex];
  454. let midPos = this.beizePickMidPos[this.iIndex];
  455. let moveTime = 0.5;
  456. var opts1 = Object.create(null);
  457. opts1.progress = (start, end, current, t)=> {
  458. current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
  459. current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
  460. return current;
  461. }
  462. card.stopAllActions();
  463. cc.tween(card)
  464. .parallel(
  465. cc.tween().to(moveTime, {position: endPos}, opts1),
  466. cc.tween().to(moveTime, {scale: 0.6})
  467. )
  468. .call(()=>{
  469. card.active = false;
  470. if(endCall) {
  471. endCall();
  472. }
  473. })
  474. .start()
  475. }
  476. },
  477. throwOneCardToLixo(cardId,magiccards,callback) {
  478. if(this.iIndex <= 0) return;
  479. let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
  480. if(card) {
  481. card.getComponent("CachetaCard").setId(0,0);
  482. card.active = true;
  483. card.position = this.handCardPos[this.iIndex];
  484. card.scale = 0.6;
  485. let endPos = cc.v2(167, 5);
  486. let midPos = this.beizeOutMidPos[this.iIndex];//cc.v2(555,555);
  487. let moveTime = 0.5;
  488. var opts1 = Object.create(null);
  489. opts1.progress = (start, end, current, t)=> {
  490. current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
  491. current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
  492. return current;
  493. }
  494. card.stopAllActions();
  495. cc.tween(card)
  496. .parallel(
  497. cc.tween().to(moveTime, {position: endPos}, opts1),
  498. cc.tween().to(moveTime, {scale: 0.8})
  499. )
  500. .call(()=>{
  501. SoundFun.playEffectEX(SoundFun.FLIPCARD);
  502. })
  503. .to(0.15, {eulerAngles: cc.v3(0,90,0)})
  504. .call(()=>{
  505. card.getComponent("CachetaCard").setId(cardId,magiccards);
  506. })
  507. .to(0.15, {eulerAngles: cc.v3(0,0,0)})
  508. .call(()=>{
  509. if(callback) {
  510. callback();
  511. }
  512. card.active = false;
  513. })
  514. .start()
  515. }
  516. },
  517. throwMyCardToLixo(card, callback) {
  518. if(this.iIndex > 0) return;
  519. if(!card) return;
  520. card.active = true;
  521. card.color = cc.color(255,255,255);
  522. let endPos = cc.v2(167, 5);
  523. let midPos = this.beizeOutMidPos[this.iIndex];//cc.v2(555,555);
  524. let moveTime = 0.5;
  525. var opts1 = Object.create(null);
  526. opts1.progress = (start, end, current, t)=> {
  527. current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
  528. current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
  529. return current;
  530. }
  531. card.stopAllActions();
  532. cc.tween(card)
  533. .parallel(
  534. cc.tween().to(moveTime, {position: endPos}, opts1),
  535. cc.tween().to(moveTime, {scale: 0.8})
  536. )
  537. .call(()=>{
  538. card.active = false;
  539. if(callback) {
  540. callback();
  541. }
  542. })
  543. .start()
  544. },
  545. setHandCards(cards) {
  546. for(let i = 0; i < cards.length; ++i) {
  547. if(cards[i] > 0) {
  548. this.myHandCards.push(cards[i]);
  549. }
  550. }
  551. this.upSelfTrusteeState();
  552. },
  553. addOneCard(cardid) {
  554. if(cardid > 0) {
  555. this.myHandCards.push(cardid);
  556. this.upSelfTrusteeState();
  557. }
  558. },
  559. outOneCard(cardid) {
  560. for(let i = 0; i < this.myHandCards.length; ++i) {
  561. if(this.myHandCards[i] == cardid) {
  562. this.myHandCards.splice(i, 1);
  563. this.upSelfTrusteeState();
  564. return;
  565. }
  566. }
  567. },
  568. getHandCards() {
  569. return this.myHandCards;
  570. },
  571. upSelfTrusteeState() {
  572. if(this.iIndex > 0) return;
  573. if(!this.trusteeState) return;
  574. let maskW = this.myHandCards.length < 10 || this.myHandCards[9] == 0 ? 793 : 875;
  575. let jsGameSence = ScenceManager.Instance().getGameComponent();
  576. jsGameSence.upTrusteeMask(maskW);
  577. },
  578. });