OperationalActivities_1.lua 18 KB

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