|
- local defs = require("pk_nanchongdoudizhu.luaScript.Def_53")
- local Functions = require("pk_nanchongdoudizhu.luaScript.Functions_53")
- local PokerUtil = require('pk_nanchongdoudizhu.luaScript.Views.Room.PokerUtil') -- 基类文件
- local newPokerUtil = class("newPokerUtil", PokerUtil)
-
- local isResetSelectCard = true -- 是否启动滑动手牌并返回特殊的牌型
- local Value_2 = 0x0d -- 2的具体值
- local Value_Joker_Little = 0x0e -- 小鬼的具体值
- local Value_Joker_Big = 0x0f -- 大鬼的具体值
-
- function newPokerUtil:ctor(param)
- newPokerUtil.super.ctor(self, param)
- local isLzWanFa = Functions.getRuleIncludeLzWanFa()
-
- -- 没有癞子玩法
- if not isLzWanFa then
- newPokerUtil.Card_Max_Length = 20
- newPokerUtil.Is_Use_God_Card = false
- else
- newPokerUtil.Card_Max_Length = 21
- newPokerUtil.Is_Use_God_Card = true
- end
- end
-
- function newPokerUtil:initTypeMap()
- newPokerUtil.super.initTypeMap(self)
- table.insert(self.Card_Type_Map[2], #self.Card_Type_Map[2], self.isLzBombKing) -- 加入癞子王炸弹判断(放在王炸之前)
- table.insert(self.Card_Type_Map[4], #self.Card_Type_Map[4], self.isLzBombNormal) -- 加入癞子炸弹判断(放在炸弹之前)
- end
-
- -- 获得提示(cards是userdata)
- function newPokerUtil:getTip(cards, lastData)
- print('jxjx 进入getTip')
- dump(cards, 'cards')
- dump(lastData, 'lastData')
- local tipResult = {}
- local lastCardInfo = self:getCardsType(lastData)
-
- if lastCardInfo.cardType < defs.CARD_TYPE.BOMB_LAIZI then
- local f = newPokerUtil.Card_Tip_Map[lastCardInfo.cardType]
- if f then
- print(string.format('jxjx..牌型提示..%s', defs.CARD_TYPE_NAME[lastCardInfo.cardType]))
- -- tipResult = newPokerUtil.Card_Tip_Map[lastCardInfo.cardType](self, cards, lastData) -- f是方法 启用initTipMap
- tipResult = self[f](self, cards, lastData) -- f是str
- end
- end
-
- -- 添加软炸弹
- if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_LAIZI then
- print('jxjx..getTip 添加软炸弹')
- local result = self:getBombLZTip(cards, lastData)
- if table.nums(result) > 0 then
- for _, bomb in ipairs(result) do
- table.insert(tipResult, bomb)
- end
- end
- end
-
- -- 添加炸弹
- if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB then
- print('jxjx..getTip 添加炸弹')
- local result = self:getBombTip(cards, lastData)
- if table.nums(result) > 0 then
- for _, bomb in ipairs(result) do
- table.insert(tipResult, bomb)
- end
- end
- end
-
- --王炸
- if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_KING then
- print('jxjx..getTip 添加王炸')
- local result = self:getBombKingTip(cards, lastData)
- if table.nums(result) > 0 then
- for _, bomb in ipairs(result) do -- 王炸只有1个,虽然多此一举用了循环...
- table.insert(tipResult, bomb)
- end
- end
- end
-
- dump(tipResult, 'jxjx gettip 结果')
- return tipResult
- end
-
- -- 滑牌>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- -- 选择的牌的处理(飞机,连对,顺子)
- function newPokerUtil:getCardInSelectCard(selectCards)
- if not isResetSelectCard then
- return selectCards
- end
-
- local selectCards = clone(selectCards)
- local valueList, valueCard = self:parseCard(selectCards)
-
- -----------------------------------------------------------------------------
- -- <<飞机>>
- -- 将非王牌,带2的牌,炸弹牌,组合在一起(用于判断连续值)
- -- 移除手牌中的炸弹
- local temp = {}
- for _, v in pairs(valueCard) do
- if #v == 3 then -- 插入刚好等于3张的牌
- table.insert(temp, v[1]) -- 插入一个值即可,用于检测飞机
- end
- end
-
- -- 移除手牌中的王牌和2
- local nt = self:removeValue_Joker_And_2(temp)
- local t = self:getMinInLine(nt, PokerUtil.Less_Plane / 3)
- local sameTable = self:getSameValueByVal(selectCards, t, 3)
- if #sameTable > 0 then
- print('jxjx 滑牌选牌,返回飞机')
- return sameTable
- end
-
- -----------------------------------------------------------------------------
- -- <<连对>>
- local temp = {}
- for _, v in pairs(valueCard) do
- if #v > 1 and #v < 4 then -- 插入大于1张,非炸弹的牌
- table.insert(temp, v[1]) -- 插入一个值即可,用于检测连对
- end
- end
-
- -- 移除手牌中的王牌和2
- local nt = self:removeValue_Joker_And_2(temp)
- local t = self:getMinInLine(nt, PokerUtil.Less_Lian_Dui / 2)
- local sameTable = self:getSameValueByVal(selectCards, t, 2)
- if #sameTable > 0 then
- print('jxjx 滑牌选牌,返回连对')
- return sameTable
- end
-
- -----------------------------------------------------------------------------
- -- <<顺子>>
- local temp = {}
- for _, v in pairs(valueCard) do
- if #v ~= 4 then -- 插入非炸弹的牌
- table.insert(temp, v[1]) -- 插入一个值即可,用于检测顺子
- end
- end
-
- -- 移除手牌中的王牌和2
- local nt = self:removeValue_Joker_And_2(temp)
- local t = self:getMinInLine(nt, PokerUtil.Less_Line)
- local sameTable = self:getSameValueByVal(selectCards, t, 1)
- if #sameTable > 0 then
- print('jxjx 滑牌选牌,返回顺子')
- return sameTable
- end
-
- return selectCards
- end
-
- -- 移除王牌和2
- function newPokerUtil:removeValue_Joker_And_2(cards)
- if not cards then
- return {}
- end
-
- local t = self:changeCardValue_Standard_To_Specific(cards) -- 返回的是与cards顺序一致的具体牌值表
- local nt = {}
- for i, value in ipairs(t) do
- if value ~= Value_2 and value ~= Value_Joker_Little and value ~= Value_Joker_Big then
- table.insert(nt, cards[i])
- end
- end
- table.sort(nt, PokerUtil.sortOrder_By_PokerValue)
- return nt
- end
-
- -- 获取包含最小值的连续值表,长度最低是lessLength
- function newPokerUtil:getMinInLine(pCards, lessLength)
- local subLines = self:getSubLine(pCards)
-
- for i = #subLines, 1, -1 do
- if #subLines[i] < lessLength then
- table.remove(subLines, i)
- end
- end
-
- if next(subLines) then
- return subLines[1]
- else
- return {}
- end
- end
-
- -- sCards中,取tCards获得同样具体牌值的数值表 maxCount 单个数值最大个数
- function newPokerUtil:getSameValueByVal( sCards, tCards, maxCount)
- local temp = {}
- for _, t in ipairs(tCards) do
- local count = 0
- for _, s in ipairs(sCards) do
- local tVal = self:getCardValue(t)
- local sVal = self:getCardValue(s)
- if tVal == sVal and count < maxCount then
- table.insert(temp, s)
- count = count + 1
- end
- end
- end
-
- return temp
- end
-
- -- 检测牌组是否是连续的(返回连续的表值 cards每个值里面有且只有1个)
- function newPokerUtil:getSubLine(cards)
- local sub = {}
- local parseCards = self:changeCardValue_Standard_To_Specific(cards)
-
- for i=#parseCards,1,-1 do
- if parseCards[i] and parseCards[i-1] then
- if parseCards[i]-1~=parseCards[i-1] then
- --断开了
- local tmp = {}
- for j=#parseCards,i,-1 do
- table.insert(tmp, parseCards[j])
- end
- table.insert(sub, clone(tmp))
- for j=#parseCards,i,-1 do
- table.remove(parseCards, j)
- end
- else
- if i == 2 then
- table.insert(sub, clone(parseCards))
- end
- end
- end
- end
-
- -- 内部数据从小到大排序
- for i, v in ipairs(sub) do
- table.sort(v, PokerUtil.sortOrder)
- end
-
- -- 外部数据从小到大排序
- table.sort(sub, function(a, b)
- return a[1] < b[1]
- end)
- return sub
- end
-
- -- 替代牌>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- function newPokerUtil:getGodCardLzBombReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- if min < 14 then
- for i = 1, 4 - valueList[min] do
- table.insert(result, min)
- end
- else
- if (valueList[Value_Joker_Little] or 0) > 0 then
- table.insert(result, 0x4f)
- elseif (valueList[Value_Joker_Big] or 0) > 0 then
- table.insert(result, 0x4e)
- end
- end
-
- return result
- end
-
- -- 牌提示>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- -- 软炸弹
- function newPokerUtil:getBombLZTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local godCardCount = #godCards
- local result = {}
-
- if self:isUseGodCard() and godCardCount > 0 then
- local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB_LAIZI and 1 or lastCardInfo.min + 1
-
- -- 软炸弹
- for i = tpIndex, 13 do
- local tpReplace = {}
- valueList[i] = valueList[i] or 0
- if valueList[i] < 4 then
- local needGodCardCount = 4 - valueList[i]
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for _, v in ipairs(valueCard[i]) do
- table.insert(tpReplace, v)
- end
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- end
- table.insert(result, tpReplace)
- end
- end
- end
- end
-
- -- 软王炸
- if (valueList[Value_Joker_Little] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4e)
- table.insert(tpReplace, godCards[1])
- table.insert(result, tpReplace)
- end
-
- if (valueList[Value_Joker_Big] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4f)
- table.insert(tpReplace, godCards[1])
- table.insert(result, tpReplace)
- end
-
- if self:isUseAllSameGodCard() and godCardCount > 1 then
- local tpReplace = {}
- table.insert(tpReplace, godCards[1])
- table.insert(tpReplace, godCards[2])
- table.insert(result, tpReplace)
- end
-
- end
-
- return result
- end
-
- function newPokerUtil:getBombTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local godCardCount = #godCards
- local result = {}
-
- local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB and 1 or lastCardInfo.min + 1
- for i = tpIndex, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 4 then
- for j = 1, 4 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
-
- return result
- end
-
-
- -- 获得王炸提示
- function newPokerUtil:getBombKingTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- local result = {}
-
- if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4e)
- table.insert(tpReplace, 0x4f)
- table.insert(result, tpReplace)
- end
-
- return result
- end
-
- -- 牌判断>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- -- 癞子王炸
- function newPokerUtil:isLzBombKing(cards, godCards)
- print('jxjx 判断是否是癞子王炸 isLzBombKing')
- local temp = clone(cards)
- for i, v in ipairs(temp) do
- if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
- return false
- end
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 2 - #cards
- if godCardCount >= needGodCardCount then
- return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.BOMB_LAIZI, godCards[1], true
- end
- end
- end
-
- return
- end
-
- -- 癞子炸弹
- function newPokerUtil:isLzBombNormal(cards, godCards)
- print('jxjx 判断是否是癞子炸弹 isLzBombNormal')
- local tag = self:checkIsTheSameCards(cards)
- local godCardCount = #godCards
-
- if not (#cards == 0) then
- if not tag then
- return false
- end
- end
-
- if #cards == 4 then
- return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1]
- end
-
- local needGodCardCount = 4 - #cards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- if godCardCount >= needGodCardCount then
- return true, defs.CARD_TYPE.BOMB_LAIZI, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.BOMB_LAIZI, godCards[1], true
- end
- end
- end
-
- return
- end
-
- -- 炸弹
- function newPokerUtil:isBomb(cards, godCards)
- print('jxjx 判断是否是炸弹 isBomb')
- local tag = self:checkIsTheSameCards(cards)
- local godCardCount = #godCards
-
- if not (#cards == 0) then
- if not tag then
- return false
- end
- end
-
- if #cards == 4 then
- return true, defs.CARD_TYPE.BOMB, cards[1]
- end
-
- return false
- end
-
- -- 王炸
- function newPokerUtil:isKingBomb(cards, godCards)
- local temp = clone(cards)
- for i, v in ipairs(temp) do
- if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
- return false
- end
- end
-
- if cards[1] == Value_Joker_Little and cards[2] == Value_Joker_Big then
- return true, defs.CARD_TYPE.BOMB_KING, cards[1]
- end
-
- return false
- end
-
- -- 配置>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- -- 修改配置
- newPokerUtil.Card_Max_Length = 21
- newPokerUtil.Is_Use_God_Card = true
- newPokerUtil.God_Card_Value = 0x51 --0x5d
-
- newPokerUtil.God_Card_Replace_Card_Map = {
- [defs.CARD_TYPE.NULL] = nil,
- [defs.CARD_TYPE.SINGLE] = 'getGodCardSingleReplace',
- [defs.CARD_TYPE.DUIZI] = 'getGodCardDuiZiReplReplace',
- [defs.CARD_TYPE.SANZHANG] = 'getGodCardSanZhangReplace',
- [defs.CARD_TYPE.SHUNZI] = 'getGodCardShunZiReplace',
- [defs.CARD_TYPE.SHUANGSHUN] = 'getGodCardLianDuiReplace',
- [defs.CARD_TYPE.SANSHUN] = 'getGodCardSanShunReplace',
- [defs.CARD_TYPE.SANDAIYI] = 'getGodCardSanDaiYiReplace',
- [defs.CARD_TYPE.SANDAIDUI] = nil,
- [defs.CARD_TYPE.SIDAIYI] = nil,
- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
- [defs.CARD_TYPE.SIDAIER] = 'getGodCardSiDaiErSingleReplace',
- [defs.CARD_TYPE.SIDAIERDUI] = nil,
- [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getGodCardAirPlaneSingleReplace',
- [defs.CARD_TYPE.AIRPLANE_DUAD] = nil,
- [defs.CARD_TYPE.BOMB] = 'getGodCardBombReplace',
- [defs.CARD_TYPE.BOMB_KING] = 'getGodCardBombKingReplace',
-
- [defs.CARD_TYPE.BOMB_LAIZI] = 'getGodCardLzBombReplace',
- }
-
- newPokerUtil.Card_Tip_Map = {
- [defs.CARD_TYPE.NULL] = nil,
- [defs.CARD_TYPE.SINGLE] = 'getSingleTip',
- [defs.CARD_TYPE.DUIZI] = 'getDuiZiTip',
- [defs.CARD_TYPE.SANZHANG] = 'getSanZhangTip',
- [defs.CARD_TYPE.SHUNZI] = 'getShunZiTip',
- [defs.CARD_TYPE.SHUANGSHUN] = 'getLianDuiTip',
- [defs.CARD_TYPE.SANSHUN] = 'getSanShunTip',
- [defs.CARD_TYPE.SANDAIYI] = 'getSanDaiYiTip',
- [defs.CARD_TYPE.SANDAIDUI] = nil,
- [defs.CARD_TYPE.SIDAIYI] = nil,
- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
- [defs.CARD_TYPE.SIDAIER] = 'getSiDaiErSingleTip',
- [defs.CARD_TYPE.SIDAIERDUI] = nil,
- [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getAirPlaneSingleTip',
- [defs.CARD_TYPE.AIRPLANE_DUAD] = nil,
- [defs.CARD_TYPE.BOMB] = 'getBombTip',
- [defs.CARD_TYPE.BOMB_KING] = 'getBombKingTip',
-
- [defs.CARD_TYPE.BOMB_LAIZI] = 'getBombLZTip',
- }
- return newPokerUtil
|