WeekendLoopActManager.lua 13 KB

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