You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

855 lines
24 KiB

  1. local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
  2. local PKFunctions = {}
  3. --预加载图片
  4. function PKFunctions.loadSpriteFromFile(fileName)
  5. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile(fileName);
  6. end
  7. --获取版本号
  8. function PKFunctions.getPKCurVersion()
  9. local versionInfo = PKFramework.PKImport("PKVersion")
  10. return versionInfo.ResourceVersion
  11. end
  12. --创建一个imageNode
  13. function PKFunctions.createImageNode(fileName)
  14. local img = cc.ImageView:createNode()
  15. img:loadTextureFromPlist(fileName)
  16. return img
  17. end
  18. --获取创建房间时选择的人数
  19. function PKFunctions.getCreateRoomPlayerNum()
  20. local roomInfo = app.room.roomInfo;
  21. local jsonInfo = json.decode(roomInfo.strGameInfo)
  22. if jsonInfo then
  23. if jsonInfo.playerNum == 5 then
  24. return 4
  25. else
  26. return jsonInfo.playerNum
  27. end
  28. end
  29. return nil
  30. end
  31. function PKFunctions.getCardValue(card)
  32. if not card then
  33. logE("card:",card)
  34. logE("getCardValue error:")
  35. return
  36. end
  37. local value = card - math.floor(card / 16) * 16;
  38. return value;
  39. end
  40. function PKFunctions.getCardColor(card)
  41. if not card then
  42. logE("card:",card)
  43. logE("getCardColor error:")
  44. return
  45. end
  46. local color = math.floor(card / 16);
  47. return color;
  48. end
  49. --获取字牌资源名字
  50. function PKFunctions.getPKCardImgByValue(card)
  51. if card == 0xff then
  52. return "pk_cards_back.png";
  53. else
  54. local color = PKFunctions.getCardColor(card);
  55. local value = PKFunctions.getCardValue(card);
  56. local file = "pk_cards_"..color.."_"..value..".png";
  57. return file;
  58. end
  59. end
  60. function PKFunctions.logCard(card)
  61. local cardColor = PKFunctions.getCardColor(card);
  62. local cardValue = PKFunctions.getCardValue(card);
  63. local str = "找不到这个牌";
  64. local valueStr = "";
  65. if cardValue < 9 then
  66. cardValue = cardValue + 2;
  67. valueStr = cardValue.."";
  68. elseif cardValue == 9 then
  69. valueStr = "J";
  70. elseif cardValue == 10 then
  71. valueStr = "Q";
  72. elseif cardValue == 11 then
  73. valueStr = "K";
  74. elseif cardValue == 12 then
  75. valueStr = "A";
  76. elseif cardValue == 13 then
  77. valueStr = "2";
  78. end
  79. if cardColor == 0 then
  80. str = "方块" .. valueStr;
  81. elseif cardColor == 1 then
  82. str = "梅花".. valueStr;
  83. elseif cardColor == 2 then
  84. str = "红桃" .. valueStr;
  85. elseif cardColor == 3 then
  86. str = "黑桃" .. valueStr;
  87. elseif cardColor == 4 then
  88. if cardValue == 14 then
  89. str = "小王";
  90. else
  91. str = "大王";
  92. end
  93. end
  94. str = str .. "(原数据:" .. card .. ")";
  95. logD(str)
  96. end
  97. function PKFunctions.getIsCanOutCard(list, cardInfo, lastData)
  98. local tpCardsList = {}
  99. if 0 == table.nums(lastData.cardList) then
  100. if table.nums(cardInfo) > 0 then
  101. for k,v in pairs(cardInfo) do
  102. table.insert(tpCardsList,v.cards)
  103. end
  104. end
  105. return tpCardsList
  106. end
  107. local tpCardList = {}
  108. for i = 1,table.nums(lastData.cardList) do
  109. table.insert(tpCardList,lastData.cardList[i])
  110. end
  111. local tpLastInfo = PKFunctions.getCardType(tpCardList)
  112. for _k2,v in pairs(cardInfo) do
  113. if v.cardType == tpLastInfo[1].cardType then
  114. if v.cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN or
  115. v.cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN or
  116. v.cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN then
  117. if table.nums(list) > table.nums(lastData.cardList) then
  118. table.insert(tpCardsList,v.cards)
  119. else
  120. if table.nums(list) == table.nums(lastData.cardList) and v.minCard > tpLastInfo[1].minCard then
  121. table.insert(tpCardsList,v.cards)
  122. end
  123. end
  124. else
  125. if v.minCard > tpLastInfo[1].minCard and table.nums(list) == table.nums(lastData.cardList) then
  126. table.insert(tpCardsList,v.cards)
  127. end
  128. end
  129. else
  130. if v.cardType > tpLastInfo[1].cardType and v.cardType > PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUNZI then
  131. table.insert(tpCardsList,v.cards)
  132. end
  133. end
  134. end
  135. return tpCardsList
  136. end
  137. function PKFunctions.getRogueCount(list)
  138. local tpCount = 0
  139. for i = 1,table.nums(list) do
  140. if 14 == PKFunctions.getCardValue(list[i]) then
  141. tpCount = tpCount + 1
  142. end
  143. end
  144. return tpCount
  145. end
  146. function PKFunctions.getCardType(list)
  147. logD("getCardType list:",table.tostring(list))
  148. --存储非癞子值
  149. local tt = {}
  150. --存储非癞子的原始数据(包括花色和值)
  151. local ttt = {}
  152. local tpCardInfo = {}
  153. local laiCount = PKFunctions.getRogueCount(list)
  154. for i = 1,table.nums(list) do
  155. local value = PKFunctions.getCardValue(list[i]);
  156. if 0x0e ~= value then
  157. table.insert(tt,value)
  158. table.insert(ttt,list[i])
  159. end
  160. end
  161. local max = table.nums(tt)
  162. if max <= 0 then
  163. return tpCardInfo
  164. end
  165. local function sortFunc(a,b)
  166. local numA = tonumber(a)
  167. local numB = tonumber(b)
  168. if numA ~= nil and numB ~= nil then
  169. return numA < numB
  170. else
  171. return a < b
  172. end
  173. end
  174. table.sort(tt,sortFunc)
  175. table.sort(ttt,sortFunc)
  176. if max + laiCount < 3 then
  177. if tt[1] == tt[max] then
  178. if max + laiCount == 1 then--单张
  179. table.insert(tpCardInfo,{
  180. minCard = tt[1],
  181. cardType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SINGLE,
  182. cards = list
  183. })
  184. elseif (max + laiCount == 2) then --对子
  185. local tpList = {}
  186. for i = 1, table.nums(ttt) do
  187. table.insert(tpList,ttt[i])
  188. end
  189. for i = 1,laiCount do
  190. table.insert(tpList,0x50 + PKFunctions.getCardValue(ttt[1]))
  191. end
  192. table.insert(tpCardInfo,{
  193. minCard = tt[1],
  194. cardType = PKDef.CARD_TYPE.BANZIPAO_TYPE_DUIZI,
  195. cards = tpList
  196. })
  197. end
  198. end
  199. elseif tt[1] == tt[max] then
  200. if max + laiCount == 3 then
  201. local tpList = {}
  202. for i = 1,table.nums(ttt) do
  203. table.insert(tpList,ttt[i])
  204. end
  205. for i = 1,laiCount do
  206. table.insert(tpList,0x50 + PKFunctions.getCardValue(ttt[1]))
  207. end
  208. table.insert(tpCardInfo,{
  209. minCard = tt[1],
  210. cardType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SANZHANG,
  211. cards = tpList
  212. })
  213. elseif max + laiCount == 4 then
  214. local tpList = {}
  215. for i = 1,table.nums(ttt)do
  216. table.insert(tpList,ttt[i])
  217. end
  218. for i = 1,laiCount do
  219. table.insert(tpList,0x50 + PKFunctions.getCardValue(ttt[1]))
  220. end
  221. table.insert(tpCardInfo,{
  222. minCard = tt[1],
  223. cardType = PKDef.CARD_TYPE.BANZIPAO_TYPE_BOMB,
  224. cards = tpList
  225. })
  226. end
  227. else
  228. --定义个新数组
  229. --其中a[1]的值为list中重复一次(单张牌)的牌,
  230. -- a[2]的值为list中重复二次(对牌)的牌,
  231. -- a[3]的值为list中重复三次(三张)的牌,
  232. -- a[4]的值为list中重复四次(炸弹)的牌。
  233. local a = {}
  234. for i = 1,4 do
  235. a[i] = {}
  236. end
  237. local valueList = {} --(key是值,value是数量)
  238. for i = 1, table.nums(tt) do
  239. local value = PKFunctions.getCardValue(tt[i])
  240. if not valueList[value] then
  241. valueList[value] = 0
  242. end
  243. valueList[value] = valueList[value] + 1;
  244. end
  245. for card,count in pairs(valueList) do
  246. card = tonumber(card)
  247. if count == 1 then
  248. table.insert(a[1],card)
  249. elseif count == 2 then
  250. table.insert(a[2],card)
  251. elseif count == 3 then
  252. table.insert(a[3],card)
  253. elseif count == 4 then
  254. table.insert(a[4],card)
  255. end
  256. end
  257. local isHaveKindOr2 = false;
  258. for i = 1,max do
  259. local value = tt[i]
  260. if 0x0d == value then
  261. isHaveKindOr2 = true
  262. end
  263. end
  264. --_idx :某个牌的个数
  265. --_k :组数
  266. local function tpMove(_idx, _k)
  267. local tpCards = {}
  268. local laiCount2 = PKFunctions.getRogueCount(list)
  269. local valueList = {} --(key是值,value是数量) 除去癞子
  270. for i = 1, table.nums(list) do
  271. local value = PKFunctions.getCardValue(list[i])
  272. if 0x0e ~= value then
  273. if not valueList[value] then
  274. valueList[value] = 0
  275. end
  276. valueList[value] = valueList[value] + 1
  277. end
  278. end
  279. --33 4 55 ?
  280. for i = 1,12 do --3-A
  281. local tpIdx = i
  282. local tpCount = 0
  283. local laiziList = {}
  284. local totalLaiZi = laiCount2
  285. while tpCount <= table.nums(list) and tpIdx <= 12 do
  286. if not valueList[tpIdx] then
  287. valueList[tpIdx] = 0
  288. end
  289. if not (valueList[tpIdx] + totalLaiZi >= _k) then
  290. break
  291. end
  292. local needLaiZiNum = _k - valueList[tpIdx]
  293. needLaiZiNum = needLaiZiNum >= 0 and needLaiZiNum or 0
  294. for l = 1,needLaiZiNum do
  295. table.insert(laiziList,0x50 + tpIdx)
  296. end
  297. totalLaiZi = totalLaiZi - needLaiZiNum
  298. tpCount = tpCount + _k
  299. tpIdx = tpIdx + 1
  300. end
  301. if table.nums(list) == tpCount then
  302. table.insert(tpCards,{
  303. cards = laiziList,
  304. min = i
  305. })
  306. end
  307. end
  308. local tpType = 0
  309. if _idx == 1 then
  310. tpType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUNZI;
  311. elseif _idx == 2 then
  312. tpType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN;
  313. elseif _idx == 3 then
  314. tpType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN;
  315. elseif _idx == 4 then
  316. tpType = PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN;
  317. end
  318. if table.nums(tpCards) > 0 and tpType then
  319. for k1 ,v1 in pairs(tpCards) do
  320. local _tpList3 = {}
  321. for _i8 = 1, table.nums(ttt) do
  322. table.insert(_tpList3,ttt[_i8])
  323. end
  324. for k2,v2 in pairs(v1.cards) do
  325. table.insert(_tpList3,v2)
  326. end
  327. local function sortFunc2(a,b)
  328. return tonumber(PKFunctions.getCardValue(a)) < tonumber(PKFunctions.getCardValue(b))
  329. end
  330. table.sort(_tpList3,sortFunc2)
  331. table.insert(tpCardInfo,{
  332. minCard = tpCards[k1].min,
  333. cardType = tpType,
  334. cards = _tpList3
  335. })
  336. end
  337. end
  338. end
  339. local tpTotalCount = max + laiCount
  340. if not isHaveKindOr2 then
  341. local tpDif = math.abs(tt[1] - tt[max])
  342. for k1 = table.nums(a),1,-1 do
  343. local tpk = k1
  344. local tpDis = tpTotalCount / tpk - 1
  345. if tpTotalCount >= 3 * tpk and tpTotalCount % tpk == 0 and tpDif <= tpDis then
  346. if table.nums(a[k1]) * tpk == max then
  347. tpMove(k1, tpk)
  348. else
  349. local tpLen = table.nums(a[k1]) * tpk
  350. for k2 = 1, k1 - 1 do
  351. tpLen = tpLen + table.nums(a[k2]) * k2
  352. end
  353. if tpLen == max then
  354. tpMove(k1, tpk)
  355. end
  356. end
  357. end
  358. end
  359. end
  360. --天牌(初略判断:十三张牌全不一样(赖子可重复)则为天牌)
  361. if table.nums(list) == 13 and table.nums(a[2]) == 0 and table.nums(a[3]) == 0 and table.nums(a[4]) == 0 then
  362. local _tpList3 = {}
  363. for i = 1,table.nums(ttt) do
  364. table.insert(_tpList3,ttt[i])
  365. end
  366. for i = 1,13 do
  367. if table.nums(_tpList3) < 13 then
  368. if not valueList[i] then
  369. table.insert(_tpList3,0x50 + i)
  370. end
  371. else
  372. break
  373. end
  374. end
  375. table.insert(tpCardInfo,{
  376. minCard = ttt[1],
  377. cardType = PKDef.CARD_TYPE.BANZIPAO_TYPE_TIANPAI,
  378. cards = _tpList3
  379. })
  380. end
  381. end
  382. table.sort(tpCardInfo,function (a,b)
  383. return b.cardType < a.cardType
  384. end)
  385. logD("getCardType tpCardInfo:",table.tostring(tpCardInfo))
  386. return tpCardInfo
  387. end
  388. function PKFunctions.getTip(list, lastData)
  389. local laiCard = {}
  390. local weaveList = {}
  391. local a = {}
  392. for i = 1,4 do
  393. a[i] = {}
  394. end
  395. local valueList = {}
  396. local valueCard = {}
  397. for i = 1, table.nums(list) do
  398. local value = PKFunctions.getCardValue(list[i])
  399. if 14 == value then
  400. table.insert(laiCard,list[i])
  401. else
  402. if not valueList[value] then
  403. valueList[value] = 0
  404. end
  405. if not valueCard[value] then
  406. valueCard[value] = {}
  407. end
  408. valueList[value] = valueList[value] + 1;
  409. table.insert(valueCard[value],list[i])
  410. end
  411. end
  412. for card,v in pairs(valueList) do
  413. card = tonumber(card)
  414. local count = valueList[card]
  415. if 1 == count then
  416. table.insert(a[1],card)
  417. elseif count == 2 then
  418. table.insert(a[2],card)
  419. elseif count == 3 then
  420. table.insert(a[3],card)
  421. elseif count == 4 then
  422. table.insert(a[4],card)
  423. end
  424. end
  425. function sortNumber(a, b)
  426. return a < b;
  427. end
  428. if not lastData or not lastData.cardList or table.nums(lastData.cardList) <= 0 then
  429. local tpCardInfo = PKFunctions.getCardType(list)
  430. if tpCardInfo and table.nums(tpCardInfo) > 0 then
  431. table.insert(weaveList,list)
  432. end
  433. function sortNumber(a, b)
  434. return PKFunctions.getCardValue(a[1]) < PKFunctions.getCardValue(b[1]);
  435. end
  436. for k = 1,4 do
  437. for i = 1, table.nums(a[k]) do
  438. local value = a[k][i]
  439. for j = 1, 1 do
  440. local curCard = valueCard[value][j]
  441. table.insert(weaveList,{curCard})
  442. end
  443. if k == 1 then
  444. table.sort(weaveList,sortNumber)
  445. end
  446. end
  447. end
  448. return weaveList
  449. end
  450. local tpCardList = {}
  451. for k,v in ipairs(lastData.cardList) do
  452. table.insert(tpCardList,v)
  453. end
  454. local cardInfo = PKFunctions.getCardType(tpCardList)
  455. local laiCount = PKFunctions.getRogueCount(list)
  456. local cardList = lastData.cardList;
  457. local cardValueList = {}
  458. for k,v in ipairs(lastData.cardList) do
  459. table.insert(cardValueList,PKFunctions.getCardValue(v))
  460. end
  461. table.sort(cardValueList,sortNumber)
  462. local lastValue = cardValueList[1] or 0
  463. if cardInfo[1].cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SINGLE then
  464. for k = 1,4 do
  465. for i = 1,table.nums(a[k]) do
  466. local value = a[k][i];
  467. for j = 1,1 do
  468. if value > lastValue then
  469. local curCard = valueCard[value][j];
  470. table.insert(weaveList,{curCard})
  471. end
  472. end
  473. end
  474. end
  475. elseif cardInfo[1].cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_DUIZI then
  476. for i = cardInfo[1].minCard + 1,13 do --yihuo
  477. local _tpReplace = {}
  478. valueList[i] = valueList[i] or 0;
  479. if valueList[i] ~= 0 and valueList[i] + laiCount >= 2 then
  480. local tpNum = 2 - valueList[i];
  481. if tpNum < 0 then
  482. tpNum = 0
  483. end
  484. for l = 1,tpNum do
  485. table.insert(_tpReplace,laiCard[l])
  486. end
  487. for m = 1,valueList[i] do
  488. if m <= 2 then
  489. table.insert(_tpReplace,valueCard[i][m])
  490. end
  491. end
  492. table.insert(weaveList,_tpReplace)
  493. end
  494. end
  495. elseif cardInfo[1].cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUNZI then
  496. for i = cardInfo[1].minCard + 1, 13 - table.nums(cardList) do --yihuo
  497. local tpIdx = i;
  498. local tpCount = 0;
  499. local tpReplace2 = {};
  500. local tpNotAllLai = false;
  501. local totalLaiZi = laiCount;
  502. while tpCount < table.nums(list) and tpCount < table.nums(cardList) and tpIdx <= 12 do
  503. valueList[tpIdx] = valueList[tpIdx] or 0;
  504. if not (valueList[tpIdx] + totalLaiZi >= 1) then
  505. break
  506. end
  507. local tpNum = 1 - valueList[tpIdx];
  508. if tpNum < 0 then
  509. tpNum = 0
  510. end
  511. --[[ for p = 1, tpNum do
  512. table.insert(tpReplace2,laiCard[p])
  513. end--]]
  514. local i = laiCount - totalLaiZi
  515. for p = 1, tpNum do
  516. i = i + 1
  517. table.insert(tpReplace2,laiCard[i])
  518. end
  519. for m = 1, valueList[tpIdx] do
  520. if m <= 1 then
  521. table.insert(tpReplace2,valueCard[tpIdx][m])
  522. tpNotAllLai = true;
  523. end
  524. end
  525. totalLaiZi = totalLaiZi - tpNum;
  526. tpCount = tpCount + 1
  527. tpIdx = tpIdx + 1;
  528. end
  529. if tpNotAllLai and tpCount == table.nums(cardList) then
  530. table.insert(weaveList,tpReplace2)
  531. end
  532. end
  533. --去除重复的组合,比如456+癞可以组合 3456,4567
  534. local tt = {}
  535. local removeIdx= {}
  536. for k,list in ipairs(weaveList) do
  537. local curSum = 0
  538. for j,card in ipairs(list) do
  539. local value = PKFunctions.getCardValue(card)
  540. curSum = curSum + value
  541. end
  542. if tt[curSum] then
  543. table.insert(removeIdx,k)
  544. end
  545. tt[curSum] = k
  546. end
  547. for k,v in ipairs(removeIdx) do
  548. if weaveList[k] then
  549. table.remove(weaveList,k)
  550. end
  551. end
  552. end
  553. if cardInfo[1].cardType <= PKDef.CARD_TYPE.BANZIPAO_TYPE_SANZHANG then
  554. if cardInfo[1].cardType < PKDef.CARD_TYPE.BANZIPAO_TYPE_SANZHANG then
  555. tpIndex = 1
  556. else
  557. tpIndex = cardInfo[1].minCard + 1
  558. end
  559. for _i12 = tpIndex ,13 do -- yihuo
  560. local _tpReplace3 = {}
  561. valueList[_i12] = valueList[_i12] or 0;
  562. if valueList[_i12] > 0 and valueList[_i12] + laiCount >= 3 then
  563. local _tpNum2 = 3 - valueList[_i12]
  564. if _tpNum2 < 0 then
  565. _tpNum2 = 0
  566. end
  567. for _l2 = 1, _tpNum2 do
  568. table.insert(_tpReplace3,laiCard[_l2])
  569. end
  570. for _m2 = 1,valueList[_i12] do
  571. if _m2 <= 3 then
  572. table.insert(_tpReplace3,valueCard[_i12][_m2])
  573. end
  574. end
  575. table.insert(weaveList,_tpReplace3)
  576. end
  577. end
  578. end
  579. if cardInfo[1].cardType <= PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN then
  580. for _i13 = 1, 13 - (table.nums(cardList) / 2) do --yihuo
  581. local tpIdx = _i13
  582. local tpCount = 0
  583. local tpReplace = {}
  584. local haveLai = laiCount;
  585. while tpCount < table.nums(list) and tpIdx <= 12 do
  586. if not valueList[tpIdx] then
  587. valueList[tpIdx] = 0
  588. end
  589. if not (valueList[tpIdx] + haveLai >= 2) then
  590. break;
  591. end
  592. local _tpNum3 = 2 - valueList[tpIdx];
  593. if _tpNum3 >= 0 then
  594. _tpNum3 = _tpNum3
  595. else
  596. _tpNum3 = 0
  597. end
  598. local _l3 = laiCount - haveLai
  599. for _p = 1, _tpNum3 do
  600. _l3 = _l3 + 1
  601. table.insert(tpReplace,laiCard[_l3])
  602. end
  603. for _m3 = 1,valueList[tpIdx] do
  604. if _m3 <= 2 then
  605. table.insert(tpReplace,valueCard[tpIdx][_m3]);
  606. end
  607. end
  608. haveLai = haveLai - _tpNum3;
  609. tpCount = tpCount + 2;
  610. if tpCount >= 6 and (cardInfo[1].cardType < PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN or
  611. ((_i13 > cardInfo[1].minCard and tpCount >= table.nums(cardList)) or
  612. (_i13 <= cardInfo[1].minCard and tpCount > table.nums(cardList)))) then
  613. local tpReplace2 = {};
  614. for k1,v in pairs(tpReplace) do
  615. table.insert(tpReplace2,tpReplace[k1]);
  616. end
  617. table.insert(weaveList,tpReplace2)
  618. end
  619. tpIdx = tpIdx + 1;
  620. end
  621. end
  622. end
  623. if cardInfo[1].cardType <= PKDef.CARD_TYPE.BANZIPAO_TYPE_BOMB then
  624. if cardInfo[1].cardType < PKDef.CARD_TYPE.BANZIPAO_TYPE_BOMB then
  625. _tpIndex = 1
  626. else
  627. _tpIndex = cardInfo[1].minCard + 1;
  628. end
  629. for _i14 = _tpIndex, 13 do --yihuo
  630. local _tpReplace4 = {};
  631. if not valueList[_i14] then
  632. valueList[_i14] = 0
  633. end
  634. if valueList[_i14] > 0 and valueList[_i14] + laiCount >= 4 then
  635. local _tpNum4 = 4 - valueList[_i14];
  636. if _tpNum4 < 0 then
  637. _tpNum4 = 0
  638. end
  639. for _l4 = 1, _tpNum4 do
  640. table.insert(_tpReplace4,laiCard[_l4])
  641. end
  642. for _m4 = 1, valueList[_i14] do
  643. if _m4 <= 4 then
  644. table.insert(_tpReplace4,valueCard[_i14][_m4])
  645. end
  646. end
  647. table.insert(weaveList,_tpReplace4)
  648. end
  649. end
  650. end
  651. if cardInfo[1].cardType <= PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN then
  652. for _i15 = 1,13 - (table.nums(cardList) / 3) do --yihuo
  653. local _tpIdx2 = _i15;
  654. local _tpCount2 = 0;
  655. local _tpReplace5 = {};
  656. local _haveLai2 = laiCount;
  657. while _tpCount2 < table.nums(list)and _tpIdx2 <= 12 do
  658. if not valueList[_tpIdx2] then
  659. valueList[_tpIdx2] = 0
  660. end
  661. if not (valueList[_tpIdx2] + _haveLai2 >= 3) then
  662. break
  663. end
  664. local _tpNum5 = 3 - valueList[_tpIdx2];
  665. if _tpNum5 < 0 then
  666. _tpNum5 = 0
  667. end
  668. local _l5 = laiCount - _haveLai2
  669. for _p2 = 1,_tpNum5 do
  670. table.insert(_tpReplace5,laiCard[_l5])
  671. _l5 = _l5 + 1
  672. end
  673. for _m5 = 1, valueList[_tpIdx2] do
  674. if _m5 <= 3 then
  675. table.insert(_tpReplace5,valueCard[_tpIdx2][_m5])
  676. end
  677. end
  678. _haveLai2 = _haveLai2 - _tpNum5
  679. _tpCount2 = _tpCount2 + 3;
  680. if _tpCount2 >= 9 and
  681. (cardInfo[1].cardType < PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN or
  682. ((_i15 > cardInfo[1].minCard and _tpCount2 >= table.nums(cardList)) or
  683. (_i15 <= cardInfo[1].minCard and _tpCount2 > table.nums(cardList)))) then
  684. local tpReplace2 = {}
  685. for k1,v in pairs(_tpReplace5) do
  686. table.insert(tpReplace2,_tpReplace5[k1]);
  687. end
  688. table.insert(weaveList,tpReplace2)
  689. end
  690. _tpIdx2 = _tpIdx2 + 1
  691. end
  692. end
  693. end
  694. if cardInfo[1].cardType <= PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN then
  695. for _i16 = 1, 13 - (table.nums(cardList) / 4) do
  696. local _tpIdx3 = _i16;
  697. local _tpCount3 = 0;
  698. local _tpReplace6 = {}
  699. local _haveLai3 = laiCount;
  700. while _tpCount3 < table.nums(list) and _tpIdx3 <= 12 do
  701. if not valueList[_tpIdx3] then
  702. valueList[_tpIdx3] = 0
  703. end
  704. if not (valueList[_tpIdx3] + _haveLai3 >= 4) then
  705. break
  706. end
  707. local _tpNum6 = 4 - valueList[_tpIdx3];
  708. if _tpNum6 < 0 then
  709. _tpNum6 = 0
  710. end
  711. local _l6 = laiCount - _haveLai3
  712. for _p3 = 1, _tpNum6 do
  713. table.insert(_tpReplace6,laiCard[_l6]);
  714. _l6 = _l6 + 1
  715. end
  716. for _m6 = 1,valueList[_tpIdx3] do
  717. if _m6 <= 4 then
  718. table.insert(_tpReplace6,valueCard[_tpIdx3][_m6]);
  719. end
  720. end
  721. _haveLai3 = _haveLai3 - _tpNum6;
  722. _tpCount3 = _tpCount3 + 4;
  723. if _tpCount3 >= 12 and
  724. (cardInfo[1].cardType < PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN or
  725. ((_i16 > cardInfo[1].minCard and _tpCount3 >= table.nums(cardList)) or
  726. (_i16 <= cardInfo[1].minCard and _tpCount3 > table.nums(cardList)))) then
  727. local tpReplace2 = {}
  728. for k1,v in pairs(_tpReplace6) do
  729. table.insert(tpReplace2,_tpReplace6[k1])
  730. end
  731. table.insert(weaveList,tpReplace2)
  732. end
  733. _tpIdx3 = _tpIdx3 + 1
  734. end
  735. end
  736. end
  737. logD("weaveList:",table.tostring(weaveList))
  738. return weaveList;
  739. end
  740. function PKFunctions.convertToCards(str)
  741. str = string.trim(str)
  742. local tab = string.split(str, " ")
  743. if str == "" then
  744. tab = {}
  745. end
  746. return tab
  747. end
  748. function PKFunctions.playAniOnce(parent,max,everyFrame,path,pos,callback,scale)
  749. local firstImg = string.format(path,1)
  750. -- 创建图片
  751. local nodeImage = cc.ImageView:createNode()
  752. nodeImage:loadTextureFromPlist(firstImg);
  753. parent:addChild(nodeImage)
  754. local size = parent:getContentSize();
  755. nodeImage:setPosition(pos);
  756. --判断纹理是否存在
  757. local cache = cc.SpriteFrameCache:getInstance()
  758. local spriteFrame = cache:getSpriteFrameByName(firstImg);
  759. if tolua.isnull(spriteFrame) then
  760. print("spriteFrame is not in cache")
  761. nodeImage:removeFromParent()
  762. return
  763. end
  764. if scale then
  765. nodeImage:setScale(scale)
  766. end
  767. nodeImage:runAction(cc.Sequence:create(cc.CallFunc:create(function ()
  768. local indexFace = 0;
  769. --每隔多少秒切换一张图片
  770. --local everyFrame = 0.1;
  771. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  772. indexFace = indexFace + 1
  773. if 0 < indexFace and indexFace <= max then
  774. local name = string.format(path,indexFace)
  775. if not tolua.isnull(nodeImage) then
  776. nodeImage:loadTexture(name, cc.TextureResType.plistType)
  777. end
  778. else
  779. indexFace = 0
  780. end
  781. end))
  782. local seq2 = cc.Sequence:create(cc.Repeat:create(seq,max),cc.CallFunc:create(function ()
  783. nodeImage:removeFromParent()
  784. if callback then
  785. callback()
  786. end
  787. end));
  788. nodeImage:runAction(seq2)
  789. end)))
  790. end
  791. return PKFunctions