CommonActLoginGift.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. -- 通用节日活动 - 登录豪礼
  2. -- db
  3. --[=[
  4. human.db.absAct[actId] = {
  5. getRecordData = {
  6. [gitftType] = {
  7. [day1] = true,
  8. [day3] = true,
  9. },
  10. },
  11. buyGiftType = nil, -- 已经购买的礼包类型
  12. }
  13. ]=]--
  14. local Msg = require("core.Msg")
  15. local Grid = require("bag.Grid")
  16. local BagLogic = require("bag.BagLogic")
  17. local AbsActLogic = require("absAct.AbsActLogic")
  18. local Broadcast = require("broadcast.Broadcast")
  19. local Lang = require("common.Lang")
  20. local LoginGiftConfig = require("excel.commonact").loginreward
  21. local CommonDefine = require("common.CommonDefine")
  22. local Util = require("common.Util")
  23. local YunYingLogic = require("yunying.YunYingLogic")
  24. local AbsActExcel = require("excel.absAct")
  25. local BuyLogic = require("topup.BuyLogic")
  26. local LOGTYPE = "CommonActLoginGift"
  27. local COMMONACT_LOGINGIFT_ID = 7505
  28. local function getActData(human)
  29. return human.db.absAct[COMMONACT_LOGINGIFT_ID]
  30. end
  31. local function updateGetRecordData(human, giftType, dayIdx)
  32. human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData = human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData or {}
  33. human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType] = human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType] or {}
  34. human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType][dayIdx] = true
  35. end
  36. local function updateBuyGiftType(human, giftType)
  37. human.db.absAct[COMMONACT_LOGINGIFT_ID].buyGiftType = giftType
  38. end
  39. local function isOpenAct(human, funcID)
  40. return AbsActLogic.isStarted(human, funcID)
  41. end
  42. local function transformCfg()
  43. local tb = {}
  44. for _, giftCfg in ipairs(LoginGiftConfig) do
  45. if not tb[giftCfg.giftType] then
  46. tb[giftCfg.giftType] = {}
  47. end
  48. local t = tb[giftCfg.giftType]
  49. t[#t+1] = giftCfg
  50. end
  51. return tb
  52. end
  53. local function getAwardState(human, giftType, dayIdx)
  54. local actData = getActData(human)
  55. local diffDays = Util.diffDay(actData.realStartTime) + 1
  56. local getRecordData = actData and actData.getRecordData or {}
  57. local nowGiftTypeGetRecord = getRecordData[giftType] or {}
  58. local buyGiftType = actData and actData.buyGiftType
  59. local isBuy = true
  60. local state = CommonDefine.COMMON_PRIZE_STATE_CANGET
  61. if giftType ~= 1 and (not buyGiftType or buyGiftType ~= giftType) then -- 需要充值的礼包类型
  62. state = CommonDefine.COMMON_PRIZE_STATE_NOGET
  63. isBuy = false
  64. end
  65. if isBuy then
  66. if diffDays < dayIdx then
  67. state = CommonDefine.COMMON_PRIZE_STATE_NOGET
  68. else
  69. if nowGiftTypeGetRecord[dayIdx] then
  70. state = CommonDefine.COMMON_PRIZE_STATE_GET
  71. end
  72. end
  73. end
  74. return state
  75. end
  76. -- 检查是否有可领取的奖励
  77. local function isCanGet(human)
  78. local type_2_cfg = transformCfg()
  79. for giftType, giftCfgArr in pairs(type_2_cfg) do
  80. for _, giftCfg in ipairs(giftCfgArr) do
  81. local state = getAwardState(human, giftType, giftCfg.dayIdx)
  82. if state == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  83. return true
  84. end
  85. end
  86. end
  87. return false
  88. end
  89. -- 填充协议结构
  90. local function populateGiftMsg(human, net, giftCfg, nowGiftType)
  91. net.reward[0] = #giftCfg.reward
  92. for i, itemInfo in ipairs(giftCfg.reward) do
  93. Grid.makeItem(net.reward[i], itemInfo[1], itemInfo[2])
  94. end
  95. net.reallyDays = giftCfg.dayIdx
  96. net.rewardState = getAwardState(human, nowGiftType, giftCfg.dayIdx)
  97. BuyLogic.fontBuyItem(human, net.buyMsg, giftCfg.buyId)
  98. net.giftType = nowGiftType
  99. end
  100. -- 主动刷新一次红点
  101. local function updateRedDot(human)
  102. YunYingLogic.sendBanner(human)
  103. local config = AbsActExcel.absActivity[COMMONACT_LOGINGIFT_ID]
  104. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACT_LOGINGIFT_ID], human, config.panelID)
  105. end
  106. function isRed(human, YYInfo, funcConfig)
  107. local state = isOpenAct(human, funcConfig and funcConfig.funcID)
  108. if not state then
  109. return false
  110. end
  111. return isCanGet(human)
  112. end
  113. function isOpen(human, YYInfo, funcConfig)
  114. return isOpenAct(human, funcConfig and funcConfig.funcID)
  115. end
  116. function isActive(human, YYInfo, funcConfig)
  117. return not isOpen(human, YYInfo, funcConfig)
  118. end
  119. function onCharge(human, price, funcID, buyID, buyNum)
  120. local actData = getActData(human)
  121. local buyGiftType = actData and actData.buyGiftType
  122. if buyGiftType then
  123. return
  124. end
  125. local type_2_cfg = transformCfg()
  126. for giftType, giftCfgArr in pairs(type_2_cfg) do
  127. local singleCfg = giftCfgArr[1]
  128. if singleCfg.buyId == buyID then
  129. updateBuyGiftType(human, giftType)
  130. updateRedDot(human)
  131. CommonActLoginGift_Query(human)
  132. break
  133. end
  134. end
  135. end
  136. function updateDaily(human, funcID)
  137. if isOpenAct(human, COMMONACT_LOGINGIFT_ID) then
  138. return
  139. end
  140. updateRedDot(human)
  141. end
  142. -- 查询
  143. function CommonActLoginGift_Query(human)
  144. local msgRet = Msg.gc.GC_ABS_COMONACT_LOGINGIFT_QUERY
  145. msgRet.giftDatafree[0] = 0
  146. msgRet.giftData68[0] = 0
  147. msgRet.giftData128[0] = 0
  148. msgRet.giftData328[0] = 0
  149. msgRet.giftData648[0] = 0
  150. msgRet.isEnd = 0
  151. msgRet.isStart = 1
  152. msgRet.buyGiftType = 0
  153. local actData = getActData(human)
  154. msgRet.buyGiftType = actData and actData.buyGiftType or 0
  155. local len, msgOnceLen = 0, 5
  156. local type_2_cfg = transformCfg()
  157. local configNum = type_2_cfg[1] and #type_2_cfg[1] or 0
  158. local num = configNum
  159. for i=1, configNum do
  160. len = len + 1
  161. if type_2_cfg[1] then
  162. msgRet.giftDatafree[0] = len
  163. populateGiftMsg(human, msgRet.giftDatafree[len], type_2_cfg[1][i], 1)
  164. end
  165. if type_2_cfg[2] and type_2_cfg[2][i] then
  166. msgRet.giftData68[0] = len
  167. populateGiftMsg(human, msgRet.giftData68[len], type_2_cfg[2][i], 2)
  168. end
  169. if type_2_cfg[3] and type_2_cfg[3][i] then
  170. msgRet.giftData128[0] = len
  171. populateGiftMsg(human, msgRet.giftData128[len], type_2_cfg[3][i], 3)
  172. end
  173. if type_2_cfg[4] and type_2_cfg[4][i] then
  174. msgRet.giftData328[0] = len
  175. populateGiftMsg(human, msgRet.giftData328[len], type_2_cfg[4][i], 4)
  176. end
  177. if type_2_cfg[5] and type_2_cfg[5][i] then
  178. msgRet.giftData648[0] = len
  179. populateGiftMsg(human, msgRet.giftData648[len], type_2_cfg[5][i], 5)
  180. end
  181. if len >= msgOnceLen then
  182. num = num - len
  183. if num <= 0 then
  184. msgRet.isEnd = 1
  185. return Msg.send(msgRet, human.fd)
  186. end
  187. Msg.send(msgRet, human.fd)
  188. len = 0
  189. msgRet.isStart = 0
  190. end
  191. end
  192. if len > 0 then
  193. msgRet.isEnd = 1
  194. Msg.send(msgRet, human.fd)
  195. end
  196. end
  197. -- 领取奖励
  198. function CommonActLoginGift_GetReward(human, targetGiftType)
  199. local type_2_cfg = transformCfg()
  200. local giftArr = type_2_cfg[targetGiftType]
  201. if not giftArr then
  202. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  203. end
  204. local actData = getActData(human)
  205. local buyGiftType = actData and actData.buyGiftType
  206. if targetGiftType ~= 1 and (not buyGiftType or buyGiftType ~= targetGiftType) then
  207. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  208. end
  209. local itemArr = {}
  210. for _, giftCfg in ipairs(giftArr) do
  211. local state = getAwardState(human, targetGiftType, giftCfg.dayIdx)
  212. if state == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  213. for _, itemInfo in ipairs(giftCfg.reward) do
  214. itemArr[#itemArr+1] = { itemInfo[1], itemInfo[2] }
  215. end
  216. -- 记录领取
  217. updateGetRecordData(human, targetGiftType, giftCfg.dayIdx)
  218. end
  219. end
  220. if #itemArr == 0 then
  221. return Broadcast.sendErr(human, Lang.HO_NO_CAN_GET)
  222. end
  223. -- 发放道具
  224. BagLogic.addItemList(human, itemArr, LOGTYPE)
  225. -- 更红点
  226. updateRedDot(human)
  227. -- 推送最新数给客户端
  228. CommonActLoginGift_Query(human)
  229. end