BigSecretRealm.lua 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. --- 大天使秘境副本
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by zhoutao.
  4. --- DateTime: 2024/11/20 16:43
  5. BigSecretRealm = {}
  6. local this = {}
  7. --- 获取大天使秘境面板信息
  8. --- @param actor table 角色对象
  9. function BigSecretRealm.getPanelInfo(actor)
  10. -- 获取钥匙等级
  11. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  12. keyLevel = keyLevel and tonumber(keyLevel) or 0
  13. -- 获取大天使秘境副本评分
  14. local score = getplaydef(actor, string.format(PlayerDefKey.bigSecretRealm.SCORE, keyLevel))
  15. score = score and score or ""
  16. -- 获取是否领取奖励
  17. local isReceiveReward = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD)
  18. -- 获取剩余奖励次数
  19. local rewardCount = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT)
  20. -- 获取副本加成信息
  21. local bonusInfo = getsysvar(SystemVarConst.BIG_SECRET_REALM_BONUS_INFO)
  22. if table.isNullOrEmpty(bonusInfo) then
  23. bonusInfo = this.getRandomBonusInfo()
  24. setsysvar(SystemVarConst.BIG_SECRET_REALM_BONUS_INFO, bonusInfo)
  25. end
  26. local text = ConfigDataManager.getTableValue("cfg_bigUncharted_buff", "text", "id", bonusInfo["id"])
  27. local str = (bonusInfo["value"] / 100) .. "%"
  28. text = string.format(text, str)
  29. sendluamsg(actor, LuaMessageIdToClient.RES_BIG_SECRET_REALM_PANEL_INFO, {
  30. ["score"] = score,
  31. ["keyLevel"] = keyLevel,
  32. ["isReceiveReward"] = isReceiveReward,
  33. ["rewardCount"] = rewardCount,
  34. ["bonusInfo"] = text
  35. })
  36. end
  37. --- 设置默认领取奖励状态
  38. --- @param actor table 角色对象
  39. function BigSecretRealm.setReceiveStatus(actor)
  40. local receiveStatus = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD)
  41. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD, not receiveStatus)
  42. sendluamsg(actor, LuaMessageIdToClient.RES_BIG_SECRET_REALM_RECEIVE_STATUS, not receiveStatus)
  43. end
  44. --- 进入大天使秘境副本
  45. --- @param actor table 角色对象
  46. --- @param configId number 副本配置id
  47. function BigSecretRealm.ReqEnterBigSecretRealm(actor, configId)
  48. -- 重置发送邮件标识
  49. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_SEND_EMAIL, false)
  50. -- 判断角色等级是否满足
  51. local playerLevel = tonumber(getbaseinfo(actor, "level"))
  52. local levelConfig = ConfigDataManager.getTableValue("cfg_rep", "level", "id", configId)
  53. local levelList = string.split(levelConfig, "#")
  54. local minLevel = tonumber(levelList[1])
  55. local maxLevel = tonumber(levelList[2])
  56. if playerLevel < minLevel or playerLevel > maxLevel then
  57. noticeTip.noticeinfo(actor, StringIdConst.LEVEL_NOT_MATCH)
  58. return
  59. end
  60. -- 判断秘境钥匙等级是否满足
  61. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  62. local repLevel = ConfigDataManager.getTableValue("cfg_rep", "repLevel", "id", configId)
  63. if not keyLevel or keyLevel < tonumber(repLevel) then
  64. noticeTip.noticeinfo(actor, StringIdConst.TEXT495)
  65. return
  66. end
  67. local x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
  68. local mapId = DuplicateCommon.CreateDupMapCommon(actor, configId, true)
  69. -- 回蓝回血
  70. DuplicateCommon.RecoverHPMP(actor)
  71. -- 删除秘境钥匙道具
  72. local keyId = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.KEY_ID)
  73. Bag.cost(actor, keyId, 1)
  74. -- 进入副本
  75. enterduplicate(actor, mapId, x, y)
  76. sendluamsg(actor, LuaMessageIdToClient.RES_ENTER_BIG_SECRET_REALM, configId)
  77. end
  78. --- 副本状态更新
  79. function BigSecretRealm.DupStateUpdate(system, mapId, state, nextStateStartTime, configId)
  80. if state == DuplicateState.PREPARE then
  81. -- 初始化第一个任务
  82. this.initTask(mapId, configId)
  83. elseif state == DuplicateState.FIGHT then
  84. -- 战斗阶段
  85. local monsterId = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", configId)
  86. DuplicateCommon.DupGenMonsterCommon(mapId, monsterId) --刷怪
  87. this.ResAllTaskPhaseUpdate(mapId)
  88. end
  89. end
  90. --- 进入副本响应任务信息
  91. function BigSecretRealm.AfterEnterBigSecretRealm(actor, mapId, state, nextStateStartTime, configId)
  92. -- 记录开始时间
  93. this.recordStartTime(mapId)
  94. local startTime = getplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME)
  95. local offlineTime = getplaydef(actor, PlayerDefKey.offline.START_TIME)
  96. if startTime and offlineTime and startTime <= offlineTime then
  97. this.ResAllTaskPhaseUpdate(mapId)
  98. end
  99. end
  100. --- 怪物死亡
  101. --- @param mapId number 地图id
  102. --- @param monCfgId number 怪物配置id
  103. function BigSecretRealm.BigSecretRealmMonsterDie(mapId, killer, monCfgId, monActor)
  104. local taskInfo = getenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO)
  105. local taskId = taskInfo[2]
  106. local taskType = taskInfo[3]
  107. if taskType == DuplicateTaskType.KILL_MONSTER_COUNT then
  108. local totalCount = taskInfo[4]
  109. local oldCount = taskInfo[5]
  110. local newCount = oldCount + 1
  111. if newCount >= totalCount then
  112. -- 完成任务,给客户端回包
  113. this.FinishTask(mapId, taskId)
  114. else
  115. -- 更新记录,给客户端回包
  116. taskInfo[5] = newCount
  117. setenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO, taskInfo)
  118. end
  119. elseif taskType == DuplicateTaskType.KILL_TARGET_MONSTER then
  120. local targetMon = taskInfo[6]
  121. local totalCount = taskInfo[4]
  122. local oldCount = taskInfo[5]
  123. if tonumber(monCfgId) ~= targetMon then
  124. return
  125. end
  126. local newCount = oldCount + 1
  127. if newCount >= totalCount then
  128. -- 调用副本完成方法
  129. DuplicateCommon.FinishDupActivity(killer, getbaseinfo(killer, "mapid"))
  130. -- 完成任务,给客户端回包
  131. this.FinishTask(mapId, taskId)
  132. end
  133. -- 更新记录,给客户端回包
  134. taskInfo[5] = newCount
  135. setenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO, taskInfo)
  136. end
  137. this.ResAllTaskPhaseUpdate(mapId) -- 任务信息
  138. end
  139. --- 钥匙升级
  140. --- @param actor table 角色对象
  141. --- @param msgData table 消息数据
  142. function BigSecretRealm.keyLevelUp(actor, upgradeLevel)
  143. if string.isNullOrEmpty(upgradeLevel) then
  144. info("BigSecretRealm.keyLevelUp upgradeLevel is null")
  145. return
  146. end
  147. if upgradeLevel > 0 then
  148. -- 钥匙升级操作
  149. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_KEY_LEVEL_UP, upgradeLevel)
  150. else
  151. -- 发送当前等级钥匙
  152. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_CURRENT_KEY_LEVEL, upgradeLevel)
  153. end
  154. end
  155. --- 领取通关奖励
  156. --- @param actor table 角色对象
  157. --- @param configId number 副本配置id
  158. function BigSecretRealm.receiveReward(actor, configId)
  159. -- 判断奖励次数是否大于零
  160. local rewardCount = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT)
  161. if rewardCount <= 0 then
  162. return
  163. end
  164. -- 获取奖励列表
  165. local rewardTable = ConfigDataManager.getTableValue("cfg_bigUncharted", "reward", "id", configId)
  166. if string.isNullOrEmpty(rewardTable) then
  167. return
  168. end
  169. local splitTable = string.split(rewardTable, "|")
  170. local rewards = {}
  171. for _, item in ipairs(splitTable) do
  172. local itemInfo = string.split(item, "#")
  173. local itemId = tonumber(itemInfo[1])
  174. local itemCount = tonumber(itemInfo[2])
  175. rewards[itemId] = itemCount
  176. end
  177. -- 发放奖励
  178. Bag.sendRewards(actor, rewards, ItemAction.BIG_SECRET_REALM_REWARD)
  179. -- 减少奖励次数
  180. setplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT, rewardCount - 1)
  181. end
  182. --- 退出大天使秘境副本
  183. --- @param actor table 角色对象
  184. --- @param configId number 副本配置id
  185. function BigSecretRealm.quitBigSecretRealm(actor, configId)
  186. -- 查询角色是否通关
  187. local isPassed = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_PASSED_LEVEL)
  188. -- 没有通关手动退出读表降级钥匙
  189. if not isPassed then
  190. local penalize = ConfigDataManager.getTableValue("cfg_bigUncharted", "penalize", "id", configId)
  191. penalize = tonumber(penalize)
  192. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_QUIT_KEY_LEVEL_DOWN, -penalize)
  193. end
  194. -- 退出副本重置
  195. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_PASSED_LEVEL, false)
  196. -- 清空副本开始时间
  197. setplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME, nil)
  198. -- 调用退出副本接口
  199. quitduplicate(actor)
  200. end
  201. --- 秘境副本扫荡
  202. --- @param actor table 角色对象
  203. --- @param configId number 副本配置id
  204. function BigSecretRealm.sweep(actor, configId)
  205. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  206. -- 判断评分是否可以开启扫荡
  207. local score = getplaydef(actor, string.format(PlayerDefKey.bigSecretRealm.SCORE, keyLevel))
  208. local scoreCondition = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.SWEEP_CONDITION)
  209. local scoreValue = ConfigDataManager.getTableValue("cfg_bigUncharted", "score", "id", configId)
  210. if not string.isNullOrEmpty(scoreValue) then
  211. local scoreSplit = string.split(scoreValue, "#")
  212. local scoreIndex = table.getKey(scoreSplit, score)
  213. local scoreConditionIndex = table.getKey(scoreSplit, scoreCondition)
  214. if scoreIndex > scoreConditionIndex then
  215. gameDebug.print("大天使秘境副本评分不足,无法扫荡 score:", score)
  216. return
  217. end
  218. -- 判断奖励次数是否支持扫荡
  219. local rewardCount = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT)
  220. if rewardCount and rewardCount > 0 then
  221. -- 直接发放奖励
  222. BigSecretRealm.receiveReward(actor, configId)
  223. -- 响应面板信息
  224. BigSecretRealm.getPanelInfo(actor)
  225. else
  226. return
  227. end
  228. end
  229. end
  230. --- 如果是首次登录则初始化大天使秘境信息
  231. --- @param actor table 角色对象
  232. function BigSecretRealm.login(actor)
  233. -- 初始化剩余奖励次数
  234. local rewardCount = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT)
  235. if string.isNullOrEmpty(rewardCount) then
  236. rewardCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.REWARD_COUNT)
  237. setplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT, tonumber(string.split(rewardCount, "#")[1]))
  238. end
  239. -- 初始化是否默认领取奖励
  240. local isReceiveReward = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD)
  241. if not isReceiveReward then
  242. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD, false)
  243. end
  244. -- 初始化副本加成信息
  245. local bonusInfo = getsysvar(actor, SystemVarConst.BIG_SECRET_REALM_BONUS_INFO)
  246. if table.isNullOrEmpty(bonusInfo) then
  247. bonusInfo = this.getRandomBonusInfo()
  248. setsysvar(actor, SystemVarConst.BIG_SECRET_REALM_BONUS_INFO, bonusInfo)
  249. end
  250. -- 判断是否为离线超时退出副本,是否发送邮件
  251. local isPassed = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_PASSED_LEVEL)
  252. local isSend = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_SEND_EMAIL)
  253. local startTime = getplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME)
  254. if not isPassed and not isSend and startTime then
  255. local offlineTime = getplaydef(actor, PlayerDefKey.offline.START_TIME)
  256. local now = getbaseinfo("now")
  257. local timeout = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.DUPLICATE_TIME_OUT)
  258. if offlineTime and now - offlineTime > tonumber(timeout) * TimeUnit.MILLISECOND then
  259. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_QUIT_KEY_LEVEL_DOWN, -1)
  260. setplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME, nil)
  261. end
  262. end
  263. end
  264. --- 初始化大天使秘境钥匙等级
  265. --- @param actor table 角色对象
  266. --- @param itemCfgId number 物品配置id
  267. function BigSecretRealm.initKeyLevel(actor, itemCfgId)
  268. local keyId = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.KEY_ID)
  269. if itemCfgId == tonumber(keyId) then
  270. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  271. if not keyLevel then
  272. setplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL, 1)
  273. end
  274. end
  275. end
  276. --- 重置大天使秘境副本奖励次数与副本加成信息
  277. function BigSecretRealm.refreshBigSecretRealm()
  278. local seconds = getbaseinfo("nowsec")
  279. local now = TimeUtil.timeToDate(seconds)
  280. if now.min == 0 then
  281. gameDebug.print("BigSecretRealm.refreshBigSecretRealm now.hour:", now.hour)
  282. gameDebug.print("BigSecretRealm.refreshBigSecretRealm now.min:", now.min)
  283. gameDebug.print("BigSecretRealm.refreshBigSecretRealm now.sec:", now.sec)
  284. local refreshTime = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.REFRESH_TIME)
  285. local rewardCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.REWARD_COUNT)
  286. local split = string.split(rewardCount, "#")
  287. local incrementCount = tonumber(split[1])
  288. local limit = tonumber(split[2])
  289. if string.isNullOrEmpty(refreshTime) then
  290. gameDebug.print("BigSecretRealm cfg_repGlobal refreshTime is nil")
  291. return
  292. end
  293. local refreshTime_split = string.split(refreshTime, "#")
  294. local type = tonumber(refreshTime_split[1])
  295. local time = tonumber(refreshTime_split[2])
  296. if type == 1 then
  297. if now.hour == tonumber(time) and now.min == 0 and now.sec >= 0 then
  298. local allRoleInfos = getallrolesummaryinfos()
  299. if table.isNullOrEmpty(allRoleInfos) then
  300. return
  301. end
  302. for _, roleInfo in pairs(allRoleInfos) do
  303. local actor = roleInfo["actor"]
  304. -- 刷新奖励次数
  305. this.refreshCount(actor, incrementCount, limit)
  306. -- 刷新副本buff
  307. local bonusInfo = this.getRandomBonusInfo()
  308. setsysvar(SystemVarConst.BIG_SECRET_REALM_BONUS_INFO, bonusInfo)
  309. end
  310. end
  311. return
  312. end
  313. if type == 2 then
  314. if now.wday == 1 and now.hour == tonumber(time) and now.min == 0 and now.sec >= 0 then
  315. local allRoleInfos = getallrolesummaryinfos()
  316. if table.isNullOrEmpty(allRoleInfos) then
  317. return
  318. end
  319. for _, roleInfo in pairs(allRoleInfos) do
  320. local actor = roleInfo["actor"]
  321. -- 刷新奖励次数
  322. this.refreshCount(actor, incrementCount, limit)
  323. -- 刷新副本buff
  324. local bonusInfo = this.getRandomBonusInfo()
  325. setsysvar(SystemVarConst.BIG_SECRET_REALM_BONUS_INFO, bonusInfo)
  326. end
  327. end
  328. return
  329. end
  330. end
  331. end
  332. --- 初始化任务信息
  333. --- @param mapId number 地图id
  334. --- @param configId number 副本配置id
  335. function this.initTask(mapId, configId)
  336. --当前任务信息
  337. local taskId = ConfigDataManager.getTableValue("cfg_rep", "repTarget", "id", configId)
  338. local taskInfo = DuplicateCommon.GenDupTaskInfoCommon(taskId)
  339. table.insert(taskInfo, 1, BigSecretRealmTaskPhase.ONE)
  340. setenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO, taskInfo)
  341. end
  342. --- 记录开始时间
  343. --- @param mapId number 副本id
  344. function this.recordStartTime(mapId)
  345. local dupInfo = getduplicate(mapId)
  346. local players = dupInfo["players"]
  347. for _, actor in ipairs(players) do
  348. local startTime = getplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME)
  349. if not startTime then
  350. setplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME, getbaseinfo("now"))
  351. end
  352. end
  353. end
  354. --- 响应客户端任务更新
  355. --- @param actor table 角色对象
  356. --- @param mapId number 副本id
  357. --- @param configId number 副本配置id
  358. function this.ResTaskPhaseUpdate(actor, mapId, configId)
  359. local taskInfo = getenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO)
  360. local nowPhase = taskInfo[1]
  361. local taskId = taskInfo[2]
  362. local totalCount = taskInfo[4]
  363. local nowCount = taskInfo[5]
  364. local dupInfo = getduplicate(mapId)
  365. local nextStateStartTime = dupInfo["nextstatetime"]
  366. local response = {}
  367. response["phase"] = nowPhase
  368. response["taskId"] = taskId
  369. response["nowCount"] = nowCount
  370. response["totalCount"] = totalCount
  371. response["configId"] = configId
  372. response["nextStateStartTime"] = nextStateStartTime
  373. sendluamsg(actor, LuaMessageIdToClient.RES_BIG_SECRET_REALM_TASK_UPDATE, response)
  374. end
  375. function this.ResAllTaskPhaseUpdate(mapId)
  376. local dupInfo = getduplicate(mapId)
  377. local players = dupInfo["players"]
  378. local configId = dupInfo["dupcfgid"]
  379. for _, actor in ipairs(players) do
  380. this.ResTaskPhaseUpdate(actor, mapId, configId)
  381. end
  382. end
  383. --- 完成任务
  384. --- @param mapId number 副本id
  385. --- @param taskId number 任务id
  386. function this.FinishTask(mapId, taskId)
  387. local taskInfo = getenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO)
  388. local nextTaskId = ConfigDataManager.getTableValue("cfg_repTask", "nextID", "id", taskId)
  389. local dupInfo = getduplicate(mapId)
  390. local configId = dupInfo["dupcfgid"]
  391. if string.isNullOrEmpty(nextTaskId) then
  392. -- 根据条件判断 发送钥匙升级弹窗信息
  393. this.sendKeyLevelUpPanelInfo(mapId)
  394. -- 如果副本玩家离线则直接发放钥匙与奖励
  395. this.offlineHandle(mapId)
  396. return
  397. end
  398. local dupLevel = ConfigDataManager.getTableValue("cfg_rep", "repLevel", "id", configId)
  399. dupLevel = tonumber(dupLevel)
  400. local nowPhase = taskInfo[1]
  401. if nowPhase == BigSecretRealmTaskPhase.ONE then
  402. nowPhase = nowPhase + 1
  403. end
  404. local type = ConfigDataManager.getTableValue("cfg_repTask", "type", "id", nextTaskId)
  405. if type == DuplicateTaskType.KILL_TARGET_MONSTER then
  406. nowPhase = nowPhase + 1
  407. end
  408. if nowPhase == BigSecretRealmTaskPhase.TWO then
  409. --阶段二,刷新小怪
  410. DuplicateCommon.DupGenMonsterCommon(mapId, nextTaskId) --刷怪
  411. elseif nowPhase == BigSecretRealmTaskPhase.THREE then
  412. --阶段三,刷新BOSS
  413. DuplicateCommon.DupGenMonsterCommon(mapId, nextTaskId) --刷怪
  414. end
  415. -- 设置下一个任务
  416. local nextTaskInfo = DuplicateCommon.GenDupTaskInfoCommon(nextTaskId)
  417. table.insert(nextTaskInfo, 1, nowPhase)
  418. setenvirvar(mapId, DuplicateVarConst.BIG_SECRET_REALM_TASK_INFO, nextTaskInfo)
  419. end
  420. --- 发送钥匙升级与奖励弹窗信息
  421. --- @param mapId number 副本id
  422. function this.sendKeyLevelUpPanelInfo(mapId)
  423. local dupInfo = getduplicate(mapId)
  424. local players = dupInfo["players"]
  425. local dupCfgId = dupInfo["dupcfgid"]
  426. local now = getbaseinfo("now")
  427. for _, actor in ipairs(players) do
  428. if not isofflineplay(actor) then
  429. -- 标识角色是否已经通关此次副本
  430. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_PASSED_LEVEL, true)
  431. local startTime = getplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME)
  432. local dupTime = (now - startTime)
  433. local tableValue = ConfigDataManager.getTable("cfg_bigUncharted", "id", dupCfgId)
  434. local resLevelUp, currentScore = this.checkKeyLevelUpOrDown(actor, dupTime, tableValue)
  435. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  436. if resLevelUp < 0 then
  437. -- 钥匙降级发送邮件
  438. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_KEY_LEVEL_DOWN, resLevelUp)
  439. end
  440. -- 响应客户端通关成功面板信息
  441. sendluamsg(actor, LuaMessageIdToClient.RES_BIG_SECRET_REALM_CLEARANCE_PANEL_INFO, {
  442. ["keyLevel"] = keyLevel,
  443. ["score"] = currentScore,
  444. ["resLevelUp"] = resLevelUp,
  445. ["isReceiveReward"] = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD),
  446. ["rewardCount"] = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT),
  447. ["rewardItems"] = string.toStringStringMap(tableValue[1]["reward"], "#", "|"),
  448. ["passedTime"] = dupTime,
  449. })
  450. end
  451. end
  452. end
  453. --- 钥匙升级或降级
  454. --- @param actor table 角色对象
  455. --- @param dupTime number 副本通关时间
  456. --- @param tableValue table 配置表数据
  457. --- @return number 升级或降级等级
  458. function this.checkKeyLevelUpOrDown(actor, dupTime, tableValue)
  459. -- 根据通关时间来计算评分、钥匙升降级
  460. local minutes = math.ceil(dupTime / TimeUnit.MILLISECOND / TimeUnit.MINUTE)
  461. local time = tableValue[1]["time"]
  462. local score = tableValue[1]["score"]
  463. local levelUp = tableValue[1]["levelup"]
  464. local splitStr = string.split(time, "#")
  465. local strIndex
  466. for index, value in pairs(splitStr) do
  467. if tonumber(value) >= minutes then
  468. strIndex = index
  469. break
  470. end
  471. end
  472. if not strIndex then
  473. strIndex = #splitStr
  474. end
  475. -- 判断之前的评分是否优于此次,优于此次则不更新
  476. local scoreKey = string.format(PlayerDefKey.bigSecretRealm.SCORE, getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL))
  477. local lastScore = getplaydef(actor, scoreKey)
  478. local scoreSplit = string.split(score, "#")
  479. setplaydef(actor, PlayerDefKey.bigSecretRealm.NEW_SCORE, scoreSplit[strIndex])
  480. if lastScore then
  481. for index, value in pairs(scoreSplit) do
  482. if lastScore == value and index > strIndex then
  483. setplaydef(actor, scoreKey, scoreSplit[strIndex])
  484. break
  485. end
  486. end
  487. else
  488. setplaydef(actor, scoreKey, scoreSplit[strIndex])
  489. end
  490. local resLevelUp = string.split(levelUp, "#")[strIndex]
  491. return tonumber(resLevelUp), scoreSplit[strIndex]
  492. end
  493. --- 钥匙升降级发送邮件给玩家
  494. --- @param actor table 角色对象
  495. --- @param mailConfigId number 邮件配置id
  496. --- @param levelChange number 钥匙升降的等级
  497. function this.keyLevelChange(actor, mailConfigId, levelChange)
  498. -- 此前发送过邮件则返回
  499. local isSend = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_SEND_EMAIL)
  500. if isSend then
  501. return
  502. end
  503. -- 通关得分
  504. local keyLevel = getplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL)
  505. local score = getplaydef(actor, PlayerDefKey.bigSecretRealm.NEW_SCORE)
  506. if tonumber(levelChange) ~= 0 then
  507. -- 钥匙等级处理
  508. if (keyLevel + tonumber(levelChange)) > 0 then
  509. keyLevel = keyLevel + tonumber(levelChange)
  510. else
  511. keyLevel = 1
  512. end
  513. end
  514. -- 获取钥匙itemConfigId
  515. local itemConfigId = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.bigSecretRealm.KEY_ID)
  516. local param = ""
  517. if mailConfigId == MailConfig.BIG_SECRET_REALM_QUIT_KEY_LEVEL_DOWN or mailConfigId == MailConfig.BIG_SECRET_REALM_CURRENT_KEY_LEVEL then
  518. param = keyLevel
  519. else
  520. param = score .. "#" .. keyLevel
  521. end
  522. -- 标识已经发送过邮件,避免重复发送
  523. setplaydef(actor, PlayerDefKey.bigSecretRealm.IS_SEND_EMAIL, true)
  524. -- 设置钥匙等级
  525. setplaydef(actor, PlayerDefKey.bigSecretRealm.KEY_LEVEL, keyLevel)
  526. -- 发送邮件
  527. sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), mailConfigId, { [tonumber(itemConfigId)] = 1 }, param)
  528. end
  529. --- 离线处理
  530. --- @param mapId number 副本id
  531. function this.offlineHandle(mapId)
  532. local dupInfo = getduplicate(mapId)
  533. local players = dupInfo["players"]
  534. local configId = dupInfo["dupcfgid"]
  535. local now = getbaseinfo("now")
  536. for _, actor in ipairs(players) do
  537. if isofflineplay(actor) then
  538. local startTime = getplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME)
  539. local levelUpOrDown
  540. if not startTime then
  541. levelUpOrDown = -1
  542. else
  543. local dupTime = (now - startTime)
  544. local tableValue = ConfigDataManager.getTable("cfg_bigUncharted", "id", configId)
  545. levelUpOrDown, _ = this.checkKeyLevelUpOrDown(actor, dupTime, tableValue)
  546. end
  547. -- 根据钥匙升级还是降级发送不同的邮件
  548. if levelUpOrDown > 0 then
  549. -- 执行钥匙升级操作
  550. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_KEY_LEVEL_UP, levelUpOrDown)
  551. else
  552. -- 执行钥匙降级操作
  553. this.keyLevelChange(actor, MailConfig.BIG_SECRET_REALM_KEY_LEVEL_DOWN, levelUpOrDown)
  554. end
  555. local isReceive = getplaydef(actor, PlayerDefKey.bigSecretRealm.IS_RECEIVE_REWARD)
  556. if isReceive then
  557. BigSecretRealm.receiveReward(actor, configId)
  558. end
  559. -- 清空副本开始时间
  560. setplaydef(actor, PlayerDefKey.bigSecretRealm.START_TIME, nil)
  561. -- 调用退出副本接口
  562. quitduplicate(actor)
  563. end
  564. end
  565. end
  566. --- 刷新奖励次数
  567. --- @param incrementCount number 增加的次数
  568. --- @param limit number 次数上限
  569. function this.refreshCount(actor, incrementCount, limit)
  570. local rewardCount = getplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT)
  571. if not rewardCount then
  572. setplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT, incrementCount)
  573. elseif rewardCount + incrementCount > limit then
  574. setplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT, limit)
  575. else
  576. setplaydef(actor, PlayerDefKey.bigSecretRealm.REWARD_COUNT, rewardCount + incrementCount)
  577. end
  578. end
  579. --- 获取随机加成信息
  580. --- @return number 加成id
  581. function this.getRandomBonusInfo()
  582. local tableInfo = ConfigDataManager.getTable("cfg_bigUncharted_buff")
  583. if table.isNullOrEmpty(tableInfo) then
  584. gameDebug.print("cfg_bigUncharted_buff is nil")
  585. return
  586. end
  587. local randomIndex = math.random(1, #tableInfo)
  588. local id = tableInfo[randomIndex]["id"]
  589. local attNumber = tableInfo[randomIndex]["attnumber"]
  590. local splits = string.split(attNumber, "#")
  591. local min = splits[1]
  592. local max = splits[2]
  593. local attValue = math.random(min, max)
  594. return { ["id"] = id, ["value"] = attValue }
  595. end
  596. --- 判断角色是否在大秘境副本中
  597. --- @param actor table 角色对象
  598. function this.isInBigSecretRealm(actor)
  599. local activityId = getbaseinfo(actor, "activityid")
  600. if string.isNullOrEmpty(activityId) then
  601. return false
  602. end
  603. return tonumber(activityId) == DuplicateType.BIG_SECRET_REALM
  604. end