ActivityManager.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. -- 活动管理器
  2. -- 整合世界BOSS、攻城战、怪物军团等活动系统
  3. local this = {}
  4. -- 导入活动模块
  5. -- 活动类型
  6. local ACTIVITY_TYPE = {
  7. WORLD_BOSS = 1, -- 世界BOSS争夺战
  8. SIEGE_WAR = 2, -- 攻城战
  9. MONSTER_LEGION = 3, -- 怪物军团
  10. FIRST_RECHARGE = 4, -- 首充活动
  11. MONTHLY_GROW = 5 -- 月卡活动
  12. }
  13. -- 活动配置
  14. local ACTIVITY_CONFIG = {
  15. [ACTIVITY_TYPE.WORLD_BOSS] = {
  16. name = "世界BOSS争夺战",
  17. description = "每周日晚8点开启,所有玩家均可报名参加",
  18. module = WorldBoss,
  19. enabled = true
  20. },
  21. [ACTIVITY_TYPE.SIEGE_WAR] = {
  22. name = "攻城战",
  23. description = "开服2周后开启,战盟争夺城堡控制权",
  24. module = SiegeWar,
  25. enabled = true
  26. },
  27. [ACTIVITY_TYPE.MONSTER_LEGION] = {
  28. name = "怪物军团",
  29. description = "每周三、周五晚上7点开启,抵御怪物入侵",
  30. module = MonsterLegion,
  31. enabled = true
  32. },
  33. [ACTIVITY_TYPE.FIRST_RECHARGE] = {
  34. name = "首充活动",
  35. description = "首充送体验天使",
  36. module = ActFirstRecharge,
  37. enabled = true
  38. },
  39. [ACTIVITY_TYPE.MONTHLY_GROW] = {
  40. name = "月卡活动",
  41. description = "购买送经验,金币,挂机加成",
  42. module = ActMonthlyGrow,
  43. enabled = true
  44. }
  45. }
  46. -- 初始化所有活动系统
  47. function this.Init()
  48. info("活动管理器初始化开始")
  49. -- 初始化各个活动系统
  50. for activityType, config in pairs(ACTIVITY_CONFIG) do
  51. if config.enabled and config.module and config.module.Init then
  52. local success, err = pcall(config.module.Init)
  53. if success then
  54. info("活动系统初始化成功:", config.name)
  55. else
  56. error("活动系统初始化失败:", config.name, ",错误:", err)
  57. end
  58. end
  59. end
  60. -- 启动活动检查定时器
  61. this.StartActivityCheckTimer()
  62. info("活动管理器初始化完成")
  63. end
  64. -- 启动活动检查定时器
  65. function this.StartActivityCheckTimer()
  66. -- 每30秒检查一次活动状态
  67. setTimer(
  68. 30000,
  69. function()
  70. this.CheckAllActivities()
  71. end
  72. )
  73. end
  74. -- 检查所有活动状态
  75. function this.CheckAllActivities()
  76. for activityType, config in pairs(ACTIVITY_CONFIG) do
  77. if config.enabled and config.module then
  78. -- 这里可以添加活动状态检查逻辑
  79. -- 例如:检查活动是否异常、是否需要重启等
  80. end
  81. end
  82. end
  83. -- 获取活动信息
  84. function this.GetActivityInfo(activityType)
  85. local config = ACTIVITY_CONFIG[activityType]
  86. if not config or not config.enabled then
  87. return nil
  88. end
  89. local module = config.module
  90. local info = {
  91. type = activityType,
  92. name = config.name,
  93. description = config.description,
  94. status = "unknown",
  95. phase = "unknown",
  96. timeRemaining = 0,
  97. participants = 0
  98. }
  99. -- 获取活动状态
  100. if module.GetActivityStatus then
  101. info.status = module.GetActivityStatus()
  102. end
  103. -- 获取当前阶段
  104. if module.GetCurrentPhase then
  105. info.phase = module.GetCurrentPhase()
  106. end
  107. -- 获取剩余时间
  108. if module.GetActivityRemainingTime then
  109. info.timeRemaining = module.GetActivityRemainingTime()
  110. end
  111. -- 获取参与人数
  112. if module.GetParticipantCount then
  113. info.participants = module.GetParticipantCount()
  114. end
  115. return info
  116. end
  117. -- 获取所有活动信息
  118. function this.GetAllActivitiesInfo()
  119. local activities = {}
  120. for activityType, config in pairs(ACTIVITY_CONFIG) do
  121. if config.enabled then
  122. local info = this.GetActivityInfo(activityType)
  123. if info then
  124. table.insert(activities, info)
  125. end
  126. end
  127. end
  128. return activities
  129. end
  130. -- 启动指定活动
  131. function this.StartActivity(activityType)
  132. local config = ACTIVITY_CONFIG[activityType]
  133. if not config or not config.enabled then
  134. return false, "活动不存在或已禁用"
  135. end
  136. local module = config.module
  137. if module.StartActivity then
  138. local success, err = pcall(module.StartActivity)
  139. if success then
  140. info("活动启动成功:", config.name)
  141. return true
  142. else
  143. error("活动启动失败:", config.name, ",错误:", err)
  144. return false, "活动启动失败:" .. err
  145. end
  146. else
  147. return false, "活动模块不支持启动功能"
  148. end
  149. end
  150. -- 停止指定活动
  151. function this.StopActivity(activityType)
  152. local config = ACTIVITY_CONFIG[activityType]
  153. if not config or not config.enabled then
  154. return false, "活动不存在或已禁用"
  155. end
  156. local module = config.module
  157. if module.EndActivity then
  158. local success, err = pcall(module.EndActivity)
  159. if success then
  160. info("活动停止成功:", config.name)
  161. return true
  162. else
  163. error("活动停止失败:", config.name, ",错误:", err)
  164. return false, "活动停止失败:" .. err
  165. end
  166. else
  167. return false, "活动模块不支持停止功能"
  168. end
  169. end
  170. -- 玩家参与活动
  171. function this.PlayerJoinActivity(actor, activityType)
  172. local config = ACTIVITY_CONFIG[activityType]
  173. if not config or not config.enabled then
  174. return false, "活动不存在或已禁用"
  175. end
  176. local module = config.module
  177. -- 根据活动类型调用相应的报名函数
  178. if activityType == ACTIVITY_TYPE.WORLD_BOSS then
  179. if module.PlayerRegister then
  180. return module.PlayerRegister(actor)
  181. end
  182. elseif activityType == ACTIVITY_TYPE.SIEGE_WAR then
  183. if module.AllianceRegister then
  184. return module.AllianceRegister(actor)
  185. end
  186. elseif activityType == ACTIVITY_TYPE.MONSTER_LEGION then
  187. if module.PlayerRegister then
  188. return module.PlayerRegister(actor)
  189. end
  190. end
  191. return false, "活动不支持报名功能"
  192. end
  193. -- 检查玩家是否可参与活动
  194. function this.CanPlayerJoinActivity(actor, activityType)
  195. local config = ACTIVITY_CONFIG[activityType]
  196. if not config or not config.enabled then
  197. return false, "活动不存在或已禁用"
  198. end
  199. local module = config.module
  200. if module.CanPlayerParticipate then
  201. return module.CanPlayerParticipate(actor)
  202. end
  203. return false, "活动不支持参与检查"
  204. end
  205. -- 获取活动排行榜
  206. function this.GetActivityRanking(activityType, rankingType)
  207. local config = ACTIVITY_CONFIG[activityType]
  208. if not config or not config.enabled then
  209. return {}
  210. end
  211. local module = config.module
  212. if rankingType == "player" then
  213. if module.GetPlayerScoreRanking then
  214. return module.GetPlayerScoreRanking()
  215. elseif module.GetPlayerDamageRanking then
  216. return module.GetPlayerDamageRanking()
  217. end
  218. elseif rankingType == "alliance" then
  219. if module.GetAllianceScoreRanking then
  220. return module.GetAllianceScoreRanking()
  221. elseif module.GetAllianceDamageRanking then
  222. return module.GetAllianceDamageRanking()
  223. end
  224. end
  225. return {}
  226. end
  227. -- 获取活动详细状态
  228. function this.GetActivityDetailedStatus(activityType)
  229. local config = ACTIVITY_CONFIG[activityType]
  230. if not config or not config.enabled then
  231. return nil
  232. end
  233. local module = config.module
  234. local status = {
  235. type = activityType,
  236. name = config.name,
  237. enabled = config.enabled
  238. }
  239. -- 获取活动状态
  240. if module.GetActivityStatus then
  241. status.status = module.GetActivityStatus()
  242. end
  243. -- 获取当前阶段
  244. if module.GetCurrentPhase then
  245. status.phase = module.GetCurrentPhase()
  246. end
  247. -- 获取剩余时间
  248. if module.GetActivityRemainingTime then
  249. status.timeRemaining = module.GetActivityRemainingTime()
  250. end
  251. -- 获取参与人数
  252. if module.GetParticipantCount then
  253. status.participants = module.GetParticipantCount()
  254. end
  255. -- 根据活动类型获取特定信息
  256. if activityType == ACTIVITY_TYPE.WORLD_BOSS then
  257. if module.GetBossHPInfo then
  258. status.bossHP = module.GetBossHPInfo()
  259. end
  260. if module.GetCurrentBoss then
  261. status.currentBoss = module.GetCurrentBoss()
  262. end
  263. elseif activityType == ACTIVITY_TYPE.SIEGE_WAR then
  264. if module.GetCastleHPInfo then
  265. status.castleHP = module.GetCastleHPInfo()
  266. end
  267. elseif activityType == ACTIVITY_TYPE.MONSTER_LEGION then
  268. if module.GetCurrentWave then
  269. status.currentWave = module.GetCurrentWave()
  270. end
  271. if module.GetActivityStats then
  272. status.stats = module.GetActivityStats()
  273. end
  274. end
  275. return status
  276. end
  277. -- 发送活动公告
  278. function this.SendActivityNotice(activityType, message)
  279. local config = ACTIVITY_CONFIG[activityType]
  280. if not config or not config.enabled then
  281. return false
  282. end
  283. local module = config.module
  284. if module.SendWorldNotice then
  285. module.SendWorldNotice(message)
  286. return true
  287. end
  288. return false
  289. end
  290. -- 获取活动配置
  291. function this.GetActivityConfig(activityType)
  292. local config = ACTIVITY_CONFIG[activityType]
  293. if not config then
  294. return nil
  295. end
  296. return {
  297. type = activityType,
  298. name = config.name,
  299. description = config.description,
  300. enabled = config.enabled
  301. }
  302. end
  303. -- 获取所有活动配置
  304. function this.GetAllActivityConfigs()
  305. local configs = {}
  306. for activityType, config in pairs(ACTIVITY_CONFIG) do
  307. table.insert(configs, this.GetActivityConfig(activityType))
  308. end
  309. return configs
  310. end
  311. -- 启用/禁用活动
  312. function this.SetActivityEnabled(activityType, enabled)
  313. local config = ACTIVITY_CONFIG[activityType]
  314. if not config then
  315. return false, "活动不存在"
  316. end
  317. config.enabled = enabled
  318. if enabled then
  319. info("活动已启用:", config.name)
  320. else
  321. info("活动已禁用:", config.name)
  322. end
  323. return true
  324. end
  325. -- 重启活动系统
  326. function this.RestartActivitySystem(activityType)
  327. local config = ACTIVITY_CONFIG[activityType]
  328. if not config or not config.enabled then
  329. return false, "活动不存在或已禁用"
  330. end
  331. local module = config.module
  332. -- 停止当前活动
  333. if module.EndActivity then
  334. pcall(module.EndActivity)
  335. end
  336. -- 重新初始化
  337. if module.Init then
  338. local success, err = pcall(module.Init)
  339. if success then
  340. info("活动系统重启成功:", config.name)
  341. return true
  342. else
  343. error("活动系统重启失败:", config.name, ",错误:", err)
  344. return false, "活动系统重启失败:" .. err
  345. end
  346. end
  347. return false, "活动模块不支持重启功能"
  348. end
  349. -- 获取活动统计信息
  350. function this.GetActivityStatistics()
  351. local stats = {
  352. totalActivities = 0,
  353. enabledActivities = 0,
  354. activeActivities = 0,
  355. activities = {}
  356. }
  357. for activityType, config in pairs(ACTIVITY_CONFIG) do
  358. stats.totalActivities = stats.totalActivities + 1
  359. if config.enabled then
  360. stats.enabledActivities = stats.enabledActivities + 1
  361. local status = this.GetActivityDetailedStatus(activityType)
  362. if status and status.status and status.status > 0 then
  363. stats.activeActivities = stats.activeActivities + 1
  364. end
  365. table.insert(
  366. stats.activities,
  367. {
  368. type = activityType,
  369. name = config.name,
  370. status = status
  371. }
  372. )
  373. end
  374. end
  375. return stats
  376. end
  377. -- 清理活动数据
  378. function this.CleanupActivityData(activityType)
  379. local config = ACTIVITY_CONFIG[activityType]
  380. if not config or not config.enabled then
  381. return false, "活动不存在或已禁用"
  382. end
  383. local module = config.module
  384. if module.CleanupActivityData then
  385. local success, err = pcall(module.CleanupActivityData)
  386. if success then
  387. info("活动数据清理成功:", config.name)
  388. return true
  389. else
  390. error("活动数据清理失败:", config.name, ",错误:", err)
  391. return false, "活动数据清理失败:" .. err
  392. end
  393. end
  394. return false, "活动模块不支持数据清理功能"
  395. end
  396. -- 清理所有活动数据
  397. function this.CleanupAllActivityData()
  398. local results = {}
  399. for activityType, config in pairs(ACTIVITY_CONFIG) do
  400. if config.enabled then
  401. local success, message = this.CleanupActivityData(activityType)
  402. results[activityType] = {
  403. success = success,
  404. message = message
  405. }
  406. end
  407. end
  408. return results
  409. end
  410. -- 导出模块
  411. return this