| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- -- 活动管理器
- -- 整合世界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
|