OperationalActivities.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. --- 运营活动
  2. OperationalActivities = {}
  3. local this = {}
  4. local CONDITION = {
  5. TIME_TYPE = 971,
  6. MAIN_DURATION_TYPE = 980,
  7. SUB_DURATION_TYPE = 981,
  8. CHECK_WEEK = 991,
  9. }
  10. ACTIVE_TYPE = {
  11. DIRECT = 1, -- 直购
  12. TOTAL_RECHARGE = 2, -- 累充
  13. PRIZE_DRAW = 3, -- 抽奖
  14. DIAMOND_PACK = 4, -- 钻石礼包
  15. CONSUMER_RANK = 5, -- 消费排行
  16. }
  17. CURRENT_ACTIVE = "R$_CURRENT_ACTIVE"
  18. -- @description 判断子活动是否在关闭状态
  19. -- @param 活动类型
  20. -- @return
  21. function OperationalActivities.judgeActiveClose(actor,activeType)
  22. local currentActive = getsysvar(actor, CURRENT_ACTIVE)
  23. if table.isNullOrEmpty(currentActive) then
  24. return false
  25. end
  26. local currentTime = getbaseinfo(actor,"now")
  27. if currentTime > currentActive.mainActive.closeTime then
  28. return false
  29. end
  30. local mainGroup = currentActive.mainActive.mainGroup
  31. local closeCondition = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","closeCondition","mainGroup",mainGroup,"subType",activeType)
  32. if closeCondition == nil then
  33. return false
  34. end
  35. return ConditionManager.Check(actor, closeCondition)
  36. end
  37. -- 登录时整理主活动信息
  38. function this.getMainActive(actor,currentActive,currentActiveInfoTable)
  39. local currentActiveInfo = currentActiveInfoTable[1]
  40. local currentTime = getbaseinfo(actor,"now")
  41. local isShow = true
  42. if currentTime > currentActive.mainActive.closeTime then
  43. isShow = false
  44. end
  45. local mainActiveInfo = {
  46. activeId = tonumber(currentActiveInfo.id),
  47. mainGroup = tonumber(currentActiveInfo.maingroup),
  48. startTime = currentActive.mainActive.startTime,
  49. closeTime = currentActive.mainActive.closeTime,
  50. isShow = isShow
  51. }
  52. return mainActiveInfo
  53. end
  54. -- 玩家登录时向玩家发送当前运营活动信息
  55. function OperationalActivities.openActive(actor,currentActive)
  56. local activeInfo = {}
  57. if table.isNullOrEmpty(currentActive) then
  58. currentActive = getsysvar(actor, CURRENT_ACTIVE)
  59. end
  60. if table.isNullOrEmpty(currentActive) then
  61. -- sendluamsg(actor,LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO,activeInfo)
  62. return activeInfo
  63. end
  64. local mainActive = currentActive.mainActive
  65. local currentActiveInfoTable = ConfigDataManager.getTable("cfg_OperateActivity_all","id",mainActive.activeId)
  66. if table.isNullOrEmpty(currentActiveInfoTable) then
  67. error("主活动配置错误")
  68. return activeInfo
  69. end
  70. local mainActiveInfo = this.getMainActive(actor,currentActive,currentActiveInfoTable)
  71. activeInfo["mainActive"] = mainActiveInfo
  72. if not mainActiveInfo.isShow then
  73. -- 当前主活动不展示,不用去整理字子活动信息
  74. sendluamsg(actor,LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO,activeInfo)
  75. return activeInfo
  76. end
  77. local subActive = currentActive.subActive
  78. local allSubActiveInfo = {}
  79. local currentTime = getbaseinfo(actor,"now")
  80. if not table.isNullOrEmpty(subActive) then
  81. for id, subActiveDetail in pairs(subActive) do
  82. if subActiveDetail.openState and not subActiveDetail.closeState then
  83. local subActiveInfo = {}
  84. subActiveInfo["id"] = subActiveDetail.id
  85. subActiveInfo["openTime"] = subActiveDetail.openTime
  86. table.insert(allSubActiveInfo,subActiveInfo)
  87. end
  88. end
  89. end
  90. activeInfo["subActive"] = allSubActiveInfo
  91. OperationalActivities.subActiveDetail(actor,activeInfo,currentActive)
  92. sendluamsg(actor,LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO,activeInfo)
  93. return activeInfo
  94. end
  95. -- 玩家打开子活动页签
  96. function OperationalActivities.openSubActive(actor,msgData)
  97. local activeInfo = {}
  98. local currentActive = getsysvar(actor, CURRENT_ACTIVE)
  99. if table.isNullOrEmpty(currentActive) then
  100. return
  101. end
  102. local mainActive = currentActive.mainActive
  103. local currentActiveInfoTable = ConfigDataManager.getTable("cfg_OperateActivity_all","id",mainActive.activeId)
  104. if table.isNullOrEmpty(currentActiveInfoTable) then
  105. error("主活动配置错误")
  106. return
  107. end
  108. local mainActiveInfo = this.getMainActive(actor,currentActive,currentActiveInfoTable)
  109. activeInfo["mainActive"] = mainActiveInfo
  110. local subActive = currentActive.subActive
  111. local allSubActiveInfo = {}
  112. local currentTime = getbaseinfo(actor,"now")
  113. if not table.isNullOrEmpty(subActive) then
  114. for id, subActiveDetail in pairs(subActive) do
  115. if currentTime > subActiveDetail.openTime and currentTime < subActiveDetail.closeTime then
  116. local subActiveInfo = {}
  117. subActiveInfo["id"] = subActiveDetail.id
  118. subActiveInfo["openTime"] = subActiveDetail.openTime
  119. table.insert(allSubActiveInfo,subActiveInfo)
  120. end
  121. end
  122. end
  123. activeInfo["subActive"] = allSubActiveInfo
  124. local subType = msgData.subType
  125. OperationalActivities.subActiveDetail(actor,activeInfo,currentActive,subType)
  126. sendluamsg(actor,LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO,activeInfo)
  127. end
  128. -- 获取子活动类型
  129. function OperationalActivities.subActiveDetail(actor,activeInfo,currentActive,subType)
  130. if subType ~= nil then
  131. this.setSubActiveInfo(actor,subType,currentActive,activeInfo)
  132. else
  133. -- 没有类型的时候就放全部活动数据
  134. local allSubActiveInfo = ConfigDataManager.getTable("cfg_OperateActivity_subActivity","mainGroup",activeInfo.mainActive.mainGroup)
  135. if not table.isNullOrEmpty(allSubActiveInfo) then
  136. for _, subActiveInfo in pairs(allSubActiveInfo) do
  137. this.setSubActiveInfo(actor,tonumber(subActiveInfo.subtype),currentActive,activeInfo)
  138. end
  139. end
  140. end
  141. end
  142. -- 设置子活动信息
  143. function this.setSubActiveInfo(actor,subType,currentActive,activeInfo)
  144. if OperationalActivities.judgeActiveClose(actor, subType) then
  145. -- 活动开启
  146. if subType == ACTIVE_TYPE.DIRECT then
  147. -- 直购开启
  148. local directInfo = DirectPurchase.reqRechargeAction(actor,currentActive.mainActive.mainGroup)
  149. activeInfo["directSubActive"] = directInfo
  150. elseif subType == ACTIVE_TYPE.TOTAL_RECHARGE then
  151. -- 累充活动
  152. local directInfo = AccumulatedRecharge.reqRechargeAction(actor,currentActive.mainActive.mainGroup)
  153. activeInfo["totalSubActive"] = directInfo
  154. elseif subType == ACTIVE_TYPE.PRIZE_DRAW then
  155. -- 轮盘抽奖
  156. local turntableRaffleInfo = TurntableRaffle.getPanelInfo(actor, currentActive.mainActive.mainGroup)
  157. activeInfo["turntableRaffleActive"] = turntableRaffleInfo
  158. elseif subType == ACTIVE_TYPE.DIAMOND_PACK then
  159. -- 钻石礼包
  160. local diamondPackInfo = DiamondPack.reqRechargeAction(actor,currentActive.mainActive.mainGroup)
  161. activeInfo["diamondPackInfo"] = diamondPackInfo
  162. elseif subType == ACTIVE_TYPE.CONSUMER_RANK then
  163. -- 消费排行
  164. local diamondPackInfo = ConsumerRank.reqRechargeAction(actor,currentActive.mainActive.mainGroup)
  165. activeInfo["consumerRank"] = diamondPackInfo
  166. end
  167. end
  168. end
  169. -- 不同的时间段检查当前有没有活动要开启
  170. function OperationalActivities.checkActive()
  171. local currentActive = getsysvar(CURRENT_ACTIVE)
  172. if table.isNullOrEmpty(currentActive) then
  173. -- 检测当前有没有新活动开始
  174. this.mainActiveChange()
  175. return
  176. end
  177. local currentTime = getbaseinfo("now")
  178. local mainActive = currentActive["mainActive"]
  179. if mainActive.closeTime ~= nil and mainActive.closeTime > currentTime then
  180. -- 当前活动还没有结束,无需添加新的活动
  181. local send = this.checkSubActiveChange(currentActive)
  182. setsysvar(CURRENT_ACTIVE,currentActive)
  183. if send then
  184. this.activeChange(currentActive)
  185. end
  186. return
  187. end
  188. this.checkSubActiveChange(currentActive)
  189. setsysvar(CURRENT_ACTIVE,currentActive)
  190. this.mainActiveChange()
  191. end
  192. -- 主活动变化
  193. function this.mainActiveChange()
  194. local mainActiveTable = ConfigDataManager.getList("cfg_OperateActivity_all")
  195. if table.isNullOrEmpty(mainActiveTable) then
  196. -- 没有主活动信息,不用检查
  197. return
  198. end
  199. local canOpenActive = {}
  200. for _, mainActive in pairs(mainActiveTable) do
  201. local openCondition = mainActive.opencondition
  202. if openCondition ~= nil then
  203. if ConditionManager.Check(111, openCondition) then
  204. table.insert(canOpenActive,mainActive)
  205. end
  206. end
  207. end
  208. this.openMainActive(canOpenActive)
  209. this.activeChange()
  210. end
  211. -- 检查子活动是否变化
  212. function this.checkSubActiveChange(currentActive)
  213. local allSubActiveInfo = currentActive.subActive
  214. local send = false
  215. local currentTime = getbaseinfo("now")
  216. local currentSecTime = tonumber(getbaseinfo("nowsec"))
  217. if not table.isNullOrEmpty(allSubActiveInfo) then
  218. for _, subActiveInfo in pairs(allSubActiveInfo) do
  219. -- 判断当前子活动有没有关闭
  220. if not subActiveInfo.closeState and subActiveInfo.closeTime <= currentTime then
  221. subActiveInfo.closeState = true
  222. this.closeSubActive(subActiveInfo.id)
  223. send = true
  224. end
  225. end
  226. end
  227. local mainGroup = currentActive.mainActive.mainGroup
  228. local allSubActiveTable = ConfigDataManager.getTable("cfg_OperateActivity_subActivity","mainGroup",mainGroup)
  229. for _, subActiveTable in pairs(allSubActiveTable) do
  230. local have = false
  231. for _, subActiveInfo in pairs(allSubActiveInfo) do
  232. if subActiveInfo.id == tonumber(subActiveTable.id) then
  233. have = true
  234. end
  235. end
  236. if not have and ConditionManager.Check(111, allSubActiveTable.opencondition) then
  237. -- 开启子活动
  238. local subActiveInfo = {}
  239. subActiveInfo["id"] = allSubActiveTable.id
  240. subActiveInfo["openTime"] = currentSecTime * 1000
  241. local durationDay = this.getSubActiveDay(allSubActiveTable.closecondition)
  242. local closeTime = TimeUtil.addDayEnd(currentSecTime,durationDay - 1)
  243. subActiveInfo["closeTime"] = closeTime * 1000
  244. subActiveInfo["openState"] = true
  245. subActiveInfo["closeState"] = false
  246. table.insert(allSubActiveInfo,subActiveInfo)
  247. send = true
  248. end
  249. end
  250. currentActive.subActive = allSubActiveInfo
  251. return send
  252. end
  253. function this.closeSubActive(subActiveId)
  254. -- 处理子活动关闭信息
  255. local tableValue = ConfigDataManager.getTable("cfg_OperateActivity_subActivity", "id", subActiveId)
  256. if not table.isNullOrEmpty(tableValue) then
  257. -- 活动类型
  258. local subType = tonumber(tableValue[1]["subtype"])
  259. if string.isNullOrEmpty(subType) then
  260. error("cfg_OperateActivity_subActivity subType is null id:", subActiveId)
  261. return
  262. end
  263. -- 主活动组
  264. local mainGroup = tonumber(tableValue[1]["maingroup"])
  265. if string.isNullOrEmpty(mainGroup) then
  266. error("cfg_OperateActivity_subActivity mainGroup is null id:", subActiveId)
  267. return
  268. end
  269. if subType == ACTIVE_TYPE.DIRECT then
  270. -- 直购
  271. DirectPurchase.closeActive(mainGroup)
  272. elseif subType == ACTIVE_TYPE.TOTAL_RECHARGE then
  273. -- 累充
  274. OperationalActivities.closeActive(mainGroup)
  275. elseif subType == ACTIVE_TYPE.PRIZE_DRAW then
  276. -- 抽奖
  277. TurntableRaffle.sendUnReceiveRewards(mainGroup)
  278. elseif subType == ACTIVE_TYPE.DIAMOND_PACK then
  279. -- 钻石礼包
  280. DiamondPack.closeActive(mainGroup)
  281. elseif subType == ACTIVE_TYPE.CONSUMER_RANK then
  282. -- 消费排名
  283. ConsumerRank.closeActive(mainGroup)
  284. end
  285. end
  286. end
  287. -- 开启主活动
  288. function this.openMainActive(canOpenActive)
  289. if table.isNullOrEmpty(canOpenActive) then
  290. return
  291. end
  292. local maxLevel = 0
  293. local mainActive = {}
  294. for _, openActive in pairs(canOpenActive) do
  295. if maxLevel < tonumber(openActive.priority) then
  296. maxLevel = tonumber(openActive.priority)
  297. mainActive = openActive
  298. end
  299. end
  300. if table.isNullOrEmpty(mainActive) then
  301. return
  302. end
  303. local currentActive = {}
  304. -- 添加主活动
  305. local mainActiveInfo = {}
  306. -- 活动开启
  307. local mainActiveId = mainActive.id
  308. mainActiveInfo["activeId"] = mainActiveId
  309. mainActiveInfo["mainGroup"] = mainActive.maingroup
  310. local currentTime = getbaseinfo("nowsec")
  311. local currentData = TimeUtil.timeToDate(currentTime)
  312. local mainStartTime = TimeUtil.earlyOneMorning(currentData.year,currentData.month,currentData.day)
  313. mainActiveInfo["startTime"] = mainStartTime * 1000
  314. local durationDay = 0
  315. local closeCondition = mainActive.closecondition
  316. local groupStrs = string.split(closeCondition, '/')
  317. for _, groupStr in pairs(groupStrs) do
  318. local singleStrs = string.split(groupStr, '&')
  319. for _, singleStr in pairs(singleStrs) do
  320. local singleStrInfo = string.split(singleStr, '#')
  321. if tonumber(singleStrInfo[1]) == CONDITION.MAIN_DURATION_TYPE then
  322. durationDay = tonumber(singleStrInfo[3])
  323. local closeTime = TimeUtil.addDayEnd(mainStartTime, durationDay - 1)
  324. mainActiveInfo["closeTime"] = closeTime * 1000
  325. end
  326. end
  327. end
  328. currentActive["mainActive"] = mainActiveInfo
  329. -- 整理页签到期时间
  330. local mainGroup = tonumber(mainActive.maingroup)
  331. local subActivityTable = ConfigDataManager.getTable("cfg_OperateActivity_subActivity","mainGroup",mainGroup)
  332. if table.isNullOrEmpty(subActivityTable) then
  333. currentActive["subActive"] = {}
  334. setsysvar(CURRENT_ACTIVE,currentActive)
  335. return
  336. end
  337. local currentTime = getbaseinfo("nowsec")
  338. local subActive = {}
  339. for k, subActivityInfo in pairs(subActivityTable) do
  340. local subActiveInfo = {}
  341. subActiveInfo["id"] = tonumber(subActivityInfo.id)
  342. local openCondition = subActivityInfo.opencondition
  343. if ConditionManager.Check(111, openCondition) then
  344. local currentTime = getbaseinfo("nowsec")
  345. subActiveInfo["openTime"] = currentTime * 1000
  346. local durationDay = this.getSubActiveDay(subActivityInfo.closecondition)
  347. local closeTime = TimeUtil.addDayEnd(currentTime,durationDay - 1)
  348. subActiveInfo["closeTime"] = closeTime * 1000
  349. subActiveInfo["openState"] = true
  350. subActiveInfo["closeState"] = false
  351. table.insert(subActive,subActiveInfo)
  352. end
  353. end
  354. currentActive["subActive"] = subActive
  355. setsysvar(CURRENT_ACTIVE,currentActive)
  356. end
  357. -- 获取子活动持续天数
  358. function this.getSubActiveDay(closeCondition)
  359. if string.isNullOrEmpty(closeCondition) then
  360. return 0
  361. end
  362. local groupStrs = string.split(closeCondition, '/')
  363. for k, groupStr in pairs(groupStrs) do
  364. local singleStrs = string.split(groupStr, '&')
  365. for k, singleStr in pairs(singleStrs) do
  366. local singleStrInfo = string.split(singleStr, '#')
  367. if tonumber(singleStrInfo[1]) == CONDITION.SUB_DURATION_TYPE then
  368. return tonumber(singleStrInfo[4])
  369. end
  370. end
  371. end
  372. return 0
  373. end
  374. -- 给当前在线玩家发送活动已经改变
  375. function this.activeChange(currentActive)
  376. local allRoleInfos = getallrolesummaryinfos()
  377. local activeInfo = {}
  378. if not table.isNullOrEmpty(allRoleInfos) then
  379. for k, roleInfo in pairs(allRoleInfos) do
  380. local actor = roleInfo["actor"]
  381. if table.isNullOrEmpty(activeInfo) then
  382. activeInfo = OperationalActivities.openActive(actor,currentActive)
  383. else
  384. sendluamsg(actor,LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO,activeInfo)
  385. end
  386. end
  387. end
  388. end
  389. --- 获取当前活动期数
  390. function OperationalActivities.getCurrentMainGroup(actor)
  391. local currentActive = getsysvar(actor,CURRENT_ACTIVE)
  392. if table.isNullOrEmpty(currentActive) then
  393. return 0
  394. end
  395. return tonumber(currentActive.mainActive.mainGroup)
  396. end
  397. --- 合服时清除活动信息
  398. function OperationalActivities.combine()
  399. setsysvar(CURRENT_ACTIVE,{})
  400. end
  401. function clearactive(actor)
  402. setsysvar(actor,CURRENT_ACTIVE,{})
  403. end
  404. function lookactive(actor)
  405. local activity = getsysvar(actor,CURRENT_ACTIVE)
  406. jprint("activity",activity)
  407. end
  408. function checkactive(actor)
  409. OperationalActivities.checkActive()
  410. end
  411. function sendmsgactive(actor)
  412. OperationalActivities.openSubActive(actor,111)
  413. end
  414. LoginEventListerTable:eventLister("0", "运营框架", OperationalActivities.openActive)