BusThreeActDice.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. return table.concat(tPoint, "|")
  77. end,
  78. }
  79. end
  80. -- 根据类型获取对应的随机点数
  81. local function BusThreeGrandGift_GetPoint(nType, nAppointPoint)
  82. if not typeFuncMap then
  83. BusThreeActDice_InitTypeFuncMap()
  84. end
  85. if not typeFuncMap or not typeFuncMap[nType] then
  86. return false, nil
  87. end
  88. local func = typeFuncMap[nType]
  89. return true, func(nAppointPoint)
  90. end
  91. local function BusThreeActDice_DiceDo(human, tMsgData, nNum)
  92. local nAllWeight = 0
  93. local tPrizeData = {}
  94. for _, v in ipairs(tDiceConf) do
  95. nAllWeight = nAllWeight + v.nWeight
  96. table.insert(tPrizeData, {nWeight = nAllWeight, tPrize = v.Prize, nType = v.nType, nPoint = v.nPoint})
  97. end
  98. local tItemList = {}
  99. tMsgData.tPrize[0] = nNum
  100. for i = 1, nNum, 1 do
  101. local tOneDiceData = tMsgData.tPrize[i]
  102. local nRandWeight = math.random(1, nAllWeight)
  103. local tChoseData = nil
  104. for _, v in ipairs(tPrizeData) do
  105. if nRandWeight <= v.nWeight then
  106. tChoseData = v
  107. break
  108. end
  109. end
  110. if not tChoseData then
  111. return false
  112. end
  113. local bRet = false
  114. bRet, tOneDiceData.tPoint = BusThreeGrandGift_GetPoint(tChoseData.nType, tChoseData.nPoint)
  115. if false == bRet then
  116. print("[BusThreeActDice_DiceDo] 获取点数失败")
  117. return false
  118. end
  119. tOneDiceData.titemData[0] = #tChoseData.tPrize
  120. for j, v in ipairs(tChoseData.tPrize) do
  121. Grid.makeItem(tOneDiceData.titemData[j], v[1], v[2])
  122. if not tItemList[v[1]] then
  123. tItemList[v[1]] = 0
  124. end
  125. tItemList[v[1]] = tItemList[v[1]] + v[2]
  126. end
  127. print("[BusThreeActDice_DiceDo] 第"..i.."次掷骰子结果: "..tOneDiceData.tPoint)
  128. end
  129. for nGoodID, nGoodNum in pairs(tItemList) do
  130. BagLogic.addItem(human, nGoodID, nGoodNum, "BusThreeActDice")
  131. end
  132. return true
  133. end
  134. ----------------------------------------- 客户端请求 -------------------------------------
  135. function BusThreeActDice_DO(human, nNum)
  136. if 1 ~= nNum and 10 ~= nNum then
  137. return
  138. end
  139. print("[BusThreeActDice_DO] 进行抽取 nNum = "..nNum)
  140. local nGoodsNum = BagLogic.getItemCnt(human, BUSDICE_GOODID)
  141. if nGoodsNum < nNum then
  142. return
  143. end
  144. print("[BusThreeActDice_DO] 物品数量足够 nGoodsNum = "..nGoodsNum)
  145. local tMsgData = Msg.gc.GC_NEW_BUSTHREEACT_DICEDO
  146. local bRet = BusThreeActDice_DiceDo(human, tMsgData, nNum)
  147. if not bRet then
  148. print("[BusThreeActDice_DO] 进行抽取报错")
  149. return
  150. end
  151. BagLogic.delItem(human, BUSDICE_GOODID, nNum, "BusThreeActDice")
  152. BusActGrandGift.BusThreeGrandGift_NumChange(human, nNum)
  153. print("[BusThreeActDice_DO] 物品扣除完成 nGoodsNum = "..nNum)
  154. Msg.send(tMsgData, human.fd)
  155. print("[BusThreeActDice_DO] 发送协议完成")
  156. end