CommonActCharge.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. -- 处理新增配置
  43. local tPrizeData = human.db.absAct[COMMONACTCHARGEABSID].tPrizeData
  44. if tPrizeData and #tPrizeData < #Config then
  45. for i= #tPrizeData+1, #Config do
  46. tPrizeData[i] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  47. end
  48. end
  49. end
  50. -- 获取DB奖励数据
  51. local function CommonActCharge_GetDBPrizeData(human)
  52. return human.db.absAct[COMMONACTCHARGEABSID].tPrizeData
  53. end
  54. -- 获取DB奖励状态
  55. local function CommonActCharge_GetDBPrizeStatus(human, nIndex)
  56. local tPrizeData = CommonActCharge_GetDBPrizeData(human)
  57. return tPrizeData[nIndex]
  58. end
  59. -- 设置DB奖励状态
  60. local function CommonActCharge_SetDBPrizeStatus(human, nIndex, nStatus)
  61. local tPrizeData = CommonActCharge_GetDBPrizeData(human)
  62. tPrizeData[nIndex] = nStatus
  63. end
  64. -- 获取DB天数充值金额
  65. local function CommonActCharge_GetDBDayCharge(human)
  66. return human.db.absAct[COMMONACTCHARGEABSID].nAllMoney
  67. end
  68. -- 设置DB天数充值金额
  69. local function CommonActCharge_SetDBDayCharge(human, nAddMoney)
  70. human.db.absAct[COMMONACTCHARGEABSID].nAllMoney = human.db.absAct[COMMONACTCHARGEABSID].nAllMoney + nAddMoney
  71. end
  72. ----------------------------------------- 客户端请求处理开始 -------------------------------------
  73. -- 请求数据
  74. function CommonActCharge_Query(human)
  75. CheckAndCreateDB(human)
  76. local tConf = CommonActCharge_GetCof()
  77. local tMsgData = Msg.gc.GC_ABS_FESTIVAL_RECHARGE_QUERY
  78. tMsgData.tPrize[0] = 0
  79. tMsgData.nNowCharge = CommonActCharge_GetDBDayCharge(human)
  80. local nLen = 0
  81. for nID, v in ipairs(tConf) do
  82. nLen = nLen + 1
  83. local tPrizeData = tMsgData.tPrize[nLen]
  84. tPrizeData.nID = nID
  85. tPrizeData.nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  86. tPrizeData.nNeedCharge = v.nMoney
  87. tPrizeData.tPrize[0] = #v.tPrize
  88. for nIndex, tItem in ipairs(v.tPrize) do
  89. local nGoodsID = tItem[1]
  90. local nGoodsNum = tItem[2]
  91. Grid.makeItem(tPrizeData.tPrize[nIndex], nGoodsID, nGoodsNum)
  92. end
  93. end
  94. tMsgData.tPrize[0] = nLen
  95. Msg.send(tMsgData, human.fd)
  96. end
  97. -- 请求领取奖励
  98. function CommonActCharge_Get(human, nIndex)
  99. local tConf = CommonActCharge_GetCof()
  100. local tItem = {}
  101. for nID, v in ipairs(tConf) do
  102. local nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  103. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
  104. CommonActCharge_SetDBPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  105. for _, tPrize in ipairs(v.tPrize) do
  106. if not tItem[tPrize[1]] then
  107. tItem[tPrize[1]] = 0
  108. end
  109. tItem[tPrize[1]] = tItem[tPrize[1]] + tPrize[2]
  110. end
  111. end
  112. end
  113. if nil ~= _G.next(tItem) then
  114. local tPrize = {}
  115. for nID, nNum in pairs(tItem) do
  116. table.insert(tPrize, {nID, nNum})
  117. end
  118. BagLogic.addItemList(human, tPrize, "CommonActCharge")
  119. CommonActCharge_Query(human)
  120. YunYingLogic.sendBanner(human)
  121. local config = AbsActExcel.absActivity[COMMONACTCHARGEABSID]
  122. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTCHARGEABSID], human, config.panelID)
  123. end
  124. end
  125. ----------------------------------------- 外部调用 -------------------------------------
  126. function isRed(human)
  127. local state, nEndTime, nOpenTime = AbsActLogic.isStarted(human, COMMONACTCHARGEABSID)
  128. if not state then
  129. return false
  130. end
  131. CheckAndCreateDB(human)
  132. local tConf = CommonActCharge_GetCof()
  133. for nID, v in ipairs(tConf) do
  134. local nState = CommonActCharge_GetDBPrizeStatus(human, nID)
  135. if nState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  136. return true
  137. end
  138. end
  139. return false
  140. end
  141. function isOpen(human, YYInfo, funcConfig)
  142. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig and funcConfig.funcID or COMMONACTCHARGEABSID)
  143. if not state then
  144. print("[CommonActCharge_isOpen] 当前活动未开启")
  145. return
  146. end
  147. -- print("[CommonActCharge__isOpen] 进入判断 endTime = "..endTime.." startTime = "..startTime)
  148. return true, endTime, startTime
  149. end
  150. function isActive(human, YYInfo, funcConfig)
  151. return not isOpen(human, YYInfo, funcConfig)
  152. end
  153. function onCharge(human, price, funcID, buyID)
  154. local state, endTime, startTime = AbsActLogic.isStarted(human, COMMONACTCHARGEABSID)
  155. if not state then
  156. return
  157. end
  158. CheckAndCreateDB(human)
  159. local tConf = CommonActCharge_GetCof()
  160. local bQuery = false
  161. local nNewChareNum = CommonActCharge_GetDBDayCharge(human)
  162. nNewChareNum = nNewChareNum + price
  163. for nID, v in ipairs(tConf) do
  164. local nStatus = CommonActCharge_GetDBPrizeStatus(human, nID)
  165. if nStatus == CommonDefine.COMMON_PRIZE_STATE_NOGET and nNewChareNum >= v.nMoney then
  166. CommonActCharge_SetDBPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  167. bQuery = true
  168. end
  169. end
  170. CommonActCharge_SetDBDayCharge(human, price)
  171. if true == bQuery then
  172. CommonActCharge_Query(human)
  173. YunYingLogic.sendBanner(human)
  174. local config = AbsActExcel.absActivity[COMMONACTCHARGEABSID]
  175. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTCHARGEABSID], human, config.panelID)
  176. end
  177. end
  178. function onLogin(human)
  179. local state, endTime, startTime = AbsActLogic.isStarted(human, COMMONACTCHARGEABSID)
  180. if not state then
  181. return
  182. end
  183. CheckAndCreateDB(human)
  184. if not human.db.absAct[COMMONACTCHARGEABSID].IsAddCharge then
  185. human.db.absAct[COMMONACTCHARGEABSID].IsAddCharge = true
  186. if human.db.topupAcountDaily and human.db.topupAcountDaily > 0 then
  187. onCharge(human, human.db.topupAcountDaily)
  188. end
  189. end
  190. end