Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

445 wiersze
13 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPFunctions = {}
  3. --获取字牌资源名字
  4. function ZPFunctions.getZPCardImgByValue(value,cardType)
  5. if not value then
  6. logE("ZPFunctions.getZPCardImgByValue", "value:", value, "cardType:", cardType)
  7. return ""
  8. end
  9. -- value小写:1 - 10
  10. -- value大写:17- 26
  11. --资源是1-20,牌背名称特殊,value > 20即可
  12. --此个if是配合代码里的资源
  13. if value >= 17 and value <= 26 then
  14. value = value - 6
  15. end
  16. local cacheGameCard = "ZPCardType"..(ZPDef.GameID or app.gameId)
  17. local cardTypeRes = tonumber(loadUserInfo(cacheGameCard)) or ZPDef.defaultCardRes
  18. local textureName = ""
  19. if cardType == ZPDef.CardType.CARD_TYPE_HAND then --手牌
  20. if value <= 20 then
  21. textureName = string.format(ZPDef.CardFile.CARD_FILE_HAND,cardTypeRes,value)
  22. else
  23. textureName = string.format(ZPDef.CardFile.CARD_FILE_HAND_BACK,cardTypeRes)
  24. end
  25. elseif cardType == ZPDef.CardType.CARD_TYPE_TABLE then --组合牌
  26. if value <= 20 then
  27. textureName = string.format(ZPDef.CardFile.CARD_FILE_WEAVE_CARD,cardTypeRes,value)
  28. else
  29. textureName = string.format(ZPDef.CardFile.CARD_FILE_WEAVE_CARD_BACK,cardTypeRes)
  30. end
  31. elseif cardType == ZPDef.CardType.CARD_TYPE_OUTCARD then --出牌
  32. if value <= 20 then
  33. textureName = string.format(ZPDef.CardFile.CARD_FILE_OUT_CARD,cardTypeRes,value)
  34. else
  35. textureName = string.format(ZPDef.CardFile.CARD_FILE_OUT_CARD_BACK,cardTypeRes)
  36. end
  37. end
  38. return textureName
  39. end
  40. --字牌是否是2710
  41. function ZPFunctions.getZPIsErQiShi(card)
  42. return card == 0x02 or card == 0x12 or card == 0x07 or card == 0x17 or card == 0x0A or card == 0x1A
  43. end
  44. --字牌是否是1510
  45. function ZPFunctions.getZPIsYiWuShi(card)
  46. return card == 0x01 or card == 0x11 or card == 0x05 or card == 0x15 or card == 0x0A or card == 0x1A
  47. end
  48. --[[
  49. @boolean:true为大写,false为小写
  50. ]]
  51. function ZPFunctions.getZPCardIsBig(card)
  52. return card - 10 > 0
  53. end
  54. --是否是二七十,也作红牌判断
  55. function ZPFunctions.getIsErQiShi(card)
  56. return card == 0x02 or card == 0x12 or card == 0x07 or card == 0x17 or card == 0x0A or card == 0x1A
  57. end
  58. function ZPFunctions.getIsYiWuShi(card)
  59. return card == 0x01 or card == 0x11 or card == 0x05 or card == 0x15 or card == 0x0A or card == 0x1A
  60. end
  61. --根据一张牌和类型,获取组合牌
  62. function ZPFunctions.getZPCardList(card,mType)
  63. if mType == ZPDef.SendCardType.GUN_ZI_FOUR_SAME or mType == ZPDef.SendCardType.CHI_PAI_TI then --四张同牌 提
  64. return {card,card,card,card},ZPDef.OpType.OP_TYPE_TI
  65. elseif mType == ZPDef.SendCardType.KUAI_SHUI_FOUR_SAME or mType == ZPDef.SendCardType.CHI_PAI_SHAO_PAO or mType == ZPDef.SendCardType.CHI_PAI_PENG_PAO then --四张同牌 跑
  66. return {card,card,card,card},ZPDef.OpType.OP_TYPE_PAO
  67. elseif mType == ZPDef.SendCardType.KAN_THREE_SAME then -- 暗偎
  68. return {card,card,card},ZPDef.OpType.OP_TYPE_ANWEI
  69. elseif mType == ZPDef.SendCardType.DIRTY_THREE_SAME then -- 明偎
  70. return {card,card,card},ZPDef.OpType.OP_TYPE_MINGWEI
  71. elseif mType == ZPDef.SendCardType.DUI_THREE_SAME then --碰
  72. return {card,card,card},ZPDef.OpType.OP_TYPE_PENG
  73. elseif mType == ZPDef.SendCardType.TWO_SEVEN_TEN then --2.7,10
  74. return {card,card+5,card+8},ZPDef.OpType.OP_TYPE_CHI
  75. elseif mType == ZPDef.SendCardType.ONE_FIVE_TEN then --1.5,10
  76. return {card,card + 4,card + 9},ZPDef.OpType.OP_TYPE_CHI
  77. elseif mType == ZPDef.SendCardType.ONE_TWO_THREE then --1,2,3
  78. return {card,card+1,card+2},ZPDef.OpType.OP_TYPE_CHI
  79. elseif mType == ZPDef.SendCardType.SHUN_ZI then --顺子
  80. return {card,card+1,card+2},ZPDef.OpType.OP_TYPE_CHI
  81. elseif mType == ZPDef.SendCardType.DA_ZI_TWO_AND_ONE then -- 二同牌+同数字其它花色牌 吃操作
  82. if card - 10 > 0 then
  83. return {card,card - 16,card - 16},ZPDef.OpType.OP_TYPE_CHI
  84. else
  85. return {card + 16,card + 16,card},ZPDef.OpType.OP_TYPE_CHI
  86. end
  87. elseif mType == ZPDef.SendCardType.ZHUANG_ZI then --对子
  88. return {card,card},0
  89. elseif mType == ZPDef.SendCardType.MIX_ZHUANG_ZI then --混对子,如大壹与小一
  90. if card - 10 > 0 then
  91. return {card,card - 16},0
  92. else
  93. return {card + 16,card},0
  94. end
  95. elseif mType == ZPDef.SendCardType.SINGLE_CARD then --单牌
  96. return {card},0
  97. end
  98. end
  99. --获取操作显示类型
  100. function ZPFunctions.getZPOperationType(mType,isHaveGuo,isChongZhao)
  101. local mResult = {}
  102. --判断是否有吃
  103. local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
  104. local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
  105. local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
  106. local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
  107. local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
  108. local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
  109. local ret7 = bit32.band(mType,ZPDef.OpCode.OP_CHI_ONE_FIVE_TEN)
  110. if ret1 > 0 or ret2 > 0 or ret3 > 0 or ret4 > 0 or ret5 > 0 or ret6 > 0 or ret7 > 0 then
  111. table.insert(mResult,ZPDef.OpType.OP_TYPE_CHI)
  112. end
  113. --判断是否有碰
  114. local retPeng = bit32.band(mType,ZPDef.OpCode.OP_PENG)
  115. if retPeng > 0 then
  116. table.insert(mResult,ZPDef.OpType.OP_TYPE_PENG)
  117. end
  118. --判断是否有明偎
  119. local retShao = bit32.band(mType,ZPDef.OpCode.OP_MING_SHAO)
  120. if retShao > 0 then
  121. table.insert(mResult,ZPDef.OpType.OP_TYPE_MINGWEI)
  122. end
  123. --判断是否有暗偎
  124. local retShao = bit32.band(mType,ZPDef.OpCode.OP_AN_SHAO)
  125. if retShao > 0 then
  126. table.insert(mResult,ZPDef.OpType.OP_TYPE_ANWEI)
  127. end
  128. --判断是否有提
  129. local retChuang = bit32.band(mType,ZPDef.OpCode.OP_TI)
  130. if retChuang > 0 then
  131. table.insert(mResult,ZPDef.OpType.OP_TYPE_TI)
  132. end
  133. --判断是否有重跑
  134. local retKaiZhao = bit32.band(mType,ZPDef.OpCode.OP_PAO)
  135. if retKaiZhao > 0 then
  136. if isChongZhao then
  137. table.insert(mResult,ZPDef.OpType.OP_TYPE_CHONG_PAO)
  138. else
  139. table.insert(mResult,ZPDef.OpType.OP_TYPE_PAO)
  140. end
  141. end
  142. --判断是否有胡
  143. local retHu = bit32.band(mType,ZPDef.OpCode.OP_HU)
  144. if retHu > 0 then
  145. table.insert(mResult,ZPDef.OpType.OP_TYPE_HU)
  146. end
  147. --默认有过操作
  148. if isHaveGuo then
  149. table.insert(mResult,ZPDef.OpType.OP_TYPE_CANCEL)
  150. end
  151. print("getZiPaiOperationType : "..table.tostring(mResult))
  152. return mResult
  153. end
  154. --获取吃牌组合牌
  155. function ZPFunctions.getZPEatCardWeave(card,mType)
  156. if mType == ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI then
  157. return {card,card + 1,card + 2}
  158. elseif mType == ZPDef.OpCode.OP_CHI_MID_SHUN_ZI then
  159. return {card,card - 1,card + 1}
  160. elseif mType == ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI then
  161. return {card,card - 2,card - 1}
  162. elseif mType == ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME then
  163. if card - 10 > 0 then
  164. return {card,card - 16,card - 16}
  165. else
  166. return {card,card + 16,card + 16}
  167. end
  168. elseif mType == ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX then
  169. if card - 10 > 0 then
  170. return {card,card,card - 16}
  171. else
  172. return {card,card,card + 16}
  173. end
  174. elseif mType == ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN then
  175. if card - 10 > 0 then
  176. if card == 18 then
  177. return {18,23,26}
  178. elseif card == 23 then
  179. return {23,18,26}
  180. elseif card == 26 then
  181. return {26,18,23}
  182. end
  183. else
  184. if card == 2 then
  185. return {2,7,10}
  186. elseif card == 7 then
  187. return {7,2,10}
  188. elseif card == 10 then
  189. return {10,2,7}
  190. end
  191. end
  192. elseif mType == ZPDef.OpCode.OP_CHI_ONE_FIVE_TEN then
  193. if card - 10 > 0 then
  194. if card == 17 then
  195. return {17,21,26}
  196. elseif card == 21 then
  197. return {21,17,26}
  198. elseif card == 26 then
  199. return {26,17,21}
  200. end
  201. else
  202. if card == 1 then
  203. return {1,5,10}
  204. elseif card == 5 then
  205. return {5,1,10}
  206. elseif card == 10 then
  207. return {10,1,5}
  208. end
  209. end
  210. end
  211. end
  212. --预加载图片
  213. function ZPFunctions.loadSpriteFromFile(fileName)
  214. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile(fileName);
  215. end
  216. --操作牌放在第一位置
  217. function ZPFunctions.getOpCardFirstList(operationType,list,card)
  218. --排序优先操作牌在第一张
  219. if operationType == ZPDef.OpType.OP_TYPE_CHI then
  220. local sameCount = 0
  221. for i = 1,3 do
  222. if card == list[i] then
  223. sameCount = sameCount + 1
  224. end
  225. end
  226. for i = 1,3 do
  227. if card == list[i] then
  228. table.remove(list,i)
  229. break
  230. end
  231. end
  232. local tt = {}
  233. tt[1] = card
  234. if sameCount == 2 then
  235. tt[2] = card
  236. if card < 16 then
  237. tt[3] = card + 16
  238. else
  239. tt[3] = card - 16
  240. end
  241. else
  242. tt[2] = list[1]
  243. tt[3] = list[2]
  244. end
  245. list = tt
  246. end
  247. return list
  248. end
  249. --根据组合牌获取胡息
  250. function ZPFunctions.getHuXiByList(card,mType)
  251. if not card then
  252. return
  253. end
  254. --判断大小写
  255. local isBig = ZPFunctions.getZPCardIsBig(card)
  256. local zpTp = (isBig == true) and 2 or 1--小字1 大字2
  257. return ZPDef.SendCardTypeYou[mType][zpTp]
  258. end
  259. --获取版本号
  260. function ZPFunctions.getZPCurVersion()
  261. local versionInfo = ZPFramework.ZPImport("zp_base.luaScript.ZPVersion")
  262. return versionInfo.ResourceVersion
  263. end
  264. --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
  265. function ZPFunctions.switchToCardIndex(cardData)
  266. --设置变量
  267. local cbCardIndex = {}
  268. for i = 1,20 do
  269. cbCardIndex[i] = 0
  270. end
  271. for i = 1,#cardData do
  272. if cardData[i] then
  273. local index = ZPFunctions.switchToIndex(cardData[i])
  274. cbCardIndex[index] = cbCardIndex[index] + 1
  275. end
  276. end
  277. return cbCardIndex
  278. end
  279. --扑克转换
  280. function ZPFunctions.switchToIndex(cbCardData)--返回牌的位置,从小写1-10,大写依次返回11-20
  281. if cbCardData - 10 > 0 then
  282. return cbCardData - 16 + 10
  283. else
  284. return cbCardData
  285. end
  286. end
  287. --创建一个imageNode
  288. function ZPFunctions.createImageNode(fileName)
  289. local img = cc.ImageView:createNode()
  290. img:loadTextureFromPlist(fileName)
  291. return img
  292. end
  293. --获取创建房间时选择的人数
  294. function ZPFunctions.getCreateRoomPlayerNum()
  295. local roomInfo = app.room.roomInfo;
  296. local jsonInfo = json.decode(roomInfo.strGameInfo)
  297. if jsonInfo then
  298. if jsonInfo.playnum == -1 then
  299. return 4
  300. else
  301. return jsonInfo.playnum or ZPDef.GameConst.ZiPai_GAME_CONST_PLAYER
  302. end
  303. end
  304. return nil
  305. end
  306. --获取是否是自摸
  307. function ZPFunctions.isZiMo(ty)
  308. local ret = getNumBand(ty,ZPDef.HuType.ZI_MO_HU)
  309. if ret > 0 then
  310. return true
  311. end
  312. return false
  313. end
  314. --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
  315. function ZPFunctions.switchToCardIndexForRecord(cardData)
  316. --设置变量
  317. local cbCardIndex = {}
  318. cbCardIndex[1] = {}
  319. cbCardIndex[2] = {}
  320. local cbCardBigCount = 0
  321. local cbCardLittleCount = 0
  322. for i = 1,10 do
  323. cbCardIndex[1][i] = 0 --小写
  324. cbCardIndex[2][i] = 0 --大写
  325. end
  326. --数组为cbCardIndex【1】小写牌下标有多少张,最后一个为小写总共多少张
  327. --数组为cbCardIndex【2】大写牌下标有多少张,最后一个为大写总共多少张
  328. for i = 1,#cardData do
  329. if cardData[i] then
  330. local index = ZPFunctions.switchToIndex(cardData[i])
  331. if index > 10 then
  332. index = index - 10
  333. end
  334. if ZPFunctions.getZPCardIsBig(cardData[i]) then
  335. cbCardIndex[2][index] = cbCardIndex[2][index] + 1
  336. else
  337. cbCardIndex[1][index] = cbCardIndex[1][index] + 1
  338. end
  339. end
  340. end
  341. for i = 1,10 do
  342. if cbCardIndex[1][i] then
  343. cbCardLittleCount = cbCardIndex[1][i] + cbCardLittleCount
  344. end
  345. if cbCardIndex[2][i] then
  346. cbCardBigCount = cbCardBigCount + cbCardIndex[2][i]
  347. end
  348. end
  349. cbCardIndex[1][11] = cbCardLittleCount
  350. cbCardIndex[2][11] = cbCardBigCount
  351. return cbCardIndex
  352. end
  353. --获取游戏速度,默认使用通用里的一套(快速)
  354. function ZPFunctions.getGameSpeed()
  355. local roomInfo = app.room.roomInfo;
  356. local jsonInfo = json.decode(roomInfo.strGameInfo)
  357. if jsonInfo then
  358. return jsonInfo.speed
  359. end
  360. return nil
  361. end
  362. function ZPFunctions.getClubInviteWanFa( gameId, roomInfo )
  363. local data = json.decode(roomInfo.strGameInfo or "")
  364. if data == nil then
  365. return ""
  366. end
  367. local gamerule = data.gamerule or 1 -- 玩法
  368. local roundCount = roomInfo.nTotalGameNum or 0 -- 局数
  369. local gameConfig = getSubGameConfig(gameId) or {}
  370. local gameType = gameConfig.GameType or {}
  371. local content = string.format("%s局 %s", roundCount, gameType[gamerule] or gameConfig.gameName)
  372. return content
  373. end
  374. function ZPFunctions.isPropFobided( )
  375. if not app.room then
  376. return
  377. end
  378. local roomInfo = app.room.roomInfo or {}
  379. local strGameInfo = app.room.roomInfo.strGameInfo or ""
  380. local info = json.decode(strGameInfo) or {}
  381. local isFobided = info.forbidProp == 1
  382. return isFobided
  383. end
  384. ---
  385. -- 检测语音是否可以使用
  386. -- 亲友圈配置
  387. -- @return
  388. --
  389. function ZPFunctions.isVoiceFobided ()
  390. if not app.room then
  391. return
  392. end
  393. local roomInfo = app.room.roomInfo or {}
  394. local strGameInfo = app.room.roomInfo.strGameInfo or ""
  395. local info = json.decode(strGameInfo) or {}
  396. local isFobided = false
  397. if not info.forbidVoice then--此字段没有说明还没有分开控制
  398. return ZPFunctions:isPropFobided ()
  399. end
  400. isFobided = info.forbidVoice == 1
  401. return isFobided
  402. end
  403. return ZPFunctions