UnionEctypeLogic.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. -------------------------------------------------------
  2. -- 公会副本
  3. -- db.ectypeCnt 挑战次数
  4. -- db.killEctype 击杀奖励领取标记
  5. -- db.unionThing = { likeTime , likeCnt : 点赞时间 点赞 次数 }
  6. -- 每天可挑战4次,挑战失败进入CD(16小时),可花钻石跳过
  7. -------------------------------------------------------
  8. local MonsterExcel = require("excel.monster")
  9. local CommonDB = require("common.CommonDB")
  10. local Config = require("Config")
  11. local Lang = require("common.Lang")
  12. local FilterUtil = require("common.FilterUtil")
  13. local UnionDBLogic = require("union.UnionDBLogic")
  14. local UnionExcel = require("excel.union")
  15. local MailManager = require("mail.MailManager")
  16. local MailExcel = require("excel.mail")
  17. local RoleDBLogic = require("role.RoleDBLogic")
  18. local Msg = require("core.Msg")
  19. local Broadcast = require("broadcast.Broadcast")
  20. local ObjHuman = require("core.ObjHuman")
  21. local Util = require("common.Util")
  22. local Grid = require("bag.Grid")
  23. local CombatLogic = require("combat.CombatLogic")
  24. local CombatImpl = require("combat.CombatImpl")
  25. local BossLogic = require("boss.BossLogic")
  26. local BossDBLogic = require("boss.BossDBLogic")
  27. local CombatDefine = require("combat.CombatDefine")
  28. local CombatObj = require("combat.CombatObj")
  29. local BagLogic = require("bag.BagLogic")
  30. local RoleDefine = require("role.RoleDefine")
  31. local RoleLogic = require("role.RoleLogic")
  32. local CombatPosLogic = require("combat.CombatPosLogic")
  33. local UnionDefine = require("union.UnionDefine")
  34. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  35. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  36. local ChatUnion = require("chat.ChatUnion")
  37. local MoshouLogic = require("moshou.MoshouLogic")
  38. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  39. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  40. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  41. local LiLianLogic = require("dailyTask.LiLianLogic")
  42. local UnionLogic = require("union.UnionLogic")
  43. local CombatPosExcel = require("excel.combatPos")
  44. local UnionLivenessLogic = require("union.UnionLivenessLogic")
  45. local UnionDefine = require("union.UnionDefine")
  46. local MailDefine = require("mail.MailIdDefine")
  47. local MengxinLogic = require("present.MengxinLogic")
  48. local YunYingLogic = require("yunying.YunYingLogic")
  49. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  50. local TriggerLogic = require("trigger.TriggerLogic")
  51. local TriggerDefine = require("trigger.TriggerDefine")
  52. UNION_ECTYPE_LIKE_MAX = 3 -- 公会副本 点赞每日最大次数
  53. UNION_ECTYPE_FREE_CNT = 3 -- 公会副本 每日免费挑战次数
  54. UNION_ECTYPE_JIJIE_TIME = 60 * 60
  55. FIGHT_MAX_CNT = 4
  56. local PAGE_PER_CNT = 9
  57. local FIGHT_FAIL_CD = 16 * 3600
  58. local FIGHT_COST_ZUANSHI = {0, 0, 0, 20, 30, 40, 60, 80, 100}
  59. local STATU_BOSS_DIE = 0
  60. local STATU_BOSS_ING = 1
  61. local STATU_BOSS_READY = 2
  62. local CLAN_ORDER_TYPE = 3
  63. -- 初始化副本
  64. -- unionUuid 公会Uuid
  65. -- level 关卡等级
  66. function initEctype(unionUuid, level)
  67. local conf = UnionExcel.ectype[level]
  68. if not conf then return end
  69. local monsterOutID = conf.monsterOutID
  70. local mapID = conf.mapID
  71. local cbParam = {}
  72. cbParam.level = level
  73. return BossDBLogic.createBossData(BossDBLogic.BOSS_TYPE_UNION, unionUuid, monsterOutID, mapID, cbParam)
  74. end
  75. -- 获取副本头像
  76. local function getBossHead(conf)
  77. local monsterOutConfig = MonsterExcel.monsterOut[conf.monsterOutID]
  78. local bossId = monsterOutConfig.member[1][1]
  79. local monsterConfig = MonsterExcel.monster[bossId]
  80. if not monsterConfig then return 0 end
  81. return monsterConfig.head
  82. end
  83. --
  84. local function getParamLv(bossData)
  85. if not bossData then return 0 end
  86. if not bossData.cbParam then return 0 end
  87. return bossData.cbParam.level or 0
  88. end
  89. -- 获取Boss
  90. local function getBossData(unionUuid, level)
  91. local bossDataList = BossDBLogic.getBossDatas(BossDBLogic.BOSS_TYPE_UNION, unionUuid)
  92. if not bossDataList then return end
  93. for _, bossData in ipairs(bossDataList) do
  94. if getParamLv(bossData) == level then
  95. return bossData
  96. end
  97. end
  98. end
  99. -- 根据排名获取奖励
  100. local function getRewardIndexByRank(rank)
  101. if rank <= 3 then return rank end
  102. if rank <= 10 then return 4 end
  103. if rank <= 15 then return 5 end
  104. if rank <= 20 then return 6 end
  105. return 7
  106. end
  107. local function getMinMaxRankByRank(rank)
  108. if rank <= 3 then return rank,rank end
  109. if rank == 4 then return 4, 10 end
  110. if rank == 5 then return 11,15 end
  111. if rank == 6 then return 16,20 end
  112. return 21,50
  113. end
  114. -- 获取页数
  115. local function getDefaultPage(union)
  116. local bossLv = math.min(#UnionExcel.ectype, union.bossLv)
  117. return math.ceil(bossLv / PAGE_PER_CNT)
  118. end
  119. local function getCurTzCnt(human)
  120. if not human.db.ectypeCnt then
  121. return UNION_ECTYPE_FREE_CNT
  122. else
  123. local cnt = human.db.ectypeCnt or 0
  124. local cur = UNION_ECTYPE_FREE_CNT - cnt
  125. return cur > 0 and cur or 0
  126. end
  127. end
  128. -- 副本查询,分页查询
  129. -- page 页码
  130. function ectypeQuery(human)
  131. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  132. if not union then
  133. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  134. end
  135. local msgRet = Msg.gc.GC_UNION_ECTYPE_QUERY
  136. msgRet.ectypeState[0] = 0
  137. msgRet.isStart = 0
  138. msgRet.isEnd = 0
  139. for i = 1, #UnionExcel.ectype do
  140. local conf = UnionExcel.ectype[i]
  141. if not conf then break end
  142. local monsterOutConfig = MonsterExcel.monsterOut[conf.monsterOutID]
  143. local bossId = monsterOutConfig.member[1][1]
  144. local monsterConfig = MonsterExcel.monster[bossId]
  145. if not monsterConfig then
  146. print(" not monsterConfig : ", bossId, " monsterOutID is : ", conf.monsterOutID , " , ectype id :", i )
  147. end
  148. if i == 1 then msgRet.isStart = 1 end
  149. msgRet.ectypeState[0] = msgRet.ectypeState[0] + 1
  150. local ectNet = msgRet.ectypeState[msgRet.ectypeState[0]]
  151. ectNet.statu = (i == union.bossLv) and STATU_BOSS_ING or STATU_BOSS_DIE
  152. if i > union.bossLv then ectNet.statu = STATU_BOSS_READY end
  153. ectNet.bossID = getBossHead(conf)
  154. ectNet.level = i
  155. ectNet.name = monsterConfig.name or ""
  156. if msgRet.ectypeState[0] >= 50 then
  157. if i == #UnionExcel.ectype then msgRet.isEnd = 1 end
  158. Msg.send(msgRet, human.fd)
  159. msgRet.ectypeState[0] = 0
  160. msgRet.isStart = 0
  161. msgRet.isEnd = 0
  162. end
  163. end
  164. if msgRet.ectypeState[0] > 0 then
  165. msgRet.isEnd = 1
  166. Msg.send(msgRet, human.fd)
  167. end
  168. end
  169. -- 获取副本buff
  170. function getEctypeBuff(union)
  171. local lv = 0
  172. local endTime = 0
  173. local buff = {}
  174. if union and union.copyBuff then
  175. local now = os.time()
  176. if now < union.copyBuff.endTime then
  177. lv = union.copyBuff.lv
  178. endTime = union.copyBuff.endTime - now
  179. end
  180. end
  181. return lv, endTime
  182. end
  183. -- 激活 或升级 公会BUF
  184. function upEctypeBuff(human, level)
  185. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  186. if not union then
  187. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  188. end
  189. local lv,endTime = getEctypeBuff(union)
  190. local newLv = lv + 1
  191. if newLv > #UnionExcel.ectypeBuff then
  192. return
  193. end
  194. local nextConifg = UnionExcel.ectypeBuff[newLv]
  195. if not nextConifg then return end
  196. if not ObjHuman.checkRMB(human, nextConifg.needZuanshi) then
  197. return
  198. end
  199. if endTime <= 0 then
  200. endTime = 0
  201. end
  202. ObjHuman.decZuanshi(human, -nextConifg.needZuanshi, "unionBoss")
  203. union.copyBuff = union.copyBuff or {}
  204. union.copyBuff.lv = newLv
  205. union.copyBuff.endTime = os.time() + endTime + nextConifg.addTime
  206. UnionDBLogic.updateEctypeBuf(union)
  207. oneEctypeQuery(human, level)
  208. if newLv == 1 then
  209. Broadcast.sendErr(human, Lang.UNION_ECTYPE_ACTIVATE_SUCCESS)
  210. UnionLivenessLogic.touchLiveness(human,UnionDefine.UNION_LIVENESS_BOSS_BUFF,1)
  211. else
  212. Broadcast.sendErr(human, Lang.UNION_TECH_LV_UP_SUCCESS)
  213. end
  214. end
  215. function toUnionBossLvGm(human, lv)
  216. -- 公会是否存在
  217. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  218. if not union then
  219. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  220. end
  221. UnionDBLogic.updateBossLv(union, lv)
  222. end
  223. -- 指定某个公会副本查询
  224. -- level 指定关卡
  225. function oneEctypeQuery(human, level)
  226. -- 公会是否存在
  227. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  228. if not union then
  229. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  230. end
  231. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1002, true) then
  232. return
  233. end
  234. -- 传入关卡是否合法
  235. if level > union.bossLv then
  236. return Broadcast.sendErr(human, Lang.UNION_ECTYPE_LEVEL_ERR)
  237. end
  238. local conf = UnionExcel.ectype[level]
  239. if not conf then return end
  240. local monsterOutConfig = MonsterExcel.monsterOut[conf.monsterOutID]
  241. local bossId = monsterOutConfig.member[1][1]
  242. local monsterConfig = MonsterExcel.monster[bossId]
  243. if not monsterConfig then return end
  244. -- 副本是否存在
  245. local bossData = getBossData(human.db.unionUuid, level)
  246. if not bossData then
  247. bossData = initEctype(human.db.unionUuid, level)
  248. end
  249. if not bossData then return end
  250. local boardList = BossDBLogic.getHurtBoard(bossData)
  251. local boardLen = boardList and #boardList or 0
  252. local msgRet = Msg.gc.GC_UNION_ONE_ECTYPE_QUERY
  253. msgRet.praiseCnt = UNION_ECTYPE_LIKE_MAX
  254. local dataNet = msgRet.ectypeMsg
  255. dataNet.level = level
  256. dataNet.monsterName = monsterConfig.name
  257. dataNet.body = monsterConfig.body
  258. msgRet.lastHurt = 0
  259. if human.db.ectypHurt and human.db.ectypHurt[level] then
  260. msgRet.lastHurt = human.db.ectypHurt[level].hurtSum
  261. end
  262. dataNet.bloodVolume = BossDBLogic.getBossHpSum(bossData)
  263. if level < union.bossLv then
  264. dataNet.bloodVolume = 0
  265. end
  266. dataNet.allBlood = BossDBLogic.getBossHpMaxSum(bossData)
  267. dataNet.comEff = conf.comEff
  268. dataNet.rankList[0] = 0
  269. for i = 1, boardLen do
  270. if dataNet.rankList[0] >= #dataNet.rankList then
  271. break
  272. end
  273. local bdata = boardList[i]
  274. local rank = dataNet.rankList[0] + 1
  275. local rankNet = dataNet.rankList[rank]
  276. local rewardIndex = getRewardIndexByRank(rank)
  277. local rconf = conf.rankReward[rewardIndex]
  278. if RoleLogic.getRoleBaseByUuid(bdata.uuid, rankNet.roleBase) then
  279. rankNet.damage = bdata.hurt
  280. rankNet.like = bdata.like or 0
  281. rankNet.isLike = getGiveLikeSate(human, bdata.uuid) and 1 or 0
  282. rankNet.reward[0] = rconf and #rconf or 0
  283. for j = 1, rankNet.reward[0] do
  284. local itemID = rconf[j][1]
  285. local itemCnt = rconf[j][2]
  286. Grid.makeItem(rankNet.reward[j], itemID, itemCnt)
  287. end
  288. dataNet.rankList[0] = dataNet.rankList[0] + 1
  289. local member = UnionDBLogic.getUnionMember(union, bdata.uuid)
  290. rankNet.post = member and member.post or UnionDefine.POST_MEMBER
  291. end
  292. end
  293. dataNet.rankReward[0] = #conf.rankReward
  294. for i = 1, dataNet.rankReward[0] do
  295. local minRank,maxRank = getMinMaxRankByRank(i)
  296. local rewardNet = dataNet.rankReward[i]
  297. local rconf = conf.rankReward[i]
  298. rewardNet.minRank = minRank
  299. rewardNet.maxRank = maxRank
  300. rewardNet.reward[0] = #rconf
  301. for j = 1, rewardNet.reward[0] do
  302. local itemID = rconf[j][1]
  303. local itemCnt = rconf[j][2]
  304. Grid.makeItem(rewardNet.reward[j], itemID, itemCnt)
  305. end
  306. end
  307. dataNet.reward[0] = #conf.onceReward
  308. for i = 1, dataNet.reward[0] do
  309. local itemID = conf.onceReward[i][1]
  310. local itemCnt = conf.onceReward[i][2]
  311. Grid.makeItem(dataNet.reward[i], itemID, itemCnt)
  312. end
  313. dataNet.killReward[0] = #conf.killReward
  314. for i = 1, dataNet.killReward[0] do
  315. local itemID = conf.killReward[i][1]
  316. local itemCnt = conf.killReward[i][2]
  317. Grid.makeItem(dataNet.killReward[i], itemID, itemCnt)
  318. end
  319. local fightCnt = (human.db.ectypeCnt or 0) + 1
  320. msgRet.curCnt = getCurTzCnt(human)
  321. msgRet.curBuy = #FIGHT_COST_ZUANSHI - UNION_ECTYPE_FREE_CNT
  322. if msgRet.curCnt <= 0 then
  323. msgRet.curBuy = msgRet.curBuy - human.db.ectypeCnt + UNION_ECTYPE_FREE_CNT
  324. end
  325. msgRet.needZuanShi = FIGHT_COST_ZUANSHI[fightCnt] or FIGHT_COST_ZUANSHI[#FIGHT_COST_ZUANSHI]
  326. local lv , endTime = getEctypeBuff(union)
  327. if lv > 0 then
  328. local bufConfig = UnionExcel.ectypeBuff[lv]
  329. msgRet.buffMsg.lv = lv
  330. msgRet.buffMsg.maxLv = #UnionExcel.ectypeBuff
  331. msgRet.buffMsg.endTime = endTime
  332. msgRet.buffMsg.upNeed = 0
  333. msgRet.buffMsg.attr[0] = 0
  334. msgRet.buffMsg.nextAttr[0] = 0
  335. for k, v in ipairs(bufConfig.buff) do
  336. local net = msgRet.buffMsg.attr[k]
  337. net.key = v[1]
  338. net.value = v[2]
  339. end
  340. msgRet.buffMsg.attr[0] = #bufConfig.buff
  341. local nextBufConfig = UnionExcel.ectypeBuff[lv + 1]
  342. if nextBufConfig then
  343. msgRet.buffMsg.upNeed = nextBufConfig.needZuanshi
  344. for k, v in ipairs(nextBufConfig.buff) do
  345. local net = msgRet.buffMsg.nextAttr[k]
  346. net.key = v[1]
  347. net.value = v[2]
  348. end
  349. msgRet.buffMsg.nextAttr[0] = #nextBufConfig.buff
  350. end
  351. else
  352. local bufConfig = UnionExcel.ectypeBuff[1]
  353. msgRet.buffMsg.lv = 0
  354. msgRet.buffMsg.maxLv = #UnionExcel.ectypeBuff
  355. msgRet.buffMsg.endTime = 0
  356. msgRet.buffMsg.upNeed = bufConfig.needZuanshi
  357. msgRet.buffMsg.nextAttr[0] = 0
  358. for k, v in ipairs(bufConfig.buff) do
  359. local net = msgRet.buffMsg.nextAttr[k]
  360. net.key = v[1]
  361. net.value = v[2]
  362. end
  363. msgRet.buffMsg.nextAttr[0] = #bufConfig.buff
  364. msgRet.buffMsg.attr[0] = 0
  365. end
  366. msgRet.jijieTime = 0
  367. if union.jihuoTime then
  368. local endTime = UNION_ECTYPE_JIJIE_TIME - (os.time() - union.jihuoTime)
  369. msgRet.jijieTime = endTime >= 0 and endTime or 0
  370. end
  371. if human.db.ectypeCnt and human.db.ectypeCnt > UNION_ECTYPE_FREE_CNT then
  372. msgRet.curBuy = #FIGHT_COST_ZUANSHI - human.db.ectypeCnt
  373. end
  374. if human.db.ectypeLike and human.db.ectypeLike > 0 then
  375. msgRet.praiseCnt = UNION_ECTYPE_LIKE_MAX - human.db.ectypeLike
  376. msgRet.praiseCnt = msgRet.praiseCnt > 0 and msgRet.praiseCnt or 0
  377. end
  378. -- Msg.trace(msgRet)
  379. Msg.send(msgRet, human.fd)
  380. end
  381. -- 获取点赞状态
  382. function getGiveLikeSate(human, uuid)
  383. if not uuid or uuid == "" then return end
  384. if human.db.ectypLikeUuid and human.db.ectypLikeUuid[uuid] then
  385. return true
  386. end
  387. end
  388. -- 点赞
  389. function giveLike(human, level, uuid)
  390. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1002, true) then
  391. return
  392. end
  393. -- 不能点赞自己
  394. if human.db._id == uuid then
  395. return
  396. end
  397. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  398. if not union then
  399. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  400. end
  401. if level > union.bossLv then
  402. return Broadcast.sendErr(human, Lang.UNION_ECTYPE_LEVEL_ERR)
  403. end
  404. if human.db.ectypLikeUuid and human.db.ectypLikeUuid[uuid] then
  405. return
  406. end
  407. local conf = UnionExcel.ectype[level]
  408. if not conf then return end
  409. if human.db.ectypeLike and human.db.ectypeLike >= UNION_ECTYPE_LIKE_MAX then
  410. return Broadcast.sendErr(human, Lang.UNION_ECTYPE_LIKE_MAX_ERR)
  411. end
  412. local bossData = getBossData(human.db.unionUuid, level)
  413. if not bossData then return end
  414. local state = BossLogic.giveLikeBossRecord(bossData, uuid)
  415. if not state then return end
  416. human.db.ectypLikeUuid = human.db.ectypLikeUuid or {}
  417. human.db.ectypLikeUuid[uuid] = 1
  418. human.db.ectypeLike = human.db.ectypeLike or 0
  419. human.db.ectypeLike = human.db.ectypeLike + 1
  420. -- 点赞成功
  421. BagLogic.cleanMomentItemList()
  422. BagLogic.updateMomentItem(1, 101, 1000)
  423. BagLogic.addMomentItemList(human, "unionBoss")
  424. oneEctypeQuery(human, level)
  425. end
  426. -- 集结
  427. function jiJie(human, level,str)
  428. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  429. if not union then
  430. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  431. end
  432. local config = UnionExcel.ectype[level]
  433. if not config then
  434. return
  435. end
  436. -- 检测官职 能否满足要求
  437. local member = UnionDBLogic.getUnionMember(union, human.db._id)
  438. if not member
  439. or (member.post ~= UnionDefine.POST_PRESIDENT and member.post ~= UnionDefine.POST_OFFICIAL) then
  440. return Broadcast.sendErr(human, Lang.UNION_HAVE_NO_POWER)
  441. end
  442. local lastTime = union.jihuoTime or 0
  443. local now = os.time()
  444. if now - lastTime < UNION_ECTYPE_JIJIE_TIME then
  445. return
  446. end
  447. union.jihuo = level
  448. union.jihuoTime = now
  449. UnionDBLogic.updateJihuo(union)
  450. -- 发送 聊天 到公会
  451. if ChatUnion.chatUnionEctype(human, str) == 1 then
  452. return
  453. end
  454. Broadcast.sendErr(human, Lang.UNION_ECTYPE_JIJIE_SUCCESS)
  455. oneEctypeQuery(human, level)
  456. end
  457. -- 可否打开上阵
  458. function checkCombatPos(human, args)
  459. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  460. if not union then
  461. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  462. end
  463. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1002, true) then
  464. return
  465. end
  466. local level = tonumber(args[1])
  467. local touch = tonumber(args[2] or 0)
  468. if union.bossLv ~= level then
  469. return Broadcast.sendErr(human,Lang.UNION_ECTYPE_LEVEL_ERR)
  470. end
  471. local bossData = getBossData(human.db.unionUuid, level)
  472. if not bossData then return end
  473. getCurTzCnt(human)
  474. local ectypeCnt = (human.db.ectypeCnt or 0)
  475. local cost = nil
  476. local killCnt = 0
  477. if touch == 0 then
  478. local fightCnt = ectypeCnt + 1
  479. cost = FIGHT_COST_ZUANSHI[fightCnt]
  480. killCnt = 1
  481. else
  482. for i = ectypeCnt + 1, #FIGHT_COST_ZUANSHI do
  483. cost = cost or 0
  484. cost = cost + FIGHT_COST_ZUANSHI[i]
  485. killCnt = killCnt + 1
  486. end
  487. end
  488. if not cost then
  489. return Broadcast.sendErr(human,Lang.BATTLE_CNT_OVER)
  490. end
  491. if cost > 0 then
  492. if not ObjHuman.checkRMB(human, cost) then
  493. return
  494. end
  495. end
  496. return true, bossData, cost, killCnt
  497. end
  498. function getCombatObjList(human, side, args)
  499. if side ~= CombatDefine.DEFEND_SIDE then return end
  500. local level = tonumber(args[1])
  501. local conf = UnionExcel.ectype[level]
  502. if not conf then return end
  503. local bossData = getBossData(human.db.unionUuid, level)
  504. if not bossData then return end
  505. local monsterOutConfig = MonsterExcel.monsterOut[conf.monsterOutID]
  506. if not monsterOutConfig then return end
  507. local mationConfig = CombatPosExcel.formation[monsterOutConfig.formation]
  508. local posList = mationConfig.pos
  509. if not posList then return end
  510. local objList = nil
  511. local zhandouli = 0
  512. for i, member in ipairs(monsterOutConfig.member) do
  513. local monsterID = member[1]
  514. local monsterConfig = MonsterExcel.monster[monsterID]
  515. if posList[i] then
  516. local monsterLv = member[2]
  517. local attrID = monsterOutConfig.attrID[i]
  518. local obj = CombatLogic.createMonsterObj(monsterID, monsterLv, attrID, i, CombatDefine.COMBAT_OBJ_TYPE2, monsterOutConfig.beSkill[i])
  519. if obj then
  520. zhandouli = zhandouli + obj.attrs[RoleDefine.ZHANDOULI]
  521. objList = objList or {}
  522. local pos = posList[i]
  523. objList[pos] = obj
  524. end
  525. end
  526. end
  527. if not objList then
  528. assert(nil, "getMonsterObjList is nil, monsterOutID = " .. monsterOutConfig.monsterOutID)
  529. end
  530. local rolebase = CombatLogic.createRoleBaseByMOutID(monsterOutConfig.monsterOutID, zhandouli, args)
  531. local helpList = {}
  532. return BossLogic.getCombatObjList(bossData, conf.comEff), nil, rolebase, monsterOutConfig.formation
  533. end
  534. -- 刷副本
  535. function fight(human, args, combatType)
  536. local isok, bossData, cost = checkCombatPos(human, args)
  537. if not isok then return end
  538. if cost > 0 then
  539. ObjHuman.decZuanshi(human, -cost, "unionBoss")
  540. end
  541. -- human.db.ectypeCnt = (human.db.ectypeCnt or 0) + 1
  542. local level = tonumber(args[1])
  543. local conf = UnionExcel.ectype[level]
  544. local mapID = conf.mapID
  545. CombatLogic.combatBegin(human, mapID, args, combatType, bossData)
  546. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_10,1)
  547. end
  548. -- 获取当前地图ID
  549. function getMapID(human, args)
  550. local isok, cf, throne, lv, exp = checkCombatPos(human, args)
  551. if not isok then return end
  552. return cf.mapID
  553. end
  554. function onFightBegin(human, bossData)
  555. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  556. if not union then
  557. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  558. end
  559. local lv , endTime = getEctypeBuff(union)
  560. if lv > 0 then
  561. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  562. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  563. local atkObj = CombatImpl.objList[atkPos]
  564. if atkObj then
  565. local bufConfig = UnionExcel.ectypeBuff[lv]
  566. for k, v in ipairs(bufConfig.buff) do
  567. local key = v[1]
  568. local value = v[2]
  569. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  570. atkObj.isSysAttrChange = true
  571. end
  572. end
  573. end
  574. end
  575. BossLogic.onFightBegin(human, bossData)
  576. end
  577. -- 挑战结束
  578. local FieldsKill = {killEctype = 1}
  579. function onFightEnd(human, result, combatType, bossData, combatInfo)
  580. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  581. if not union then return end
  582. local level = getParamLv(bossData)
  583. local conf = UnionExcel.ectype[level]
  584. if not conf then return end
  585. combatInfo.defender.name = Util.format(Lang.COMBAT_UNIONECTYPE_NAME, level)
  586. combatInfo.defender.head = getBossHead(conf)
  587. local hurtSum , hurtList = BossLogic.onFightHurt(human, bossData, combatInfo)
  588. -- 从DB 中获取最新的BOSS DB 来计算 防止玩家在战斗画面中 未fightEnd 播完 别的玩家 扫荡打出伤害
  589. local realBoss = getBossData(human.db.unionUuid, level)
  590. local oldIsSkill = BossDBLogic.isBossDie(realBoss)
  591. if oldIsSkill then
  592. combatInfo.double = 0
  593. return
  594. end
  595. local realHurt = BossLogic.updateFightHurt(human, realBoss, hurtList, combatInfo)
  596. local bKill = BossDBLogic.isBossDie(realBoss)
  597. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_6, 1)
  598. LiLianLogic.onCallbackByCombat(human,combatInfo)
  599. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_11,1)
  600. UnionLogic.addUnionLog(union._id, 9, human.db.name,UnionDefine.UNION_LOG_CLASSIFY_BOSS, realHurt)
  601. human.db.ectypeCnt = (human.db.ectypeCnt or 0) + 1
  602. human.db.ectypHurt = {}
  603. human.db.ectypHurt[level] = {}
  604. human.db.ectypHurt[level].hurtSum = realHurt
  605. human.db.ectypHurt[level].hurtList = Util.copyTable(hurtList)
  606. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1002)
  607. local rewardCnt = double and 2 or 1
  608. for i = 1, #conf.onceReward do
  609. local itemID = conf.onceReward[i][1]
  610. local itemCnt = conf.onceReward[i][2] * rewardCnt
  611. BagLogic.addItem(human, itemID, itemCnt, "unionBoss")
  612. combatInfo.rewardItem[#combatInfo.rewardItem + 1] = {itemID, itemCnt}
  613. end
  614. combatInfo.double = double and 2 or 0
  615. -- boss死亡
  616. if bKill then
  617. UnionDBLogic.updateBossLv(union, level + 1)
  618. -- 给击杀者发送奖励
  619. local mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD2
  620. local title = MailExcel.mail[mailID].title
  621. local content = Util.format(MailExcel.mail[mailID].content, level)
  622. local senderName = MailExcel.mail[mailID].senderName
  623. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, conf.killReward, senderName)
  624. -- 排名奖励
  625. local boardList = BossDBLogic.getHurtBoard(realBoss)
  626. local boardLen = boardList and #boardList or 0
  627. local rank = 0
  628. for i = 1, boardLen do
  629. local bdata = boardList[i]
  630. local db, online = RoleDBLogic.getDb(bdata.uuid, FieldsKill)
  631. if db then
  632. rank = rank + 1
  633. if db.killEctype and db.killEctype[level] then
  634. local mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD3
  635. local title = MailExcel.mail[mailID].title
  636. local content = MailExcel.mail[mailID].content
  637. local senderName = MailExcel.mail[mailID].senderName
  638. MailManager.add(MailManager.SYSTEM, db._id, title, content, nil, senderName)
  639. else
  640. db.killEctype = db.killEctype or {}
  641. db.killEctype[level] = 1
  642. if not online then RoleDBLogic.saveRoleSset(db) end
  643. local mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD1
  644. local title = MailExcel.mail[mailID].title
  645. local content = Util.format(MailExcel.mail[mailID].content, level , rank)
  646. local senderName = MailExcel.mail[mailID].senderName
  647. local rewardIndex = getRewardIndexByRank(rank)
  648. local rconf = conf.rankReward[rewardIndex]
  649. MailManager.add(MailManager.SYSTEM, db._id, title, content, rconf, senderName)
  650. end
  651. end
  652. end
  653. end
  654. if bKill then
  655. oneEctypeQuery(human, level + 1)
  656. else
  657. oneEctypeQuery(human, level)
  658. end
  659. local WarOrder = require("shop.WarOrder")
  660. WarOrder.trigger(human,CLAN_ORDER_TYPE)
  661. UnionLivenessLogic.touchLiveness(human,UnionDefine.UNION_LIVENESS_ECTYPE,1)
  662. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1002)
  663. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1001)
  664. YunYingLogic.onCallBack(human, "onUnionEctypeFight",1)
  665. ---周任务公会boss挑战次数
  666. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_4, 1)
  667. TriggerLogic.PublishEvent(TriggerDefine.UNIONS_CHALLENGE_BOSS, human.db._id, 1)
  668. end
  669. function saodang(human, level, touch)
  670. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  671. if not union then return end
  672. if not human.db.ectypHurt or not human.db.ectypHurt[level] then
  673. return
  674. end
  675. if not human.db.ectypHurt[level].hurtList then
  676. return
  677. end
  678. local lastHurt = human.db.ectypHurt[level].hurtSum
  679. if lastHurt < 0 then
  680. return
  681. end
  682. local args = {}
  683. args[1] = level
  684. args[2] = touch or 1
  685. local isok, bossData, cost, killCnt = checkCombatPos(human, args)
  686. if not isok then return end
  687. local conf = UnionExcel.ectype[level]
  688. local totalRealHurt = 0
  689. local bKill = nil
  690. local ectypeCnt = (human.db.ectypeCnt or 0)
  691. local phyCnt = 0
  692. local nextIndex = ectypeCnt + 1
  693. local hadCost = 0
  694. for i=1, killCnt do
  695. local realHurt = BossLogic.saodangEnd(human, bossData, human.db.ectypHurt[level].hurtList)
  696. bKill = BossDBLogic.isBossDie(bossData)
  697. totalRealHurt = totalRealHurt + realHurt
  698. phyCnt = phyCnt + 1
  699. if not FIGHT_COST_ZUANSHI[nextIndex] then
  700. return
  701. end
  702. hadCost = hadCost + FIGHT_COST_ZUANSHI[nextIndex]
  703. nextIndex = nextIndex + 1
  704. if bKill then
  705. break
  706. end
  707. end
  708. if cost ~= hadCost then
  709. cost = hadCost
  710. killCnt = phyCnt
  711. end
  712. if cost > 0 then
  713. ObjHuman.decZuanshi(human, -cost, "unionBoss")
  714. end
  715. human.db.ectypeCnt = (human.db.ectypeCnt or 0) + killCnt
  716. UnionLogic.addUnionLog(union._id, 10, human.db.name,UnionDefine.UNION_LOG_CLASSIFY_BOSS, totalRealHurt)
  717. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1002)
  718. local rewardCnt = double and 2 or 1
  719. local msgRet = Msg.gc.GC_UNION_ECTYPE_REWARD
  720. msgRet.result = bKill and 1 or 0
  721. msgRet.hurt = totalRealHurt
  722. msgRet.double = double and 1 or 0
  723. msgRet.reward[0] = #conf.onceReward
  724. for i = 1, msgRet.reward[0] do
  725. local itemID = conf.onceReward[i][1]
  726. local itemCnt = conf.onceReward[i][2] * rewardCnt * killCnt
  727. BagLogic.addItem(human, itemID, itemCnt, "unionBoss")
  728. Grid.makeItem(msgRet.reward[i], itemID, itemCnt)
  729. end
  730. Msg.send(msgRet, human.fd)
  731. -- boss死亡
  732. if bKill then
  733. UnionDBLogic.updateBossLv(union, level + 1)
  734. -- 给击杀者发送奖励
  735. local mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD2
  736. local title = MailExcel.mail[mailID].title
  737. local content = Util.format(MailExcel.mail[mailID].content, level)
  738. local senderName = MailExcel.mail[mailID].senderName
  739. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, conf.killReward, senderName)
  740. -- 排名奖励
  741. local boardList = BossDBLogic.getHurtBoard(bossData)
  742. local boardLen = boardList and #boardList or 0
  743. local rank = 0
  744. for i = 1, boardLen do
  745. local bdata = boardList[i]
  746. local db, online = RoleDBLogic.getDb(bdata.uuid, FieldsKill)
  747. if db then
  748. rank = rank + 1
  749. if db.killEctype and db.killEctype[level] then
  750. mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD3
  751. local title = MailExcel.mail[mailID].title
  752. local content = MailExcel.mail[mailID].content
  753. local senderName = MailExcel.mail[mailID].senderName
  754. MailManager.add(MailManager.SYSTEM, db._id, title, content, nil, senderName)
  755. else
  756. db.killEctype = db.killEctype or {}
  757. db.killEctype[level] = 1
  758. if not online then RoleDBLogic.saveRoleSset(db) end
  759. mailID = MailDefine.MAIL_ID_UNION_BOSS_REWARD1
  760. local title = MailExcel.mail[mailID].title
  761. local content = Util.format(MailExcel.mail[mailID].content, level, rank)
  762. local senderName = MailExcel.mail[mailID].senderName
  763. local rewardIndex = getRewardIndexByRank(rank)
  764. local rconf = conf.rankReward[rewardIndex]
  765. MailManager.add(MailManager.SYSTEM, db._id, title, content, rconf, senderName)
  766. end
  767. end
  768. end
  769. end
  770. if bKill then
  771. oneEctypeQuery(human, level + 1)
  772. else
  773. oneEctypeQuery(human, level)
  774. end
  775. UnionLivenessLogic.touchLiveness(human,UnionDefine.UNION_LIVENESS_ECTYPE,1)
  776. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_6, killCnt)
  777. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_11,1)
  778. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1002)
  779. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1001)
  780. local WarOrder = require("shop.WarOrder")
  781. WarOrder.trigger(human,CLAN_ORDER_TYPE,killCnt or 1)
  782. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_4, killCnt or 1)
  783. YunYingLogic.onCallBack(human, "onUnionEctypeFight", killCnt or 0)
  784. TriggerLogic.PublishEvent(TriggerDefine.UNIONS_CHALLENGE_BOSS, human.db._id, killCnt or 1)
  785. end
  786. function isDot(human)
  787. if human.db.unionUuid == nil then
  788. return
  789. end
  790. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1002) then
  791. return
  792. end
  793. if getCurTzCnt(human) > 0 then
  794. return true
  795. end
  796. end