WarAllianceBoss.lua 31 KB

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