WeekenActivities_1.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 = WeekDirectPurchase.reqRechargeAction(actor, currentActive.mainActive.mainGroup)
  144. -- activeInfo["directSubActive"] = directInfo
  145. -- elseif subType == ACTIVE_TYPE.TOTAL_RECHARGE then
  146. -- -- 累充活动
  147. -- local directInfo = WeekAccumulatedRecharge.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 = WeekDiamondPack.reqRechargeAction(actor, currentActive.mainActive.mainGroup)
  156. -- activeInfo["diamondPackInfo"] = diamondPackInfo
  157. -- elseif subType == ACTIVE_TYPE.CONSUMER_RANK then
  158. -- -- 消费排行
  159. -- local diamondPackInfo = WeekConsumerRank.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 tonumber(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. -- WeekDirectPurchase.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. -- WeekDiamondPack.closeActive(mainGroup)
  283. -- elseif subType == ACTIVE_TYPE.CONSUMER_RANK then
  284. -- -- 消费排名
  285. -- WeekConsumerRank.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. -- setsysvar(CURRENT_WEEKEN_ACTIVE, currentActive)
  359. end
  360. -- 获取子活动持续天数
  361. function this.getSubActiveDay(closeCondition)
  362. -- if string.isNullOrEmpty(closeCondition) then
  363. -- return 0
  364. -- end
  365. -- local groupStrs = string.split(closeCondition, '/')
  366. -- for k, groupStr in pairs(groupStrs) do
  367. -- local singleStrs = string.split(groupStr, '&')
  368. -- for k, singleStr in pairs(singleStrs) do
  369. -- local singleStrInfo = string.split(singleStr, '#')
  370. -- if tonumber(singleStrInfo[1]) == CONDITION.SUB_DURATION_TYPE then
  371. -- return tonumber(singleStrInfo[4])
  372. -- end
  373. -- end
  374. -- end
  375. return 0
  376. end
  377. -- 给当前在线玩家发送活动已经改变
  378. function this.activeChange(currentActive)
  379. -- local allRoleInfos = getallrolesummaryinfos()
  380. -- local activeInfo = {}
  381. -- if not table.isNullOrEmpty(allRoleInfos) then
  382. -- for k, roleInfo in pairs(allRoleInfos) do
  383. -- local actor = roleInfo["actor"]
  384. -- local onlineState = getbaseinfo(actor, "onlinestate")
  385. -- if onlineState == 1 then
  386. -- if table.isNullOrEmpty(activeInfo) then
  387. -- activeInfo = WeekActives.openActive(actor, currentActive)
  388. -- else
  389. -- sendluamsg(actor, LuaMessageIdToClient.RES_WEEKEN_GIFT, activeInfo)
  390. -- end
  391. -- end
  392. -- end
  393. -- end
  394. end
  395. --- 获取当前活动期数
  396. function WeekActives.getCurrentMainGroup(actor)
  397. local currentActive = getsysvar(actor, CURRENT_WEEKEN_ACTIVE)
  398. if table.isNullOrEmpty(currentActive) then
  399. return 0
  400. end
  401. return tonumber(currentActive.mainActive.mainGroup)
  402. end
  403. --- 合服时清除活动信息
  404. function WeekActives.combine()
  405. setsysvar(CURRENT_WEEKEN_ACTIVE, {})
  406. end
  407. function clearactive1(actor)
  408. setsysvar(actor, CURRENT_WEEKEN_ACTIVE, {})
  409. end
  410. function lookactive1(actor)
  411. local activity = getsysvar(actor, CURRENT_WEEKEN_ACTIVE)
  412. lg("activity", activity)
  413. end
  414. function checkactive1(actor)
  415. WeekActives.checkActive()
  416. end
  417. function sendmsgactive1(actor)
  418. WeekActives.openSubActive(actor, 111)
  419. end
  420. LoginEventListerTable:eventLister("0", "幸运周末框架", WeekActives.openActive)