AbsSignGiftLogic.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. Json = Json or require("common.Json")
  2. local AbsActLogic = require("absAct.AbsActLogic")
  3. local AbsActExcel = require("excel.absAct")
  4. local buyExcel = require("excel.buy").buy
  5. local Msg = require("core.Msg")
  6. local Grid = require("bag.Grid")
  7. local BagLogic = require("bag.BagLogic")
  8. local AbsActDefine = require("absAct.AbsActDefine")
  9. local YunYingLogic = require("yunying.YunYingLogic")
  10. local PanelDefine = require("broadcast.PanelDefine")
  11. local Util = require("common.Util")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local Lang = require("common.Lang")
  14. local BuyLogic = require("topup.BuyLogic")
  15. --[[
  16. absAct.xlsx-signGift
  17. 情人节活动
  18. 1、每天免费请求一次礼包
  19. 2、购买专属浪漫签
  20. DB:
  21. human.db.absAct[id] = {
  22. [buyStatus] = xxx, -- 礼包购买状态
  23. [configId] = {
  24. signStatus = xxx -- 签到状态 0未签到 1可签到 2已签到
  25. giftStatus = xxx, -- 专属礼包签到状态 0未签到 1可签到 2已签到
  26. }
  27. }
  28. local:
  29. wrapSignGiftNet() -- 包装情人节数据
  30. getConfigIdBuyId() -- 通过活动子id和buyID取得购买配置信息
  31. public:
  32. getAndSendMsg() -- 发送活动数据
  33. isRed() -- 红点提醒
  34. isActive() -- 激活状态
  35. isOpen() -- 活动开启
  36. getLeftTime() -- 得到活动剩余时间
  37. signGift() -- 购买当天专属礼包
  38. ]]
  39. GIFT_STATE_0 = 0 -- 未签到
  40. GIFT_STATE_1 = 1 -- 已签到
  41. GIFT_STATE_2 = 2 -- 不可签到
  42. SIGN_STATE_0 = 0 -- 未签到
  43. SIGN_STATE_1 = 1 -- 已签到
  44. SIGN_STATE_2 = 2 -- 不可签到
  45. BUY_STATE_0 = 0 -- 未购买
  46. BUY_STATE_1 = 1 -- 已购买
  47. local buyIdToConfigIds = {}
  48. local function getConfigIdBuyId(actId, buyId)
  49. if buyIdToConfigIds[actId] then
  50. return buyIdToConfigIds[actId][buyId]
  51. end
  52. buyIdToConfigIds[actId] = {}
  53. local signGiftConfig = AbsActExcel.signGift
  54. for id, buyInfo in ipairs(signGiftConfig) do
  55. if actId == buyInfo.actId then
  56. buyIdToConfigIds[actId][buyInfo.buyID] = id
  57. end
  58. end
  59. return buyIdToConfigIds[actId][buyId]
  60. end
  61. function isOpen(human, YYInfo, funcConfig)
  62. return AbsActLogic.isStarted(human, funcConfig.funcID)
  63. end
  64. function isActive(human, YYInfo, funcConfig)
  65. return not isOpen(human, YYInfo, funcConfig)
  66. end
  67. function getLeftTime(human, YInfo, funcConfig)
  68. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  69. return state and endTime - os.time() or 0
  70. end
  71. function isRed(human, YYInfo, funcConfig)
  72. local funcID = funcConfig.funcID
  73. local state, endTime, starTime = AbsActLogic.isStarted(human, funcID)
  74. if not state then
  75. return
  76. end
  77. local absConfig = AbsActExcel.absActivity[funcID]
  78. local absAct = human.db.absAct[funcID]
  79. if not absAct then
  80. return true
  81. end
  82. local curDay = Util.diffDay(starTime) + 1
  83. for confID, conf in pairs(AbsActExcel.signGift) do
  84. if conf.day <= curDay then
  85. local absActDB = absAct[confID]
  86. if not absActDB then
  87. return true
  88. else
  89. if absActDB.signStatus == SIGN_STATE_0 then
  90. return true
  91. end
  92. if absAct.buyStatus == BUY_STATE_1 and absActDB.giftStatus == SIGN_STATE_0 then
  93. return true
  94. end
  95. end
  96. end
  97. end
  98. return false
  99. end
  100. local function wrapSignGiftNet(human, absAct, net, id, index, actInfo, day, region)
  101. absAct[index] = absAct[index] or {}
  102. net.id = id
  103. net.funcID = index
  104. net.day = actInfo.day
  105. local freeItemCnt = #actInfo.freeItem
  106. net.signItems[0] = freeItemCnt
  107. for i = 1, freeItemCnt do
  108. Grid.makeItem(net.signItems[i], actInfo.freeItem[i][1], actInfo.freeItem[i][2])
  109. end
  110. local giftItemCnt = #actInfo.giftItem
  111. net.giftItems[0] = giftItemCnt
  112. for i = 1, giftItemCnt do
  113. Grid.makeItem(net.giftItems[i], actInfo.giftItem[i][1], actInfo.giftItem[i][2])
  114. end
  115. if day >= actInfo.day then
  116. net.signStatus = absAct[index].signStatus or SIGN_STATE_0
  117. if absAct.buyStatus == BUY_STATE_1 then
  118. net.giftStatus = absAct[index].giftStatus or GIFT_STATE_0
  119. else
  120. net.giftStatus = absAct[index].giftStatus or GIFT_STATE_2
  121. end
  122. else
  123. net.signStatus = absAct[index].signStatus or SIGN_STATE_2
  124. net.giftStatus = absAct[index].giftStatus or GIFT_STATE_2
  125. end
  126. end
  127. function signGift(human, id, conf)
  128. local status = AbsActLogic.isStarted(human, id)
  129. local absConfig = AbsActExcel.absActivity[id]
  130. if not absConfig or not status then
  131. return
  132. end
  133. local absAct = human.db.absAct[id]
  134. if not absAct then
  135. return
  136. end
  137. local giftID = conf.args[1]
  138. local config = AbsActExcel.signGift[giftID]
  139. if not config then
  140. return
  141. end
  142. local absActDB = human.db.absAct[id]
  143. local signStatus = absActDB[giftID].signStatus
  144. if signStatus and signStatus ~= SIGN_STATE_1 then
  145. return
  146. end
  147. human.db.absAct[id].buyStatus = BUY_STATE_1
  148. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  149. getAndSendMsg(human, id)
  150. YunYingLogic.sendBanner(human)
  151. YunYingLogic.updateIcon(YYInfo[id], human)
  152. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  153. end
  154. function getAndSendMsg(human, id)
  155. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  156. if not state then
  157. return
  158. end
  159. local absAct = human.db.absAct[id]
  160. local curDay = Util.diffDay(starTime) + 1
  161. if curDay > 3 or curDay < 1 then
  162. return
  163. end
  164. local msgRet = Msg.gc.GC_ABS_SIGNGIFT_QUERY
  165. msgRet.buyStatus = absAct.buyStatus or BUY_STATE_0
  166. msgRet.curDay = curDay
  167. local buyID
  168. local len = 0
  169. for index, actInfo in pairs(AbsActExcel.signGift) do
  170. if not buyID and actInfo.buyID ~= 0 then
  171. buyID = actInfo.buyID
  172. end
  173. len = len + 1
  174. wrapSignGiftNet(human, absAct, msgRet.list[len], id, index, actInfo, curDay, human.region)
  175. end
  176. BuyLogic.fontBuyItem(human, msgRet.buyItem, buyID)
  177. msgRet.list[0] = len
  178. Msg.send(msgRet, human.fd)
  179. end
  180. --[[
  181. 请求签到道具
  182. ]]
  183. function getItem(human, id, funcID, type)
  184. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  185. if not state then return end
  186. local absConfig = AbsActExcel.absActivity[id]
  187. if not absConfig then
  188. return
  189. end
  190. local config = AbsActExcel.signGift[funcID]
  191. if not config then
  192. return
  193. end
  194. local curDay = Util.diffDay(starTime) + 1
  195. if curDay < config.day then
  196. return
  197. end
  198. local typeStr = type == 1 and "signStatus" or "giftStatus"
  199. local absAct = human.db.absAct[id]
  200. local actInfoDB = absAct[funcID]
  201. if type == 1 and actInfoDB.signStatus and actInfoDB.signStatus ~= SIGN_STATE_0 then
  202. return
  203. end
  204. if type == 2 and (absAct.buyStatus == BUY_STATE_0 or actInfoDB.giftStatus and actInfoDB.giftStatus ~= GIFT_STATE_0) then
  205. return
  206. end
  207. if type == 1 then
  208. human.db.absAct[id][funcID].signStatus = SIGN_STATE_1
  209. BagLogic.addItemList(human, config.freeItem, "abs_sign_reward")
  210. elseif type == 2 then
  211. human.db.absAct[id][funcID].giftStatus = GIFT_STATE_1
  212. BagLogic.addItemList(human, config.giftItem, "abs_sign_gift")
  213. end
  214. Broadcast.sendErr(human, Lang.ITEM_GET_SUCCESS)
  215. getAndSendMsg(human, id)
  216. YunYingLogic.sendBanner(human)
  217. YunYingLogic.updateIcon(YYInfo[id], human)
  218. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  219. end
  220. function updateDaily(human, funcID)
  221. local state, endTime, starTime = AbsActLogic.isStarted(human, funcID)
  222. if not state then
  223. return
  224. end
  225. local absAct = human.db.absAct[funcID]
  226. if not absAct then
  227. return
  228. end
  229. local curDay = Util.diffDay(starTime) + 1
  230. for giftID, conf in pairs(AbsActExcel.signGift) do
  231. if conf.day == curDay then
  232. absAct[giftID].signStatus = SIGN_STATE_0
  233. if absAct.buyStatus == BUY_STATE_1 then
  234. absAct[giftID].giftStatus = SIGN_STATE_0
  235. end
  236. end
  237. end
  238. end