WarAllianceBoss_1.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. -- 战盟拍卖相关全局表id
  2. local WarAllianceGlobalConfig = {
  3. REWARD_COUNT_LIMIT = 14001001, -- 奖励拍卖战盟数量限制
  4. AUCTION_DIVIDEND = 14001002, -- 分红比例
  5. PHRASE_AND_TRANS_POINT = 14001003, -- 层级和传送点
  6. KILL_BOSS_REWARD_EXP_CFGID = 14001004 -- 击杀boss获得的战盟经验奖励
  7. }
  8. local WarAllianceTaskPhrase = {
  9. ONE = 1,
  10. FIVE = 5
  11. }
  12. -- 战盟副本数据
  13. local WarAllianceConst = {
  14. KILL_MONSTER_COUNT = 2, -- 任务类型 杀指定怪
  15. WAR_ALLIANCE_DUP_HORSE_LAMP = 66, -- 战盟boss被击杀跑马灯id
  16. WAR_ALLIANCE_DUP_CHAT = 75, -- 战盟boss被击杀世界频道
  17. WAR_ALLIANCE_TYPE = 14001, -- 战盟boss任务活动类型
  18. WAR_ALLIANCE_DUP_TASK_INFO = "G$AllianceDupTaskInfo", -- 战盟副本任务信息
  19. WAR_ALLIANCE_DUP_BELONGS = "G$AllianceDupBelongs", -- 战盟地图归属
  20. WAR_ALLIANCE_DUP_TRANS_POINT = "G$AllianceDupTransPoint", -- 传送点信息
  21. WAR_ALLIANCE_PLAYER = "G$InvolovedPlayers", -- 进入过副本的玩家
  22. WAR_ALLIANCE_MONSTER_STATE = "G$MonsterState", -- 怪物状态
  23. WAR_ALLIANCE_CURR_MAX_LEVEL = "G$AllianceMaxLevel", -- 战盟共享的最高关卡进度,战盟进入下一个阶段跟新
  24. WAR_ALLIANCE_CAN_REWARD_ALLIANCES = "G$CanRewardAlliances", -- 前n个可以领取奖励的战盟
  25. WAR_ALLIANCE_BOSS_HURT = "G$CuseDamage" -- 对战盟boss造成过伤害的玩家
  26. }
  27. -- 战盟玩家变量
  28. local WarAlliancePlayerConst = {
  29. MY_ALLIANCE_MAP_INFO = "J$MyAllianceMapInfo"
  30. }
  31. -- 拍卖玩家变量
  32. local AuctionConst = {
  33. AUCTION_WAY = 1, -- 战盟boss全部可拍卖物品ID
  34. AUCTION_DIVIDE_EMAIL = 106012 -- 拍卖分红邮件
  35. }
  36. WarAlliance = {}
  37. function WarAlliance.WarAllianceStateUpdate(system, mapId, state, nextStateStartTime, configId)
  38. if state == DuplicateState.PREPARE then
  39. WarAlliance.InitWarAllianceTaskInfo(mapId, configId)
  40. elseif state == DuplicateState.FIGHT then
  41. local monsterId = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", configId)
  42. DuplicateCommon.DupGenMonsterCommon(mapId, monsterId)
  43. WarAlliance.ResAllPlayCurrencyStateInfo(mapId)
  44. elseif state == DuplicateState.FINISH then
  45. -- lg("清除所有个人副本信息key", key)
  46. local involvedAactors = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_PLAYER) or {}
  47. if involvedAactors == "" then
  48. involvedAactors = {}
  49. end
  50. -- lg("要清除信息的involvedAactors", involvedAactors)
  51. for i = 1, #involvedAactors do
  52. local thisActor = involvedAactors[i]
  53. setplaydef(thisActor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO, {})
  54. end
  55. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_PLAYER, {})
  56. WarAlliance.ResAllPlayCurrencyStateInfo(mapId)
  57. end
  58. end
  59. -- @description 初始化副本数据
  60. function WarAlliance.InitWarAllianceTaskInfo(mapId, configId)
  61. --初始化任务信息
  62. local taskId = ConfigDataManager.getTableValue("cfg_rep", "reptarget", "id", configId)
  63. local taskInfo = DuplicateCommon.GenDupTaskInfoCommon(taskId)
  64. table.insert(taskInfo, 1, WarAllianceTaskPhrase.ONE)
  65. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO, taskInfo)
  66. WarAlliance.ResAllTaskPhaseUpdate(mapId)
  67. end
  68. -- @description 客户端请求面板数据
  69. function WarAlliance.GetWarAlliancePanelInfo(actor, msgData)
  70. local configId = tonumber(msgData["configId"])
  71. if configId == nil or configId <= 0 then
  72. -- 拿到距离开服的天数最近的副本cfgid
  73. local severOpenDays = getbaseinfo(actor, "serveropendays")
  74. configId = WarAlliance.GetShouldEnterDupCfgId(severOpenDays)
  75. end
  76. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  77. local leftCount = getleftcountofactivity(actor, activityId)
  78. local activityInfo = getactivityinfo(activityId)
  79. local isOpen = activityInfo["open"]
  80. local nextOpenTime
  81. if isOpen then
  82. nextOpenTime = activityInfo["closetime"]
  83. else
  84. nextOpenTime = activityInfo["nextopentime"]
  85. end
  86. -- 战盟的进度
  87. local maxLevels = getsysvar(actor, WarAllianceConst.WAR_ALLIANCE_CURR_MAX_LEVEL) or {}
  88. if maxLevels == "" then
  89. maxLevels = {}
  90. end
  91. local allianceId = getbaseinfo(actor, "guildid")
  92. local maxLevel = maxLevels[allianceId] or 0
  93. local resInfo = {configId, leftCount, isOpen, tostring(nextOpenTime), maxLevel}
  94. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_BOSS_PANEL, resInfo)
  95. end
  96. -- 进入副本之后响应一些数据
  97. function WarAlliance.AfterEnterWarAlliance(actor, mapId, state, nextStateStartTime, configId)
  98. info(actor, actor, "玩家进入战盟boss")
  99. local playerDupInfo = getplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO)
  100. local newEnter = false
  101. if playerDupInfo == nil or playerDupInfo == "" or next(playerDupInfo) == nil then
  102. newEnter = true
  103. else
  104. local lastMapId = playerDupInfo[1]
  105. if mapId ~= lastMapId then
  106. newEnter = true
  107. end
  108. end
  109. if newEnter == true then
  110. clearallbuff(actor)
  111. sethp(actor, getattrinfo(actor, "maxHP"))
  112. setmp(actor, getattrinfo(actor, "maxMP"))
  113. clearallskillcd(actor)
  114. end
  115. -- 进入新的副本,初始化玩家变量
  116. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  117. local nowPhrase = taskInfo[1] -- 当前玩家自己所在的副本阶段,相对于总任务阶段
  118. local position = nowPhrase -- 玩家当前所在第几层位置
  119. playerDupInfo = {mapId, configId, nowPhrase, position}
  120. setplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO, playerDupInfo)
  121. local players = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_PLAYER) or {}
  122. if players == "" then
  123. players = {}
  124. end
  125. local hasRecord = false
  126. for _, player in ipairs(players) do
  127. if player:toString() == actor:toString() then
  128. hasRecord = true
  129. break
  130. end
  131. end
  132. if not hasRecord then
  133. table.insert(players, actor)
  134. end
  135. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_PLAYER, players)
  136. WarAlliance.ResCurrencyStateInfo(actor, mapId)
  137. WarAlliance.ResTaskPhaseUpdate(actor, mapId)
  138. end
  139. -- @description 请求进入战盟boss活动
  140. function WarAlliance.ReqEnterWarAlliance(actor, msgData)
  141. if WarAlliance.isWarAlliance(actor) then
  142. tipinfo(actor, "您已经在战盟boss挑战中")
  143. return
  144. end
  145. local configId = msgData["configId"]
  146. if configId == nil then
  147. local severOpenDays = getbaseinfo(actor, "serveropendays")
  148. configId = WarAlliance.GetShouldEnterDupCfgId(severOpenDays)
  149. end
  150. -- 检查是否满足战盟boss进入条件
  151. if not WarAlliance.CanEnterWarAlliance(actor, configId) then
  152. noticeTip.noticeinfo(actor, StringIdConst.TEXT393)
  153. return
  154. end
  155. -- 通用检查
  156. if DuplicateCommon.CheckEnterConditonCommon(actor, configId) ~= EnterLimitResultConst.ALLOW then
  157. tipinfo(actor, "战盟boss副本进入条件不满足")
  158. return
  159. end
  160. -- 寻找是否有可进入的副本,如果没有创建副本
  161. local mapId = WarAlliance.FindEnterableDup(actor, configId, 1)
  162. local x, y
  163. if mapId ~= 0 then
  164. -- 找到一个已经有的,判断如果不是一阶段,传送点应该是前一个阶段的目标传送点
  165. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  166. if taskInfo then
  167. local nowPhrase = taskInfo[1]
  168. if nowPhrase > 1 then
  169. -- 前一个阶段
  170. nowPhrase = nowPhrase - 1
  171. local transferPointInfo = WarAlliance.GetShouldEnteredPoint(nowPhrase)
  172. if transferPointInfo == nil then
  173. error("战盟boss传送点未找到")
  174. return
  175. end
  176. local targetPonit = transferPointInfo["targetposition"]
  177. local targetXY = string.splitByAll(targetPonit, "#")
  178. -- lg("进入地图寻找点", nowPhrase, targetXY[1], targetXY[2])
  179. x, y = tonumber(targetXY[1]), tonumber(targetXY[2])
  180. else
  181. x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
  182. end
  183. end
  184. else
  185. x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
  186. end
  187. if mapId == 0 then
  188. mapId = DuplicateCommon.CreateDupMapCommon(actor, configId, true)
  189. end
  190. WarAlliance.PlayerEnterWarAlliance(actor, mapId, x, y, configId)
  191. end
  192. function WarAlliance.isWarAlliance(actor)
  193. local mapId = getbaseinfo(actor, "unimapid")
  194. local dupInfo = getduplicate(mapId)
  195. if not dupInfo then
  196. return false
  197. end
  198. local type = dupInfo["type"]
  199. if type ~= DuplicateType.WAR_ALLIANCE then
  200. return false
  201. end
  202. return true
  203. end
  204. -- 进入副本根据当前阶段获取进入的坐标
  205. function WarAlliance.GetShouldEnteredPoint(nowPhrase)
  206. local transferInfo =
  207. ConfigDataManager.getTableValue("cfg_repglobal", "value", "id", WarAllianceGlobalConfig.PHRASE_AND_TRANS_POINT)
  208. if transferInfo == "" then
  209. error("战盟boss传送点未找到")
  210. return
  211. end
  212. -- 获取传送点
  213. local nowTransferPointId
  214. local phraseAndPoints = string.splitByAll(transferInfo, "|")
  215. for _, phraseAndPoint in ipairs(phraseAndPoints) do
  216. local phraseAndPointInfo = string.splitByAll(phraseAndPoint, "#")
  217. local phrase = tonumber(phraseAndPointInfo[1])
  218. if phrase == nowPhrase then
  219. nowTransferPointId = tonumber(phraseAndPointInfo[2])
  220. end
  221. end
  222. local transferPointInfos = ConfigDataManager.getTable("cfg_transfer_point", "id", nowTransferPointId)
  223. if next(transferPointInfos) == nil then
  224. error("战盟boss传送点未找到")
  225. return
  226. end
  227. local transferPointInfo = transferPointInfos[1]
  228. return transferPointInfo
  229. end
  230. -- 根据开服天数获取应该进入的副本配置rep_id
  231. function WarAlliance.GetShouldEnterDupCfgId(openDays)
  232. local configId =
  233. ConfigDataManager.getTableValue("cfg_rep", "id", "type", DuplicateType.WAR_ALLIANCE, "startday", openDays)
  234. if configId ~= "" and type ~= nil then
  235. return tonumber(configId)
  236. end
  237. local lines = ConfigDataManager.getTable("cfg_rep", "type", DuplicateType.WAR_ALLIANCE)
  238. local findLine
  239. local maxDay = 0
  240. for _, line in ipairs(lines) do
  241. local day = tonumber(line["startday"])
  242. if day > maxDay then
  243. findLine = line
  244. maxDay = day
  245. end
  246. end
  247. if findLine then
  248. configId = findLine["id"]
  249. return tonumber(configId)
  250. end
  251. error("找不到对应的任务关卡配置")
  252. end
  253. -- 根据当前战盟的击杀层数和副本cfgid,找到应该去的任务配置
  254. function WarAlliance.FindShouldEnterDupByLevel(level, cfgId)
  255. local nextId = ConfigDataManager.getTableValue("cfg_repTask", "nextid", "id", cfgId)
  256. if nextId == "" or nextId == nil then
  257. return cfgId
  258. end
  259. nextId = tonumber(nextId)
  260. level = level - 1
  261. if level == 0 then
  262. return nextId
  263. end
  264. return WarAlliance.FindShouldEnterDupByLevel(level, nextId)
  265. end
  266. -- 尝试找出一个本战盟且可进入的副本
  267. function WarAlliance.FindEnterableDup(actor, configId, needSize)
  268. local warAllianceId = getbaseinfo(actor, "guildid")
  269. local mapId = 0
  270. local maxSize = ConfigDataManager.getTableValue("cfg_rep", "warNumMax", "id", configId)
  271. if maxSize == "" or tonumber(maxSize) <= 0 then
  272. local alliance = getunioninfo(actor)
  273. maxSize = alliance["maxnum"]
  274. end
  275. local type = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  276. local existDupList = getduplicatelist(type)
  277. for index, dupInfo in ipairs(existDupList) do
  278. local players = dupInfo["players"]
  279. local state = dupInfo["state"]
  280. local dupConfig = dupInfo["dupcfgid"]
  281. local leftSize = tonumber(maxSize) - #players
  282. local currMapId = dupInfo["id"]
  283. local currBelongsAllianceId = getenvirvar(currMapId, WarAllianceConst.WAR_ALLIANCE_DUP_BELONGS) or 0
  284. if
  285. (state == DuplicateState.PREPARE or state == DuplicateState.FIGHT) and leftSize >= needSize and
  286. tonumber(dupConfig) == tonumber(configId) and
  287. warAllianceId == currBelongsAllianceId
  288. then
  289. mapId = currMapId
  290. break
  291. end
  292. end
  293. return mapId
  294. end
  295. -- @description 玩家能否进入战盟boss活动
  296. function WarAlliance.CanEnterWarAlliance(actor, configId)
  297. -- 检查活动是否开启
  298. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  299. local activityInfo = getactivityinfo(activityId)
  300. if not activityInfo["open"] then
  301. return false
  302. end
  303. -- 检查是否拥有战盟
  304. local warAllianceId = getbaseinfo(actor, "guildid")
  305. if warAllianceId == 0 then
  306. return false
  307. end
  308. return true
  309. end
  310. -- @description 玩家传送进战盟boss活动
  311. function WarAlliance.PlayerEnterWarAlliance(actor, mapId, x, y, configId)
  312. -- 把这个副本设置为战盟专属
  313. WarAlliance.SetDupBelongs(actor, mapId)
  314. -- 强制战斗模式为战盟
  315. setplayersetting(actor, 1, 5)
  316. -- 扣除次数
  317. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  318. reduceactivitytimes(actor, activityId)
  319. enterduplicate(actor, mapId, x, y)
  320. end
  321. -- 设置战盟专属副本
  322. function WarAlliance.SetDupBelongs(actor, mapId)
  323. local currBelongsAllianceId = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_BELONGS)
  324. local allianceId = getbaseinfo(actor, "guildid")
  325. if not currBelongsAllianceId then
  326. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_BELONGS, allianceId)
  327. end
  328. end
  329. -- @description 玩家击杀战盟boss
  330. function WarAlliance.OnKillWarAllianceMonster(mapId, killer, monCfgId, monActor)
  331. if mapId <= 0 then
  332. return
  333. end
  334. local dupInfo = getduplicate(mapId)
  335. if dupInfo == nil or next(dupInfo) == nil then
  336. return
  337. end
  338. local dupType = dupInfo["type"]
  339. if dupType ~= WarAllianceConst.WAR_ALLIANCE_TYPE then
  340. return
  341. end
  342. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  343. -- lg("怪物死亡taskInfo", taskInfo)
  344. local taskId = taskInfo[2]
  345. local taskType = taskInfo[3]
  346. if taskType == WarAllianceConst.KILL_MONSTER_COUNT then
  347. local totalCount = taskInfo[4]
  348. local oldCount = taskInfo[5]
  349. local newCount = oldCount + 1
  350. if newCount >= totalCount then
  351. WarAlliance.UpdateOwnTaskInfo(killer, taskInfo, taskId, totalCount, newCount, dupInfo)
  352. -- 怪物死亡数量,单独记录是因为最后一阶段不会更新任务信息
  353. -- 根据怪物死亡数给新进的玩家推送最后一层信息
  354. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_MONSTER_STATE, newCount)
  355. WarAlliance.UpdateNextTaskPhrase(mapId, taskId, killer)
  356. else
  357. -- 更新任务
  358. taskInfo[5] = newCount
  359. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO, taskInfo)
  360. WarAlliance.ResAllTaskPhaseUpdate(mapId)
  361. end
  362. end
  363. -- 战盟经验奖励
  364. WarAlliance.GiveRewardToAlliance(killer)
  365. local allianceName = getbaseinfo(killer, "guildname")
  366. local bossName = ConfigDataManager.getTableValue("cfg_monster", "name", "id", monCfgId)
  367. noticeTip.noticeinfo(killer, WarAllianceConst.WAR_ALLIANCE_DUP_HORSE_LAMP, allianceName, bossName)
  368. noticeTip.noticeinfo(killer, WarAllianceConst.WAR_ALLIANCE_DUP_CHAT, allianceName, bossName)
  369. end
  370. function WarAlliance.UpdateOwnTaskInfo(killer, taskInfo, taskId, totalCount, newCount, dupInfo)
  371. local nowPhrase = taskInfo[1]
  372. local response = {}
  373. response["phrase"] = nowPhrase
  374. response["taskId"] = taskId
  375. response["nowCount"] = newCount
  376. response["totalCount"] = totalCount
  377. local playerMapInfo = getplaydef(killer, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO) or {}
  378. response["position"] = playerMapInfo[4]
  379. local myPhrase = playerMapInfo[3] + 1 > 5 and 5 or playerMapInfo[3] + 1
  380. response["myCurrPhrase"] = myPhrase
  381. local players = dupInfo["players"]
  382. for index, actor in ipairs(players) do
  383. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_TASK_INFO, response)
  384. end
  385. end
  386. -- 战盟经验奖励
  387. function WarAlliance.GiveRewardToAlliance(actor)
  388. local itemAndCount =
  389. ConfigDataManager.getTableValue(
  390. "cfg_repglobal",
  391. "value",
  392. "id",
  393. WarAllianceGlobalConfig.KILL_BOSS_REWARD_EXP_CFGID
  394. )
  395. if itemAndCount ~= "" and itemAndCount ~= nil then
  396. local item = string.splitByAll(itemAndCount, "#")[1]
  397. local count = string.splitByAll(itemAndCount, "#")[2]
  398. Bag.addItemToBag(actor, tonumber(item), tonumber(count), 0, 9999, "战盟BOSS")
  399. end
  400. end
  401. -- @description 更新下一关任务,
  402. function WarAlliance.UpdateNextTaskPhrase(mapId, taskId, actor)
  403. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  404. local nextTaskId = ConfigDataManager.getTableValue("cfg_repTask", "nextid", "id", taskId)
  405. -- lg("下一关任务id:", nextTaskId)
  406. if nextTaskId == nil or nextTaskId == "" then
  407. -- 后进游戏的玩家要发上一个阶段的任务信息,下一个阶段的任务信息虽然已经存了
  408. -- 但是还没开始发放,页面显示的还是上一个阶段的任务信息,只有怪物数变了
  409. local monsterDieCount = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_MONSTER_STATE) or 0
  410. if monsterDieCount ~= 0 then
  411. taskInfo[5] = tonumber(monsterDieCount)
  412. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO, taskInfo)
  413. end
  414. end
  415. local nowPhrase = taskInfo[1]
  416. -- 保存共享的关卡进度
  417. local guild = getmyguild(actor)
  418. local allianceId = tonumber(guild:toString())
  419. local maxLevels = getsysvar(actor, WarAllianceConst.WAR_ALLIANCE_CURR_MAX_LEVEL) or {}
  420. if maxLevels == "" then
  421. maxLevels = {}
  422. end
  423. maxLevels[allianceId] = nowPhrase
  424. setsysvar(actor, WarAllianceConst.WAR_ALLIANCE_CURR_MAX_LEVEL, maxLevels)
  425. --最后一个阶段,有N个战盟到达最后关,开启拍卖行
  426. if nowPhrase == WarAllianceTaskPhrase.FIVE then
  427. local canReward = getsysvar(actor, WarAllianceConst.WAR_ALLIANCE_CAN_REWARD_ALLIANCES) or {}
  428. if canReward == "" then
  429. canReward = {}
  430. end
  431. local count = #canReward
  432. local limit =
  433. ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", WarAllianceGlobalConfig.REWARD_COUNT_LIMIT)
  434. limit = tonumber(limit)
  435. if count == limit then
  436. -- info("战盟boss拍卖名额已满", actor:toString())
  437. return
  438. end
  439. local hasRecord = WarAlliance.HasRecord(canReward, allianceId)
  440. if count < limit and (not hasRecord) then
  441. table.insert(canReward, guild)
  442. count = #canReward
  443. setsysvar(actor, WarAllianceConst.WAR_ALLIANCE_CAN_REWARD_ALLIANCES, canReward)
  444. taskInfo[7] = true
  445. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO, taskInfo)
  446. -- 外置竞拍行
  447. local hasDamgeInfos = getsysvar(actor, WarAllianceConst.WAR_ALLIANCE_BOSS_HURT) or {}
  448. local myHurtMember = hasDamgeInfos[allianceId] or {}
  449. -- info("战盟boss开启拍卖行,战盟id:", allianceId, "本战盟伤害列表:", myHurtMember,"所有战盟列表:", canReward)
  450. Auction.NoticeClientToStartAuction(actor, allianceId, myHurtMember, canReward)
  451. WarAlliance.FlushActivity(actor)
  452. return
  453. end
  454. WarAlliance.FlushActivity(actor)
  455. return
  456. end
  457. WarAlliance.transferAndflushTask(actor, mapId, taskInfo, nextTaskId)
  458. end
  459. function WarAlliance.HasRecord(canReward, allianceId)
  460. for _, guild in ipairs(canReward) do
  461. if tonumber(guild:toString()) == allianceId then
  462. return true
  463. end
  464. end
  465. return false
  466. end
  467. function WarAlliance.FlushActivity(actor)
  468. local severOpenDays = getbaseinfo(actor, "serveropendays")
  469. local configId = WarAlliance.GetShouldEnterDupCfgId(severOpenDays)
  470. DuplicateCommon.FinishDupActivity(actor, configId)
  471. end
  472. -- 准备传送数据,更新任务
  473. function WarAlliance.transferAndflushTask(actor, mapId, taskInfo, nextTaskId)
  474. -- 任务阶段
  475. local nowPhrase = taskInfo[1]
  476. local transferPointInfo = WarAlliance.GetShouldEnteredPoint(nowPhrase)
  477. if transferPointInfo == nil then
  478. error("战盟boss传送点未找到")
  479. return
  480. end
  481. local targetMapCfgId = transferPointInfo["targetid"]
  482. local showPonit = transferPointInfo["position"]
  483. local showXY = string.splitByAll(showPonit, "#")
  484. local targetPonit = transferPointInfo["targetposition"]
  485. local targetXY = string.splitByAll(targetPonit, "#")
  486. local targetPointInfo = {
  487. showXY = showXY,
  488. targetXY = targetXY,
  489. targetMapCfgId = targetMapCfgId
  490. }
  491. -- 保存传送目标点信息
  492. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TRANS_POINT, targetPointInfo)
  493. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_OPEN_TRANSFER, {showXY = showXY})
  494. -- 刷怪
  495. DuplicateCommon.DupGenMonsterCommon(mapId, nextTaskId)
  496. -- 设置更新下一个任务
  497. local nextPhrase = nowPhrase + 1
  498. local nextTaskInfo = DuplicateCommon.GenDupTaskInfoCommon(nextTaskId)
  499. table.insert(nextTaskInfo, 1, nextPhrase)
  500. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO, nextTaskInfo)
  501. end
  502. function WarAlliance.CheckTransfer(actor, currX, currY, x, y)
  503. local mapId = getbaseinfo(actor, "unimapid")
  504. local dupInfo = getduplicate(mapId)
  505. if not dupInfo then
  506. return nil
  507. end
  508. if tonumber(dupInfo["activityid"]) == WarAllianceConst.WAR_ALLIANCE_TYPE then
  509. local targetPointInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TRANS_POINT)
  510. if targetPointInfo == nil or next(targetPointInfo) == nil or targetPointInfo == "" then
  511. return {result = true, reason = "传送点信息为空", ignoreNotice = true}
  512. end
  513. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  514. local nowPhrase = taskInfo[1]
  515. local playerMapInfo = getplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO) or {}
  516. if playerMapInfo == "" then
  517. playerMapInfo = {}
  518. end
  519. local position = playerMapInfo[4]
  520. if nowPhrase == playerMapInfo[3] and nowPhrase == position then
  521. return {result = true, reason = "同一层不执行传送", ignoreNotice = true}
  522. end
  523. -- 计算自己当前层数时和传送点位置的距离
  524. local myPointInfo = WarAlliance.GetShouldEnteredPoint(position) or {}
  525. local showPonit = myPointInfo["position"]
  526. local showXY = string.splitByAll(showPonit, "#")
  527. local distance =
  528. math.abs(tonumber(currX) - tonumber(showXY[1])) ^ 2 + math.abs(tonumber(currY) - tonumber(showXY[2])) ^ 2
  529. if distance > 9 then
  530. return {result = true, reason = "不在传送点附近,不能传送", ignoreNotice = true}
  531. end
  532. return WarAlliance.DoTransferAndFlushTask(actor, nowPhrase, playerMapInfo)
  533. end
  534. return {result = true, reason = "该副本内传送", ignoreNotice = true}
  535. end
  536. -- 执行传送和任务回包
  537. function WarAlliance.DoTransferAndFlushTask(actor, nowPhrase, playerMapInfo)
  538. local mapId = getbaseinfo(actor, "unimapid")
  539. local targetPointInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TRANS_POINT)
  540. local targetXY = targetPointInfo["targetXY"]
  541. local targetMapCfgId = targetPointInfo["targetMapCfgId"]
  542. -- info("战盟boss传送", actor:toString(), targetXY[1],targetXY[2], targetMapCfgId)
  543. maptransfer(actor, tonumber(targetXY[1]), tonumber(targetXY[2]), tonumber(targetMapCfgId))
  544. local myPhrase = playerMapInfo[3] or 1
  545. if nowPhrase > myPhrase then
  546. playerMapInfo[3] = nowPhrase
  547. end
  548. -- local position = playerMapInfo[4] or 1
  549. playerMapInfo[4] = math.max(myPhrase, nowPhrase)
  550. setplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO, playerMapInfo)
  551. -- 设置怪物死亡数量为零
  552. local monsterState = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_MONSTER_STATE)
  553. if monsterState ~= 0 then
  554. setenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_MONSTER_STATE, 0)
  555. end
  556. WarAlliance.ResTaskPhaseUpdate(actor, mapId)
  557. return {result = true, reason = "战盟boss副本内传送", ignoreNotice = true}
  558. end
  559. -- @description 通知地图所有玩家更新当前阶段
  560. function WarAlliance.ResAllPlayCurrencyStateInfo(mapId)
  561. local dupInfo = getduplicate(mapId)
  562. local players = dupInfo["players"]
  563. for index, actor in ipairs(players) do
  564. WarAlliance.ResCurrencyStateInfo(actor, mapId)
  565. end
  566. end
  567. -- @description 响应给客户端当前阶段
  568. function WarAlliance.ResCurrencyStateInfo(actor, mapId)
  569. local dupInfo = getduplicate(mapId)
  570. local state = dupInfo["state"]
  571. local configId = dupInfo["dupcfgid"]
  572. local nextStateStartTime = dupInfo["nextstatetime"]
  573. -- lg("当前阶段信息:", { state, tostring(nextStateStartTime), configId })
  574. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_STATE_INFO, {state, tostring(nextStateStartTime), configId})
  575. end
  576. -- @description 通知地图玩家任务阶段更新响应
  577. function WarAlliance.ResAllTaskPhaseUpdate(mapId)
  578. local dupInfo = getduplicate(mapId)
  579. local players = dupInfo["players"]
  580. for index, actor in ipairs(players) do
  581. WarAlliance.ResTaskPhaseUpdate(actor, mapId)
  582. end
  583. end
  584. -- @description 任务阶段更新响应
  585. function WarAlliance.ResTaskPhaseUpdate(actor, mapId)
  586. local playerMapInfo = getplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO) or {}
  587. local myPhrase = playerMapInfo[3] or 1
  588. local position = playerMapInfo[4] or 1
  589. local taskInfo = getenvirvar(mapId, WarAllianceConst.WAR_ALLIANCE_DUP_TASK_INFO)
  590. -- lg("任务阶段更新信息:", taskInfo)
  591. local nowPhrase = taskInfo[1]
  592. local taskId = taskInfo[2]
  593. local totalCount = taskInfo[4]
  594. local nowCount = taskInfo[5]
  595. local response = {}
  596. response["phrase"] = nowPhrase
  597. response["taskId"] = taskId
  598. response["nowCount"] = nowCount
  599. response["totalCount"] = totalCount
  600. response["myCurrPhrase"] = myPhrase
  601. response["position"] = position
  602. local openedGoods = taskInfo[7] or false
  603. if openedGoods then
  604. local goods = Auction.GetSomeGoods(actor, {0, 0, 0, 0, 0, 0}, true)
  605. if #goods > 0 then
  606. response["goAuction"] = true
  607. end
  608. end
  609. -- lg(response)
  610. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_TASK_INFO, response)
  611. end
  612. -- 记录造成伤害的玩家,用来分红
  613. function WarAlliance.savePlayerInvloveInfo(caster, target, hurt, monsterId)
  614. if hurt <= 0 then
  615. return
  616. end
  617. local allianceId = getbaseinfo(caster, "guildid")
  618. if allianceId == 0 then
  619. return
  620. end
  621. local mapId = getbaseinfo(caster, "unimapid")
  622. local dupInfo = getduplicate(mapId)
  623. if not dupInfo then
  624. return
  625. end
  626. local activityId = dupInfo["activityid"]
  627. if activityId ~= WarAllianceConst.WAR_ALLIANCE_TYPE then
  628. return
  629. end
  630. local openDays = getbaseinfo(caster, "serveropendays")
  631. local dupId = WarAlliance.GetShouldEnterDupCfgId(openDays)
  632. local firstLevelCfgId = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", dupId)
  633. -- 判断target是否为战盟boss怪物
  634. local bosses = {}
  635. WarAlliance.getBosses(bosses, tonumber(firstLevelCfgId))
  636. for i = 1, #bosses do
  637. if tonumber(monsterId) == tonumber(bosses[i]) then
  638. -- 1.判断是否开启了拍卖,开启过了不记录
  639. local canReward = getsysvar(caster, WarAllianceConst.WAR_ALLIANCE_CAN_REWARD_ALLIANCES) or {}
  640. if canReward == "" then
  641. canReward = {}
  642. end
  643. local count = #canReward
  644. local limit =
  645. ConfigDataManager.getTableValue(
  646. "cfg_repGlobal",
  647. "value",
  648. "id",
  649. WarAllianceGlobalConfig.REWARD_COUNT_LIMIT
  650. )
  651. limit = tonumber(limit)
  652. if count >= limit then
  653. return
  654. end
  655. if WarAlliance.HasRecord(canReward, allianceId) then
  656. return
  657. end
  658. -- 2.判断caster是否记录过
  659. local hasDamgeInfos = getsysvar(caster, WarAllianceConst.WAR_ALLIANCE_BOSS_HURT) or {}
  660. if hasDamgeInfos == "" then
  661. hasDamgeInfos = {}
  662. end
  663. local myAllianceDamgeMembers = hasDamgeInfos[allianceId] or {}
  664. local hasDamge = array.contains(myAllianceDamgeMembers, caster:toString())
  665. if not hasDamge then
  666. -- info("战盟boss记录伤害,战盟id:" , allianceId , ",玩家id:" , caster:toString())
  667. table.insert(myAllianceDamgeMembers, caster:toString())
  668. hasDamgeInfos[allianceId] = myAllianceDamgeMembers
  669. setsysvar(caster, WarAllianceConst.WAR_ALLIANCE_BOSS_HURT, hasDamgeInfos)
  670. end
  671. end
  672. end
  673. end
  674. function WarAlliance.getBosses(bosses, repMonsterCfgId)
  675. local monsterInfo = ConfigDataManager.getTableValue("cfg_repmonster", "monster", "id", repMonsterCfgId)
  676. local monster = string.splitByAll(monsterInfo, "#")[1]
  677. if not array.contains(bosses, monster) then
  678. table.insert(bosses, monster)
  679. end
  680. local nextRepMonsterCfgId = ConfigDataManager.getTableValue("cfg_repmonster", "nextid", "id", repMonsterCfgId)
  681. if nextRepMonsterCfgId ~= "" and tonumber(nextRepMonsterCfgId) > 0 then
  682. WarAlliance.getBosses(bosses, nextRepMonsterCfgId)
  683. end
  684. end
  685. function WarAlliance.ClearThisTimeGameData()
  686. local time = TimeUtil.timeFormat(getbaseinfo("nowsec"))
  687. -- info("清除本次战盟副本数据,时间:" , time)
  688. setsysvar(WarAllianceConst.WAR_ALLIANCE_BOSS_HURT, {})
  689. setsysvar(WarAllianceConst.WAR_ALLIANCE_CURR_MAX_LEVEL, {})
  690. setsysvar(WarAllianceConst.WAR_ALLIANCE_CAN_REWARD_ALLIANCES, {})
  691. end
  692. --- 退出副本
  693. function WarAlliance.reqExitWarAlliance(actor)
  694. -- local mapId = getbaseinfo(actor, "unimapid")
  695. -- local dupInfo = getduplicate(mapId)
  696. -- if dupInfo then
  697. -- quitduplicate(actor)
  698. -- sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_EXIT, {})
  699. -- end
  700. quitduplicate(actor)
  701. sendluamsg(actor, LuaMessageIdToClient.RES_WAR_ALLIANCE_EXIT, {})
  702. end
  703. --- 玩家复活后发送战盟BOSS任务状态
  704. function WarAlliance.playerRelive(actor, reviveType)
  705. local mapId = getbaseinfo(actor, "unimapid")
  706. local dupInfo = getduplicate(mapId)
  707. if dupInfo == nil then
  708. return
  709. end
  710. local type = dupInfo["type"]
  711. if type ~= DuplicateType.WAR_ALLIANCE then
  712. return
  713. end
  714. local playerMapInfo = getplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO) or {}
  715. if reviveType ~= 3 then
  716. playerMapInfo[4] = 1
  717. end
  718. setplaydef(actor, WarAlliancePlayerConst.MY_ALLIANCE_MAP_INFO, playerMapInfo)
  719. WarAlliance.ResTaskPhaseUpdate(actor, mapId)
  720. end