UnionEctypeLogic.lua 32 KB

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