WeekendLoopActManager.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. Log.write(Log.LOGID_OSS_WEEKLOOP_ACT, "[WeekLoopACT_SetCardBatch] 获取不到之前的批次 设置批次为1 设置新批次结束")
  193. return
  194. end
  195. local nLen = (nNowCardBatch + 1) % WeekLoopActDef.WEEKACT_CARD_TYPE_LEN
  196. nNowCardBatch = (0 == nLen) and WeekLoopActDef.WEEKACT_CARD_TYPE_LEN or nLen
  197. CommonDB.setWeekCardBatch(nNowCardBatch)
  198. Log.write(Log.LOGID_OSS_WEEKLOOP_ACT, "[WeekLoopACT_SetCardBatch] 设置新批次结束 nNowCardBatch = "..nNowCardBatch)
  199. end
  200. ----------------------------------------- 外部调用开始 -------------------------------------
  201. function onZeroAll(funcID)
  202. local nNowTime = os.time()
  203. local tDate = os.date("*t",nNowTime)
  204. local nOpenServerDay = CommonDB.getServerOpenDay()
  205. if nOpenServerDay <= 7 then
  206. return
  207. end
  208. if WeekLoopActDef.WEEKACT_TIME ~= tDate.hour then
  209. return
  210. end
  211. print("[WeekLoopACT_onZeroAll] 进入定时处理")
  212. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday then
  213. print("[WeekLoopACT_onZeroAll] 周末活动开始打印")
  214. tWeekActInfo = {}
  215. tWeekActInfo.isRun = true
  216. tWeekActInfo.nStartTime = nNowTime
  217. -- 计算过期时间,转成0时0分
  218. local nNextTime = nNowTime + 4 * 86400
  219. local tEndDate = os.date("*t",nNextTime)
  220. tEndDate.hour = 0
  221. tEndDate.min = 0
  222. tEndDate.sec = 0
  223. local nEndTime = os.time(tEndDate)
  224. tWeekActInfo.nEendTime = nEndTime
  225. tWeekActInfo.nCardBatch = WeekLoopACT_GetCardBatch()
  226. -- 活动开始
  227. WeekLoopACT_Begin()
  228. print("[WeekLoopACT_onZeroAll] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  229. elseif WeekLoopActDef.WEEKACT_ENDDAY == tDate.wday then
  230. print("[WeekLoopACT_onZeroAll] 周末活动结束打印")
  231. -- 活动结束
  232. WeekLoopACT_End()
  233. -- 设置新的批次
  234. WeekLoopACT_SetCardBatch()
  235. tWeekActInfo = nil
  236. end
  237. end
  238. -- 起服初始化
  239. function WeekLoopACT_Init()
  240. local nNowTime = os.time()
  241. local tDate = os.date("*t",nNowTime)
  242. local nOpenServerDay = CommonDB.getServerOpenDay()
  243. if nOpenServerDay < 7 then
  244. return
  245. end
  246. print("[WeekLoopACT_Init] 起服初始化 wday = "..tDate.wday.." m = "..tDate.month.." d = "..tDate.day.." h = "..tDate.hour)
  247. -- 等于星期六 或者 小于星期三
  248. if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday or WeekLoopActDef.WEEKACT_ENDDAY > tDate.wday then
  249. if not tWeekActInfo then
  250. tWeekActInfo = {}
  251. tWeekActInfo.isRun = true
  252. local nDiffDay = WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday and 0 or tDate.wday
  253. local nTime = nNowTime - nDiffDay * 86400
  254. local tCalDate = os.date("*t",nTime)
  255. tCalDate.hour = 0
  256. tCalDate.min = 0
  257. tCalDate.sec = 0
  258. tWeekActInfo.nStartTime = os.time(tCalDate)
  259. local nEndTime = tWeekActInfo.nStartTime + 4 * 86400
  260. tCalDate = os.date("*t",nEndTime)
  261. tCalDate.hour = 0
  262. tCalDate.min = 0
  263. tCalDate.sec = 0
  264. tWeekActInfo.nEendTime = os.time(tCalDate)
  265. tWeekActInfo.nCardBatch = WeekLoopACT_GetCardBatch()
  266. print("[WeekLoopACT_Init] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
  267. end
  268. end
  269. for nID, v in pairs(WeekLoopActCof.WeekLoopAct) do
  270. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  271. if moduleFn then
  272. tWeekActModuel[nID] = moduleFn
  273. if moduleFn.Init then
  274. local bRet = moduleFn.Init()
  275. if false == bRet then
  276. print("[WeekLoopACT_Init] 初始化模块数据失败 nID ".. nID)
  277. end
  278. end
  279. print("[WeekLoopACT_Init] 加载模块成功 name = "..v.name)
  280. else
  281. print("[WeekLoopACT_Init] 加载模块失败 nID ".. nID)
  282. end
  283. end
  284. end
  285. -- 是否还在活动期间
  286. function WeekLoopACT_IsRun()
  287. if not tWeekActInfo then
  288. return false
  289. end
  290. return tWeekActInfo.isRun
  291. end
  292. -- 玩家登录
  293. function onLogin(human, funcID)
  294. if not human then
  295. return
  296. end
  297. local nOpenServerDay = CommonDB.getServerOpenDay()
  298. if nOpenServerDay < 7 then
  299. print("[onLogin] 玩家登录,当前服务器开放时间不足,直接返回 nOpenServerDay = "..nOpenServerDay)
  300. return
  301. end
  302. local nLastEndTime = WeekLoopACT_GetHumanEndTime(human)
  303. local nState = WeekLoopACT_GetHumanEndMail(human)
  304. local nSendMail = nState and 1 or 0
  305. print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
  306. -- 未开始
  307. if false == WeekLoopACT_IsRun() then
  308. if true == nState or -1 >= nLastEndTime then
  309. return
  310. end
  311. WeekLoopACT_EndAllAct(human)
  312. return
  313. end
  314. -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
  315. if nLastEndTime < tWeekActInfo.nStartTime then
  316. if false == nState then
  317. -- 处理上一次的奖励数据
  318. WeekLoopACT_HandleEndData(human)
  319. end
  320. WeekLoopACT_BeginAllAct(human)
  321. return
  322. end
  323. -- 下发活动基础数据
  324. if true == WeekLoopACT_IsRun() then
  325. WeekLoopACT_SendActInfo(human)
  326. end
  327. end
  328. -- 英雄星级改变回调
  329. function onHeroStarChange(human, funcID, parameter, parameter2)
  330. if not human or "table" ~= type(parameter) then
  331. return
  332. end
  333. if false == WeekLoopACT_IsRun() then
  334. return
  335. end
  336. WeekLoopActHeroStar.WeekActHeroStar_HeroStarUp(human, parameter[1], parameter[2])
  337. end
  338. -- 是否开启
  339. function isOpen(human, YYInfo, funcConfig)
  340. local bRet = WeekLoopACT_IsRun()
  341. local nRet = bRet and 1 or 0
  342. print("WeekLoopACT_isOpen 结束 nRet = "..nRet)
  343. return bRet
  344. end
  345. --
  346. function isActive(human, YYInfo, funcConfig)
  347. return not isOpen(human, YYInfo, funcConfig)
  348. end
  349. function isRed(human, YYInfo, funcConfig)
  350. local bRet = false
  351. for id, v in pairs(WeekLoopActCof.WeekLoopAct) do
  352. if tWeekActModuel[id] and tWeekActModuel[id].isRed then
  353. bRet = tWeekActModuel[id].isRed(human)
  354. if true == bRet then
  355. break
  356. end
  357. end
  358. end
  359. return bRet
  360. end
  361. -- 消耗古玉回调
  362. function onDecZuanshi(human, funcID, parameter, parameter2)
  363. if not human or "number" ~= type(parameter) then
  364. return
  365. end
  366. if false == WeekLoopACT_IsRun() then
  367. return
  368. end
  369. local nGuYu = math.abs(parameter)
  370. if 0 >= nGuYu then
  371. return
  372. end
  373. WeekLoopActGuYu.WeekActGuYu_UseGuYu(human, nGuYu)
  374. end
  375. -- 高级召唤回调
  376. function onDrawCard(human, funcID, parameter, parameter2)
  377. if not human or "number" ~= type(parameter) then
  378. return
  379. end
  380. if false == WeekLoopACT_IsRun() then
  381. return
  382. end
  383. print("[onDrawCard] 高级召唤回调 parameter = "..parameter)
  384. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_HIGH)
  385. end
  386. -- 天命召唤回调
  387. function onTMDrawCard(human, funcID, parameter, parameter2)
  388. if not human or "number" ~= type(parameter) then
  389. return
  390. end
  391. if false == WeekLoopACT_IsRun() then
  392. return
  393. end
  394. print("[onDrawCard] 天命召唤回调 parameter = "..parameter)
  395. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_TIANMING)
  396. end
  397. -- 寻星回调
  398. function onFindStar(human, funcID, parameter, parameter2)
  399. if not human or "number" ~= type(parameter) then
  400. return
  401. end
  402. if false == WeekLoopACT_IsRun() then
  403. return
  404. end
  405. print("[onDrawCard] 寻星回调 parameter = "..parameter)
  406. weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_FINDSTAR)
  407. end
  408. -- GM 命令
  409. function GMResetWeekAct(human)
  410. if WeekLoopACT_IsRun() then
  411. WeekLoopACT_EndAllAct(human)
  412. WeekLoopACT_SetCardBatch()
  413. WeekLoopACT_BeginAllAct(human)
  414. end
  415. end
  416. function onCharge(human, price, funcID, buyID)
  417. if not human then
  418. return
  419. end
  420. if false == WeekLoopACT_IsRun() then
  421. return
  422. end
  423. print("[onCharge] 玩家充值回调开始 name = "..human.db.name.." price = "..price)
  424. weekLoopActRank.onCharge(human, price, funcID, buyID)
  425. end