CommonActCharge.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. --------------------------------
  2. -- 文件名 : CommonActCharge.lua
  3. -- 文件说明 : 通用节日活动-连充豪礼
  4. -- 创建时间 : 2025/09
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Msg = require("core.Msg")
  8. local Grid = require("bag.Grid")
  9. local BagLogic = require("bag.BagLogic")
  10. local AbsActLogic = require("absAct.AbsActLogic")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local Lang = require("common.Lang")
  13. local Config = require("excel.commonact").allcharge
  14. local CommonDefine = require("common.CommonDefine")
  15. local YunYingLogic = require("yunying.YunYingLogic")
  16. local AbsActExcel = require("excel.absAct")
  17. local COMMONACTCHARGEABSID = 7503
  18. ----------------------------------------- 内部处理开始 -------------------------------------
  19. -- 获取配置
  20. local function CommonActCharge_GetCof()
  21. return Config
  22. end
  23. -- 初始化DB数据()
  24. function CreatDB(human)
  25. if not human.db.absAct[COMMONACTCHARGEABSID] then
  26. human.db.absAct[COMMONACTCHARGEABSID] = {}
  27. end
  28. if not human.db.absAct[COMMONACTCHARGEABSID].tPrizeData then
  29. human.db.absAct[COMMONACTCHARGEABSID].tPrizeData = {}
  30. end
  31. human.db.absAct[COMMONACTCHARGEABSID].nAllMoney = 0
  32. for index, v in ipairs(Config) do
  33. human.db.absAct[COMMONACTCHARGEABSID].tPrizeData[index] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  34. end
  35. return true
  36. end
  37. -- 检测并创建DB数据
  38. local function CheckAndCreateDB(human)
  39. if not human.db.absAct[COMMONACTCHARGEABSID] or not human.db.absAct[COMMONACTCHARGEABSID].tPrizeData then
  40. CreatDB(human)
  41. end
  42. end
  43. -- 获取DB奖励数据
  44. local function CommonActCharge_GetDBPrizeData(human)
  45. return human.db.absAct[COMMONACTCHARGEABSID].tPrizeData
  46. end
  47. -- 获取DB奖励状态
  48. local function CommonActCharge_GetDBPrizeStatus(human, nIndex)
  49. local tPrizeData = CommonActCharge_GetDBPrizeData(human)
  50. return tPrizeData[nIndex]
  51. end
  52. -- 设置DB奖励状态
  53. local function CommonActCharge_SetDBPrizeStatus(human, nIndex, nStatus)
  54. local tPrizeData = CommonActCharge_GetDBPrizeData(human)
  55. tPrizeData[nIndex] = nStatus
  56. end
  57. -- 获取DB天数充值金额
  58. local function CommonActCharge_GetDBDayCharge(human)
  59. return human.db.absAct[COMMONACTCHARGEABSID].nAllMoney
  60. end
  61. -- 设置DB天数充值金额
  62. local function CommonActCharge_SetDBDayCharge(human, nAddMoney)
  63. human.db.absAct[COMMONACTCHARGEABSID].nAllMoney = human.db.absAct[COMMONACTCHARGEABSID].nAllMoney + nAddMoney
  64. end
  65. ----------------------------------------- 客户端请求处理开始 -------------------------------------
  66. -- 请求数据
  67. function CommonActCharge_Query(human)
  68. CheckAndCreateDB(human)
  69. local tConf = CommonActCharge_GetCof()
  70. local tMsgData = Msg.gc.GC_ABS_FESTIVAL_RECHARGE_QUERY
  71. tMsgData.tPrize[0] = 0
  72. tMsgData.nNowCharge = CommonActCharge_GetDBDayCharge(human)
  73. local nLen = 0
  74. for nID, v in ipairs(tConf) do
  75. nLen = nLen + 1
  76. local tPrizeData = tMsgData.tPrize[nLen]
  77. tPrizeData.nID = nID
  78. tPrizeData.nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  79. tPrizeData.nNeedCharge = v.nMoney
  80. tPrizeData.tPrize[0] = #v.tPrize
  81. for nIndex, tItem in ipairs(v.tPrize) do
  82. local nGoodsID = tItem[1]
  83. local nGoodsNum = tItem[2]
  84. Grid.makeItem(tPrizeData.tPrize[nIndex], nGoodsID, nGoodsNum)
  85. end
  86. end
  87. tMsgData.tPrize[0] = nLen
  88. Msg.send(tMsgData, human.fd)
  89. end
  90. -- 请求领取奖励
  91. function CommonActCharge_Get(human, nIndex)
  92. local tConf = CommonActCharge_GetCof()
  93. local tItem = {}
  94. for nID, v in ipairs(tConf) do
  95. local nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  96. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
  97. CommonActCharge_SetDBPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  98. for _, tPrize in ipairs(v.tPrize) do
  99. if not tItem[tPrize[1]] then
  100. tItem[tPrize[1]] = 0
  101. end
  102. tItem[tPrize[1]] = tItem[tPrize[1]] + tPrize[2]
  103. end
  104. end
  105. end
  106. if nil ~= _G.next(tItem) then
  107. local tPrize = {}
  108. for nID, nNum in pairs(tItem) do
  109. table.insert(tPrize, {nID, nNum})
  110. end
  111. BagLogic.addItemList(human, tPrize, "CommonActCharge")
  112. CommonActCharge_Query(human)
  113. YunYingLogic.sendBanner(human)
  114. local config = AbsActExcel.absActivity[COMMONACTCHARGEABSID]
  115. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTCHARGEABSID], human, config.panelID)
  116. end
  117. end
  118. ----------------------------------------- 外部调用 -------------------------------------
  119. function isRed(human)
  120. local state, nEndTime, nOpenTime = AbsActLogic.isStarted(human, COMMONACTCHARGEABSID)
  121. if not state then
  122. return false
  123. end
  124. CheckAndCreateDB(human)
  125. local tConf = CommonActCharge_GetCof()
  126. for nID, v in ipairs(tConf) do
  127. local nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  128. if nState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  129. return true
  130. end
  131. end
  132. return false
  133. end
  134. function isOpen(human, YYInfo, funcConfig)
  135. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig and funcConfig.funcID or COMMONACTCHARGEABSID)
  136. if not state then
  137. print("[CommonActCharge_isOpen] 当前活动未开启")
  138. return
  139. end
  140. print("[CommonActCharge__isOpen] 进入判断 endTime = "..endTime.." startTime = "..startTime)
  141. return true, endTime, startTime
  142. end
  143. function isActive(human, YYInfo, funcConfig)
  144. return not isOpen(human, YYInfo, funcConfig)
  145. end
  146. function onCharge(human, price, funcID, buyID)
  147. local state, endTime, startTime = AbsActLogic.isStarted(human, COMMONACTCHARGEABSID)
  148. if not state then
  149. return
  150. end
  151. CheckAndCreateDB(human)
  152. local tConf = CommonActCharge_GetCof()
  153. local bQuery = false
  154. local nNewChareNum = CommonActCharge_GetDBDayCharge(human)
  155. nNewChareNum = nNewChareNum + price
  156. for nID, v in ipairs(tConf) do
  157. local nStatus = CommonActCharge_GetDBPrizeStatus(human, nID)
  158. if nStatus == CommonDefine.COMMON_PRIZE_STATE_NOGET and nNewChareNum >= v.nMoney then
  159. CommonActCharge_SetDBPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  160. bQuery = true
  161. end
  162. end
  163. CommonActCharge_SetDBDayCharge(human, price)
  164. if true == bQuery then
  165. CommonActCharge_Query(human)
  166. YunYingLogic.sendBanner(human)
  167. local config = AbsActExcel.absActivity[COMMONACTCHARGEABSID]
  168. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTCHARGEABSID], human, config.panelID)
  169. end
  170. end