選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

506 行
16 KiB

  1. local defs = require("pk_nanchongdoudizhu.luaScript.Def_53")
  2. local Functions = require("pk_nanchongdoudizhu.luaScript.Functions_53")
  3. local PokerUtil = require('pk_nanchongdoudizhu.luaScript.Views.Room.PokerUtil') -- 基类文件
  4. local newPokerUtil = class("newPokerUtil", PokerUtil)
  5. local isResetSelectCard = true -- 是否启动滑动手牌并返回特殊的牌型
  6. local Value_2 = 0x0d -- 2的具体值
  7. local Value_Joker_Little = 0x0e -- 小鬼的具体值
  8. local Value_Joker_Big = 0x0f -- 大鬼的具体值
  9. function newPokerUtil:ctor(param)
  10. newPokerUtil.super.ctor(self, param)
  11. local isLzWanFa = Functions.getRuleIncludeLzWanFa()
  12. -- 没有癞子玩法
  13. if not isLzWanFa then
  14. newPokerUtil.Card_Max_Length = 20
  15. newPokerUtil.Is_Use_God_Card = false
  16. else
  17. newPokerUtil.Card_Max_Length = 21
  18. newPokerUtil.Is_Use_God_Card = true
  19. end
  20. end
  21. function newPokerUtil:initTypeMap()
  22. newPokerUtil.super.initTypeMap(self)
  23. table.insert(self.Card_Type_Map[2], #self.Card_Type_Map[2], self.isLzBombKing) -- 加入癞子王炸弹判断(放在王炸之前)
  24. table.insert(self.Card_Type_Map[4], #self.Card_Type_Map[4], self.isLzBombNormal) -- 加入癞子炸弹判断(放在炸弹之前)
  25. end
  26. -- 获得提示(cards是userdata)
  27. function newPokerUtil:getTip(cards, lastData)
  28. print('jxjx 进入getTip')
  29. dump(cards, 'cards')
  30. dump(lastData, 'lastData')
  31. local tipResult = {}
  32. local lastCardInfo = self:getCardsType(lastData)
  33. if lastCardInfo.cardType < defs.CARD_TYPE.BOMB_LAIZI then
  34. local f = newPokerUtil.Card_Tip_Map[lastCardInfo.cardType]
  35. if f then
  36. print(string.format('jxjx..牌型提示..%s', defs.CARD_TYPE_NAME[lastCardInfo.cardType]))
  37. -- tipResult = newPokerUtil.Card_Tip_Map[lastCardInfo.cardType](self, cards, lastData) -- f是方法 启用initTipMap
  38. tipResult = self[f](self, cards, lastData) -- f是str
  39. end
  40. end
  41. -- 添加软炸弹
  42. if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_LAIZI then
  43. print('jxjx..getTip 添加软炸弹')
  44. local result = self:getBombLZTip(cards, lastData)
  45. if table.nums(result) > 0 then
  46. for _, bomb in ipairs(result) do
  47. table.insert(tipResult, bomb)
  48. end
  49. end
  50. end
  51. -- 添加炸弹
  52. if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB then
  53. print('jxjx..getTip 添加炸弹')
  54. local result = self:getBombTip(cards, lastData)
  55. if table.nums(result) > 0 then
  56. for _, bomb in ipairs(result) do
  57. table.insert(tipResult, bomb)
  58. end
  59. end
  60. end
  61. --王炸
  62. if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_KING then
  63. print('jxjx..getTip 添加王炸')
  64. local result = self:getBombKingTip(cards, lastData)
  65. if table.nums(result) > 0 then
  66. for _, bomb in ipairs(result) do -- 王炸只有1个,虽然多此一举用了循环...
  67. table.insert(tipResult, bomb)
  68. end
  69. end
  70. end
  71. dump(tipResult, 'jxjx gettip 结果')
  72. return tipResult
  73. end
  74. -- 滑牌>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  75. -- 选择的牌的处理(飞机,连对,顺子)
  76. function newPokerUtil:getCardInSelectCard(selectCards)
  77. if not isResetSelectCard then
  78. return selectCards
  79. end
  80. local selectCards = clone(selectCards)
  81. local valueList, valueCard = self:parseCard(selectCards)
  82. -----------------------------------------------------------------------------
  83. -- <<飞机>>
  84. -- 将非王牌,带2的牌,炸弹牌,组合在一起(用于判断连续值)
  85. -- 移除手牌中的炸弹
  86. local temp = {}
  87. for _, v in pairs(valueCard) do
  88. if #v == 3 then -- 插入刚好等于3张的牌
  89. table.insert(temp, v[1]) -- 插入一个值即可,用于检测飞机
  90. end
  91. end
  92. -- 移除手牌中的王牌和2
  93. local nt = self:removeValue_Joker_And_2(temp)
  94. local t = self:getMinInLine(nt, PokerUtil.Less_Plane / 3)
  95. local sameTable = self:getSameValueByVal(selectCards, t, 3)
  96. if #sameTable > 0 then
  97. print('jxjx 滑牌选牌,返回飞机')
  98. return sameTable
  99. end
  100. -----------------------------------------------------------------------------
  101. -- <<连对>>
  102. local temp = {}
  103. for _, v in pairs(valueCard) do
  104. if #v > 1 and #v < 4 then -- 插入大于1张,非炸弹的牌
  105. table.insert(temp, v[1]) -- 插入一个值即可,用于检测连对
  106. end
  107. end
  108. -- 移除手牌中的王牌和2
  109. local nt = self:removeValue_Joker_And_2(temp)
  110. local t = self:getMinInLine(nt, PokerUtil.Less_Lian_Dui / 2)
  111. local sameTable = self:getSameValueByVal(selectCards, t, 2)
  112. if #sameTable > 0 then
  113. print('jxjx 滑牌选牌,返回连对')
  114. return sameTable
  115. end
  116. -----------------------------------------------------------------------------
  117. -- <<顺子>>
  118. local temp = {}
  119. for _, v in pairs(valueCard) do
  120. if #v ~= 4 then -- 插入非炸弹的牌
  121. table.insert(temp, v[1]) -- 插入一个值即可,用于检测顺子
  122. end
  123. end
  124. -- 移除手牌中的王牌和2
  125. local nt = self:removeValue_Joker_And_2(temp)
  126. local t = self:getMinInLine(nt, PokerUtil.Less_Line)
  127. local sameTable = self:getSameValueByVal(selectCards, t, 1)
  128. if #sameTable > 0 then
  129. print('jxjx 滑牌选牌,返回顺子')
  130. return sameTable
  131. end
  132. return selectCards
  133. end
  134. -- 移除王牌和2
  135. function newPokerUtil:removeValue_Joker_And_2(cards)
  136. if not cards then
  137. return {}
  138. end
  139. local t = self:changeCardValue_Standard_To_Specific(cards) -- 返回的是与cards顺序一致的具体牌值表
  140. local nt = {}
  141. for i, value in ipairs(t) do
  142. if value ~= Value_2 and value ~= Value_Joker_Little and value ~= Value_Joker_Big then
  143. table.insert(nt, cards[i])
  144. end
  145. end
  146. table.sort(nt, PokerUtil.sortOrder_By_PokerValue)
  147. return nt
  148. end
  149. -- 获取包含最小值的连续值表,长度最低是lessLength
  150. function newPokerUtil:getMinInLine(pCards, lessLength)
  151. local subLines = self:getSubLine(pCards)
  152. for i = #subLines, 1, -1 do
  153. if #subLines[i] < lessLength then
  154. table.remove(subLines, i)
  155. end
  156. end
  157. if next(subLines) then
  158. return subLines[1]
  159. else
  160. return {}
  161. end
  162. end
  163. -- sCards中,取tCards获得同样具体牌值的数值表 maxCount 单个数值最大个数
  164. function newPokerUtil:getSameValueByVal( sCards, tCards, maxCount)
  165. local temp = {}
  166. for _, t in ipairs(tCards) do
  167. local count = 0
  168. for _, s in ipairs(sCards) do
  169. local tVal = self:getCardValue(t)
  170. local sVal = self:getCardValue(s)
  171. if tVal == sVal and count < maxCount then
  172. table.insert(temp, s)
  173. count = count + 1
  174. end
  175. end
  176. end
  177. return temp
  178. end
  179. -- 检测牌组是否是连续的(返回连续的表值 cards每个值里面有且只有1个)
  180. function newPokerUtil:getSubLine(cards)
  181. local sub = {}
  182. local parseCards = self:changeCardValue_Standard_To_Specific(cards)
  183. for i=#parseCards,1,-1 do
  184. if parseCards[i] and parseCards[i-1] then
  185. if parseCards[i]-1~=parseCards[i-1] then
  186. --断开了
  187. local tmp = {}
  188. for j=#parseCards,i,-1 do
  189. table.insert(tmp, parseCards[j])
  190. end
  191. table.insert(sub, clone(tmp))
  192. for j=#parseCards,i,-1 do
  193. table.remove(parseCards, j)
  194. end
  195. else
  196. if i == 2 then
  197. table.insert(sub, clone(parseCards))
  198. end
  199. end
  200. end
  201. end
  202. -- 内部数据从小到大排序
  203. for i, v in ipairs(sub) do
  204. table.sort(v, PokerUtil.sortOrder)
  205. end
  206. -- 外部数据从小到大排序
  207. table.sort(sub, function(a, b)
  208. return a[1] < b[1]
  209. end)
  210. return sub
  211. end
  212. -- 替代牌>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  213. function newPokerUtil:getGodCardLzBombReplace(cards, min)
  214. local valueList, valueCard, godCards = self:parseCard(cards)
  215. local result = {}
  216. if min < 14 then
  217. for i = 1, 4 - valueList[min] do
  218. table.insert(result, min)
  219. end
  220. else
  221. if (valueList[Value_Joker_Little] or 0) > 0 then
  222. table.insert(result, 0x4f)
  223. elseif (valueList[Value_Joker_Big] or 0) > 0 then
  224. table.insert(result, 0x4e)
  225. end
  226. end
  227. return result
  228. end
  229. -- 牌提示>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  230. -- 软炸弹
  231. function newPokerUtil:getBombLZTip(cards, lastData)
  232. local valueList, valueCard, godCards = self:parseCard(cards)
  233. local lastCardInfo = self:getCardsType(lastData)
  234. local godCardCount = #godCards
  235. local result = {}
  236. if self:isUseGodCard() and godCardCount > 0 then
  237. local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB_LAIZI and 1 or lastCardInfo.min + 1
  238. -- 软炸弹
  239. for i = tpIndex, 13 do
  240. local tpReplace = {}
  241. valueList[i] = valueList[i] or 0
  242. if valueList[i] < 4 then
  243. local needGodCardCount = 4 - valueList[i]
  244. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  245. if godCardCount >= needGodCardCount then
  246. for _, v in ipairs(valueCard[i]) do
  247. table.insert(tpReplace, v)
  248. end
  249. for j = 1, needGodCardCount do
  250. table.insert(tpReplace, godCards[j])
  251. end
  252. table.insert(result, tpReplace)
  253. end
  254. end
  255. end
  256. end
  257. -- 软王炸
  258. if (valueList[Value_Joker_Little] or 0) > 0 then
  259. local tpReplace = {}
  260. table.insert(tpReplace, 0x4e)
  261. table.insert(tpReplace, godCards[1])
  262. table.insert(result, tpReplace)
  263. end
  264. if (valueList[Value_Joker_Big] or 0) > 0 then
  265. local tpReplace = {}
  266. table.insert(tpReplace, 0x4f)
  267. table.insert(tpReplace, godCards[1])
  268. table.insert(result, tpReplace)
  269. end
  270. if self:isUseAllSameGodCard() and godCardCount > 1 then
  271. local tpReplace = {}
  272. table.insert(tpReplace, godCards[1])
  273. table.insert(tpReplace, godCards[2])
  274. table.insert(result, tpReplace)
  275. end
  276. end
  277. return result
  278. end
  279. function newPokerUtil:getBombTip(cards, lastData)
  280. local valueList, valueCard, godCards = self:parseCard(cards)
  281. local lastCardInfo = self:getCardsType(lastData)
  282. local godCardCount = #godCards
  283. local result = {}
  284. local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB and 1 or lastCardInfo.min + 1
  285. for i = tpIndex, 13 do
  286. local tpReplace = {}
  287. if (valueList[i] or 0) >= 4 then
  288. for j = 1, 4 do
  289. table.insert(tpReplace, valueCard[i][j])
  290. end
  291. table.insert(result, tpReplace)
  292. end
  293. end
  294. return result
  295. end
  296. -- 获得王炸提示
  297. function newPokerUtil:getBombKingTip(cards, lastData)
  298. local valueList, valueCard, godCards = self:parseCard(cards)
  299. local godCardCount = #godCards
  300. local result = {}
  301. if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
  302. local tpReplace = {}
  303. table.insert(tpReplace, 0x4e)
  304. table.insert(tpReplace, 0x4f)
  305. table.insert(result, tpReplace)
  306. end
  307. return result
  308. end
  309. -- 牌判断>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  310. -- 癞子王炸
  311. function newPokerUtil:isLzBombKing(cards, godCards)
  312. print('jxjx 判断是否是癞子王炸 isLzBombKing')
  313. local temp = clone(cards)
  314. for i, v in ipairs(temp) do
  315. if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
  316. return false
  317. end
  318. end
  319. local godCardCount = #godCards
  320. if self:isUseGodCard() and godCardCount > 0 then
  321. if #cards > 0 then
  322. local needGodCardCount = 2 - #cards
  323. if godCardCount >= needGodCardCount then
  324. return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1], true
  325. end
  326. else
  327. if self:isUseAllSameGodCard() then
  328. return true, defs.CARD_TYPE.BOMB_LAIZI, godCards[1], true
  329. end
  330. end
  331. end
  332. return
  333. end
  334. -- 癞子炸弹
  335. function newPokerUtil:isLzBombNormal(cards, godCards)
  336. print('jxjx 判断是否是癞子炸弹 isLzBombNormal')
  337. local tag = self:checkIsTheSameCards(cards)
  338. local godCardCount = #godCards
  339. if not (#cards == 0) then
  340. if not tag then
  341. return false
  342. end
  343. end
  344. if #cards == 4 then
  345. return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1]
  346. end
  347. local needGodCardCount = 4 - #cards
  348. if self:isUseGodCard() and godCardCount > 0 then
  349. if #cards > 0 then
  350. if godCardCount >= needGodCardCount then
  351. return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1], true
  352. end
  353. else
  354. if self:isUseAllSameGodCard() then
  355. return true, defs.CARD_TYPE.BOMB_LAIZI, godCards[1], true
  356. end
  357. end
  358. end
  359. return
  360. end
  361. -- 炸弹
  362. function newPokerUtil:isBomb(cards, godCards)
  363. print('jxjx 判断是否是炸弹 isBomb')
  364. local tag = self:checkIsTheSameCards(cards)
  365. local godCardCount = #godCards
  366. if not (#cards == 0) then
  367. if not tag then
  368. return false
  369. end
  370. end
  371. if #cards == 4 then
  372. return true, defs.CARD_TYPE.BOMB, cards[1]
  373. end
  374. return false
  375. end
  376. -- 王炸
  377. function newPokerUtil:isKingBomb(cards, godCards)
  378. local temp = clone(cards)
  379. for i, v in ipairs(temp) do
  380. if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
  381. return false
  382. end
  383. end
  384. if cards[1] == Value_Joker_Little and cards[2] == Value_Joker_Big then
  385. return true, defs.CARD_TYPE.BOMB_KING, cards[1]
  386. end
  387. return false
  388. end
  389. -- 配置>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  390. -- 修改配置
  391. newPokerUtil.Card_Max_Length = 21
  392. newPokerUtil.Is_Use_God_Card = true
  393. newPokerUtil.God_Card_Value = 0x51 --0x5d
  394. newPokerUtil.God_Card_Replace_Card_Map = {
  395. [defs.CARD_TYPE.NULL] = nil,
  396. [defs.CARD_TYPE.SINGLE] = 'getGodCardSingleReplace',
  397. [defs.CARD_TYPE.DUIZI] = 'getGodCardDuiZiReplReplace',
  398. [defs.CARD_TYPE.SANZHANG] = 'getGodCardSanZhangReplace',
  399. [defs.CARD_TYPE.SHUNZI] = 'getGodCardShunZiReplace',
  400. [defs.CARD_TYPE.SHUANGSHUN] = 'getGodCardLianDuiReplace',
  401. [defs.CARD_TYPE.SANSHUN] = 'getGodCardSanShunReplace',
  402. [defs.CARD_TYPE.SANDAIYI] = 'getGodCardSanDaiYiReplace',
  403. [defs.CARD_TYPE.SANDAIDUI] = nil,
  404. [defs.CARD_TYPE.SIDAIYI] = nil,
  405. [defs.CARD_TYPE.SIDAIYIDUI] = nil,
  406. [defs.CARD_TYPE.SIDAIER] = 'getGodCardSiDaiErSingleReplace',
  407. [defs.CARD_TYPE.SIDAIERDUI] = nil,
  408. [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getGodCardAirPlaneSingleReplace',
  409. [defs.CARD_TYPE.AIRPLANE_DUAD] = nil,
  410. [defs.CARD_TYPE.BOMB] = 'getGodCardBombReplace',
  411. [defs.CARD_TYPE.BOMB_KING] = 'getGodCardBombKingReplace',
  412. [defs.CARD_TYPE.BOMB_LAIZI] = 'getGodCardLzBombReplace',
  413. }
  414. newPokerUtil.Card_Tip_Map = {
  415. [defs.CARD_TYPE.NULL] = nil,
  416. [defs.CARD_TYPE.SINGLE] = 'getSingleTip',
  417. [defs.CARD_TYPE.DUIZI] = 'getDuiZiTip',
  418. [defs.CARD_TYPE.SANZHANG] = 'getSanZhangTip',
  419. [defs.CARD_TYPE.SHUNZI] = 'getShunZiTip',
  420. [defs.CARD_TYPE.SHUANGSHUN] = 'getLianDuiTip',
  421. [defs.CARD_TYPE.SANSHUN] = 'getSanShunTip',
  422. [defs.CARD_TYPE.SANDAIYI] = 'getSanDaiYiTip',
  423. [defs.CARD_TYPE.SANDAIDUI] = nil,
  424. [defs.CARD_TYPE.SIDAIYI] = nil,
  425. [defs.CARD_TYPE.SIDAIYIDUI] = nil,
  426. [defs.CARD_TYPE.SIDAIER] = 'getSiDaiErSingleTip',
  427. [defs.CARD_TYPE.SIDAIERDUI] = nil,
  428. [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getAirPlaneSingleTip',
  429. [defs.CARD_TYPE.AIRPLANE_DUAD] = nil,
  430. [defs.CARD_TYPE.BOMB] = 'getBombTip',
  431. [defs.CARD_TYPE.BOMB_KING] = 'getBombKingTip',
  432. [defs.CARD_TYPE.BOMB_LAIZI] = 'getBombLZTip',
  433. }
  434. return newPokerUtil