WeekendLoopActManager.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. local WeekLoopActGuYu = require("WeekendLoopActivity.WeekendLoopActUseGuYu")
  26. local weekLoopActCard = require("WeekendLoopActivity.WeekendLoopActCard")
  27. -- 活动信息
  28. tWeekActInfo = nil
  29. -- {
  30. -- nStartTime = nil, -- 开始时间
  31. -- nEendTime = nil, -- 结束时间
  32. -- isRun = nil, -- 是否在活动中
  33. -- }
  34. -- 加载的模块
  35. tWeekActModuel = {}
  36. ----------------------------------------- 内部处理开始 -------------------------------------
  37. -- 下发数据
  38. local function WeekLoopACT_SendData(tMsgData, fd)
  39. Msg.send(tMsgData, fd)
  40. end
  41. -- 下发活动数据
  42. function WeekLoopACT_SendActInfo(human)
  43. if not human or not tWeekActInfo then
  44. return
  45. end
  46. print("[WeekLoopACT_SendActInfo] 下发活动数据 开始 ")
  47. local tMsgData = Msg.gc.GC_WEEKLOOP_ACT_ALLINFO
  48. tMsgData.nStartTime = tWeekActInfo.nStartTime
  49. tMsgData.nEendTime = tWeekActInfo.nEendTime
  50. tMsgData.tActID[0] = #WeekLoopActCof.WeekLoopAct
  51. local nIndex = 1
  52. for id, v in pairs(WeekLoopActCof.WeekLoopAct) do
  53. local tActData = tMsgData.tActID[nIndex]
  54. nIndex = nIndex + 1
  55. tActData.ID = id
  56. tActData.name = v.name
  57. tActData.nSortID = v.sortID
  58. tActData.nIcon = v.icon
  59. tActData.nPanelID = v.panelID
  60. local bRed = false
  61. if tWeekActModuel[id] and tWeekActModuel[id].isRed then
  62. bRed = tWeekActModuel[id].isRed(human)
  63. end
  64. tActData.nRed = bRed and 1 or 0
  65. end
  66. YunYingLogic.sendBanner(human)
  67. WeekLoopACT_SendData(tMsgData, human.fd)
  68. print("[WeekLoopACT_SendActInfo] 下发活动数据 结束 ")
  69. end
  70. -- 获取记录在人物身上的结束时间
  71. local function WeekLoopACT_GetHumanEndTime(human)
  72. if not human then
  73. return -1
  74. end
  75. if not human.db.nWeekLoopEndTime then
  76. return -1
  77. end
  78. return human.db.nWeekLoopEndTime
  79. end
  80. -- 设置记录在人物身上的结束时间
  81. local function WeekLoopACT_SetHumanEndTime(human, nTime)
  82. if not human or 0 >= nTime then
  83. return
  84. end
  85. human.db.nWeekLoopEndTime = nTime
  86. end
  87. -- 获取记录在人物身上的奖励处理标识
  88. local function WeekLoopACT_GetHumanEndMail(human)
  89. if not human then
  90. return true
  91. end
  92. -- 没有 则认为未参加上一次活动
  93. if not human.db.nWeekLoopEndMail then
  94. print("[WeekLoopACT_GetHumanEndMail] 没有参加活动")
  95. return true
  96. end
  97. return human.db.nWeekLoopEndMail
  98. end
  99. -- 设置记录在人物身上的奖励处理标识
  100. local function WeekLoopACT_SetHumanEndMail(human, nValue)
  101. if not human or not nValue then
  102. return
  103. end
  104. human.db.nWeekLoopEndMail = nValue
  105. end
  106. -- 各个子活动重置活动数据
  107. local function WeekLoopACT_ResetData(human)
  108. if not human then
  109. return
  110. end
  111. -- 这里实际上应该 遍历modulefunc
  112. WeekLoopActHeroStar.WeekActHeroStar_ResetData(human)
  113. WeekLoopActGuYu.WeekActGuYu_ResetData(human)
  114. weekLoopActCard.WeekActCard_ResetData(human)
  115. end
  116. -- 各个子活动处理结束数据
  117. local function WeekLoopACT_HandleEndData(human)
  118. if not human then
  119. return
  120. end
  121. WeekLoopActHeroStar.WeekActHeroStar_End(human)
  122. end
  123. -- 所有活动初始化数据开始
  124. local function WeekLoopACT_BeginAllAct(human)
  125. if not human or not tWeekActInfo then
  126. return
  127. end
  128. local nEndTime = tWeekActInfo.nEendTime
  129. print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据开始 ")
  130. -- 设置时间
  131. WeekLoopACT_SetHumanEndTime(human, nEndTime)
  132. -- 设置标记
  133. WeekLoopACT_SetHumanEndMail(human, false)
  134. -- 各个子活动重置数据
  135. WeekLoopACT_ResetData(human)
  136. -- 最后下发活动数据
  137. WeekLoopACT_SendActInfo(human)
  138. print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据结束 ")
  139. end
  140. -- 结束所有活动
  141. local function WeekLoopACT_EndAllAct(human)
  142. -- 各个子活动处理数据
  143. WeekLoopACT_HandleEndData(human)
  144. WeekLoopACT_SetHumanEndMail(human, true)
  145. end
  146. -- 活动开始
  147. local function WeekLoopACT_Begin()
  148. if not tWeekActInfo then
  149. return
  150. end
  151. -- 遍历在线玩家
  152. for uuid, human in pairs(ObjHuman.onlineUuid) do
  153. WeekLoopACT_BeginAllAct(human)
  154. end
  155. end
  156. -- 活动结束
  157. local function WeekLoopACT_End()
  158. -- 遍历在线玩家
  159. for uuid, human in pairs(ObjHuman.onlineUuid) do
  160. WeekLoopACT_EndAllAct(human)
  161. end
  162. end
  163. ----------------------------------------- 外部调用开始 -------------------------------------
  164. function onZeroAll(funcID)
  165. local nNowTime = os.time()
  166. local tDate = os.date("*t",nNowTime)
  167. local nOpenServerDay = CommonDB.getServerOpenDay()
  168. if nOpenServerDay < 7 then
  169. return
  170. end
  171. if WeekLoopActDef.WEEKACT_TIME ~= tDate.hour then
  172. return
  173. end
  174. print("[WeekLoopACT_onZeroAll] 进入定时处理")
  175. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday then
  176. print("[WeekLoopACT_onZeroAll] 周末活动开始打印")
  177. tWeekActInfo = {}
  178. tWeekActInfo.isRun = true
  179. tWeekActInfo.nStartTime = nNowTime
  180. -- 计算过期时间,转成0时0分
  181. local nNextTime = nNowTime + 4 * 86400
  182. local tEndDate = os.date("*t",nNextTime)
  183. tEndDate.hour = 0
  184. tEndDate.min = 0
  185. tEndDate.sec = 0
  186. local nEndTime = os.time(tEndDate)
  187. tWeekActInfo.nEendTime = nEndTime
  188. -- 活动开始
  189. WeekLoopACT_Begin()
  190. print("[WeekLoopACT_onZeroAll] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  191. elseif WeekLoopActDef.WEEKACT_ENDDAY == tDate.wday then
  192. print("[WeekLoopACT_onZeroAll] 周末活动结束打印")
  193. WeekLoopACT_End()
  194. tWeekActInfo = nil
  195. end
  196. end
  197. -- 起服初始化
  198. function WeekLoopACT_Init()
  199. local nNowTime = os.time()
  200. local tDate = os.date("*t",nNowTime)
  201. local nOpenServerDay = CommonDB.getServerOpenDay()
  202. if nOpenServerDay < 7 then
  203. return
  204. end
  205. print("[WeekLoopACT_Init] 起服初始化 wday = "..tDate.wday.." m = "..tDate.month.." d = "..tDate.day.." h = "..tDate.hour)
  206. -- 等于星期六 或者 小于星期三
  207. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday or WeekLoopActDef.WEEKACT_ENDDAY > tDate.wday then
  208. if not tWeekActInfo then
  209. tWeekActInfo = {}
  210. tWeekActInfo.isRun = true
  211. local nDiffDay = WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday and 0 or tDate.wday
  212. local nTime = nNowTime - nDiffDay * 86400
  213. local tCalDate = os.date("*t",nTime)
  214. tCalDate.hour = 0
  215. tCalDate.min = 0
  216. tCalDate.sec = 0
  217. tWeekActInfo.nStartTime = os.time(tCalDate)
  218. local nEndTime = tWeekActInfo.nStartTime + 4 * 86400
  219. tCalDate = os.date("*t",nEndTime)
  220. tCalDate.hour = 0
  221. tCalDate.min = 0
  222. tCalDate.sec = 0
  223. tWeekActInfo.nEendTime = os.time(tCalDate)
  224. print("[WeekLoopACT_Init] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  225. end
  226. end
  227. for nID, v in pairs(WeekLoopActCof.WeekLoopAct) do
  228. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  229. if moduleFn then
  230. tWeekActModuel[nID] = moduleFn
  231. if moduleFn.Init then
  232. local bRet = moduleFn.Init()
  233. if false == bRet then
  234. print("[WeekLoopACT_Init] 初始化模块数据失败 nID ".. nID)
  235. end
  236. end
  237. else
  238. print("[WeekLoopACT_Init] 加载模块失败 nID ".. nID)
  239. end
  240. end
  241. end
  242. -- 是否还在活动期间
  243. function WeekLoopACT_IsRun()
  244. if not tWeekActInfo then
  245. return false
  246. end
  247. return tWeekActInfo.isRun
  248. end
  249. -- 玩家登录
  250. function onLogin(human, funcID)
  251. if not human then
  252. return
  253. end
  254. local nOpenServerDay = CommonDB.getServerOpenDay()
  255. if nOpenServerDay < 7 then
  256. print("[onLogin] 玩家登录,当前服务器开放时间不足,直接返回 nOpenServerDay = "..nOpenServerDay)
  257. return
  258. end
  259. local nLastEndTime = WeekLoopACT_GetHumanEndTime(human)
  260. local nState = WeekLoopACT_GetHumanEndMail(human)
  261. local nSendMail = nState and 1 or 0
  262. print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
  263. -- 未开始
  264. if false == WeekLoopACT_IsRun() then
  265. if true == nState or -1 >= nLastEndTime then
  266. return
  267. end
  268. WeekLoopACT_EndAllAct(human)
  269. return
  270. end
  271. -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
  272. if nLastEndTime < tWeekActInfo.nStartTime then
  273. if false == nState then
  274. -- 处理上一次的奖励数据
  275. WeekLoopACT_HandleEndData(human)
  276. end
  277. WeekLoopACT_BeginAllAct(human)
  278. return
  279. end
  280. -- 下发活动基础数据
  281. if true == WeekLoopACT_IsRun() then
  282. WeekLoopACT_SendActInfo(human)
  283. end
  284. end
  285. -- 英雄星级改变回调
  286. function onHeroStarChange(human, funcID, parameter, parameter2)
  287. if not human or "table" ~= type(parameter) then
  288. return
  289. end
  290. if false == WeekLoopACT_IsRun() then
  291. return
  292. end
  293. WeekLoopActHeroStar.WeekActHeroStar_HeroStarUp(human, parameter[1], parameter[2])
  294. end
  295. -- 是否开启
  296. function isOpen(human, YYInfo, funcConfig)
  297. local bRet = WeekLoopACT_IsRun()
  298. local nRet = bRet and 1 or 0
  299. print("WeekLoopACT_isOpen 结束 nRet = "..nRet)
  300. return bRet
  301. end
  302. --
  303. function isActive(human, YYInfo, funcConfig)
  304. return not isOpen(human, YYInfo, funcConfig)
  305. end
  306. function isRed(human, YYInfo, funcConfig)
  307. local bRet = false
  308. for id, v in pairs(WeekLoopActCof.WeekLoopAct) do
  309. if tWeekActModuel[id] and tWeekActModuel[id].isRed then
  310. bRet = tWeekActModuel[id].isRed(human)
  311. if true == bRet then
  312. break
  313. end
  314. end
  315. end
  316. return bRet
  317. end
  318. -- 消耗古玉回调
  319. function onDecZuanshi(human, funcID, parameter, parameter2)
  320. if not human or "number" ~= type(parameter) then
  321. return
  322. end
  323. if false == WeekLoopACT_IsRun() then
  324. return
  325. end
  326. local nGuYu = math.abs(parameter)
  327. if 0 >= nGuYu then
  328. return
  329. end
  330. WeekLoopActGuYu.WeekActGuYu_UseGuYu(human, nGuYu)
  331. end
  332. -- 高级召唤回调
  333. function onDrawCard(human, funcID, parameter, parameter2)
  334. if not human or "number" ~= type(parameter) then
  335. return
  336. end
  337. if false == WeekLoopACT_IsRun() then
  338. return
  339. end
  340. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_HIGH)
  341. end
  342. -- 天命召唤回调
  343. function onTMDrawCard(human, funcID, parameter, parameter2)
  344. if not human or "number" ~= type(parameter) then
  345. return
  346. end
  347. if false == WeekLoopACT_IsRun() then
  348. return
  349. end
  350. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_TIANMING)
  351. end
  352. -- 寻星回调
  353. function onFindStar(human, funcID, parameter, parameter2)
  354. if not human or "number" ~= type(parameter) then
  355. return
  356. end
  357. if false == WeekLoopACT_IsRun() then
  358. return
  359. end
  360. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_FINDSTAR)
  361. end
  362. -- GM 命令
  363. function GMResetWeekAct(human)
  364. if WeekLoopACT_IsRun() then
  365. WeekLoopACT_EndAllAct(human)
  366. WeekLoopACT_BeginAllAct(human)
  367. end
  368. end