-- 活动管理器 -- 整合世界BOSS、攻城战、怪物军团等活动系统 local this = {} -- 导入活动模块 -- 活动类型 local ACTIVITY_TYPE = { WORLD_BOSS = 1, -- 世界BOSS争夺战 SIEGE_WAR = 2, -- 攻城战 MONSTER_LEGION = 3 -- 怪物军团 } -- 活动配置 local ACTIVITY_CONFIG = { [ACTIVITY_TYPE.WORLD_BOSS] = { name = "世界BOSS争夺战", description = "每周日晚8点开启,所有玩家均可报名参加", module = WorldBoss, enabled = true }, [ACTIVITY_TYPE.SIEGE_WAR] = { name = "攻城战", description = "开服2周后开启,战盟争夺城堡控制权", module = SiegeWar, enabled = true }, [ACTIVITY_TYPE.MONSTER_LEGION] = { name = "怪物军团", description = "每周三、周五晚上7点开启,抵御怪物入侵", module = MonsterLegion, enabled = true } } -- 初始化所有活动系统 function this.Init() info("活动管理器初始化开始") -- 初始化各个活动系统 for activityType, config in pairs(ACTIVITY_CONFIG) do if config.enabled and config.module and config.module.Init then local success, err = pcall(config.module.Init) if success then info("活动系统初始化成功:", config.name) else error("活动系统初始化失败:", config.name, ",错误:", err) end end end -- 启动活动检查定时器 this.StartActivityCheckTimer() info("活动管理器初始化完成") end -- 启动活动检查定时器 function this.StartActivityCheckTimer() -- 每30秒检查一次活动状态 setTimer(30000, function() this.CheckAllActivities() end) end -- 检查所有活动状态 function this.CheckAllActivities() for activityType, config in pairs(ACTIVITY_CONFIG) do if config.enabled and config.module then -- 这里可以添加活动状态检查逻辑 -- 例如:检查活动是否异常、是否需要重启等 end end end -- 获取活动信息 function this.GetActivityInfo(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return nil end local module = config.module local info = { type = activityType, name = config.name, description = config.description, status = "unknown", phase = "unknown", timeRemaining = 0, participants = 0 } -- 获取活动状态 if module.GetActivityStatus then info.status = module.GetActivityStatus() end -- 获取当前阶段 if module.GetCurrentPhase then info.phase = module.GetCurrentPhase() end -- 获取剩余时间 if module.GetActivityRemainingTime then info.timeRemaining = module.GetActivityRemainingTime() end -- 获取参与人数 if module.GetParticipantCount then info.participants = module.GetParticipantCount() end return info end -- 获取所有活动信息 function this.GetAllActivitiesInfo() local activities = {} for activityType, config in pairs(ACTIVITY_CONFIG) do if config.enabled then local info = this.GetActivityInfo(activityType) if info then table.insert(activities, info) end end end return activities end -- 启动指定活动 function this.StartActivity(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module if module.StartActivity then local success, err = pcall(module.StartActivity) if success then info("活动启动成功:", config.name) return true else error("活动启动失败:", config.name, ",错误:", err) return false, "活动启动失败:" .. err end else return false, "活动模块不支持启动功能" end end -- 停止指定活动 function this.StopActivity(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module if module.EndActivity then local success, err = pcall(module.EndActivity) if success then info("活动停止成功:", config.name) return true else error("活动停止失败:", config.name, ",错误:", err) return false, "活动停止失败:" .. err end else return false, "活动模块不支持停止功能" end end -- 玩家参与活动 function this.PlayerJoinActivity(actor, activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module -- 根据活动类型调用相应的报名函数 if activityType == ACTIVITY_TYPE.WORLD_BOSS then if module.PlayerRegister then return module.PlayerRegister(actor) end elseif activityType == ACTIVITY_TYPE.SIEGE_WAR then if module.AllianceRegister then return module.AllianceRegister(actor) end elseif activityType == ACTIVITY_TYPE.MONSTER_LEGION then if module.PlayerRegister then return module.PlayerRegister(actor) end end return false, "活动不支持报名功能" end -- 检查玩家是否可参与活动 function this.CanPlayerJoinActivity(actor, activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module if module.CanPlayerParticipate then return module.CanPlayerParticipate(actor) end return false, "活动不支持参与检查" end -- 获取活动排行榜 function this.GetActivityRanking(activityType, rankingType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return {} end local module = config.module if rankingType == "player" then if module.GetPlayerScoreRanking then return module.GetPlayerScoreRanking() elseif module.GetPlayerDamageRanking then return module.GetPlayerDamageRanking() end elseif rankingType == "alliance" then if module.GetAllianceScoreRanking then return module.GetAllianceScoreRanking() elseif module.GetAllianceDamageRanking then return module.GetAllianceDamageRanking() end end return {} end -- 获取活动详细状态 function this.GetActivityDetailedStatus(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return nil end local module = config.module local status = { type = activityType, name = config.name, enabled = config.enabled } -- 获取活动状态 if module.GetActivityStatus then status.status = module.GetActivityStatus() end -- 获取当前阶段 if module.GetCurrentPhase then status.phase = module.GetCurrentPhase() end -- 获取剩余时间 if module.GetActivityRemainingTime then status.timeRemaining = module.GetActivityRemainingTime() end -- 获取参与人数 if module.GetParticipantCount then status.participants = module.GetParticipantCount() end -- 根据活动类型获取特定信息 if activityType == ACTIVITY_TYPE.WORLD_BOSS then if module.GetBossHPInfo then status.bossHP = module.GetBossHPInfo() end if module.GetCurrentBoss then status.currentBoss = module.GetCurrentBoss() end elseif activityType == ACTIVITY_TYPE.SIEGE_WAR then if module.GetCastleHPInfo then status.castleHP = module.GetCastleHPInfo() end elseif activityType == ACTIVITY_TYPE.MONSTER_LEGION then if module.GetCurrentWave then status.currentWave = module.GetCurrentWave() end if module.GetActivityStats then status.stats = module.GetActivityStats() end end return status end -- 发送活动公告 function this.SendActivityNotice(activityType, message) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false end local module = config.module if module.SendWorldNotice then module.SendWorldNotice(message) return true end return false end -- 获取活动配置 function this.GetActivityConfig(activityType) local config = ACTIVITY_CONFIG[activityType] if not config then return nil end return { type = activityType, name = config.name, description = config.description, enabled = config.enabled } end -- 获取所有活动配置 function this.GetAllActivityConfigs() local configs = {} for activityType, config in pairs(ACTIVITY_CONFIG) do table.insert(configs, this.GetActivityConfig(activityType)) end return configs end -- 启用/禁用活动 function this.SetActivityEnabled(activityType, enabled) local config = ACTIVITY_CONFIG[activityType] if not config then return false, "活动不存在" end config.enabled = enabled if enabled then info("活动已启用:", config.name) else info("活动已禁用:", config.name) end return true end -- 重启活动系统 function this.RestartActivitySystem(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module -- 停止当前活动 if module.EndActivity then pcall(module.EndActivity) end -- 重新初始化 if module.Init then local success, err = pcall(module.Init) if success then info("活动系统重启成功:", config.name) return true else error("活动系统重启失败:", config.name, ",错误:", err) return false, "活动系统重启失败:" .. err end end return false, "活动模块不支持重启功能" end -- 获取活动统计信息 function this.GetActivityStatistics() local stats = { totalActivities = 0, enabledActivities = 0, activeActivities = 0, activities = {} } for activityType, config in pairs(ACTIVITY_CONFIG) do stats.totalActivities = stats.totalActivities + 1 if config.enabled then stats.enabledActivities = stats.enabledActivities + 1 local status = this.GetActivityDetailedStatus(activityType) if status and status.status and status.status > 0 then stats.activeActivities = stats.activeActivities + 1 end table.insert(stats.activities, { type = activityType, name = config.name, status = status }) end end return stats end -- 清理活动数据 function this.CleanupActivityData(activityType) local config = ACTIVITY_CONFIG[activityType] if not config or not config.enabled then return false, "活动不存在或已禁用" end local module = config.module if module.CleanupActivityData then local success, err = pcall(module.CleanupActivityData) if success then info("活动数据清理成功:", config.name) return true else error("活动数据清理失败:", config.name, ",错误:", err) return false, "活动数据清理失败:" .. err end end return false, "活动模块不支持数据清理功能" end -- 清理所有活动数据 function this.CleanupAllActivityData() local results = {} for activityType, config in pairs(ACTIVITY_CONFIG) do if config.enabled then local success, message = this.CleanupActivityData(activityType) results[activityType] = { success = success, message = message } end end return results end -- 导出模块 return this