WarAllianceBoss.lua 31 KB

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