local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine") local Mahjong3DHandCard = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.3d.Mahjong3DHandCard") local HandCard3D = class("HandCard3D", Mahjong3DHandCard) function HandCard3D:ctor(...) HandCard3D.super.ctor(self, ...) end function HandCard3D:sortHandCards() table.sort( self._handCardNodes, function(c1, c2) if c1:getValue() == 0x41 and c2:getValue() == 0x41 then return false elseif c1:getValue() == 0x41 then return true elseif c2:getValue() == 0x41 then return false else return c1:getValue() < c2:getValue() end end ) end function HandCard3D:createGroup(values, showType, viewId, groupIndex,redNum) local group = nil if showType == MJDefine.MJGroupType.Chi then group = require(MJDefine.MJConfig_3d.GROUP_CHI):new(values, viewId, groupIndex,redNum) elseif showType == MJDefine.MJGroupType.Peng then group = require(MJDefine.MJConfig_3d.GROUP_PENG):new(values, viewId, groupIndex,redNum) elseif showType == MJDefine.MJGroupType.Gang then group = require(MJDefine.MJConfig_3d.GROUP_GANG):new(values, viewId, groupIndex,redNum) elseif showType == MJDefine.MJGroupType.AnGang then group = require(MJDefine.MJConfig_3d.GROUP_ANGANG):new(values, viewId, groupIndex,redNum) elseif showType == MJDefine.MJGroupType.BaGang then group = require(MJDefine.MJConfig_3d.GROUP_BAGANG):new(values, viewId, groupIndex,redNum) end if group and viewId == MJDefine.MyViewId then group:setLocalZOrder(4 - groupIndex) end return group end function HandCard3D:createGroupCards(arg, fromViewId) for _, v in pairs(arg) do if not fromViewId then fromViewId = v.fromViewId end local group = self:createGroup(v.values, v.showType, self._viewId, table.nums(self._groupNodes) + 1,v.redNum) if group then local startPos = MJDefine.MJConfig_3d.HandCardStartPos[self._viewId] local x = startPos.x + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][#self._groupNodes + 1].x local y = startPos.y + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][#self._groupNodes + 1].y group.fromViewId = v.fromViewId ---保留触发操作的玩家位置,补杠需要 group.opType = v.opType group:setPosition(cc.p(x, y)) group:customRefresh(v) self:addChild(group) table.insert(self._groupNodes, group) end end self:refreshGroupZOrder() end function HandCard3D:removeHandCardByNum(value, num,redNum) redNum = redNum or 0 if self._viewId == MJDefine.MyViewId or self._isReplay then for i=1,num do local mj if redNum > 0 and i <= redNum then mj=self:getMjByValue(65) --红中值 else mj=self:getMjByValue(value) end if mj then table.removeItem(self._handCardNodes,mj) mj:removeFromParent() end end else for i = #self._handCardNodes, #self._handCardNodes - num + 1, -1 do self._handCardNodes[i]:removeFromParent() table.remove(self._handCardNodes, i) end end end --- HandCard3D:getGroup 获取已经存在的组合牌 -- @param mjValue int 麻将牌的值 -- @param opTypes table 麻将牌的类型 function HandCard3D:getGroup(mjValue, opTypes) if type(opTypes) ~= "table" then opTypes = {opTypes} end for _, vv in pairs(opTypes) do opType = vv for _, v in pairs(self._groupNodes) do if v.opType == opType then local redNum = 0 local mjCards = v:getCards() for i,v in pairs(mjCards) do if v:getValue() == 65 then redNum = redNum + 1 end end if v.opType == MJDefine.MJOperateType.OPREATE_ANGANG then if (mjCards[1]:getValue() == mjValue or mjCards[2]:getValue() == mjValue or mjCards[3]:getValue() == mjValue or mjCards[4]:getValue() == mjValue) then return v,redNum end else if (mjCards[1]:getValue() == mjValue or mjCards[2]:getValue() == mjValue or mjCards[3]:getValue() == mjValue) then return v,redNum end end end end end end --- HandCard3D:buGang 补杠 function HandCard3D:buGang(card, newRedNum) local oldGroup,oldRedNum = self:getGroup(card, {MJDefine.MJOperateType.OPREATE_PENG}) 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 redNum = newRedNum + oldRedNum local index = table.indexOf(self._groupNodes, oldGroup) table.remove(self._groupNodes, index) oldGroup:removeFromParent() local newGroup = self:createGroup({card, card, card, card}, MJDefine.MJGroupType.Gang, self._viewId, index, redNum) if not newGroup then return end newGroup.fromViewId = fromViewId newGroup.opType = MJDefine.MJOperateType.OPREATE_BAGANG table.insert(self._groupNodes, index, newGroup) local startPos = MJDefine.MJConfig_3d.HandCardStartPos[self._viewId] local x = startPos.x + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][index].x local y = startPos.y + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][index].y newGroup:setPosition(cc.p(x, y)) newGroup:customRefresh(newGroup) self:addChild(newGroup) self:refreshGroupZOrder() end --- HandCard3D:retoreBuGang 还原补杠 -- @param card 牌值 -- @param cardNum 牌张数 function HandCard3D:restoreBuGang(card, newRedNum) local oldGroup,oldRedNum = self:getGroup( card, { MJDefine.MJOperateType.OPREATE_BAGANG, MJDefine.MJOperateType.OPREATE_ANGANG, MJDefine.MJOperateType.OPREATE_ZHIGANG }) 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 redNum = oldRedNum 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,redNum) if not newGroup then return end newGroup.fromViewId = fromViewId newGroup.opType = MJDefine.MJOperateType.OPREATE_PENG table.insert(self._groupNodes, index, newGroup) local startPos = MJDefine.MJConfig_3d.HandCardStartPos[self._viewId] local x = startPos.x + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][index].x local y = startPos.y + MJDefine.MJConfig_3d.GroupOffsetConfig[self._viewId][index].y newGroup:setPosition(cc.p(x, y)) self:addChild(newGroup) self:refreshGroupZOrder() end return HandCard3D