ActivityManager.lua 13 KB

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