UnionEctypeLogic.lua 32 KB

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