WeekendLoopActManager.lua 10.0 KB

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