听提示列表

master
罗家炜 2025-04-10 12:25:45 +08:00
parent dce2f67297
commit 69f358c85c
4 changed files with 261 additions and 257 deletions

View File

@ -1,11 +1,11 @@
-- 检测牌是否存在 -- 检测牌是否存在
local function checkCard(eventCard,cardList,num) local function checkCard(eventCard, cardList, num)
num = num == nil and 1 or num num = num == nil and 1 or num
local result = 0 local result = 0
for i = 1,#cardList do for i = 1, #cardList do
if (cardList[i] == eventCard) then if (cardList[i] == eventCard) then
result = result + 1 result = result + 1
if(result ==num) then if (result == num) then
return true return true
end end
end end
@ -14,24 +14,24 @@ local function checkCard(eventCard,cardList,num)
end end
-- 移除指定数量的牌 -- 移除指定数量的牌
local function removeCard(cardList, card,count) local function removeCard(cardList, card, count)
for i=1,count do for i = 1, count do
list_remove(cardList,card) list_remove(cardList, card)
end end
end end
local function checkCardAndRomve(eventCard,cardList,num) local function checkCardAndRomve(eventCard, cardList, num)
if(checkCard(eventCard,cardList,num)) then if (checkCard(eventCard, cardList, num)) then
removeCard(cardList,eventCard,num) removeCard(cardList, eventCard, num)
return true return true
end end
return false return false
end end
-- 获取列表中牌数量 -- 获取列表中牌数量
local function cardNum(eventCard,cardList) local function cardNum(eventCard, cardList)
local result = 0 local result = 0
for i=1,#cardList do for i = 1, #cardList do
local card = cardList[i] local card = cardList[i]
if (card == eventCard) then if (card == eventCard) then
result = result + 1 result = result + 1
@ -40,7 +40,7 @@ local function cardNum(eventCard,cardList)
return result return result
end end
local zhongid = 0 local zhongid = 0
local M = { local M = {
@ -54,16 +54,16 @@ local M = {
} }
function M:push(cardGroup) function M:push(cardGroup)
self.stack[#self.stack+1] = cardGroup self.stack[#self.stack + 1] = cardGroup
end end
function M:rollBack() function M:rollBack()
local cardGroup = self.stack[#self.stack] local cardGroup = self.stack[#self.stack]
table.remove(self.stack,#self.stack) table.remove(self.stack, #self.stack)
for _,card in ipairs(cardGroup) do for _, card in ipairs(cardGroup) do
if (card == zhongid) then if (card == zhongid) then
self.zhong_count = self.zhong_count +1 self.zhong_count = self.zhong_count + 1
else else
self.cardList[#self.cardList + 1] = card self.cardList[#self.cardList + 1] = card
end end
@ -71,36 +71,36 @@ function M:rollBack()
table.sort(self.cardList) table.sort(self.cardList)
end end
function M:tryShunzi(card) function M:tryShunzi(card)
if (card < 400 and card % 100 > 7) then if (card < 400 and card % 100 > 7) then
return false return false
end end
if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 1, 1)
removeCard(self.cardList, card + 2, 1) removeCard(self.cardList, card + 2, 1)
local cardGroup = {card,card+1,card+2} local cardGroup = { card, card + 1, card + 2 }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryKezi(card) function M:tryKezi(card)
if (checkCardAndRomve(card, self.cardList, 3)) then if (checkCardAndRomve(card, self.cardList, 3)) then
local cardGroup = {card,card,card} local cardGroup = { card, card, card }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryPair(card) function M:tryPair(card)
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
if (checkCardAndRomve(card, self.cardList, 2)) then if (checkCardAndRomve(card, self.cardList, 2)) then
local cardGroup = {card,card} local cardGroup = { card, card }
self:push(cardGroup) self:push(cardGroup)
self.pair_count = 1 self.pair_count = 1
return true return true
@ -108,28 +108,27 @@ function M:tryPair(card)
return false return false
end end
function M:tryKezi1Zhong(card)
function M:tryKezi1Zhong(card) if (self.zhong_count >= 1 and checkCardAndRomve(card, self.cardList, 2)) then
if (self.zhong_count >= 1 and checkCardAndRomve(card, self.cardList,2)) then local cardGroup = { card, card, zhongid }
local cardGroup = {card,card,zhongid}
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
return true
end
return false
end
function M:tryKezi2Zhong(card)
if (self.zhong_count >= 2 and checkCardAndRomve(card, self.cardList,1)) then
local cardGroup = {card,zhongid,zhongid}
self:push(cardGroup)
self.zhong_count = self.zhong_count -2
return true return true
end end
return false return false
end end
function M:tryShunzi1Zhong(card) function M:tryKezi2Zhong(card)
if (self.zhong_count >= 2 and checkCardAndRomve(card, self.cardList, 1)) then
local cardGroup = { card, zhongid, zhongid }
self:push(cardGroup)
self.zhong_count = self.zhong_count - 2
return true
end
return false
end
function M:tryShunzi1Zhong(card)
if (card % 100 > 8) then if (card % 100 > 8) then
return false return false
end end
@ -141,8 +140,8 @@ function M:tryShunzi1Zhong(card)
if (checkCard(card + 1, self.cardList)) then if (checkCard(card + 1, self.cardList)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 1, 1)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
local cardGroup = {card,card+1,zhongid} local cardGroup = { card, card + 1, zhongid }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
@ -150,15 +149,15 @@ function M:tryShunzi1Zhong(card)
if (checkCard(card + 2, self.cardList) and ((card + 1) % 100 ~= 0)) then if (checkCard(card + 2, self.cardList) and ((card + 1) % 100 ~= 0)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 2, 1) removeCard(self.cardList, card + 2, 1)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
local cardGroup = {card,zhongid,card+2} local cardGroup = { card, zhongid, card + 2 }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryPair1Zhong(card) function M:tryPair1Zhong(card)
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
@ -166,28 +165,28 @@ function M:tryPair1Zhong(card)
return false return false
end end
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
local cardGroup = {card,zhongid} local cardGroup = { card, zhongid }
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
self.pair_count = 1 self.pair_count = 1
return true return true
end end
function M:tryPair2Zhong() function M:tryPair2Zhong()
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
if (self.zhong_count < 2) then if (self.zhong_count < 2) then
return false return false
end end
local cardGroup = {zhongid,zhongid} local cardGroup = { zhongid, zhongid }
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -2 self.zhong_count = self.zhong_count - 2
self.pair_count = 1 self.pair_count = 1
return true return true
end end
function M:tryWin() function M:tryWin()
if (self.zhong_count == 4 and not self.eight_laizi) or (self.zhong_count == 8 and self.eight_laizi) then if (self.zhong_count == 4 and not self.eight_laizi) or (self.zhong_count == 8 and self.eight_laizi) then
return true return true
end end
@ -233,7 +232,6 @@ function M:tryWin()
end end
if (self:tryKezi2Zhong(activeCard)) then if (self:tryKezi2Zhong(activeCard)) then
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -257,7 +255,7 @@ function M:tryWin()
return false return false
end end
function M:checkQidui() function M:checkQidui()
if (not self.qidui) then if (not self.qidui) then
return false return false
end end
@ -270,17 +268,17 @@ function M:checkQidui()
return self:isQdPari(cardList) return self:isQdPari(cardList)
end end
function M:isQdPari(cardList) function M:isQdPari(cardList)
if(self.qidui_pari_count == 7) then if (self.qidui_pari_count == 7) then
return true return true
end end
if (#cardList== 0) then if (#cardList == 0) then
return true return true
end end
local card = cardList[1] local card = cardList[1]
if (cardNum(card, cardList) >= 2) then if (cardNum(card, cardList) >= 2) then
removeCard(cardList, card, 2) removeCard(cardList, card, 2)
self.qidui_pari_count = self.qidui_pari_count +1 self.qidui_pari_count = self.qidui_pari_count + 1
if (self:isQdPari(cardList)) then if (self:isQdPari(cardList)) then
return true return true
end end
@ -289,7 +287,7 @@ function M:isQdPari(cardList)
if (self.hongzhong_count > 0) then if (self.hongzhong_count > 0) then
removeCard(cardList, card, 1) removeCard(cardList, card, 1)
self.hongzhong_count = self.hongzhong_count - 1 self.hongzhong_count = self.hongzhong_count - 1
self.qidui_pari_count = self.qidui_pari_count +1 self.qidui_pari_count = self.qidui_pari_count + 1
if (self:isQdPari(cardList)) then if (self:isQdPari(cardList)) then
return true return true
end end
@ -297,13 +295,13 @@ function M:isQdPari(cardList)
return false return false
end end
local function init(self,cardInhand,addCard,isZhong,qidui,eightLaizi) local function init(self, cardInhand, addCard, isZhong, qidui, eightLaizi)
self.stack = {} self.stack = {}
self.pair_count = 0 self.pair_count = 0
self.cardList = membe_clone(cardInhand) self.cardList = membe_clone(cardInhand)
self.qidui = qidui self.qidui = qidui
self.eight_laizi = eightLaizi self.eight_laizi = eightLaizi
self.cardList[#self.cardList+1] = addCard self.cardList[#self.cardList + 1] = addCard
if (isZhong) then if (isZhong) then
self.zhong_count = cardNum(zhongid, self.cardList) self.zhong_count = cardNum(zhongid, self.cardList)
removeCard(self.cardList, zhongid, self.zhong_count) removeCard(self.cardList, zhongid, self.zhong_count)
@ -314,65 +312,63 @@ local function init(self,cardInhand,addCard,isZhong,qidui,eightLaizi)
return self:checkQidui() or self:tryWin() return self:checkQidui() or self:tryWin()
end end
local specialCardList={400,403,406,409,412,415,418} local specialCardList = { 400, 403, 406, 409, 412, 415, 418 }
function M.tingPai(cardInhand,isZhong,qidui,eightLaizi) function M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
--printlog("isZhong",isZhong) --printlog("isZhong",isZhong)
--printlog("qidui",qidui) --printlog("qidui",qidui)
--printlog("eightLaizi",eightLaizi) --printlog("eightLaizi",eightLaizi)
--pt(cardInhand) --pt(cardInhand)
local self = setmetatable({}, {__index = M}) local self = setmetatable({}, { __index = M })
local tingList = {} local tingList = {}
if not cardInhand or #cardInhand == 0 then if not cardInhand or #cardInhand == 0 then
return tingList return tingList
end end
for k=100,300,100 do for k = 100, 300, 100 do
for i=1,9 do for i = 1, 9 do
local tem = k + i local tem = k + i
local result = init(self,cardInhand,tem,isZhong,qidui,eightLaizi) local result = init(self, cardInhand, tem, isZhong, qidui, eightLaizi)
--printlog("返回结果为===>>>",result) --printlog("返回结果为===>>>",result)
if(result) then if (result) then
tingList[#tingList + 1] = tem tingList[#tingList + 1] = tem
end end
end end
end end
for j=1,#specialCardList do for j = 1, #specialCardList do
local tem = specialCardList[j] local tem = specialCardList[j]
local result = init(self,cardInhand,tem,isZhong,qidui,eightLaizi) local result = init(self, cardInhand, tem, isZhong, qidui, eightLaizi)
if(result) then if (result) then
tingList[#tingList + 1] = tem tingList[#tingList + 1] = tem
end end
end end
return tingList return tingList
end end
function M.MuiltiplteCaculateTingPai(cardInhand,isZhong,qidui,eightLaizi) function M.MuiltiplteCaculateTingPai(cardInhand, isZhong, qidui, eightLaizi)
if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo>0 then if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo > 0 then
zhongid=DataManager.CurrenRoom.laiziInfo[1] zhongid = DataManager.CurrenRoom.laiziInfo[1]
local tempTingList2={} local tempTingList2 = {}
local tempTingList1=M.tingPai(cardInhand,isZhong,qidui,eightLaizi) local tempTingList1 = M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
if DataManager.CurrenRoom.laiziInfo[2] then if DataManager.CurrenRoom.laiziInfo[2] then
zhongid=DataManager.CurrenRoom.laiziInfo[2] zhongid = DataManager.CurrenRoom.laiziInfo[2]
tempTingList2=M.tingPai(cardInhand,isZhong,qidui,eightLaizi) tempTingList2 = M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
zhongid=DataManager.CurrenRoom.laiziInfo[1] zhongid = DataManager.CurrenRoom.laiziInfo[1]
end end
local currentTingList={} local currentTingList = {}
if #tempTingList1>0 and #tempTingList2>0 then if #tempTingList1 > 0 and #tempTingList2 > 0 then
currentTingList=CombineDictionaryAndRemoveSomeItem(tempTingList1,tempTingList2) currentTingList = CombineDictionaryAndRemoveSomeItem(tempTingList1, tempTingList2)
elseif #tempTingList1>0 then elseif #tempTingList1 > 0 then
currentTingList=tempTingList1 currentTingList = tempTingList1
elseif #tempTingList2>0 then elseif #tempTingList2 > 0 then
currentTingList=tempTingList2 currentTingList = tempTingList2
end end
return currentTingList return currentTingList
else else
zhongid=0 zhongid = 0
return M.tingPai(cardInhand,isZhong,qidui,eightLaizi) return M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
end end
end end
return M return M

View File

@ -1,11 +1,11 @@
-- 检测牌是否存在 -- 检测牌是否存在
local function checkCard(eventCard,cardList,num) local function checkCard(eventCard, cardList, num)
num = num == nil and 1 or num num = num == nil and 1 or num
local result = 0 local result = 0
for i = 1,#cardList do for i = 1, #cardList do
if (cardList[i] == eventCard) then if (cardList[i] == eventCard) then
result = result + 1 result = result + 1
if(result ==num) then if (result == num) then
return true return true
end end
end end
@ -14,24 +14,24 @@ local function checkCard(eventCard,cardList,num)
end end
-- 移除指定数量的牌 -- 移除指定数量的牌
local function removeCard(cardList, card,count) local function removeCard(cardList, card, count)
for i=1,count do for i = 1, count do
list_remove(cardList,card) list_remove(cardList, card)
end end
end end
local function checkCardAndRomve(eventCard,cardList,num) local function checkCardAndRomve(eventCard, cardList, num)
if(checkCard(eventCard,cardList,num)) then if (checkCard(eventCard, cardList, num)) then
removeCard(cardList,eventCard,num) removeCard(cardList, eventCard, num)
return true return true
end end
return false return false
end end
-- 获取列表中牌数量 -- 获取列表中牌数量
local function cardNum(eventCard,cardList) local function cardNum(eventCard, cardList)
local result = 0 local result = 0
for i=1,#cardList do for i = 1, #cardList do
local card = cardList[i] local card = cardList[i]
if (card == eventCard) then if (card == eventCard) then
result = result + 1 result = result + 1
@ -40,7 +40,7 @@ local function cardNum(eventCard,cardList)
return result return result
end end
local zhongid = 0 local zhongid = 0
local M = { local M = {
@ -54,16 +54,16 @@ local M = {
} }
function M:push(cardGroup) function M:push(cardGroup)
self.stack[#self.stack+1] = cardGroup self.stack[#self.stack + 1] = cardGroup
end end
function M:rollBack() function M:rollBack()
local cardGroup = self.stack[#self.stack] local cardGroup = self.stack[#self.stack]
table.remove(self.stack,#self.stack) table.remove(self.stack, #self.stack)
for _,card in ipairs(cardGroup) do for _, card in ipairs(cardGroup) do
if (card == zhongid) then if (card == zhongid) then
self.zhong_count = self.zhong_count +1 self.zhong_count = self.zhong_count + 1
else else
self.cardList[#self.cardList + 1] = card self.cardList[#self.cardList + 1] = card
end end
@ -71,36 +71,36 @@ function M:rollBack()
table.sort(self.cardList) table.sort(self.cardList)
end end
function M:tryShunzi(card) function M:tryShunzi(card)
if (card < 400 and card % 100 > 7) then if (card < 400 and card % 100 > 7) then
return false return false
end end
if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 1, 1)
removeCard(self.cardList, card + 2, 1) removeCard(self.cardList, card + 2, 1)
local cardGroup = {card,card+1,card+2} local cardGroup = { card, card + 1, card + 2 }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryKezi(card) function M:tryKezi(card)
if (checkCardAndRomve(card, self.cardList, 3)) then if (checkCardAndRomve(card, self.cardList, 3)) then
local cardGroup = {card,card,card} local cardGroup = { card, card, card }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryPair(card) function M:tryPair(card)
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
if (checkCardAndRomve(card, self.cardList, 2)) then if (checkCardAndRomve(card, self.cardList, 2)) then
local cardGroup = {card,card} local cardGroup = { card, card }
self:push(cardGroup) self:push(cardGroup)
self.pair_count = 1 self.pair_count = 1
return true return true
@ -108,28 +108,27 @@ function M:tryPair(card)
return false return false
end end
function M:tryKezi1Zhong(card)
function M:tryKezi1Zhong(card) if (self.zhong_count >= 1 and checkCardAndRomve(card, self.cardList, 2)) then
if (self.zhong_count >= 1 and checkCardAndRomve(card, self.cardList,2)) then local cardGroup = { card, card, zhongid }
local cardGroup = {card,card,zhongid}
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
return true
end
return false
end
function M:tryKezi2Zhong(card)
if (self.zhong_count >= 2 and checkCardAndRomve(card, self.cardList,1)) then
local cardGroup = {card,zhongid,zhongid}
self:push(cardGroup)
self.zhong_count = self.zhong_count -2
return true return true
end end
return false return false
end end
function M:tryShunzi1Zhong(card) function M:tryKezi2Zhong(card)
if (self.zhong_count >= 2 and checkCardAndRomve(card, self.cardList, 1)) then
local cardGroup = { card, zhongid, zhongid }
self:push(cardGroup)
self.zhong_count = self.zhong_count - 2
return true
end
return false
end
function M:tryShunzi1Zhong(card)
if (card % 100 > 8) then if (card % 100 > 8) then
return false return false
end end
@ -141,8 +140,8 @@ function M:tryShunzi1Zhong(card)
if (checkCard(card + 1, self.cardList)) then if (checkCard(card + 1, self.cardList)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 1, 1)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
local cardGroup = {card,card+1,zhongid} local cardGroup = { card, card + 1, zhongid }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
@ -150,15 +149,15 @@ function M:tryShunzi1Zhong(card)
if (checkCard(card + 2, self.cardList) and ((card + 1) % 100 ~= 0)) then if (checkCard(card + 2, self.cardList) and ((card + 1) % 100 ~= 0)) then
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
removeCard(self.cardList, card + 2, 1) removeCard(self.cardList, card + 2, 1)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
local cardGroup = {card,zhongid,card+2} local cardGroup = { card, zhongid, card + 2 }
self:push(cardGroup) self:push(cardGroup)
return true return true
end end
return false return false
end end
function M:tryPair1Zhong(card) function M:tryPair1Zhong(card)
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
@ -166,28 +165,28 @@ function M:tryPair1Zhong(card)
return false return false
end end
removeCard(self.cardList, card, 1) removeCard(self.cardList, card, 1)
local cardGroup = {card,zhongid} local cardGroup = { card, zhongid }
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -1 self.zhong_count = self.zhong_count - 1
self.pair_count = 1 self.pair_count = 1
return true return true
end end
function M:tryPair2Zhong() function M:tryPair2Zhong()
if (self.pair_count > 0) then if (self.pair_count > 0) then
return false return false
end end
if (self.zhong_count < 2) then if (self.zhong_count < 2) then
return false return false
end end
local cardGroup = {zhongid,zhongid} local cardGroup = { zhongid, zhongid }
self:push(cardGroup) self:push(cardGroup)
self.zhong_count = self.zhong_count -2 self.zhong_count = self.zhong_count - 2
self.pair_count = 1 self.pair_count = 1
return true return true
end end
function M:tryWin() function M:tryWin()
if (self.zhong_count == 4 and not self.eight_laizi) or (self.zhong_count == 8 and self.eight_laizi) then if (self.zhong_count == 4 and not self.eight_laizi) or (self.zhong_count == 8 and self.eight_laizi) then
return true return true
end end
@ -204,6 +203,7 @@ function M:tryWin()
local activeCard = self.cardList[1] local activeCard = self.cardList[1]
if (self:tryPair(activeCard)) then if (self:tryPair(activeCard)) then
print("tryPair")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -212,6 +212,7 @@ function M:tryWin()
end end
if (self:tryKezi(activeCard)) then if (self:tryKezi(activeCard)) then
print("tryKezi")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -219,6 +220,7 @@ function M:tryWin()
end end
if (self:tryShunzi(activeCard)) then if (self:tryShunzi(activeCard)) then
print("tryShunzi")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -226,6 +228,7 @@ function M:tryWin()
end end
if (self:tryKezi1Zhong(activeCard)) then if (self:tryKezi1Zhong(activeCard)) then
print("tryKezi1Zhong")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -233,7 +236,7 @@ function M:tryWin()
end end
if (self:tryKezi2Zhong(activeCard)) then if (self:tryKezi2Zhong(activeCard)) then
print("tryKezi2Zhong")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -241,6 +244,7 @@ function M:tryWin()
end end
if (self:tryShunzi1Zhong(activeCard)) then if (self:tryShunzi1Zhong(activeCard)) then
print("tryShunzi1Zhong")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -248,6 +252,7 @@ function M:tryWin()
end end
if (self:tryPair1Zhong(activeCard)) then if (self:tryPair1Zhong(activeCard)) then
print("tryPair1Zhong")
if (self:tryWin()) then if (self:tryWin()) then
return true return true
end end
@ -257,7 +262,7 @@ function M:tryWin()
return false return false
end end
function M:checkQidui() function M:checkQidui()
if (not self.qidui) then if (not self.qidui) then
return false return false
end end
@ -270,17 +275,17 @@ function M:checkQidui()
return self:isQdPari(cardList) return self:isQdPari(cardList)
end end
function M:isQdPari(cardList) function M:isQdPari(cardList)
if(self.qidui_pari_count == 7) then if (self.qidui_pari_count == 7) then
return true return true
end end
if (#cardList== 0) then if (#cardList == 0) then
return true return true
end end
local card = cardList[1] local card = cardList[1]
if (cardNum(card, cardList) >= 2) then if (cardNum(card, cardList) >= 2) then
removeCard(cardList, card, 2) removeCard(cardList, card, 2)
self.qidui_pari_count = self.qidui_pari_count +1 self.qidui_pari_count = self.qidui_pari_count + 1
if (self:isQdPari(cardList)) then if (self:isQdPari(cardList)) then
return true return true
end end
@ -289,7 +294,7 @@ function M:isQdPari(cardList)
if (self.hongzhong_count > 0) then if (self.hongzhong_count > 0) then
removeCard(cardList, card, 1) removeCard(cardList, card, 1)
self.hongzhong_count = self.hongzhong_count - 1 self.hongzhong_count = self.hongzhong_count - 1
self.qidui_pari_count = self.qidui_pari_count +1 self.qidui_pari_count = self.qidui_pari_count + 1
if (self:isQdPari(cardList)) then if (self:isQdPari(cardList)) then
return true return true
end end
@ -297,13 +302,13 @@ function M:isQdPari(cardList)
return false return false
end end
local function init(self,cardInhand,addCard,isZhong,qidui,eightLaizi) local function init(self, cardInhand, addCard, isZhong, qidui, eightLaizi)
self.stack = {} self.stack = {}
self.pair_count = 0 self.pair_count = 0
self.cardList = membe_clone(cardInhand) self.cardList = membe_clone(cardInhand)
self.qidui = qidui self.qidui = qidui
self.eight_laizi = eightLaizi self.eight_laizi = eightLaizi
self.cardList[#self.cardList+1] = addCard self.cardList[#self.cardList + 1] = addCard
if (isZhong) then if (isZhong) then
self.zhong_count = cardNum(zhongid, self.cardList) self.zhong_count = cardNum(zhongid, self.cardList)
removeCard(self.cardList, zhongid, self.zhong_count) removeCard(self.cardList, zhongid, self.zhong_count)
@ -314,65 +319,63 @@ local function init(self,cardInhand,addCard,isZhong,qidui,eightLaizi)
return self:checkQidui() or self:tryWin() return self:checkQidui() or self:tryWin()
end end
local specialCardList={400,403,406,409,412,415,418} local specialCardList = { 401, 402, 403, 404, 405, 406, 407 }
function M.tingPai(cardInhand,isZhong,qidui,eightLaizi) function M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
--printlog("isZhong",isZhong) printlog("isZhong", isZhong)
--printlog("qidui",qidui) printlog("qidui", qidui)
--printlog("eightLaizi",eightLaizi) printlog("eightLaizi", eightLaizi)
--pt(cardInhand) pt(cardInhand)
local self = setmetatable({}, {__index = M}) local self = setmetatable({}, { __index = M })
local tingList = {} local tingList = {}
if not cardInhand or #cardInhand == 0 then if not cardInhand or #cardInhand == 0 then
return tingList return tingList
end end
for k=100,300,100 do for k = 100, 300, 100 do
for i=1,9 do for i = 1, 9 do
local tem = k + i local tem = k + i
local result = init(self,cardInhand,tem,isZhong,qidui,eightLaizi) local result = init(self, cardInhand, tem, isZhong, qidui, eightLaizi)
--printlog("返回结果为===>>>",result) --printlog("返回结果为===>>>",result)
if(result) then if (result) then
tingList[#tingList + 1] = tem tingList[#tingList + 1] = tem
end end
end end
end end
for j=1,#specialCardList do for j = 1, #specialCardList do
local tem = specialCardList[j] local tem = specialCardList[j]
local result = init(self,cardInhand,tem,isZhong,qidui,eightLaizi) local result = init(self, cardInhand, tem, isZhong, qidui, eightLaizi)
if(result) then if (result) then
tingList[#tingList + 1] = tem tingList[#tingList + 1] = tem
end end
end end
return tingList return tingList
end end
function M.MuiltiplteCaculateTingPai(cardInhand,isZhong,qidui,eightLaizi) function M.MuiltiplteCaculateTingPai(cardInhand, isZhong, qidui, eightLaizi)
if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo>0 then if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo > 0 then
zhongid=DataManager.CurrenRoom.laiziInfo[1] zhongid = DataManager.CurrenRoom.laiziInfo[1]
local tempTingList2={} local tempTingList2 = {}
local tempTingList1=M.tingPai(cardInhand,isZhong,qidui,eightLaizi) local tempTingList1 = M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
if DataManager.CurrenRoom.laiziInfo[2] then if DataManager.CurrenRoom.laiziInfo[2] then
zhongid=DataManager.CurrenRoom.laiziInfo[2] zhongid = DataManager.CurrenRoom.laiziInfo[2]
tempTingList2=M.tingPai(cardInhand,isZhong,qidui,eightLaizi) tempTingList2 = M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
zhongid=DataManager.CurrenRoom.laiziInfo[1] zhongid = DataManager.CurrenRoom.laiziInfo[1]
end end
local currentTingList={} local currentTingList = {}
if #tempTingList1>0 and #tempTingList2>0 then if #tempTingList1 > 0 and #tempTingList2 > 0 then
currentTingList=CombineDictionaryAndRemoveSomeItem(tempTingList1,tempTingList2) currentTingList = CombineDictionaryAndRemoveSomeItem(tempTingList1, tempTingList2)
elseif #tempTingList1>0 then elseif #tempTingList1 > 0 then
currentTingList=tempTingList1 currentTingList = tempTingList1
elseif #tempTingList2>0 then elseif #tempTingList2 > 0 then
currentTingList=tempTingList2 currentTingList = tempTingList2
end end
return currentTingList return currentTingList
else else
zhongid=0 zhongid = 0
return M.tingPai(cardInhand,isZhong,qidui,eightLaizi) return M.tingPai(cardInhand, isZhong, qidui, eightLaizi)
end end
end end
return M return M

View File

@ -38,12 +38,7 @@ function M:InitView(url)
self.Laizi2Btn.visible = true self.Laizi2Btn.visible = true
self.bugangnum = self._view:GetChild("bugangnum") self.bugangnum = self._view:GetChild("bugangnum")
print("==================================jing", room.jing) self.jing = self._view:GetChild('jing')
if room.jing then
self.jing = self._view:GetChild('jing')
print("==================================self.jing", room.jing)
self.jing.visible = true
end
self:PlayerChangeLineState() self:PlayerChangeLineState()
@ -105,6 +100,17 @@ function M:UpdateRound()
self._view:GetChild("tex_round2").text = self._room.room_config.round self._view:GetChild("tex_round2").text = self._room.room_config.round
end end
function M:ShowJing()
print("==================================self._room.jing", self._room.jing)
if self._room.jing then
self.jing.icon = 'ui://Main_Majiang/' ..
get_majiang_prefix(DataManager.CurrenRoom.game_id) .. "201_" .. self._room.jing
self.jing.visible = true
else
self.jing.visible = false
end
end
function M:InitPlayerInfoView() function M:InitPlayerInfoView()
self._player_info = {} self._player_info = {}
local _player_info = self._player_info local _player_info = self._player_info
@ -159,6 +165,7 @@ function M:EventInit()
-- self:ShowHuTip() -- self:ShowHuTip()
self:UpdateRound() self:UpdateRound()
self._state.selectedIndex = 1 self._state.selectedIndex = 1
self:ShowJing()
local list = _room.player_list local list = _room.player_list
for i = 1, #list do for i = 1, #list do
local p = list[i] local p = list[i]

View File

@ -3,11 +3,11 @@ local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView")
local CardCheck = import(".CardCheck") local CardCheck = import(".CardCheck")
local M = {} local M = {}
-- --
function M.new(view,mainView) function M.new(view, mainView)
setmetatable(MJPlayerSelfCardInfoView, {__index = MJPlayerCardInfoView}) setmetatable(MJPlayerSelfCardInfoView, { __index = MJPlayerCardInfoView })
setmetatable(M, {__index = MJPlayerSelfCardInfoView}) setmetatable(M, { __index = MJPlayerSelfCardInfoView })
local self = setmetatable({},{__index = M}) local self = setmetatable({}, { __index = M })
self.class = "PlayerSelfCardInfoView" self.class = "PlayerSelfCardInfoView"
self._view = view self._view = view
self._mainView = mainView self._mainView = mainView
@ -17,16 +17,17 @@ end
function M:ShowHuTip(card_list) function M:ShowHuTip(card_list)
printlog("ShowHuTip") printlog("ShowHuTip")
local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true, DataManager.CurrenRoom.room_config.Qidui, DataManager.CurrenRoom.room_config.Laizi) local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true, DataManager.CurrenRoom.room_config.Qidui,
DataManager.CurrenRoom.room_config.Laizi)
pt(tingList)
if #tingList > 0 then if #tingList > 0 then
if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo>0 then if DataManager.CurrenRoom.laiziInfo and #DataManager.CurrenRoom.laiziInfo > 0 then
for i=1,#DataManager.CurrenRoom.laiziInfo do for i = 1, #DataManager.CurrenRoom.laiziInfo do
if IsHasDictionary(DataManager.CurrenRoom.laiziInfo[i],tingList)==false then if IsHasDictionary(DataManager.CurrenRoom.laiziInfo[i], tingList) == false then
table.insert(tingList,DataManager.CurrenRoom.laiziInfo[i] ) table.insert(tingList, DataManager.CurrenRoom.laiziInfo[i])
end end
end end
end end
end end
self._mainView._hu_tip:FillData(tingList) self._mainView._hu_tip:FillData(tingList)
end end
@ -35,32 +36,28 @@ function M:UpdateHandCard(getcard, mp)
MJPlayerSelfCardInfoView.UpdateHandCard(self, getcard, mp) MJPlayerSelfCardInfoView.UpdateHandCard(self, getcard, mp)
local _carViewList = self._carViewList local _carViewList = self._carViewList
if DataManager.CurrenRoom.laiziInfo and #self._carViewList>0 then if DataManager.CurrenRoom.laiziInfo and #self._carViewList > 0 then
for i=1,#self._carViewList do for i = 1, #self._carViewList do
local obj=self._carViewList[i] local obj = self._carViewList[i]
if obj and obj.card then if obj and obj.card then
if IsHasDictionary(obj.card_item,DataManager.CurrenRoom.laiziInfo) then if IsHasDictionary(obj.card_item, DataManager.CurrenRoom.laiziInfo) then
if obj.card.GetController then if obj.card.GetController then
if obj.card:GetController("laizi") then if obj.card:GetController("laizi") then
obj.card:GetController("laizi").selectedIndex=1 obj.card:GetController("laizi").selectedIndex = 1
end end
end
end else
else if obj.card.GetController then
if obj.card.GetController then if obj.card:GetController("laizi") then
if obj.card:GetController("laizi") then obj.card:GetController("laizi").selectedIndex = 0
obj.card:GetController("laizi").selectedIndex=0 end
end end
end end
end end
end
end end
end
end
local card_list = DataManager.CurrenRoom.self_player.card_list local card_list = DataManager.CurrenRoom.self_player.card_list
self:ShowHuTip(card_list) self:ShowHuTip(card_list)
if getcard then if getcard then
@ -73,7 +70,8 @@ function M:UpdateHandCard(getcard, mp)
local btn = _carViewList[i].card local btn = _carViewList[i].card
local card = self:GetCard(btn) local card = self:GetCard(btn)
list_remove(card_list, card) list_remove(card_list, card)
local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true, DataManager.CurrenRoom.room_config.Qidui, DataManager.CurrenRoom.room_config.Laizi) local tingList = CardCheck.MuiltiplteCaculateTingPai(card_list, true,
DataManager.CurrenRoom.room_config.Qidui, DataManager.CurrenRoom.room_config.Laizi)
if #tingList > 0 then if #tingList > 0 then
local count = 0 local count = 0
for j = 1, #tingList do for j = 1, #tingList do
@ -92,7 +90,7 @@ function M:UpdateHandCard(getcard, mp)
end) end)
-- 如果几张牌的可胡牌数一致,也只显示'三角',可胡牌数不一致才显示'多' -- 如果几张牌的可胡牌数一致,也只显示'三角',可胡牌数不一致才显示'多'
local all_same = #lst_mark ~= 0 and lst_mark[1].count == total_num / #lst_mark or false local all_same = #lst_mark ~= 0 and lst_mark[1].count == total_num / #lst_mark or false
for i = 1, #lst_mark do for i = 1, #lst_mark do
local tem = lst_mark[i] local tem = lst_mark[i]
if all_same or tem.count < lst_mark[1].count then if all_same or tem.count < lst_mark[1].count then
tem.item:GetController("mark_ting").selectedIndex = 1 tem.item:GetController("mark_ting").selectedIndex = 1
@ -109,7 +107,6 @@ function M:UpdateHandCard(getcard, mp)
end end
self._out_card = false self._out_card = false
end end
end end
function M:__OnClickHandCard(context) function M:__OnClickHandCard(context)
@ -117,17 +114,17 @@ function M:__OnClickHandCard(context)
local _carViewList = self._carViewList local _carViewList = self._carViewList
local refresh = true local refresh = true
local card_list = {} local card_list = {}
for i=1,#_carViewList do for i = 1, #_carViewList do
local btn = _carViewList[i].card local btn = _carViewList[i].card
local card = self:GetCard(btn) local card = self:GetCard(btn)
if btn ~= button and btn.selected == true then if btn ~= button and btn.selected == true then
if button.data.card_item == card then if button.data.card_item == card then
refresh = false refresh = false
else else
self._mainView:markOutCards(false, card) self._mainView:markOutCards(false, card)
end end
btn.selected = false btn.selected = false
end end
if not btn.selected then if not btn.selected then
table.insert(card_list, card) table.insert(card_list, card)
end end
@ -160,16 +157,16 @@ function M:__OnDragStart(card)
end end
function M:__OnDragEnd(context) function M:__OnDragEnd(context)
if self.outcard_button then if self.outcard_button then
self.outcard_button:Dispose() self.outcard_button:Dispose()
self.outcard_button = nil self.outcard_button = nil
end end
local button = context.sender local button = context.sender
--button:RemoveFromParent() --button:RemoveFromParent()
local card = button.data local card = button.data
local _room = DataManager.CurrenRoom local _room = DataManager.CurrenRoom
-- print("button.y"..button.y .. "_room.curren_outcard_seat".._room.curren_outcard_seat) -- print("button.y"..button.y .. "_room.curren_outcard_seat".._room.curren_outcard_seat)
if (button.y - card.old_postion.y < -50 and _room.curren_outcard_seat == _room.self_player.seat and card.card_item ~= 0) then if (button.y - card.old_postion.y < -50 and _room.curren_outcard_seat == _room.self_player.seat and card.card_item ~= 0) then
self._mainView:OutCard(card.card_item) self._mainView:OutCard(card.card_item)
@ -190,6 +187,7 @@ function M:CheckPlayerOnlineState()
end end
return true return true
end end
function M:Clear(bskip) function M:Clear(bskip)
--self._ctr_state.selectedIndex = 0 --self._ctr_state.selectedIndex = 0
self._area_fz_list.x = self._src_fz_list.x self._area_fz_list.x = self._src_fz_list.x
@ -204,10 +202,10 @@ function M:Clear(bskip)
self._mask_liangpai:RemoveChildren(0, -1, true) self._mask_liangpai:RemoveChildren(0, -1, true)
end end
for i=1,#self._carViewList do for i = 1, #self._carViewList do
self._carViewList[i].card:Dispose() self._carViewList[i].card:Dispose()
end end
self._carViewList = {} self._carViewList = {}
end end
return M
return M