|
- local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
- local MJMessage = MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
- local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
- local CommonHandCard = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.2d.CommonHandCard")
-
- local HandCard2D = class("HandCard2D", CommonHandCard)
-
- function HandCard2D:ctor(...)
- HandCard2D.super.ctor(self, ...)
- end
- --- HandCard2D:onAfterCreateHandcards 创建手牌之后的处理
- function HandCard2D:onAfterCreateHandcards()
- HandCard2D.super.onAfterCreateHandcards(self)
- end
- ---
- -- 摊牌之后的处理
- --
- function HandCard2D:onAfterCreateOpenHandcards()
- HandCard2D.super.onAfterCreateOpenHandcards(self)
- end
-
- function HandCard2D:createGroupCards(arg, fromViewId)
- for _, v in pairs(arg) do
- if not fromViewId then
- fromViewId = v.fromViewId
- end
-
- local group = nil
-
- if v.opType == MJDefine.MJOperateType.OPREATE_ANGANG then
- group = self:getGroup(v.values[1], {MJDefine.MJOperateType.OPREATE_ANGANG})
- if group then
- group:setCardNum(v.cardNum)
- group:customRefresh(v)
- return
- end
- end
-
- local groupIndex = table.nums(self._groupNodes) + 1
- group = self:createGroup(v.values, v.showType, self._viewId, groupIndex, v.cardNum)
- if group then
- group.fromViewId = v.fromViewId ---保留触发操作的玩家位置,补杠需要
- group.opType = v.opType
- local x, y = self:getGroupPosition(group, groupIndex)
- group:setPosition(cc.p(x, y))
- group:customRefresh(v)
- self:addChild(group)
- table.insert(self._groupNodes, group)
- end
- end
- self:refreshGroupZOrder()
- end
-
- ---
- -- 补杠
- -- @param card 补杠的牌
- -- @param cardNum 多头杠牌张数
- -- @return
- --
- function HandCard2D:buGang(card, cardNum)
- local oldGroup = self:getGroup(card, {MJDefine.MJOperateType.OPREATE_BAGANG, MJDefine.MJOperateType.OPREATE_ZHIGANG, MJDefine.MJOperateType.OPREATE_ANGANG})
- if oldGroup then
- -- 如果没有碰牌,则查看是否已经有补杠
- local cards = oldGroup:getCards()
- if cards and cards[4] then
- oldGroup:setCardNum(cardNum)
- cards[4]:setOperateBackImage()
- end
- return
- else
- oldGroup = self:getGroup(card, {MJDefine.MJOperateType.OPREATE_PENG})
- if not oldGroup then
- oldGroup = self:getGroup(card, {MJDefine.MJOperateType.OPREATE_TI})
- end
- end
-
- if not oldGroup then
- return
- end
-
- local fromViewId = oldGroup.fromViewId
- -- 杠牌对家,换成第四张
- if app.room:getMaxPlayerCount() == 2 and fromViewId ~= 0 then
- fromViewId = 4
- end
- if app.room:getMaxPlayerCount() == 4 and fromViewId == 2 then
- fromViewId = 4
- end
-
- local oldPos = oldGroup:getPosition()
- local index = table.indexOf(self._groupNodes, oldGroup)
- table.remove(self._groupNodes, index)
- oldGroup:removeFromParent()
-
- local newGroup = self:createGroup({card, card, card, card}, MJDefine.MJGroupType.BaGang, self._viewId, index, cardNum)
- if not newGroup then
- return
- end
- newGroup.fromViewId = fromViewId
- newGroup.opType = MJDefine.MJOperateType.OPREATE_BAGANG
- table.insert(self._groupNodes, index, newGroup)
-
- newGroup:setPosition(oldPos)
- newGroup:customRefresh(newGroup)
- self:addChild(newGroup)
- self:refreshGroupZOrder()
- end
-
- --- HandCard2D:retoreBuGang 还原补杠
- -- @param card 牌值
- -- @param cardNum 牌张数
- function HandCard2D:restoreBuGang(card, cardNum)
- local oldGroup =
- self:getGroup(
- card,
- {
- MJDefine.MJOperateType.OPREATE_BAGANG,
- MJDefine.MJOperateType.OPREATE_ANGANG,
- MJDefine.MJOperateType.OPREATE_ZHIGANG
- })
- if not oldGroup then
- return
- end
-
- if type(oldGroup.getCardNum)=='function' then
- local oldCardNum = oldGroup:getCardNum()
- if oldCardNum > 4 then
- oldCardNum = oldCardNum - 1
- oldGroup:setCardNum(oldCardNum)
- oldGroup:customRefresh()
- return
- end
- end
-
- local fromViewId = oldGroup.fromViewId
- -- 杠牌对家,换成第四张
- if app.room:getMaxPlayerCount() == 2 and fromViewId ~= 0 then
- fromViewId = 4
- end
- if app.room:getMaxPlayerCount() == 4 and fromViewId == 2 then
- fromViewId = 4
- end
-
- local oldPos = oldGroup:getPosition()
- local index = table.indexOf(self._groupNodes, oldGroup)
- table.remove(self._groupNodes, index)
- oldGroup:removeFromParent()
-
- local newGroup = self:createGroup({card, card, card}, MJDefine.MJGroupType.Peng, self._viewId, index, cardNum)
- if not newGroup then
- return
- end
-
- newGroup.fromViewId = fromViewId
- newGroup.opType = MJDefine.MJOperateType.OPREATE_PENG
- table.insert(self._groupNodes, index, newGroup)
-
- newGroup:setPosition(oldPos)
- self:addChild(newGroup)
- self:refreshGroupZOrder()
- end
-
- -- 重写排序,让听用牌放在最左边,定缺牌放最右边
- function HandCard2D:sortHandCards()
- -- 拆分
- local temp = {}
- local tCard = {}
- local nCard = {}
- local qCard = {}
-
- for i, v in ipairs(self._handCardNodes) do
- if v:getIsTingYongCard() then
- table.insert(tCard, v)
- elseif v:getIsDingQueCard() or (v:getMJColorType() == self.queType) then
- table.insert(qCard, v)
- else
- table.insert(nCard, v)
- end
- end
-
- -- 按牌值顺序排序
- local function sortFun(c1, c2)
- return c1:getValue() < c2:getValue()
- end
-
- table.sort(tCard, sortFun)
- table.sort(nCard, sortFun)
- table.sort(qCard, sortFun)
-
- -- 添加到大表temp里面
- for i, v in ipairs(tCard) do
- table.insert(temp, v)
- end
-
- for i, v in ipairs(nCard) do
- table.insert(temp, v)
- end
-
- for i, v in ipairs(qCard) do
- table.insert(temp, v)
- end
-
- self._handCardNodes = temp
- end
-
- --发送出牌消息
- function HandCard2D:sendOutCard()
- app.room:dispatchEvent({name = MJDefine.MJEvent.checkIsNeedSendGuo})
- HandCard2D.super.sendOutCard(self)
- end
-
- --判断是否符合换三张规则
- function HandCard2D:checkIsInSwapRule()
- local roomInfo=app.room.roomInfo
- local gameInfo=json.decode(roomInfo.strGameInfo)
- local selectNums = #self._selectCards
- --local tipsMessage = "当前服务器传下来换牌的张数:" .. gameInfo.swapcardcount .. "当前选中的牌张数:" .. selectNums;
- --showTooltip(tipsMessage)
-
- if selectNums ~= tonumber(gameInfo.swapcardcount) then
- return false
- end
- local huase = self._selectCards[1]:getMJColorType()
- for i,v in pairs(self._selectCards) do
- local tHuase = v:getMJColorType()
- if tHuase ~= huase then
- return false
- end
- end
- return true
- end
-
-
- -- -- todo lwq 血流专用 胡牌后,玩家的牌要躺下
- -- function HandCard2D:setIsHupai(hu)
- -- self.isHu = hu
- -- end
- -- function HandCard2D:getIsHupai(hu)
- -- return self.isHu
- -- end
-
- -- function HandCard2D:resetHandCards()
- -- logD("HandCard2D:resetHandCards", "重置手牌")
- -- -- if self.isHu and self.isHu == 1 then --todo lwq
- -- -- return
- -- -- end
- -- self:sortHandCards()
- -- local startIndex = table.nums(self._groupNodes) * 3
- -- for cardIndex, card in ipairs(self._handCardNodes) do
- -- local newCardIndex = startIndex + cardIndex
- -- local x, y = self:getCardPosition(card, self._viewId, newCardIndex)
- -- if (self._viewId ~= MJDefine.MyViewId and self._isReplay) or card:getMJType() == MJDefine.MJConfig_2d.MJType.Open
- -- or card:getMJType() == MJDefine.MJConfig_3d.MJType.Open then
- -- x, y = self:getOpenCardPosition(card, self._viewId, newCardIndex)
- -- else
- -- if self._viewId == 1 or self._viewId == 3 then
- -- if self.isHu and self.isHu == 1 then
- -- x, y = self:getOpenCardPosition(card, self._viewId, newCardIndex)
-
- -- end
- -- end
- -- end
- -- card:setPosition(cc.p(x, y))
- -- card:setMJIndex(newCardIndex)
- -- if self._viewId ~= 4 then
- -- -- 重新排序,手牌可能乱了,需要重新设置一下手牌的背景
- -- card:initBackImage()
- -- end
- -- end
-
- -- self:refreshHandCardZOrder()
- -- end
-
-
-
- function HandCard2D:getCardPosition(mjCard, viewId, mjIndex)
- local x = 0
- local y = 0
- local cardSize = mjCard:getContentSize()
- local offset = self:getHandCardOffestPos(viewId)
- local startPos = self:getHandCardStartPos(viewId)
- local groupCount = table.nums(self._groupNodes)
- local dealCardNum = self:getDealHandCardNum()
- if viewId == MJDefine.PlayerViewType.My then
- x = startPos.x + (mjIndex - 1) * (cardSize.width + offset.x)
- y = startPos.y + offset.y
- x = mjIndex == (dealCardNum + 1) and (x + 10) or x
- if groupCount > 0 then
- x = x - 180 + (4 - groupCount) * 50
- end
- elseif viewId == MJDefine.PlayerViewType.Right then
- x = startPos.x + offset.x
- y = startPos.y + (mjIndex - 1) * (cardSize.height + offset.y)
- y = mjIndex == (dealCardNum + 1) and (y + 10) or y
- if groupCount == 4 then
- y = y + 100
- elseif groupCount == 3 then
- y = y + 70
- elseif groupCount == 2 then
- y = y + 45
- elseif groupCount == 1 then
- y = y + 15
- end
- elseif viewId == MJDefine.PlayerViewType.Top then
- x = startPos.x + (1 - mjIndex) * (cardSize.width + offset.x)
- y = startPos.y + offset.y
- x = mjIndex == (dealCardNum + 1) and (x - 10) or x
- if groupCount == 4 then
- x = x - 45
- elseif groupCount == 3 then
- x = x - 35
- elseif groupCount == 2 then
- x = x - 25
- elseif groupCount == 1 then
- x = x - 15
- end
- elseif viewId == MJDefine.PlayerViewType.Left then
- x = startPos.x
- y = startPos.y + (1 - mjIndex) * (cardSize.height + offset.y)
- y = mjIndex == (dealCardNum + 1) and (y - 10) or y
- if groupCount == 4 then
- y = y - 75
- elseif groupCount == 3 then
- y = y - 55
- elseif groupCount == 2 then
- y = y - 30
- elseif groupCount == 1 then
- if self.isHu and self.isHu == 1 then -- 胡牌以后不是拿着MJDefine.MJConfig_2d.MJType.Open 的牌去判断,间距写大点
- y = y - 10 - 70
- else
- y = y - 10
- end
-
- end
- end
- return x, y
- end
-
- return HandCard2D
|