WeekendLoopActManager.lua 15 KB

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