WeekendLoopActManager.lua 13 KB

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