WeekenActivities.lua 17 KB

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