WeekendLoopActManager.lua 16 KB

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