WeekendLoopActManager.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. --------------------------------
  2. -- 文件名 : WeekendLoopActManger.lua
  3. -- 文件说明 : 周末冲刺-活动模板管理
  4. -- 创建时间 : 2024/11/25
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local MailExcel = require("excel.mail")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local MailManager = require("mail.MailManager")
  14. local BagLogic = require("bag.BagLogic")
  15. local Grid = require("bag.Grid")
  16. local PanelDefine = require("broadcast.PanelDefine")
  17. local CommonDB = require("common.CommonDB")
  18. local BuyLogic = require("topup.BuyLogic")
  19. local GuideLogic = require("guide.GuideLogic")
  20. local Log = require("common.Log")
  21. local WeekLoopActDef = require("WeekendLoopActivity.WeekendLoopActDefine")
  22. local WeekLoopActCof = require("excel.WeekLoopAct")
  23. local WeekLoopActHeroStar = require("WeekendLoopActivity.WeekendLoopActHeroStar")
  24. local YunYingLogic = require("yunying.YunYingLogic")
  25. -- 活动信息
  26. tWeekActInfo = nil
  27. -- {
  28. -- nStartTime = nil, -- 开始时间
  29. -- nEendTime = nil, -- 结束时间
  30. -- isRun = nil, -- 是否在活动中
  31. -- }
  32. -- 加载的模块
  33. tWeekActModuel = {}
  34. ----------------------------------------- 内部处理开始 -------------------------------------
  35. -- 下发数据
  36. local function WeekLoopACT_SendData(tMsgData, fd)
  37. Msg.send(tMsgData, fd)
  38. end
  39. -- 下发活动数据
  40. function WeekLoopACT_SendActInfo(human)
  41. if not human or not tWeekActInfo then
  42. return
  43. end
  44. print("[WeekLoopACT_SendActInfo] 下发活动数据 开始 ")
  45. local tMsgData = Msg.gc.GC_WEEKLOOP_ACT_ALLINFO
  46. tMsgData.nStartTime = tWeekActInfo.nStartTime
  47. tMsgData.nEendTime = tWeekActInfo.nEendTime
  48. tMsgData.tActID[0] = #WeekLoopActCof.WeekLoopAct
  49. local nIndex = 1
  50. for id, v in pairs(WeekLoopActCof.WeekLoopAct) do
  51. local tActData = tMsgData.tActID[nIndex]
  52. nIndex = nIndex + 1
  53. tActData.ID = id
  54. tActData.name = v.name
  55. tActData.nSortID = v.sortID
  56. tActData.nIcon = v.icon
  57. tActData.nPanelID = v.panelID
  58. local bRed = false
  59. if tWeekActModuel[id] and tWeekActModuel[id].isRed then
  60. bRed = tWeekActModuel[id].isRed(human)
  61. end
  62. tActData.nRed = bRed and 1 or 0
  63. end
  64. YunYingLogic.sendBanner(human)
  65. WeekLoopACT_SendData(tMsgData, human.fd)
  66. print("[WeekLoopACT_SendActInfo] 下发活动数据 结束 ")
  67. end
  68. -- 获取记录在人物身上的结束时间
  69. local function WeekLoopACT_GetHumanEndTime(human)
  70. if not human then
  71. return -1
  72. end
  73. if not human.db.nWeekLoopEndTime then
  74. return -1
  75. end
  76. return human.db.nWeekLoopEndTime
  77. end
  78. -- 设置记录在人物身上的结束时间
  79. local function WeekLoopACT_SetHumanEndTime(human, nTime)
  80. if not human or 0 >= nTime then
  81. return
  82. end
  83. human.db.nWeekLoopEndTime = nTime
  84. end
  85. -- 获取记录在人物身上的奖励处理标识
  86. local function WeekLoopACT_GetHumanEndMail(human)
  87. if not human then
  88. return true
  89. end
  90. -- 没有 则认为未参加上一次活动
  91. if not human.db.nWeekLoopEndMail then
  92. print("[WeekLoopACT_GetHumanEndMail] 没有参加活动")
  93. return true
  94. end
  95. return human.db.nWeekLoopEndMail
  96. end
  97. -- 设置记录在人物身上的奖励处理标识
  98. local function WeekLoopACT_SetHumanEndMail(human, nValue)
  99. if not human or not nValue then
  100. return
  101. end
  102. human.db.nWeekLoopEndMail = nValue
  103. end
  104. -- 各个子活动重置活动数据
  105. local function WeekLoopACT_ResetData(human)
  106. if not human then
  107. return
  108. end
  109. WeekLoopActHeroStar.WeekActHeroStar_ResetData(human)
  110. end
  111. -- 各个子活动处理结束数据
  112. local function WeekLoopACT_HandleEndData(human)
  113. if not human then
  114. return
  115. end
  116. WeekLoopActHeroStar.WeekActHeroStar_End(human)
  117. end
  118. -- 所有活动初始化数据开始
  119. local function WeekLoopACT_BeginAllAct(human)
  120. if not human or not tWeekActInfo then
  121. return
  122. end
  123. local nEndTime = tWeekActInfo.nEendTime
  124. print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据开始 ")
  125. -- 设置时间
  126. WeekLoopACT_SetHumanEndTime(human, nEndTime)
  127. -- 设置标记
  128. WeekLoopACT_SetHumanEndMail(human, false)
  129. -- 各个子活动重置数据
  130. WeekLoopACT_ResetData(human)
  131. -- 最后下发活动数据
  132. WeekLoopACT_SendActInfo(human)
  133. print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据结束 ")
  134. end
  135. -- 结束所有活动
  136. local function WeekLoopACT_EndAllAct(human)
  137. -- 各个子活动处理数据
  138. WeekLoopACT_HandleEndData(human)
  139. WeekLoopACT_SetHumanEndMail(human, true)
  140. end
  141. -- 活动开始
  142. local function WeekLoopACT_Begin()
  143. if not tWeekActInfo then
  144. return
  145. end
  146. -- 遍历在线玩家
  147. for uuid, human in pairs(ObjHuman.onlineUuid) do
  148. WeekLoopACT_BeginAllAct(human)
  149. end
  150. end
  151. -- 活动结束
  152. local function WeekLoopACT_End()
  153. -- 遍历在线玩家
  154. for uuid, human in pairs(ObjHuman.onlineUuid) do
  155. WeekLoopACT_EndAllAct(human)
  156. end
  157. end
  158. ----------------------------------------- 外部调用开始 -------------------------------------
  159. function onZeroAll(funcID)
  160. local nNowTime = os.time()
  161. local tDate = os.date("*t",nNowTime)
  162. local nOpenServerDay = CommonDB.getServerOpenDay()
  163. if nOpenServerDay < 7 then
  164. return
  165. end
  166. if WeekLoopActDef.WEEKACT_TIME ~= tDate.hour then
  167. return
  168. end
  169. print("[WeekLoopACT_onZeroAll] 进入定时处理")
  170. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday then
  171. print("[WeekLoopACT_onZeroAll] 周末活动开始打印")
  172. tWeekActInfo = {}
  173. tWeekActInfo.isRun = true
  174. tWeekActInfo.nStartTime = nNowTime
  175. -- 计算过期时间,转成0时0分
  176. local nNextTime = nNowTime + 4 * 86400
  177. local tEndDate = os.date("*t",nNextTime)
  178. tEndDate.hour = 0
  179. tEndDate.min = 0
  180. tEndDate.sec = 0
  181. local nEndTime = os.time(tEndDate)
  182. tWeekActInfo.nEendTime = nEndTime
  183. -- 活动开始
  184. WeekLoopACT_Begin()
  185. print("[WeekLoopACT_onZeroAll] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  186. elseif WeekLoopActDef.WEEKACT_ENDDAY == tDate.wday then
  187. print("[WeekLoopACT_onZeroAll] 周末活动结束打印")
  188. WeekLoopACT_End()
  189. tWeekActInfo = nil
  190. end
  191. end
  192. -- 起服初始化
  193. function WeekLoopACT_Init()
  194. local nNowTime = os.time()
  195. local tDate = os.date("*t",nNowTime)
  196. local nOpenServerDay = CommonDB.getServerOpenDay()
  197. if nOpenServerDay < 7 then
  198. return
  199. end
  200. print("[WeekLoopACT_Init] 起服初始化 wday = "..tDate.wday.." m = "..tDate.month.." d = "..tDate.day.." h = "..tDate.hour)
  201. -- 等于星期六 或者 小于星期三
  202. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday or WeekLoopActDef.WEEKACT_ENDDAY > tDate.wday then
  203. if not tWeekActInfo then
  204. tWeekActInfo = {}
  205. tWeekActInfo.isRun = true
  206. local nDiffDay = WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday and 0 or tDate.wday
  207. local nTime = nNowTime - nDiffDay * 86400
  208. local tCalDate = os.date("*t",nTime)
  209. tCalDate.hour = 0
  210. tCalDate.min = 0
  211. tCalDate.sec = 0
  212. tWeekActInfo.nStartTime = os.time(tCalDate)
  213. local nEndTime = tWeekActInfo.nStartTime + 4 * 86400
  214. tCalDate = os.date("*t",nEndTime)
  215. tCalDate.hour = 0
  216. tCalDate.min = 0
  217. tCalDate.sec = 0
  218. tWeekActInfo.nEendTime = os.time(tCalDate)
  219. print("[WeekLoopACT_Init] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  220. end
  221. end
  222. for nID, v in pairs(WeekLoopActCof.WeekLoopAct) do
  223. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  224. tWeekActModuel[nID] = moduleFn
  225. end
  226. end
  227. -- 是否还在活动期间
  228. function WeekLoopACT_IsRun()
  229. if not tWeekActInfo then
  230. return false
  231. end
  232. return tWeekActInfo.isRun
  233. end
  234. -- 玩家登录
  235. function onLogin(human, funcID)
  236. if not human then
  237. return
  238. end
  239. local nOpenServerDay = CommonDB.getServerOpenDay()
  240. if nOpenServerDay < 7 then
  241. print("[onLogin] 玩家登录,当前服务器开放时间不足,直接返回 nOpenServerDay = "..nOpenServerDay)
  242. return
  243. end
  244. local nLastEndTime = WeekLoopACT_GetHumanEndTime(human)
  245. local nState = WeekLoopACT_GetHumanEndMail(human)
  246. local nSendMail = nState and 1 or 0
  247. print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
  248. -- 未开始
  249. if false == WeekLoopACT_IsRun() then
  250. if true == nState or -1 >= nLastEndTime then
  251. return
  252. end
  253. WeekLoopACT_EndAllAct(human)
  254. return
  255. end
  256. -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
  257. if nLastEndTime < tWeekActInfo.nStartTime then
  258. if false == nState then
  259. -- 处理上一次的奖励数据
  260. WeekLoopACT_HandleEndData(human)
  261. end
  262. WeekLoopACT_BeginAllAct(human)
  263. return
  264. end
  265. -- 下发活动基础数据
  266. if true == WeekLoopACT_IsRun() then
  267. WeekLoopACT_SendActInfo(human)
  268. end
  269. end
  270. function onHeroStarChange(human, funcID, parameter, parameter2)
  271. if not human or "table" ~= type(parameter) then
  272. return
  273. end
  274. if false == WeekLoopACT_IsRun() then
  275. return
  276. end
  277. WeekLoopActHeroStar.WeekActHeroStar_HeroStarUp(human, parameter[1], parameter[2])
  278. end
  279. -- 是否开启
  280. function isOpen(human, YYInfo, funcConfig)
  281. local bRet = WeekLoopACT_IsRun()
  282. local nRet = bRet and 1 or 0
  283. print("WeekLoopACT_isOpen 结束 nRet = "..nRet)
  284. return bRet
  285. end
  286. --
  287. function isActive(human, YYInfo, funcConfig)
  288. return not isOpen(human, YYInfo, funcConfig)
  289. end
  290. function isRed(human, YYInfo, funcConfig)
  291. local bRet = WeekLoopActHeroStar.isRed(human)
  292. if bRet then
  293. return bRet
  294. end
  295. return false
  296. end