PrivilegeBoss.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. --- 特权BOSS副本
  2. PrivilegeBoss = {}
  3. local this = {}
  4. --- 获取特权BOSS信息
  5. ---@param actor 玩家对象
  6. ---@param msgData 消息数据
  7. function PrivilegeBoss.ReqPrivilegeBossPanel(actor, msgData)
  8. local configId = tonumber(msgData["configId"])
  9. if configId == nil or configId <= 0 then
  10. gameDebug.printTraceback("PrivilegeBoss.ReqPrivilegeBossInfo param is wrong", msgData)
  11. return
  12. end
  13. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  14. local leftCount = getleftcountofactivity(actor, activityId)
  15. local activityInfo = getactivityinfo(activityId)
  16. local isOpen = activityInfo["open"]
  17. local nextOpenTime
  18. if isOpen then
  19. nextOpenTime = activityInfo["closetime"]
  20. else
  21. nextOpenTime = activityInfo["nextopentime"]
  22. end
  23. local resInfo = {
  24. configId = configId,
  25. leftCount = leftCount,
  26. isOpen = isOpen,
  27. nextOpenTime = tostring(nextOpenTime)
  28. }
  29. -- 特权BOSS面板协议
  30. sendluamsg(actor, LuaMessageIdToClient.RES_PRIVILEGE_BOSS_PANEL, resInfo)
  31. end
  32. --- 请求进入特权BOSS副本
  33. ---@param actor 玩家对象
  34. ---@param configId 副本配置ID
  35. function PrivilegeBoss.ReqEnterPrivilegeBoss(actor, configId)
  36. -- 验证是否可以进入
  37. local conditionResult = DuplicateCommon.CheckEnterConditonCommon(actor, configId)
  38. if conditionResult ~= EnterLimitResultConst.ALLOW then
  39. if conditionResult == EnterLimitResultConst.LEVEL then
  40. noticeTip.noticeinfo(actor, StringIdConst.CURRENT_LEVEL_INSUFFICIENT)
  41. return
  42. end
  43. if conditionResult == EnterLimitResultConst.COUNT then
  44. tipinfo(actor, "挑战次数不足")
  45. return
  46. end
  47. return
  48. end
  49. --寻找是否有可进入的副本,如果没有创建副本
  50. local x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
  51. local mapId = DuplicateCommon.CreateDupMapCommon(actor, configId, true)
  52. setplaydef(actor, PlayerDefKey.privilegeBoss.BOSS_IS_DIE, 0)
  53. --回蓝回血
  54. DuplicateCommon.RecoverHPMP(actor)
  55. enterduplicate(actor, mapId, x, y)
  56. end
  57. --- 特权BOSS副本状态更新
  58. function PrivilegeBoss.PrivilegeBossStateUpdate(system, id, state, nextStateStartTime, configId)
  59. if state == DuplicateState.FIGHT then
  60. --战斗阶段
  61. local monsterId = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", configId)
  62. DuplicateCommon.DupGenMonsterCommon(id, monsterId) --刷怪
  63. end
  64. end
  65. --- 进入特权BOSS副本后返回客户端
  66. function PrivilegeBoss.afterEnterPrivilegeBoss(actor, mapId, state, nextStateStartTime, configId)
  67. sendluamsg(actor, LuaMessageIdToClient.RES_PRIVILEGE_BOSS_STATUS, {
  68. configId = tonumber(configId),
  69. isDie = getplaydef(actor, PlayerDefKey.privilegeBoss.BOSS_IS_DIE)
  70. })
  71. end
  72. --- 特权BOSS怪物死亡处理
  73. ---@param mapId 副本ID
  74. ---@param killer 击杀者
  75. ---@param monCfgId 怪物配置ID
  76. function PrivilegeBoss.PrivilegeBossMonsterDie(mapId, killer, monCfgId)
  77. -- 减少可挑战次数
  78. local repId = ConfigDataManager.getTableValue("cfg_rep", "id", "monsterui", monCfgId)
  79. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", repId)
  80. reduceactivitytimes(killer, activityId)
  81. setplaydef(killer, PlayerDefKey.privilegeBoss.BOSS_IS_DIE, 1)
  82. -- 更新副本状态到关闭
  83. setduplicatestate(mapId, SetDuplicateStateConst.TO_FINISH)
  84. sendluamsg(killer, LuaMessageIdToClient.RES_PRIVILEGE_BOSS_STATUS, {
  85. configId = tonumber(repId),
  86. isDie = 1
  87. })
  88. -- 刷新任务进度
  89. DuplicateCommon.FinishDupActivity(killer, repId)
  90. end
  91. --- 玩家复活后发送特权BOSS状态
  92. function PrivilegeBoss.playerRelive(actor)
  93. local mapId = getbaseinfo(actor, "unimapid")
  94. local dupInfo = getduplicate(mapId)
  95. if table.isNullOrEmpty(dupInfo) then
  96. return
  97. end
  98. local type = dupInfo["type"]
  99. if type ~= DuplicateType.PRIVILEGE_BOSS then
  100. return
  101. end
  102. sendluamsg(actor, LuaMessageIdToClient.RES_PRIVILEGE_BOSS_STATUS, {
  103. configId = tonumber(dupInfo["activityid"]),
  104. isDie = getplaydef(actor, PlayerDefKey.privilegeBoss.BOSS_IS_DIE)
  105. })
  106. end
  107. --- 服务器小时心跳增加特权BOSS挑战次数
  108. function PrivilegeBoss.incrementedPrivilegeBossCount()
  109. local serverType = getbaseinfo("servertype")
  110. if serverType == 2 then
  111. return
  112. end
  113. local seconds = getbaseinfo("nowsec")
  114. local now = TimeUtil.timeToDate(seconds)
  115. if now.min == 0 then
  116. gameDebug.print("PrivilegeBoss.incrementedPrivilegeBossCount now.hour:", now.hour)
  117. gameDebug.print("PrivilegeBoss.incrementedPrivilegeBossCount now.min:", now.min)
  118. gameDebug.print("PrivilegeBoss.incrementedPrivilegeBossCount now.sec:", now.sec)
  119. local activityRule = ConfigDataManager.getTable("cfg_activity_rule", "id", DuplicateType.PRIVILEGE_BOSS)
  120. local numberTime = activityRule[1]["numbertime"]
  121. if not string.isNullOrEmpty(numberTime) then
  122. local split = string.split(numberTime, "#")
  123. local type = tonumber(split[1])
  124. local numberTime1 = tonumber(split[2])
  125. if type == 1 then
  126. if numberTime1 == now.hour then
  127. this.countHandle()
  128. end
  129. else
  130. local numberTime2 = tonumber(split[3])
  131. if numberTime1 == now.wday and numberTime2 == now.hour then
  132. this.countHandle()
  133. end
  134. end
  135. end
  136. end
  137. end
  138. --- 特权BOSS挑战次数增加处理
  139. function this.countHandle()
  140. local allRoleInfos = getallrolesummaryinfos()
  141. if table.isNullOrEmpty(allRoleInfos) then
  142. return
  143. end
  144. for _, roleInfo in pairs(allRoleInfos) do
  145. local actor = roleInfo["actor"]
  146. -- 如果开通了任意特权,增加对应的挑战次数
  147. local currentCount = getleftcountofactivity(actor, DuplicateType.PRIVILEGE_BOSS)
  148. local numberAdd = ConfigDataManager.getTableValue("cfg_activity_rule", "numberadd", "id", DuplicateType.PRIVILEGE_BOSS)
  149. local countLimit = string.split(numberAdd, "#")[2]
  150. -- 如果使用了特权,增加对应的特权次数
  151. if PrivilegeMonth.hasAnyPrivilege(actor) then
  152. local incrementCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_PRIVILEGE_COUNT)
  153. if not (tonumber(currentCount) + tonumber(incrementCount) > tonumber(countLimit)) then
  154. -- 使用减少挑战次数接口传负数来实现增加次数
  155. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -incrementCount)
  156. end
  157. end
  158. currentCount = PrivilegeBoss.addCount(actor, PrivilegeBossCountType.GOLD_CARD, currentCount, countLimit)
  159. currentCount = PrivilegeBoss.addCount(actor, PrivilegeBossCountType.DIAMOND_CARD, currentCount, countLimit)
  160. currentCount = PrivilegeBoss.addCount(actor, PrivilegeBossCountType.VIP, currentCount, countLimit)
  161. end
  162. end
  163. --- 增长特权BOSS挑战次数
  164. ---@param actor table 玩家对象
  165. ---@param count number 增长次数
  166. ---@param type number 活动类型
  167. function PrivilegeBoss.addCount(actor, type, currentCount, countLimit)
  168. if not currentCount then
  169. currentCount = getleftcountofactivity(actor, DuplicateType.PRIVILEGE_BOSS)
  170. local numberAdd = ConfigDataManager.getTableValue("cfg_activity_rule", "numberadd", "id", DuplicateType.PRIVILEGE_BOSS)
  171. countLimit = string.split(numberAdd, "#")[2]
  172. end
  173. local countInit = getplaydef(actor, PlayerDefKey.privilegeBoss.COUNT_INIT)
  174. if string.isNullOrEmpty(countInit) then
  175. local initCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_PRIVILEGE_COUNT)
  176. -- 使用特权卡后初始化次数
  177. if PrivilegeMonth.hasAnyPrivilege(actor) then
  178. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -initCount)
  179. end
  180. -- 使用黄金特权卡后初始化次数
  181. if PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.GOLD1) then
  182. local incrementCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_GOLD_CARD)
  183. incrementCount = initCount + incrementCount
  184. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -incrementCount)
  185. end
  186. -- 使用钻石特权卡后初始化次数
  187. if PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.DIAMOND1) then
  188. local incrementCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_DIAMOND_CARD)
  189. incrementCount = initCount + incrementCount
  190. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -incrementCount)
  191. end
  192. -- 开启vip后初始化次数
  193. local isOpen, count = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.tqboss)
  194. if isOpen then
  195. count = initCount + count
  196. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -count)
  197. end
  198. setplaydef(actor, PlayerDefKey.privilegeBoss.COUNT_INIT, true)
  199. return
  200. end
  201. -- 如果使用了黄金特权卡,增加对应的挑战次数
  202. if type == PrivilegeBossCountType.GOLD_CARD and PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.GOLD1) then
  203. local incrementCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_GOLD_CARD)
  204. if not (tonumber(currentCount) + tonumber(incrementCount) > tonumber(countLimit)) then
  205. currentCount = currentCount + tonumber(incrementCount)
  206. -- 使用减少挑战次数接口传负数来实现增加次数
  207. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -incrementCount)
  208. end
  209. end
  210. -- 如果使用了钻石特权卡,增加对应的挑战次数
  211. if type == PrivilegeBossCountType.DIAMOND_CARD and PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.DIAMOND1) then
  212. local incrementCount = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.PRIVILEGE_BOSS_DIAMOND_CARD)
  213. if not (tonumber(currentCount) + tonumber(incrementCount) > tonumber(countLimit)) then
  214. currentCount = currentCount + tonumber(incrementCount)
  215. -- 使用减少挑战次数接口传负数来实现增加次数
  216. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -incrementCount)
  217. end
  218. end
  219. -- 如果开启了vip,增加对应的挑战次数
  220. if type == PrivilegeBossCountType.VIP then
  221. local isOpen, count = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.tqboss)
  222. if isOpen then
  223. if not (tonumber(currentCount) + tonumber(count) > tonumber(countLimit)) then
  224. currentCount = currentCount + tonumber(count)
  225. -- 使用减少挑战次数接口传负数来实现增加次数
  226. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, -count)
  227. end
  228. end
  229. end
  230. if tonumber(currentCount) > tonumber(countLimit) then
  231. reduceactivitytimes(actor, DuplicateType.PRIVILEGE_BOSS, tonumber(currentCount) - tonumber(countLimit))
  232. end
  233. return currentCount
  234. end
  235. --- 怪物掉落奖励面板
  236. ---@param actor table 玩家对象
  237. ---@param monsterCfgId number 怪物配置ID
  238. ---@param mapId number 地图ID
  239. ---@param dropResult number 掉落结果
  240. function PrivilegeBoss.resRewardPanel(actor, monsterCfgId, mapId, dropResult)
  241. if this.isPrivilegeBoss(monsterCfgId) and this.isPrivilegeMap(gamemap.parseMapKey(mapId)) then
  242. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, dropResult)
  243. end
  244. end
  245. --- 判断是否为特权BOSS
  246. ---@param monsterCfgId number 怪物配置ID
  247. ---@return boolean 是否为特权BOSS
  248. function this.isPrivilegeBoss(monsterCfgId)
  249. local id = gettablevalue("cfg_rep", "id", "monster", monsterCfgId, "type", DuplicateType.PRIVILEGE_BOSS)
  250. return not string.isNullOrEmpty(id)
  251. end
  252. --- 判断是否为特权BOSS副本
  253. ---@param mapId number 副本ID
  254. ---@return boolean 是否为特权BOSS副本
  255. function this.isPrivilegeMap(mapId)
  256. return mapId == DuplicateType.PRIVILEGE_BOSS
  257. end