UnionEctypeLogic.lua 32 KB

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