WeekendLoopActManager.lua 16 KB

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