BusThreeActDice.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. --------------------------------
  2. -- 文件名 : BusThreeActDice.lua
  3. -- 文件说明 : 新商业活动3-天选骰子
  4. -- 创建时间 : 2025/09/02
  5. -- 创建人 : FC
  6. --------------------------------
  7. local tDiceConf = require("excel.BusThreeActivity").Dice
  8. local Util = require("common.Util")
  9. local Msg = require("core.Msg")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local CommonDefine = require("common.CommonDefine")
  13. local AbsActLogic = require("absAct.AbsActLogic")
  14. local BuyLogic = require("topup.BuyLogic")
  15. local YunYingLogic = require("yunying.YunYingLogic")
  16. local BusActGrandGift = require("absAct.BusThreeActGrandGift")
  17. local BUSTHREEDICEABSID = 7404 -- 对应ABS活动ID
  18. -- 骰子类型
  19. local BUSDICE_TYPE_1 = 1 -- 数字全相同
  20. local BUSDICE_TYPE_2 = 2 -- 数字连续
  21. local BUSDICE_TYPE_3 = 3 -- 任意2个数字相同
  22. local BUSDICE_TYPE_4 = 4 -- 剩余情况
  23. local BUSDICE_GOODID = 1041 -- 物品ID
  24. local typeFuncMap = nil
  25. ----------------------------------------- 内部处理开始 -------------------------------------
  26. local function BusThreeActDice_InitTypeFuncMap()
  27. typeFuncMap = {
  28. [BUSDICE_TYPE_1] = function (nPoint)
  29. return nPoint.."|"..nPoint.."|"..nPoint
  30. end,
  31. [BUSDICE_TYPE_2] = function (nPoint)
  32. local nRandNum = math.random(1, 6)
  33. if nRandNum == 1 then
  34. return nRandNum.."|"..(nRandNum+1).."|"..(nRandNum+2)
  35. elseif nRandNum == 6 then
  36. return (nRandNum-2).."|"..(nRandNum-1).."|"..nRandNum
  37. else
  38. return (nRandNum-1).."|"..nRandNum.."|"..(nRandNum+1)
  39. end
  40. end,
  41. [BUSDICE_TYPE_3] = function (nPoint)
  42. local nRandNum = math.random(1, 6)
  43. local nOtherNum = nRandNum
  44. local nDoLen = 0
  45. while nOtherNum == nRandNum do
  46. nOtherNum = math.random(1, 6)
  47. nDoLen = nDoLen + 1
  48. if nDoLen > 10 then
  49. break
  50. end
  51. end
  52. if nRandNum == nOtherNum then
  53. local nDifNum = math.random(1, 2)
  54. nOtherNum = nDifNum == 1 and nRandNum - 1 or nRandNum + 1
  55. end
  56. local tPoint = {nRandNum, nRandNum, nOtherNum}
  57. table.sort(tPoint)
  58. return table.concat(tPoint, "|")
  59. end,
  60. [BUSDICE_TYPE_4] = function (nPoint)
  61. local tPoint = {}
  62. while #tPoint < 3 do
  63. local nRandNum = math.random(1, 6)
  64. local bExist = false
  65. for _, v in ipairs(tPoint) do
  66. if v == nRandNum then
  67. bExist = true
  68. break
  69. end
  70. end
  71. if not bExist then
  72. table.insert(tPoint, nRandNum)
  73. end
  74. end
  75. table.sort(tPoint)
  76. -- 连续判断
  77. if tPoint[1] + 1 == tPoint[2] and tPoint[2] + 1 == tPoint[3] then
  78. if tPoint[1] > 1 then
  79. tPoint[1] = tPoint[1] - 1
  80. else
  81. tPoint[3] = tPoint[3] + 1
  82. end
  83. end
  84. return table.concat(tPoint, "|")
  85. end,
  86. }
  87. end
  88. -- 根据类型获取对应的随机点数
  89. local function BusThreeGrandGift_GetPoint(nType, nAppointPoint)
  90. if not typeFuncMap then
  91. BusThreeActDice_InitTypeFuncMap()
  92. end
  93. if not typeFuncMap or not typeFuncMap[nType] then
  94. return false, nil
  95. end
  96. local func = typeFuncMap[nType]
  97. return true, func(nAppointPoint)
  98. end
  99. local function BusThreeActDice_DiceDo(human, tMsgData, nNum)
  100. local nAllWeight = 0
  101. local tPrizeData = {}
  102. for _, v in ipairs(tDiceConf) do
  103. nAllWeight = nAllWeight + v.nWeight
  104. table.insert(tPrizeData, {nWeight = nAllWeight, tPrize = v.Prize, nType = v.nType, nPoint = v.nPoint})
  105. end
  106. local tItemList = {}
  107. tMsgData.tPrize[0] = nNum
  108. for i = 1, nNum, 1 do
  109. local tOneDiceData = tMsgData.tPrize[i]
  110. local nRandWeight = math.random(1, nAllWeight)
  111. local tChoseData = nil
  112. for _, v in ipairs(tPrizeData) do
  113. if nRandWeight <= v.nWeight then
  114. tChoseData = v
  115. break
  116. end
  117. end
  118. if not tChoseData then
  119. return false
  120. end
  121. local bRet = false
  122. bRet, tOneDiceData.tPoint = BusThreeGrandGift_GetPoint(tChoseData.nType, tChoseData.nPoint)
  123. if false == bRet then
  124. print("[BusThreeActDice_DiceDo] 获取点数失败")
  125. return false
  126. end
  127. -- print("[BusThreeActDice_DiceDo] 第 "..i.." 次 nType = "..tChoseData.nType.." nPoint = "..tChoseData.nPoint)
  128. -- table.print_lua_table(tChoseData.tPrize)
  129. tOneDiceData.titemData[0] = #tChoseData.tPrize
  130. for j, v in ipairs(tChoseData.tPrize) do
  131. Grid.makeItem(tOneDiceData.titemData[j], v[1], v[2])
  132. if not tItemList[v[1]] then
  133. tItemList[v[1]] = 0
  134. end
  135. tItemList[v[1]] = tItemList[v[1]] + v[2]
  136. end
  137. -- print("[BusThreeActDice_DiceDo] 第"..i.."次掷骰子结果: "..tOneDiceData.tPoint)
  138. end
  139. for nGoodID, nGoodNum in pairs(tItemList) do
  140. BagLogic.addItem(human, nGoodID, nGoodNum, "BusThreeActDice")
  141. end
  142. return true
  143. end
  144. ----------------------------------------- 客户端请求 -------------------------------------
  145. function BusThreeActDice_DO(human, nNum)
  146. if 1 ~= nNum and 10 ~= nNum then
  147. return
  148. end
  149. print("[BusThreeActDice_DO] 进行抽取 nNum = "..nNum)
  150. local nGoodsNum = BagLogic.getItemCnt(human, BUSDICE_GOODID)
  151. if nGoodsNum < nNum then
  152. return
  153. end
  154. print("[BusThreeActDice_DO] 物品数量足够 nGoodsNum = "..nGoodsNum)
  155. local tMsgData = Msg.gc.GC_NEW_BUSTHREEACT_DICEDO
  156. local bRet = BusThreeActDice_DiceDo(human, tMsgData, nNum)
  157. if not bRet then
  158. print("[BusThreeActDice_DO] 进行抽取报错")
  159. return
  160. end
  161. BagLogic.delItem(human, BUSDICE_GOODID, nNum, "BusThreeActDice")
  162. BusActGrandGift.BusThreeGrandGift_NumChange(human, nNum)
  163. print("[BusThreeActDice_DO] 物品扣除完成 nGoodsNum = "..nNum)
  164. Msg.send(tMsgData, human.fd)
  165. print("[BusThreeActDice_DO] 发送协议完成")
  166. end