CardControl.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. m_CardParent: cc.Node,
  5. m_Atlas:cc.SpriteAtlas,
  6. m_CardItem:cc.Prefab,
  7. m_HandState:cc.Integer,
  8. m_CurrentCard:cc.Node,
  9. /*
  10. 上:0
  11. 左:1 右:3
  12. 下:2
  13. */
  14. },
  15. // use this for initialization
  16. onLoad: function () {
  17. this.m_HandState = parseInt(this.m_HandState);
  18. for(var i = 0; i < GameDef.CARD_COUNT; ++ i){
  19. var pNode = cc.instantiate(this.m_CardItem);
  20. if(this.m_CardWidth == 0){
  21. this.m_CardWidth = pNode.width;
  22. this.m_CardHeight = pNode.height;
  23. }
  24. if( this.m_HandState == GameDef.HAND_TOP){
  25. pNode.x=(this.m_CardWidth*i);
  26. pNode.zIndex = GameDef.CARD_COUNT - i;
  27. }else if( this.m_HandState == GameDef.HAND_LEFT){
  28. pNode.y=(i*this.m_CardHeight);
  29. pNode.zIndex = GameDef.CARD_COUNT-i;
  30. }else if( this.m_HandState == GameDef.HAND_BOTTOM){
  31. pNode.x=(this.m_CardWidth*i*-1);
  32. pNode.zIndex = i;
  33. }else if( this.m_HandState == GameDef.HAND_RIGHT){
  34. pNode.y=(i*this.m_CardHeight*-1);
  35. }
  36. var index = i;
  37. if( this.m_HandState == GameDef.HAND_BOTTOM){
  38. index = GameDef.CARD_COUNT-i-1;
  39. }
  40. this.m_CardParent.addChild(pNode);
  41. this.m_CardItemArray[index] = pNode.getComponent('CardItem');
  42. this.m_CardItemArray[index].SetCardID(index);
  43. pNode.active = false;
  44. }
  45. var CurCard = cc.instantiate(this.m_CardItem);
  46. CurCard.active = false;
  47. this.m_CurrentCard.addChild(CurCard);
  48. this.m_CardItemArray[GameDef.CARD_COUNT] = CurCard.getComponent('CardItem');
  49. this.m_CardItemArray[GameDef.CARD_COUNT].SetCardID(GameDef.CARD_COUNT);
  50. this.m_HandCard = cc.instantiate(this.m_CardItem);
  51. this.node.addChild(this.m_HandCard);
  52. this.m_HandCard.setPosition(this.m_CurrentCard.getPosition());
  53. this.m_HandCard = this.m_HandCard.getComponent('CardItem');
  54. this.m_HandCard.node.active = false;
  55. var clickNode = this.node.getChildByName('Touch');
  56. if( clickNode != null ){
  57. // clickNode.setTouchEnabled(true);
  58. clickNode.on(cc.Node.EventType.TOUCH_START, function(event) {
  59. if(this.m_bCanTouch == false) return;
  60. this.m_MoveCard.SetState(GameDef.HAND_STATE_STAND);
  61. if(this.m_MoveIng && this.m_CurMove && this.m_SelectCard != null){
  62. this.m_SelectCard.node.active = true;
  63. this.m_MoveCard.node.active = false;
  64. }
  65. this.m_SelectCard = null;
  66. if( this.m_bPositively == false ){
  67. return;
  68. }
  69. var location = event.touch.getLocation();
  70. var target = this.touchCardNode(location);
  71. if( target == null )return;
  72. if(target.GetCanOut() == false)
  73. {
  74. return;
  75. }
  76. if( target.m_CardID != GameDef.CARD_COUNT && target.m_CardID >= this.m_wCardCount - 1)
  77. {
  78. cc.log(target.m_CardID, this.m_wCardCount,"cardcontrol--3");
  79. return;
  80. }
  81. if( GameDef.g_GameEngine.m_HuiCardDate == target.GetCardData()) return;
  82. this.m_StarPos = location;
  83. this.m_MoveValue.x = 0;
  84. this.m_MoveValue.y = 0;
  85. this.m_bCurrentMoveCard = false;
  86. var moveCard = this.m_MoveCard;
  87. this.m_MoveCard.node.scale = 1;
  88. moveCard.node.active = true;
  89. if(GameDef.KIND_ID == 62007){
  90. if(GameDef.g_GameEngine.GetIsLiang()){
  91. moveCard.SetLiangCardData( target.GetCardData());
  92. }
  93. else{
  94. moveCard.SetCardData( target.GetCardData());
  95. }
  96. }
  97. else
  98. {
  99. moveCard.SetCardData( target.GetCardData());
  100. }
  101. var offset = target.node.convertToNodeSpaceAR(location);
  102. var pos = moveCard.node.parent.convertToNodeSpaceAR(location);
  103. pos.x -= offset.x;
  104. pos.y -= offset.y;
  105. moveCard.node.setPosition(pos);
  106. // // target.node.active = false;
  107. this.m_SelectCard = target;
  108. moveCard.node.active = false;
  109. this.m_MoveIng = false;
  110. this.m_CurMove = false;
  111. // cc.log("开始 ");
  112. }.bind(this),this);
  113. clickNode.on(cc.Node.EventType.TOUCH_MOVE, function(event) {
  114. if( this.m_bPositively == false || this.m_SelectCard == null )
  115. {
  116. return;
  117. }
  118. this.m_MoveCard.SetState(GameDef.HAND_STATE_STAND);
  119. var moveCard = this.m_MoveCard;
  120. var location = event.touch.getLocation();
  121. var offset = event.touch.getDelta();
  122. var pos = moveCard.node.getPosition();
  123. pos.x += offset.x;
  124. pos.y += offset.y;
  125. moveCard.node.setPosition(pos);
  126. if( this.m_StarPos.y - location.y < -50){
  127. this.m_MoveIng = true;
  128. this.m_CurMove = true;
  129. this.m_SelectCard.node.active = false;
  130. this.m_MoveCard.node.active = true;
  131. }
  132. else{
  133. this.m_SelectCard.node.active = true;
  134. this.m_MoveCard.node.active = false;
  135. this.m_MoveIng = false;
  136. }
  137. var cbCardData = moveCard.GetCardData();
  138. if( this.m_MoveIng )
  139. {
  140. // console.log('移动:'+cbCardData+' CardID:'+this.m_SelectCard.m_CardID);
  141. this.m_SelectCard.SetShoot(false,true);
  142. }
  143. this.ChangeSelectCardColor(cbCardData,true);
  144. moveCard.ChangeColor(false);
  145. }.bind(this),this);
  146. function moveEnd(event) {
  147. if( this.m_SelectCard == null ) return ;
  148. this.ChangeSelectCardColor(0,false);
  149. this.m_MoveCard.SetState(GameDef.HAND_STATE_STAND);
  150. if(this.m_bPositively && this.m_MoveIng && this.m_MoveCard.node.active == true ){
  151. var pos = this.m_MoveCard.node.convertToWorldSpaceAR(cc.v2(0,0));
  152. var cbCardData = this.m_MoveCard.GetCardData();
  153. if( this.m_bPositively && GameDef.g_GameEngine.OnOutCard != null) {
  154. this.m_OutCardIndex = this.m_SelectCard.m_CardID;
  155. this.m_OutCardData = cbCardData;
  156. if( GameDef.g_GameEngine.m_HuiCardDate == cbCardData ){
  157. GameDef.g_GameEngine.ShockHuiPai();
  158. }else{
  159. pos = this.m_SelectCard.node.parent.convertToNodeSpaceAR(pos);
  160. this.m_SelectCard.node.setPosition(pos);
  161. this.m_SelectCard.node.active = true;
  162. GameDef.g_GameEngine.OnOutCard(this.m_HandState,this.m_MoveCard.m_CardID,cbCardData);
  163. }
  164. }
  165. }
  166. else if( !this.m_CurMove ){
  167. var location = event.touch.getLocation();
  168. var node = this.touchCardNode(location);
  169. if( node != null ){
  170. //console.log('this.ClickSubCard:'+node.m_CardID);
  171. this.ClickSubCard(node, node.m_CardID);
  172. }
  173. }
  174. this.m_MoveCard.node.active = false;
  175. this.m_MoveIng = false;
  176. this.m_SelectCard = null;
  177. }
  178. clickNode.on(cc.Node.EventType.TOUCH_END, moveEnd.bind(this), this);
  179. clickNode.on(cc.Node.EventType.TOUCH_CANCEL, moveEnd.bind(this), this);
  180. }
  181. },
  182. ctor:function(){
  183. this.m_TingData = null;
  184. this.m_CardItemArray = new Array();
  185. this.m_wCardCount = 0;
  186. this.m_bPositively = false;
  187. this.m_CurrentCardData = 0;
  188. //双击出牌后的记录
  189. this.m_OutCardIndex = 0;
  190. this.m_OutCardData = 0;
  191. this.m_cbCardData = new Array();
  192. this.m_CardStartIndex = 0;
  193. this.m_MoveCard = null;
  194. this.m_SelectCard = null;
  195. this.m_StarPos = {};
  196. this.m_bCurrentMoveCard = false;
  197. this.m_MoveValue={};
  198. this.m_CurMove = false;
  199. //是否单击就出牌
  200. this.m_isClickSendCard = false;
  201. this.m_CardWidth = 0;
  202. this.m_CardHeight = 0;
  203. this.m_bCanTouch = true;
  204. },
  205. SetClickSendCard:function(click){
  206. this.m_isClickSendCard = click;
  207. },
  208. ResetPos:function(offset){
  209. offset = offset==null?0:offset;
  210. for(var i = 0; i < GameDef.CARD_COUNT; ++ i){
  211. var index = i;
  212. if( this.m_HandState == GameDef.HAND_BOTTOM){
  213. index = GameDef.CARD_COUNT-i-1;
  214. }
  215. var pNode = this.m_CardItemArray[index].node;
  216. if( this.m_HandState == GameDef.HAND_TOP){
  217. pNode.x=(this.m_CardWidth*i);
  218. pNode.zIndex = GameDef.CARD_COUNT - i;
  219. }
  220. else if( this.m_HandState == GameDef.HAND_LEFT){
  221. pNode.y=(i*this.m_CardHeight);
  222. pNode.zIndex = GameDef.CARD_COUNT-i;
  223. }
  224. else if( this.m_HandState == GameDef.HAND_BOTTOM){
  225. pNode.x=(this.m_CardWidth*i*-1 + offset*this.m_CardWidth);
  226. pNode.zIndex = i;
  227. }
  228. else if( this.m_HandState == GameDef.HAND_RIGHT){
  229. pNode.y=(i*this.m_CardHeight*-1);
  230. }
  231. }
  232. },
  233. ResetView:function(){
  234. this.ResetPos();
  235. this.SetCardData(null,0);
  236. this.m_bCanTouch = true;
  237. },
  238. ClickSubCard:function(CardNode,CardID){
  239. if(this.m_bCanTouch == false) return;
  240. var cbCardData = CardNode.GetCardData();
  241. if( this.m_isClickSendCard && this.m_bPositively){
  242. if( GameDef.g_GameEngine.OnOutCard != null){
  243. if(cbCardData == 0 ){
  244. console.log("发送0");
  245. return ;
  246. }
  247. if(this.m_CardItemArray[CardID].GetCanOut() == false)
  248. {
  249. return;
  250. }
  251. this.m_OutCardIndex = CardNode.m_CardID;
  252. this.m_OutCardData = cbCardData;
  253. if( GameDef.g_GameEngine.m_HuiCardDate == cbCardData ){
  254. GameDef.g_GameEngine.ShockHuiPai();
  255. }else{
  256. GameDef.g_GameEngine.OnOutCard(this.m_HandState,CardNode.m_CardID,cbCardData);
  257. }
  258. }
  259. return;
  260. }
  261. // if(this.m_bPositively==false)return;
  262. for(var i in this.m_CardItemArray){
  263. if(i == CardNode.m_CardID){
  264. continue;
  265. }
  266. this.m_CardItemArray[i].SetShoot(false,true);
  267. }
  268. if(CardNode.GetShoot()==false){
  269. CardNode.SetShoot(true,true);
  270. if( cc.gSoundRes != null && cc.gSoundRes.PlaySound != null){
  271. cc.gSoundRes.PlayGameSound("TIPAI");
  272. }
  273. this.ChangeSelectCardColor(cbCardData,true);
  274. CardNode.ChangeColor(false);
  275. } else {
  276. this.ChangeSelectCardColor(0,false);
  277. if( this.m_bPositively && GameDef.g_GameEngine != null && GameDef.g_GameEngine.OnOutCard != null){
  278. this.m_OutCardIndex = CardNode.m_CardID;
  279. this.m_OutCardData = cbCardData;
  280. if( GameDef.g_GameEngine.m_HuiCardDate == cbCardData ){
  281. GameDef.g_GameEngine.ShockHuiPai();
  282. }else{
  283. //this.m_MoveCard.node.active = false;
  284. this.m_SelectCard.node.active = false;
  285. GameDef.g_GameEngine.OnOutCard(this.m_HandState,CardNode.m_CardID,cbCardData);
  286. }
  287. }else{
  288. CardNode.SetShoot(false,true);
  289. }
  290. }
  291. },
  292. DoubleClick:function(CardNode,CardID){
  293. //cc.log("双击:");
  294. return;
  295. if(this.m_bPositively==false)return;
  296. var cbCardData = this.m_CardItemArray[CardID].GetCardData();
  297. if( GameDef.g_GameEngine != null && GameDef.g_GameEngine.OnOutCard != null){
  298. this.m_OutCardIndex = CardID;
  299. this.m_OutCardData = cbCardData;
  300. if( GameDef.g_GameEngine.m_HuiCardDate == cbCardData ){
  301. GameDef.g_GameEngine.ShockHuiPai();
  302. }else{
  303. GameDef.g_GameEngine.OnOutCard(this.m_HandState,CardID,cbCardData);
  304. }
  305. }
  306. },
  307. GetDoubleCardData:function(){
  308. return this.m_OutCardData;
  309. },
  310. GetDoubleCardIndex:function(){
  311. return this.m_OutCardIndex;
  312. },
  313. GetCardDataByIndex:function(index){
  314. return this.m_CardItemArray[index].GetCardData();
  315. },
  316. //设置扑克
  317. SetCurrentCard:function(cbCardData, bIsListen, bEnd){
  318. var isLookOnMode = GameDef.g_GameEngine.IsLookonMode();
  319. if(bEnd == true) isLookOnMode = false;
  320. this.m_CardItemArray[GameDef.CARD_COUNT].SetShow(cbCardData != null);
  321. cbCardData = cbCardData != null ?cbCardData:0;
  322. this.m_CardItemArray[GameDef.CARD_COUNT].SetCardData(cbCardData, isLookOnMode);
  323. this.m_CardItemArray[GameDef.CARD_COUNT].SetCanOut(true);
  324. if(bIsListen)
  325. {
  326. this.m_CardItemArray[GameDef.CARD_COUNT].SetTingTip(true);
  327. }
  328. this.m_CurrentCardData = cbCardData;
  329. if( cbCardData != 0 ){
  330. this.m_cbCardData[this.m_wCardCount++] = cbCardData;
  331. }
  332. },
  333. //设置扑克
  334. SetCurrentCard2:function(cbCardData, bIsListen, cbCantOutCard, ){
  335. this.m_CardItemArray[GameDef.CARD_COUNT].SetShow(cbCardData != null);
  336. cbCardData = cbCardData != null ?cbCardData:0;
  337. //this.m_CardItemArray[13].SetCardData(cbCardData);
  338. if(bIsListen)
  339. {
  340. //this.m_CardItemArray[13].SetTingTip(true);
  341. //this.m_CardItemArray[13].SetCanOut(true);
  342. //this.m_CardItemArray[13].SetTingTip(false);
  343. //this.m_CardItemArray[13].SetCanOut(false);
  344. for(var i in this.m_CardItemArray){
  345. if(!this.m_CardItemArray[i].GetCardData())continue;
  346. var cbCardData = this.m_CardItemArray[i].GetCardData();
  347. //亮倒后只能出上听牌
  348. var bCanOut= false;
  349. if(GameDef.g_GameEngine.m_bLiang[GameDef.g_GameEngine.GetMeChairID()]){
  350. for(var k=0;k<34;++k)
  351. {
  352. if(GameDef.g_GameEngine.m_OutEndTingData[k] != 0)
  353. {
  354. if(GameDef.g_GameEngine.m_OutEndTingData[k] == cbCardData)
  355. {
  356. bCanOut = true;
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. if(bCanOut)this.m_CardItemArray[i].SetLockTips(false);
  363. break;
  364. }
  365. }
  366. else
  367. {
  368. if( cbCantOutCard != null)
  369. {
  370. for(var i = 0; i < 18; i++)
  371. {
  372. if(cbCantOutCard[i] == 0) break;
  373. if(cbCantOutCard[i] == cbCardData)
  374. {
  375. //亮倒后只能出上听牌
  376. var bCanOut= false;
  377. if(GameDef.g_GameEngine.m_bLiang[GameDef.g_GameEngine.GetMeChairID()]){
  378. for(var k=0;k<34;++k)
  379. {
  380. if(GameDef.g_GameEngine.m_OutEndTingData[k] != 0)
  381. {
  382. if(GameDef.g_GameEngine.m_OutEndTingData[k] == cbCardData)
  383. {
  384. bCanOut = true;
  385. break;
  386. }
  387. }
  388. }
  389. }
  390. if(bCanOut)continue;
  391. this.m_CardItemArray[GameDef.CARD_COUNT].SetLockTips(true);
  392. break;
  393. }
  394. }
  395. }
  396. }
  397. // this.m_CurrentCardData = cbCardData;
  398. // if( cbCardData != 0 ){
  399. // this.m_cbCardData[this.m_wCardCount++] = cbCardData;
  400. // }
  401. },
  402. SetLiangCurrentCard:function(cbCardData, bIsListen){
  403. this.m_CardItemArray[GameDef.CARD_COUNT].SetShow(cbCardData != null);
  404. cbCardData = cbCardData != null ?cbCardData:0;
  405. this.m_CardItemArray[GameDef.CARD_COUNT].SetLiangCardData(cbCardData);
  406. if(bIsListen)
  407. {
  408. this.m_CardItemArray[GameDef.CARD_COUNT].SetTingTip(true);
  409. this.m_CardItemArray[GameDef.CARD_COUNT].SetCanOut(true);
  410. // this.m_CardItemArray[13].SetTingTip(false);
  411. // this.m_CardItemArray[13].SetCanOut(false);
  412. }
  413. this.m_CurrentCardData = cbCardData;
  414. if( cbCardData != 0 ){
  415. this.m_cbCardData[this.m_wCardCount++] = cbCardData;
  416. }
  417. },
  418. GetCardNode:function(CardIndex){
  419. if( CardIndex < 0 || CardIndex > this.m_CardItemArray.length ){
  420. return null;
  421. }
  422. return this.m_CardItemArray[CardIndex];
  423. },
  424. //设置扑克
  425. SetCardData:function(cbCardData,wCardCount, bIsListen, bEnd){
  426. var isLookOnMode = GameDef.g_GameEngine.IsLookonMode();
  427. if(bEnd == true) isLookOnMode = false;
  428. this.m_wCardCount = wCardCount;
  429. if( cbCardData != null && wCardCount > 0 ){
  430. if( this.m_MagicData != null && this.m_MagicData > 0 ){
  431. for (var i = 0; i < wCardCount; i++) {
  432. if(cbCardData[i] == this.m_MagicData){
  433. cbCardData.splice(i,1);
  434. cbCardData.splice(0,0,this.m_MagicData);
  435. }
  436. }
  437. }
  438. for (var i = 0; i < this.m_CardItemArray.length; i++) {
  439. this.m_CardItemArray[i].SetCardData(0, isLookOnMode);
  440. this.m_CardItemArray[i].SetShow(false);
  441. }
  442. for(var i = 0;i<wCardCount ;i++)
  443. {
  444. this.m_CardItemArray[i].SetShow(true);
  445. this.m_cbCardData[i] = cbCardData[i];
  446. this.m_CardItemArray[i].SetCardData(cbCardData[i], isLookOnMode);
  447. if(bIsListen)
  448. {
  449. this.m_CardItemArray[i].SetCanOut(false);
  450. this.m_CardItemArray[i].SetTingTip(false);
  451. }
  452. }
  453. if(this.m_HandState == GameDef.HAND_BOTTOM && GameDef.CARD_COUNT >= wCardCount){
  454. var offset = GameDef.CARD_COUNT-wCardCount;
  455. this.ResetPos(offset);
  456. }
  457. }
  458. else{
  459. for(var i = 0;i < this.m_CardItemArray.length;i++ )
  460. {
  461. this.m_cbCardData[i] = 0;
  462. this.m_CardItemArray[i].SetCardData(0, isLookOnMode);
  463. this.m_CardItemArray[i].SetShow(i<wCardCount);
  464. }
  465. }
  466. //this.ShowTingData(this.m_TingData);
  467. },
  468. //亮倒的牌
  469. SetLiangCardData:function(cbCardData, wCardCount, bIsListen){
  470. this.m_wCardCount = wCardCount;
  471. if( cbCardData != null && wCardCount > 0 )
  472. {
  473. //混放最前面
  474. if( this.m_MagicData != null && this.m_MagicData > 0 )
  475. {
  476. for (var i = 0; i < wCardCount; i++)
  477. {
  478. if(cbCardData[i] == this.m_MagicData)
  479. {
  480. cbCardData.splice(i,1);
  481. cbCardData.splice(0,0,this.m_MagicData);
  482. }
  483. }
  484. }
  485. //清空牌
  486. for (var i = 0; i < this.m_CardItemArray.length; i++)
  487. {
  488. this.m_CardItemArray[i].SetCardData(0);
  489. this.m_CardItemArray[i].SetShow(false);
  490. this.m_CardItemArray[i].SetCanOut(true);
  491. this.m_CardItemArray[i].SetTingTip(false);
  492. }
  493. //实际牌
  494. for(var i = 0;i<wCardCount ;i++)
  495. {
  496. this.m_CardItemArray[i].SetShow(true);
  497. this.m_cbCardData[i] = cbCardData[i];
  498. this.m_CardItemArray[i].SetLiangCardData(cbCardData[i]);
  499. if(bIsListen)
  500. {
  501. this.m_CardItemArray[i].SetCanOut(false);
  502. this.m_CardItemArray[i].SetTingTip(false);
  503. }
  504. }
  505. //位置
  506. if(this.m_HandState == GameDef.HAND_BOTTOM && GameDef.CARD_COUNT >= wCardCount)
  507. {
  508. var offset = GameDef.CARD_COUNT-wCardCount;
  509. this.ResetPos(offset);
  510. }
  511. }
  512. else{
  513. for(var i = 0;i < this.m_CardItemArray.length;i++ )
  514. {
  515. this.m_cbCardData[i] = 0;
  516. this.m_CardItemArray[i].SetCardData(0);
  517. this.m_CardItemArray[i].SetShow(i<wCardCount);
  518. }
  519. }
  520. //this.ShowTingData(this.m_TingData);
  521. },
  522. //自己亮倒的牌
  523. SetSelfLiangCardData:function(cbCardData, cbLiangCard, wCardCount, wLiangCount, bIsListen){
  524. this.m_wCardCount = wCardCount;
  525. if( cbCardData != null && wCardCount > 0 )
  526. {
  527. //亮的牌放最后面
  528. var nCardIndex = wCardCount-1;
  529. for(var i = wLiangCount-1; i >= 0; i--)
  530. {
  531. for(var j = nCardIndex; j >= 0; j--)
  532. {
  533. if(cbCardData[j] == cbLiangCard[i])
  534. {
  535. cbCardData.splice(j,1);
  536. cbCardData.splice(nCardIndex,0,cbLiangCard[i]);
  537. nCardIndex--;
  538. break;
  539. }
  540. }
  541. }
  542. //亮的牌放最前面
  543. // var nLiangIndex = 0;
  544. // for(var i = 0; i < wLiangCount; i++)
  545. // {
  546. // for(var j = nLiangIndex; j < wCardCount; j++)
  547. // {
  548. // if(cbCardData[j] == cbLiangCard[i])
  549. // {
  550. // cbCardData.splice(j,1);
  551. // cbCardData.splice(nLiangIndex,0,cbLiangCard[i]);
  552. // nLiangIndex++;
  553. // break;
  554. // }
  555. // }
  556. // }
  557. //清空牌
  558. for (var i = 0; i < this.m_CardItemArray.length; i++)
  559. {
  560. this.m_CardItemArray[i].SetCardData(0);
  561. this.m_CardItemArray[i].SetShow(false);
  562. this.m_CardItemArray[i].SetCanOut(true);
  563. this.m_CardItemArray[i].SetTingTip(false);
  564. this.m_CardItemArray[i].SetTingMask(false);
  565. this.m_CardItemArray[i].SetLockTips(false);
  566. }
  567. //实际牌
  568. for(var i = 0;i<wCardCount ;i++)
  569. {
  570. this.m_CardItemArray[i].SetShow(true);
  571. this.m_cbCardData[i] = cbCardData[i];
  572. if(wCardCount - wLiangCount > i)
  573. {
  574. this.m_CardItemArray[i].SetCardData(cbCardData[i]);
  575. }
  576. else
  577. {
  578. this.m_CardItemArray[i].SetLiangCardData(cbCardData[i]);
  579. }
  580. if(bIsListen)
  581. {
  582. this.m_CardItemArray[i].SetCanOut(false);
  583. this.m_CardItemArray[i].SetTingTip(false);
  584. }
  585. }
  586. //位置
  587. if(this.m_HandState == GameDef.HAND_BOTTOM && GameDef.CARD_COUNT >= wCardCount)
  588. {
  589. var offset = GameDef.CARD_COUNT-wCardCount;
  590. this.ResetPos(offset);
  591. }
  592. }
  593. else{
  594. for(var i = 0;i < this.m_CardItemArray.length;i++ )
  595. {
  596. this.m_cbCardData[i] = 0;
  597. this.m_CardItemArray[i].SetCardData(0);
  598. this.m_CardItemArray[i].SetShow(i<wCardCount);
  599. }
  600. }
  601. //this.ShowTingData(this.m_TingData);
  602. },
  603. SetCardItemState:function(state){
  604. for (var i = 0; i < this.m_CardItemArray.length; i++) {
  605. this.m_CardItemArray[i].SetState(state);
  606. }
  607. },
  608. ChangeSelectCardColor:function(cbCardData,bSelect){
  609. for (var i = 0; i < GameDef.m_AllCardItem.length; i++) {
  610. GameDef.m_AllCardItem[i].ChangeColor(false);
  611. if( GameDef.m_AllCardItem[i].GetCardData() == cbCardData && bSelect)
  612. GameDef.m_AllCardItem[i].ChangeColor(true);
  613. }
  614. this.m_Hook.ShowTingTip(cbCardData);
  615. },
  616. GetCardCount:function(){
  617. return this.m_wCardCount;
  618. },
  619. //获取扑克
  620. GetCurrentCard:function(){
  621. return this.m_CardItemArray[GameDef.CARD_COUNT].cbCardData;
  622. },
  623. SetPositively:function(bPositively){
  624. this.m_bPositively = bPositively;
  625. },
  626. GetPositively:function(){
  627. return this.m_bPositively;
  628. },
  629. GetShootCard: function () {
  630. for (let idx in this.m_CardItemArray) {
  631. if (!this.m_CardItemArray[idx].node.active) continue;
  632. if (!this.m_CardItemArray[idx].GetCanOut()) continue;
  633. if (!this.m_CardItemArray[idx].GetShoot()) continue;
  634. return this.m_CardItemArray[idx].GetCardData();
  635. }
  636. return 0;
  637. },
  638. //移动一张牌的动画
  639. PlayMoveCard:function(MoveIndex,CardData,CardCount){
  640. if (this.m_HandState != GameDef.HAND_BOTTOM) return true;
  641. this.m_CardItemArray[MoveIndex].SetShow(false);
  642. //出的牌是手牌,手牌不需要移动到牌堆里
  643. if( MoveIndex == GameDef.CARD_COUNT) return true;
  644. //查找手牌移入空位
  645. var HandCardData = this.m_CardItemArray[GameDef.CARD_COUNT].GetCardData();
  646. var moveStar = 0;
  647. for (var i = 0; i < GameDef.CARD_COUNT; i++) {
  648. if(HandCardData == CardData[i]){
  649. moveStar = i+this.m_CardStartIndex;
  650. break;
  651. }
  652. }
  653. //移动牌补空
  654. var dir = 1;
  655. if( MoveIndex < moveStar ){
  656. var tmp = moveStar;
  657. moveStar = MoveIndex ;
  658. MoveIndex = tmp+1;
  659. dir *= -1;
  660. }
  661. for (var i = moveStar; i < MoveIndex; i++) {
  662. var pos = this.m_CardItemArray[i].node.getPosition();
  663. pos.x += this.m_CardItemArray[i].node.width * dir;
  664. this.m_CardItemArray[i].node.runAction(cc.moveTo(0.2,pos),);
  665. }
  666. //手牌移入牌堆
  667. this.m_CardItemArray[GameDef.CARD_COUNT].SetShow(false);
  668. this.m_HandCard.node.active = true;
  669. this.m_HandCard.node.setPosition(this.m_CurrentCard.getPosition());
  670. this.m_HandCard.SetCardData(this.m_CardItemArray[GameDef.CARD_COUNT].GetCardData());
  671. var movePos = this.m_CardItemArray[moveStar].node.convertToWorldSpaceAR(cc.v2(0, 0));
  672. movePos = this.node.convertToNodeSpaceAR(movePos);
  673. var sqlHand = cc.sequence(cc.moveTo(0.2, cc.v2(movePos)),cc.callFunc(function(){
  674. this.ResetPos();
  675. if( CardData != null && CardCount > 0)
  676. this.SetCardData(CardData,CardCount);
  677. this.m_HandCard.node.active = false;
  678. },this));
  679. this.m_HandCard.node.runAction(sqlHand);
  680. },
  681. SetMagicIndex:function(magic){
  682. this.m_cbMagicIndex = magic;
  683. this.m_MagicData = GameDef.g_GameLogic.SwitchToCardData(magic);
  684. },
  685. touchCardNode:function(location){
  686. for (var i = 0; i < this.m_CardItemArray.length; i++) {
  687. if(this.m_CardItemArray[i].GetCardData() == 0)continue;
  688. var boxCollider = this.m_CardItemArray[i].node.getComponent(cc.BoxCollider);
  689. boxCollider.world.points[0].y += 70;
  690. boxCollider.world.points[3].y += 70;
  691. if (cc.Intersection.pointInPolygon(location, boxCollider.world.points)) {
  692. return this.m_CardItemArray[i];
  693. }
  694. }
  695. return null;
  696. },
  697. ShowTingData:function(pData, bListen){
  698. for(var i in this.m_CardItemArray)
  699. {
  700. this.m_CardItemArray[i].SetTingTip(false);
  701. if(bListen)
  702. {
  703. this.m_CardItemArray[i].SetCanOut(false);
  704. }
  705. else
  706. {
  707. this.m_CardItemArray[i].SetCanOut(true);
  708. }
  709. }
  710. this.m_TingData = pData;
  711. if( pData != null ){
  712. for(var i in this.m_CardItemArray)
  713. {
  714. for (var j = 0; j < pData.length; j++) {
  715. if(pData[j].cbOutCardData == this.m_CardItemArray[i].GetCardData() && this.m_CardItemArray[i].node.active )
  716. {
  717. this.m_CardItemArray[i].SetTingTip(true);
  718. this.m_CardItemArray[i].SetCanOut(true);
  719. }
  720. }
  721. }
  722. }
  723. },
  724. SetHook:function(hook){
  725. this.m_Hook = hook;
  726. },
  727. SetCanTouch:function(bCanTouch)
  728. {
  729. this.m_bCanTouch = bCanTouch;
  730. },
  731. GetCanTouch: function () {
  732. return this.m_bCanTouch;
  733. },
  734. SetOutCard:function(cbOutCardData, OutCardIndex)
  735. {
  736. this.m_OutCardData = cbOutCardData;
  737. if(OutCardIndex != null)
  738. {
  739. this.m_OutCardIndex = OutCardIndex;
  740. }
  741. else
  742. {
  743. for(var i in this.m_CardItemArray)
  744. {
  745. if(cbOutCardData == this.m_CardItemArray[i].GetCardData() && this.m_CardItemArray[i].node.active )
  746. {
  747. this.m_OutCardIndex = i;
  748. break;
  749. }
  750. }
  751. }
  752. },
  753. //锁定牌
  754. SetLockCardData:function(cbCardData, wCardCount, cbLockCardData, wLockCount, bIsListen, bHasCurr)
  755. {
  756. this.m_wCardCount = wCardCount;
  757. if(bHasCurr)
  758. {
  759. this.m_wCardCount = wCardCount - 1;
  760. }
  761. if( cbCardData != null && this.m_wCardCount > 0 )
  762. {
  763. //锁定的牌放在最前面
  764. if(cbLockCardData != null && wLockCount > 0)
  765. {
  766. var nIndex = 0;
  767. for(var i = 0; i < wLockCount; i++)
  768. {
  769. for(var j = nIndex; j < wCardCount; j++)
  770. {
  771. if(cbCardData[j] == cbLockCardData[i])
  772. {
  773. cbCardData.splice(j,1);
  774. cbCardData.splice(nIndex,0,cbLockCardData[i]);
  775. nIndex++;
  776. break;
  777. }
  778. }
  779. }
  780. }
  781. for (var i = 0; i < this.m_CardItemArray.length; i++)
  782. {
  783. this.m_CardItemArray[i].SetCardData(0);
  784. this.m_CardItemArray[i].SetShow(false);
  785. this.m_CardItemArray[i].SetLockTips(false);
  786. }
  787. for(var i = 0;i<this.m_wCardCount ;i++)
  788. {
  789. this.m_CardItemArray[i].SetShow(true);
  790. this.m_cbCardData[i] = cbCardData[i];
  791. this.m_CardItemArray[i].SetCardData(cbCardData[i]);
  792. this.m_CardItemArray[i].SetCanOut(true);
  793. if(i < wLockCount)
  794. {
  795. //亮倒后只能出上听牌
  796. var bCanOut= false;
  797. var MeChair = GameDef.g_GameEngine.GetMeChairID();
  798. if(GameDef.g_GameEngine.m_bLiang[MeChair]){
  799. for(var k=0;k<34;++k)
  800. {
  801. if(GameDef.g_GameEngine.m_OutEndTingData[k] != 0)
  802. {
  803. if(GameDef.g_GameEngine.m_OutEndTingData[k] == cbCardData[i])
  804. {
  805. bCanOut = true;
  806. break;
  807. }
  808. }
  809. }
  810. }
  811. if(bCanOut)continue;
  812. this.m_CardItemArray[i].SetLockTips(true);
  813. }
  814. if(bIsListen)
  815. {
  816. this.m_CardItemArray[i].SetCanOut(false);
  817. this.m_CardItemArray[i].SetTingTip(false);
  818. }
  819. }
  820. if(this.m_HandState == GameDef.HAND_BOTTOM && GameDef.CARD_COUNT >= this.m_wCardCount){
  821. var offset = GameDef.CARD_COUNT-this.m_wCardCount;
  822. this.ResetPos(offset, wLockCount);
  823. }
  824. }
  825. else
  826. {
  827. for(var i = 0;i < this.m_CardItemArray.length;i++ )
  828. {
  829. this.m_cbCardData[i] = 0;
  830. this.m_CardItemArray[i].SetCardData(0);
  831. this.m_CardItemArray[i].SetShow(i<this.m_wCardCount);
  832. if(i >= this.m_wCardCount - wLockCount)
  833. {
  834. this.m_CardItemArray[i].SetLockTips(true);
  835. }
  836. }
  837. }
  838. //this.ShowTingData(this.m_TingData);
  839. },
  840. });