MoZhuLogic.lua 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. ----- 次元魔珠
  2. --[[
  3. db.mozhu = {
  4. time = 1,
  5. hurtMax = 1,
  6. hurt = 1,
  7. tzCnt = 1,
  8. restCnt = 1,
  9. }
  10. ]]
  11. local InnerMsg = require("core.InnerMsg")
  12. local Msg = require("core.Msg")
  13. local ObjHuman = require("core.ObjHuman")
  14. local Util = require("common.Util")
  15. local Config = require("Config")
  16. local Lang = require("common.Lang")
  17. local Broadcast = require("broadcast.Broadcast")
  18. local CombatLogic = require("combat.CombatLogic")
  19. local CombatPosLogic = require("combat.CombatPosLogic")
  20. local CombatDefine = require("combat.CombatDefine")
  21. local Grid = require("bag.Grid")
  22. local BagLogic = require("bag.BagLogic")
  23. local MailDefine = require("mail.MailIdDefine")
  24. local MailExcel = require("excel.mail")
  25. local MailManager = require("mail.MailManager")
  26. local MoZhuExcel = require("excel.mozhu")
  27. local CombatImpl = require("combat.CombatImpl")
  28. local BeSkill = require("combat.BeSkill")
  29. local MonsterExcel = require("excel.monster")
  30. local SkillExcel = require("excel.skill").skill
  31. local UnionDBLogic = require("union.UnionDBLogic")
  32. local RoleDefine = require("role.RoleDefine")
  33. local RoleLogic = require("role.RoleLogic")
  34. local UnionDefine = require("union.UnionDefine")
  35. local ChatUnion = require("chat.ChatUnion")
  36. local JjcActLogic = require("jjc.JjcActLogic")
  37. local DragonNestLogic = require("copy.DragonNestLogic")
  38. local HeroLogic = require("hero.HeroLogic")
  39. local MozhuMiddleLogic = require("mozhu.MoZhuMiddleLogic")
  40. local YunYingLogic = require("yunying.YunYingLogic")
  41. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  42. local TriggerDefine = require("trigger.TriggerDefine")
  43. local TriggerLogic = require("trigger.TriggerLogic")
  44. MOZHU_OPEN_DAY = {[1]= 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1, [7] = 1}
  45. MOZHU_OPEN_DAY_2 = {1, 7}
  46. MOZHU_DAY_TIME = 24 * 60 * 60
  47. MOZHU_END_TIME = 22 * 60 * 60
  48. MOZHU_TIAOZHAN_CNT = 3 -- 魔蛛挑战次数
  49. MOZHU_RESET_CNT = 3 -- 魔蛛最多重置次数
  50. MOZHU_CITIAO = MOZHU_CITIAO or nil
  51. MOZHU_CITIAO_TIME = MOZHU_CITIAO_TIME or nil
  52. MOZHU_ROLE_RANK_TYPE_1 = 1 --- 玩家排名
  53. MOZHU_UNION_RANK_TYPE_2 = 2 --- 公会排名
  54. function initHuman(human)
  55. if human.db.mozhu then return end
  56. human.db.mozhu = {}
  57. human.db.mozhu.time = os.time()
  58. human.db.mozhu.hurtMax = 0
  59. human.db.mozhu.hurt = 0
  60. human.db.mozhu.tzCnt = 0
  61. human.db.mozhu.restCnt = 0
  62. end
  63. function updateDaily(human)
  64. if not human.db.mozhu then return end
  65. if Util.isSameDay(human.db.mozhu.time) then
  66. return
  67. end
  68. human.db.mozhu.time = os.time()
  69. human.db.mozhu.hurtMax = 0
  70. human.db.mozhu.hurt = 0
  71. human.db.mozhu.tzCnt = 0
  72. human.db.mozhu.restCnt = 0
  73. human.db.mozhu.unionGet = nil
  74. human.db.mozhu.onHero = nil
  75. human.db.mozhu.read = nil
  76. end
  77. function isOpen()
  78. local week = Util.getWeekDay()
  79. if MOZHU_OPEN_DAY[week] then
  80. return true
  81. end
  82. return false
  83. end
  84. function getActTime()
  85. local now = os.time()
  86. local nowWeek = Util.getWeekDay(now)
  87. if MOZHU_OPEN_DAY[nowWeek] then
  88. local startTime = Util.getDayStartTime(now)
  89. return startTime + 1, startTime + MOZHU_END_TIME
  90. elseif nowWeek < MOZHU_OPEN_DAY_2[1] then
  91. local openTime = now + MOZHU_DAY_TIME * (MOZHU_OPEN_DAY_2[1] - nowWeek)
  92. local startTime = Util.getDayStartTime(openTime)
  93. return startTime + 1, startTime + MOZHU_END_TIME
  94. elseif nowWeek < MOZHU_OPEN_DAY_2[2] then
  95. local openTime = now + MOZHU_DAY_TIME * (MOZHU_OPEN_DAY_2[2] - nowWeek)
  96. local startTime = Util.getDayStartTime(openTime)
  97. return startTime + 1, startTime + MOZHU_END_TIME
  98. elseif nowWeek > MOZHU_OPEN_DAY_2[2] then
  99. -- 暂时不会发生 防止后续策划修改时间
  100. local surDay = 7 - nowWeek + MOZHU_OPEN_DAY_2[1]
  101. local openTime = now + MOZHU_DAY_TIME * surDay
  102. local startTime = Util.getDayStartTime(openTime)
  103. return startTime + 1, startTime + MOZHU_END_TIME
  104. end
  105. end
  106. function getActState(human)
  107. -- if not human.db.unionUuid or human.db.unionUuid == "" then
  108. -- return JjcActLogic.STATE_NOOPEN, 0
  109. -- end
  110. local now = os.time()
  111. local startTime, endTime = getActTime()
  112. if now < startTime then
  113. return JjcActLogic.STATE_READY, startTime - now
  114. elseif now >= startTime and now < endTime then
  115. return JjcActLogic.STATE_START, endTime - now
  116. end
  117. return JjcActLogic.STATE_NOOPEN, 0
  118. end
  119. -----------------------font net -----------------
  120. local function fontRoleNet(msgRet, msg)
  121. local len = 0
  122. for rank, db in ipairs(msg.roleRank) do
  123. len = len + 1
  124. local net = msgRet.roleList[len]
  125. net.rank = rank
  126. net.hurt = db.hurt
  127. RoleLogic.makeRoleBase(db.roleBase, net.roleBase)
  128. net.roleBase.name = net.roleBase.name or ""
  129. net.roleBase.serverName = db.roleBase.svrName
  130. end
  131. msgRet.roleList[0] = len
  132. end
  133. local function fontUnionNet(msgRet, msg)
  134. local len = 0
  135. for rank, db in ipairs(msg.unionRank) do
  136. len = len + 1
  137. local net = msgRet.unionList[len]
  138. net.rank = rank
  139. net.unionUuid = db.unionUuid
  140. net.name = db.unionBase.unionName or ""
  141. net.bannerID = db.unionBase.bannerID or 0
  142. net.hurt = db.hurt
  143. net.svrName = db.unionBase.svrName or "S0"
  144. end
  145. msgRet.unionList[0] = len
  146. end
  147. local function fontMyRole(msgRet, msg)
  148. msgRet.myRole[0] = 0
  149. if msg.info and msg.info.myRank and msg.info.myRank.hurt then
  150. local net = msgRet.myRole[1]
  151. net.rank = msg.info.myRank.rank
  152. net.hurt = msg.info.myRank.hurt
  153. RoleLogic.makeRoleBase(msg.info.myRank.roleBase, net.roleBase)
  154. msgRet.myRole[0] = 1
  155. end
  156. end
  157. local function fontMyUnion(msgRet, msg)
  158. msgRet.myUnion[0] = 0
  159. if msg.info and msg.info.myUnion and msg.info.myUnion.hurt then
  160. local net = msgRet.myUnion[1]
  161. net.rank = msg.info.myUnion.rank
  162. net.unionUuid = msg.info.myUnion.unionUuid
  163. net.name = msg.info.myUnion.unionBase.unionName or ""
  164. net.bannerID = msg.info.myUnion.unionBase.bannerID or 0
  165. net.hurt = msg.info.myUnion.hurt
  166. net.svrName = msg.info.myUnion.unionBase.svrName
  167. msgRet.myUnion[0] = 1
  168. end
  169. end
  170. local function fontCiTiao(msgRet, list)
  171. local len = 0
  172. for id in pairs(list.citiao) do
  173. len = len + 1
  174. local config = MoZhuExcel.citiao[id]
  175. local net = msgRet.ciTiao[len]
  176. net.id = id
  177. net.name = config.citiao or ""
  178. net.desc = config.miaoshu
  179. end
  180. msgRet.ciTiao[0] = len
  181. if not MOZHU_CITIAO_TIME or MOZHU_CITIAO_TIME ~= list.citiaoTime then
  182. MOZHU_CITIAO = {}
  183. MOZHU_CITIAO = Util.copyTable(list.citiao)
  184. MOZHU_CITIAO_TIME = list.citiaoTime
  185. end
  186. end
  187. local function fontBuff(union, msgRet)
  188. local lv = union.mozhuBufLv or 0
  189. local mozhuBufTime = union.mozhuBufTime or 0
  190. local now = os.time()
  191. local endTime = mozhuBufTime - now
  192. if now >= mozhuBufTime then
  193. lv = 0
  194. endTime = 0
  195. end
  196. local config = MoZhuExcel.buff[lv]
  197. local nextConfig = MoZhuExcel.buff[lv + 1]
  198. msgRet.buffEndTime = endTime
  199. msgRet.upBuffNeed = nextConfig and nextConfig.need or 0
  200. msgRet.buffLv = lv
  201. msgRet.buff[0] = 0
  202. msgRet.nextBuff[0] = 0
  203. if config and config.attrs then
  204. for k, v in ipairs(config.attrs) do
  205. msgRet.buff[k].key = v[1]
  206. msgRet.buff[k].value = v[2]
  207. end
  208. msgRet.buff[0] = #config.attrs
  209. end
  210. if nextConfig and nextConfig.attrs then
  211. for k, v in ipairs(nextConfig.attrs) do
  212. msgRet.nextBuff[k].key = v[1]
  213. msgRet.nextBuff[k].value = v[2]
  214. end
  215. msgRet.nextBuff[0] = #nextConfig.attrs
  216. end
  217. end
  218. local function unionRewardDot(human, msg)
  219. if msg.info and msg.info.myUnion and msg.info.myUnion.hurt then
  220. local hurt = msg.info.myUnion.hurt
  221. local canID = 0
  222. for k, config in ipairs(MoZhuExcel.hurt) do
  223. if config and config.unionHurt <= hurt then
  224. canID = k
  225. end
  226. end
  227. local getId = human.db.mozhu and human.db.mozhu.unionGet or 0
  228. if canID > 0 then
  229. return getId < canID and 1 or 0
  230. else
  231. return 0
  232. end
  233. else
  234. return 0
  235. end
  236. end
  237. local function fontQueryNet(msgRet, msg)
  238. local startTime, endTime = getActTime()
  239. local now = os.time()
  240. if now >= startTime and now <= endTime then
  241. msgRet.isOpen = 1
  242. msgRet.endTime = endTime - now
  243. else
  244. msgRet.isOpen = 0
  245. msgRet.endTime = startTime - now
  246. end
  247. msgRet.isRead = 0
  248. msgRet.tzCnt = MOZHU_TIAOZHAN_CNT
  249. msgRet.restCnt = MOZHU_RESET_CNT
  250. msgRet.jijieTime = 0
  251. msgRet.buffLv = 0
  252. msgRet.buffEndTime = 0
  253. msgRet.upBuffNeed = 100
  254. msgRet.restNeed = 100
  255. msgRet.useHero[0] = 0
  256. msgRet.buff[0] = 0
  257. fontCiTiao(msgRet, msg.info)
  258. fontRoleNet(msgRet, msg)
  259. fontUnionNet(msgRet, msg)
  260. fontMyRole(msgRet, msg)
  261. fontMyUnion(msgRet, msg)
  262. end
  263. local function fontRankReward(type, msgRet)
  264. local len = 0
  265. for k, config in ipairs(MoZhuExcel.rank) do
  266. if type == 1 and config.roleMin > 0 then
  267. len = len + 1
  268. local net = msgRet.rewardList[len]
  269. net.id = k
  270. net.minRank = config.roleMin
  271. net.maxRank = config.roleMax
  272. for j, h in ipairs(config.reward) do
  273. Grid.makeItem(net.reward[j], h[1], h[2])
  274. end
  275. net.reward[0] = #config.reward
  276. elseif type == 2 and config.unionMin > 0 then
  277. len = len + 1
  278. local net = msgRet.rewardList[len]
  279. net.id = k
  280. net.minRank = config.unionMin
  281. net.maxRank = config.unionMax
  282. for j, h in ipairs(config.unionReward) do
  283. Grid.makeItem(net.reward[j], h[1], h[2])
  284. end
  285. net.reward[0] = #config.unionReward
  286. end
  287. end
  288. msgRet.rewardList[0] = len
  289. end
  290. ----------------- font net --------------------------
  291. function getJijieEndTime(union)
  292. if not union then return 0 end
  293. local mozhuTime = union.mozhuJijie or 0
  294. local now = os.time()
  295. local config = MoZhuExcel.mozhu[1]
  296. if now - mozhuTime >= config.jijie then
  297. return 0
  298. else
  299. return config.jijie - (now - mozhuTime)
  300. end
  301. end
  302. function query(human)
  303. if not human.db.unionUuid or human.db.unionUuid == "" then return end
  304. local starTime, endTime = getActTime()
  305. local now = os.time()
  306. if now < starTime or now >= endTime then
  307. if now < starTime and starTime - now <= MOZHU_DAY_TIME then
  308. else
  309. local msgRet = Msg.gc.GC_MOZHU_ACT_OVER
  310. Msg.send(msgRet, human.fd)
  311. Broadcast.sendErr(human, Lang.ACT_WAS_OVER)
  312. return
  313. end
  314. end
  315. initHuman(human)
  316. local msgInner = {}
  317. msgInner.uuid = human.db._id
  318. msgInner.unionUuid = human.db.unionUuid
  319. --[[local msgInner = InnerMsg.lw.LW_MOZHU_QUERY
  320. msgInner.uuid = human.db._id
  321. msgInner.unionUuid = human.db.unionUuid
  322. InnerMsg.sendMsg(0, msgInner)]]
  323. MozhuMiddleLogic.LW_MOZHU_QUERY(human,msgInner)
  324. end
  325. function WLQuery(human, msg)
  326. --Util.printTable(msg)
  327. updateDaily(human)
  328. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  329. local member = UnionDBLogic.getUnionMember(union, human.db._id)
  330. local config = MoZhuExcel.mozhu[1]
  331. local msgRet = Msg.gc.GC_MOZHU_QUERY
  332. msgRet.rank = msg.rank
  333. msgRet.myHurt = msg.hurt
  334. msgRet.time = os.time()
  335. fontQueryNet(msgRet, msg)
  336. fontBuff(union, msgRet)
  337. msgRet.tzCnt = MOZHU_TIAOZHAN_CNT - human.db.mozhu.tzCnt
  338. msgRet.restCnt = MOZHU_RESET_CNT - human.db.mozhu.restCnt
  339. msgRet.restNeed = config.rest[human.db.mozhu.restCnt + 1] or 0
  340. msgRet.jijieTime = getJijieEndTime(union)
  341. msgRet.isRead = human.db.mozhu.read or 0
  342. msgRet.post = member and member.post or 0
  343. if human.db.mozhu.onHero then
  344. for uuid, _ in pairs(human.db.mozhu.onHero) do
  345. msgRet.useHero[0] = msgRet.useHero[0] + 1
  346. msgRet.useHero[msgRet.useHero[0]].uuid = uuid
  347. end
  348. end
  349. msgRet.unionDot = unionRewardDot(human, msg)
  350. -- Msg.trace(msgRet)
  351. Msg.send(msgRet, human.fd)
  352. human.db.mozhu.read = 1
  353. end
  354. function queryRank(human, type)
  355. --local msgInner = InnerMsg.lw.LW_MOZHU_RANK_QUERY
  356. local msgInner = {}
  357. msgInner.uuid = human.db._id
  358. msgInner.type = type
  359. --InnerMsg.sendMsg(0, msgInner)
  360. MozhuMiddleLogic.LW_MOZHU_RANK_QUERY(0,msgInner)
  361. end
  362. function rankQueryWL(human, msg)
  363. -- Util.printTable(msg)
  364. local msgRet = Msg.gc.GC_MOZHU_RANK_QUERY
  365. msgRet.type = msg.type
  366. fontRoleNet(msgRet, msg)
  367. fontUnionNet(msgRet, msg)
  368. fontRankReward(msg.type, msgRet)
  369. -- Util.printTable(msgRet.roleList)
  370. Msg.send(msgRet, human.fd)
  371. end
  372. function unionHurtRewardQuery(human)
  373. local getId = human.db.mozhu and human.db.mozhu.unionGet or 0
  374. local msgRet = Msg.gc.GC_MOZHU_UNION_HURT_REWARD
  375. msgRet.isEnd = 0
  376. msgRet.getId = getId
  377. local len = 0
  378. for k, config in ipairs(MoZhuExcel.hurt) do
  379. len = len + 1
  380. local net = msgRet.list[len]
  381. net.id = k
  382. net.hurt = config.unionHurt
  383. for j, h in ipairs(config.reward) do
  384. Grid.makeItem(net.reward[j], h[1], h[2])
  385. end
  386. net.reward[0] = #config.reward
  387. if len >= 10 then
  388. msgRet.list[0] = len
  389. Msg.send(msgRet, human.fd)
  390. len = 0
  391. end
  392. end
  393. msgRet.list[0] = len
  394. msgRet.isEnd = 1
  395. Msg.send(msgRet, human.fd)
  396. end
  397. function unionHurtGet(human, id)
  398. if not human.db.unionUuid or human.db.unionUuid == "" then
  399. return
  400. end
  401. if not human.db.mozhu then return end
  402. local oldId = human.db.mozhu.unionGet or 0
  403. if id ~= oldId + 1 then return end
  404. local msgInner = {} -- InnerMsg.lw.LW_MOZHU_UNION_GET
  405. msgInner.uuid = human.db._id
  406. msgInner.unionUuid = human.db.unionUuid
  407. msgInner.id = id
  408. --InnerMsg.sendMsg(0, msgInner)
  409. MozhuMiddleLogic.LW_MOZHU_UNION_GET(0,msgInner)
  410. end
  411. function unionGetWL(human, msg)
  412. -- Util.printTable(msg)
  413. if msg.ret == 0 then
  414. return
  415. end
  416. local config = MoZhuExcel.hurt[msg.id]
  417. if not config then return end
  418. BagLogic.addItemList(human, config.reward, "ciYuanMozhu")
  419. human.db.mozhu.unionGet = msg.id
  420. local msgRet = Msg.gc.GC_MOZHU_REWARD_GET
  421. msgRet.id = msg.id
  422. Msg.send(msgRet, human.fd)
  423. end
  424. function jijie(human, str)
  425. if not human.db.unionUuid or human.db.unionUuid == "" then return end
  426. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  427. if not union then return end
  428. -- 检测官职 能否满足要求
  429. local member = UnionDBLogic.getUnionMember(union, human.db._id)
  430. if not member
  431. or (member.post ~= UnionDefine.POST_PRESIDENT and member.post ~= UnionDefine.POST_OFFICIAL) then
  432. return Broadcast.sendErr(human, Lang.UNION_HAVE_NO_POWER)
  433. end
  434. local mozhuTime = union.mozhuJijie or 0
  435. local now = os.time()
  436. local config = MoZhuExcel.mozhu[1]
  437. if now - mozhuTime <= config.jijie then
  438. return
  439. end
  440. union.mozhuJijie = now
  441. UnionDBLogic.updateUnionData(union)
  442. -- 发送 聊天 到公会
  443. if ChatUnion.chatUnionEctype(human, str) == 1 then
  444. return
  445. end
  446. local msgRet = Msg.gc.GC_MOZHU_JIJIE_DO
  447. msgRet.jijieTime = config.jijie
  448. Msg.send(msgRet, human.fd)
  449. Broadcast.sendErr(human, Lang.UNION_ECTYPE_JIJIE_SUCCESS)
  450. end
  451. function rest(human)
  452. if human.db.mozhu.tzCnt < 3 then
  453. return
  454. end
  455. local retstCnt = human.db.mozhu.restCnt + 1
  456. local config = MoZhuExcel.mozhu[1]
  457. if retstCnt > #config.rest then
  458. return
  459. end
  460. if not ObjHuman.checkRMB(human, config.rest[retstCnt]) then
  461. return
  462. end
  463. ObjHuman.decZuanshi(human,-config.rest[retstCnt],"ciYuanMozhu")
  464. human.db.mozhu.restCnt = human.db.mozhu.restCnt + 1
  465. human.db.mozhu.tzCnt = 0
  466. human.db.mozhu.hurt = 0
  467. human.db.mozhu.onHero = nil
  468. local msgRet = Msg.gc.GC_MOZHU_RESET
  469. msgRet.tzCnt = MOZHU_TIAOZHAN_CNT - human.db.mozhu.tzCnt
  470. msgRet.restCnt = #config.rest - human.db.mozhu.restCnt
  471. msgRet.restNeed = config.rest[retstCnt + 1] or 0
  472. Msg.send(msgRet, human.fd)
  473. end
  474. function buffUp(human)
  475. if not human.db.unionUuid or human.db.unionUuid == "" then return end
  476. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  477. if not union then return end
  478. local now = os.time()
  479. local lv = union.mozhuBufLv or 0
  480. local endTime = union.mozhuBufTime or now
  481. if endTime ~= 0 and now >= endTime then
  482. lv = 0
  483. endTime = now
  484. end
  485. if lv + 1 > #MoZhuExcel.buff then
  486. return
  487. end
  488. local config = MoZhuExcel.buff[lv + 1]
  489. if not ObjHuman.checkRMB(human, config.need) then
  490. return
  491. end
  492. ObjHuman.decZuanshi(human,-config.need,"ciYuanMozhu")
  493. union.mozhuBufLv = lv + 1
  494. union.mozhuBufTime = endTime + config.time
  495. UnionDBLogic.updateUnionData(union)
  496. local msgRet = Msg.gc.GC_MOZHU_BUFF_UP
  497. fontBuff(union, msgRet)
  498. Msg.send(msgRet, human.fd)
  499. end
  500. function ciTiaoQuery(human)
  501. if MOZHU_CITIAO then
  502. local msgRet = Msg.gc.GC_MOZHU_CITIAO_QUERY
  503. msgRet.time = MOZHU_CITIAO_TIME
  504. local len = 0
  505. for id in pairs(MOZHU_CITIAO) do
  506. len = len + 1
  507. local config = MoZhuExcel.citiao[id]
  508. local net = msgRet.list[len]
  509. net.id = id
  510. net.name = config.citiao
  511. net.desc = config.miaoshu
  512. end
  513. msgRet.list[0] = len
  514. Msg.send(msgRet, human.fd)
  515. end
  516. end
  517. -- 封装 BOSS 技能详情
  518. function fontDragonSkill(msgRet, monsterOutID)
  519. local monsterID
  520. for _, v in ipairs(MonsterExcel.monsterOut[monsterOutID].member) do
  521. if v and v[1] ~= 0 then
  522. monsterID = v[1]
  523. break
  524. end
  525. end
  526. local monsterConfig = MonsterExcel.monster[monsterID]
  527. local len = 1
  528. HeroLogic.makeSkillNet(msgRet.skillList[len], monsterConfig.normalAtkID)
  529. for k, v in ipairs(monsterConfig.skillList) do
  530. len = len + 1
  531. HeroLogic.makeSkillNet(msgRet.skillList[len], v)
  532. end
  533. for k , v in ipairs(monsterConfig.beSkillList) do
  534. if len < 4 then
  535. len = len + 1
  536. HeroLogic.makeSkillNet(msgRet.skillList[len], v)
  537. end
  538. end
  539. msgRet.skillList[0] = len
  540. end
  541. -- BOSS查询
  542. function bossQuery(human)
  543. local msgRet = Msg.gc.GC_MOZHU_BOSS_QUERY
  544. local config = MoZhuExcel.mozhu[1]
  545. msgRet.id = 1
  546. msgRet.desc = config.desc
  547. fontDragonSkill(msgRet, config.monsterOutID)
  548. Msg.send(msgRet, human.fd)
  549. end
  550. ----------------------------------- combat ------------------------------------------------------------------------
  551. function getCombatMonsterOutID(human, side, args)
  552. if side ~= CombatDefine.DEFEND_SIDE then return end
  553. local config = MoZhuExcel.mozhu[1]
  554. return config.monsterOutID
  555. end
  556. function getMapID()
  557. local config = MoZhuExcel.mozhu[1]
  558. return config.mapID
  559. end
  560. function getCombatObjList(human, side, args)
  561. if side ~= CombatDefine.DEFEND_SIDE then return end
  562. local monsterOutID = getCombatMonsterOutID(human, side)
  563. local objList, _, _,formation,jiban = CombatLogic.getMonsterObjList(monsterOutID, CombatDefine.COMBAT_OBJ_TYPE3 , args)
  564. local rolebase = CombatLogic.createRoleBaseDefault()
  565. local monsterConfig = MonsterExcel.monster[monsterOutID]
  566. if monsterConfig then
  567. rolebase.name = monsterConfig.name
  568. rolebase.lv = monsterLv or 1
  569. rolebase.head = monsterConfig.head
  570. rolebase.zhandouli = zhandouli or 0
  571. end
  572. return objList, nil, rolebase,formation,jiban
  573. end
  574. function onFightBegin(human)
  575. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  576. if not union then
  577. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  578. end
  579. local lv = union.mozhuBufLv
  580. local endTime = union.mozhuBufTime
  581. if not lv or not endTime then return end
  582. local now = os.time()
  583. if now < endTime then
  584. local bufConfig = MoZhuExcel.buff[lv]
  585. if not bufConfig then return end
  586. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  587. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  588. local atkObj = CombatImpl.objList[atkPos]
  589. if atkObj then
  590. for k, v in ipairs(bufConfig.attrs) do
  591. local key = v[1]
  592. local value = v[2]
  593. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  594. atkObj.isSysAttrChange = true
  595. end
  596. end
  597. end
  598. end
  599. end
  600. -- 不合适的下阵
  601. function updateCombatPosCheck(human)
  602. if human.db.mozhu and human.db.mozhu.onHero then
  603. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMABT_TYPE23)
  604. if not combatHero then return false end
  605. human.db.mozhu.onHero = human.db.mozhu.onHero or {}
  606. for pos, uuid in pairs(combatHero) do
  607. if human.db.mozhu.onHero[uuid] then
  608. combatHero[pos] = nil
  609. end
  610. end
  611. local len = 0
  612. for pos, uuid in pairs(combatHero) do
  613. len = len + 1
  614. end
  615. if len == 0 then
  616. return false
  617. end
  618. end
  619. return true
  620. end
  621. function fight(human, uuid)
  622. local startTime, endTime = getActTime()
  623. local now = os.time()
  624. if now < startTime or now >= endTime then
  625. Broadcast.sendErr(human, Lang.ACT_WAS_OVER)
  626. local msgRet = Msg.gc.GC_MOZHU_ACT_OVER
  627. Msg.send(msgRet, human.fd)
  628. return
  629. end
  630. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  631. if not union then
  632. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  633. end
  634. if human.db.mozhu and human.db.mozhu.tzCnt >= MOZHU_TIAOZHAN_CNT then
  635. return
  636. end
  637. --已经阵亡的英雄不能下阵
  638. if human.db.mozhu and human.db.mozhu.onHero then
  639. for it_uuid, _ in pairs(human.db.mozhu.onHero) do
  640. if uuid == it_uuid then
  641. Broadcast.sendErr(human, Lang.YJTREASURE_YAOJI_CURE_ERR2)
  642. return
  643. end
  644. end
  645. end
  646. local state = updateCombatPosCheck(human)
  647. if not state then
  648. return
  649. end
  650. local config = MoZhuExcel.mozhu[1]
  651. CombatLogic.combatBegin(human, config.mapID, 1 , CombatDefine.COMABT_TYPE23)
  652. end
  653. function setSkillAndBeskill(human,combatInfo)
  654. local myList = {}
  655. local bossList = {}
  656. for k in pairs(MOZHU_CITIAO) do
  657. local config = MoZhuExcel.citiao[k]
  658. if config.shengxiao == DragonNestLogic.CITIAO_BY_ATTACK then
  659. myList[#myList+1] = config.skillID
  660. elseif config.shengxiao == DragonNestLogic.CITIAO_BY_DEFEND then
  661. bossList[#bossList+1] = config.skillID
  662. end
  663. end
  664. if #myList > 0 then
  665. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE]) do
  666. local obj = CombatImpl.objList[pos]
  667. if obj then
  668. for _, skillID in ipairs(myList) do
  669. local skillConfig = SkillExcel[skillID]
  670. if skillConfig.beSkillType == BeSkill.BESKILL_TYPE24 then
  671. for _,skillID in ipairs(skillConfig.args) do
  672. local skillConfig = SkillExcel[skillID]
  673. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  674. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  675. skillID,
  676. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  677. skillConfig.cd[2] or 0, 0}
  678. end
  679. else
  680. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  681. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  682. skillID,
  683. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  684. skillConfig.cd[2] or 0, 0}
  685. end
  686. end
  687. end
  688. end
  689. end
  690. if #bossList > 0 then
  691. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.DEFEND_SIDE]) do
  692. local obj = CombatImpl.objList[pos]
  693. if obj then
  694. for _, skillID in ipairs(bossList) do
  695. local skillConfig = SkillExcel[skillID]
  696. if skillConfig.beSkillType == BeSkill.BESKILL_TYPE24 then
  697. for _,skillID in ipairs(skillConfig.args) do
  698. local skillConfig = SkillExcel[skillID]
  699. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  700. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  701. skillID,
  702. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  703. skillConfig.cd[2] or 0, 0}
  704. end
  705. else
  706. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  707. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  708. skillID,
  709. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  710. skillConfig.cd[2] or 0, 0}
  711. end
  712. end
  713. end
  714. end
  715. end
  716. end
  717. function makeBaseInfo(human, roleBase, unionBase)
  718. roleBase.uuid = human.db._id
  719. roleBase.name = human.db.name
  720. roleBase.lv = human.db.lv
  721. roleBase.unionUuid = human.db.unionUuid or ""
  722. roleBase.head = human.db.head or 0
  723. roleBase.headFrame = human.db.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  724. roleBase.bannerID = 0
  725. roleBase.svrName = Config.SVR_NAME
  726. roleBase.svrIndex = Config.SVR_INDEX
  727. if human.db.unionUuid then
  728. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  729. if union then
  730. roleBase.bannerID = union.bannerID
  731. unionBase.unionName = union.name
  732. unionBase.lv = union.lv
  733. unionBase.bannerID = union.bannerID
  734. unionBase.svrName = Config.SVR_NAME
  735. unionBase.svrIndex = Config.SVR_INDEX
  736. end
  737. end
  738. end
  739. function onFightEnd(human,result, combatType, cbParam , combatInfo)
  740. local atkHurt = 0
  741. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  742. local obj = combatInfo.objList and combatInfo.objList[pos]
  743. if obj then
  744. atkHurt = atkHurt + obj.result[1]
  745. -- local hero = human.db.heroBag[obj.bagIndex]
  746. -- Util.printTable(obj)
  747. end
  748. end
  749. -- 魔兽 造成伤害
  750. for _,pos in ipairs(CombatDefine.SIDE2HELPPOS[CombatDefine.ATTACK_SIDE]) do
  751. local pet = combatInfo.helpList and combatInfo.helpList[pos]
  752. if pet and pet.isPet then
  753. atkHurt = atkHurt + pet.result[1]
  754. end
  755. end
  756. if atkHurt <= 0 then
  757. atkHurt = 0
  758. end
  759. human.db.mozhu.hurt = human.db.mozhu.hurt or 0
  760. human.db.mozhu.hurt = human.db.mozhu.hurt + atkHurt
  761. --local msgInner = InnerMsg.lw.LW_MOZHU_FIGHT_END
  762. local msgInner = {}
  763. msgInner.uuid = human.db._id
  764. msgInner.unionUuid = human.db.unionUuid or ""
  765. msgInner.maxHurt = human.db.mozhu.hurt
  766. msgInner.combatInfo = {}
  767. msgInner.roleBase = {}
  768. msgInner.unionBase = {}
  769. msgInner.combatInfo = combatInfo
  770. makeBaseInfo(human, msgInner.roleBase, msgInner.unionBase)
  771. --InnerMsg.sendMsg(0, msgInner)
  772. MozhuMiddleLogic.LW_MOZHU_FIGHT_END(0,msgInner)
  773. YunYingLogic.onCallBack(human, "MoZhuCombat", 1)
  774. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_10, 1)
  775. TriggerLogic.PublishEvent(TriggerDefine.MOZHU_CHALLENGE, human.db._id, 1)
  776. end
  777. function onfightEndWL(human, msg)
  778. initHuman(human)
  779. -- Util.printTable(msg)
  780. --
  781. if msg.maxHurt ~= human.db.mozhu.maxHurt then
  782. human.db.mozhu.maxHurt = msg.maxHurt
  783. end
  784. local combatInfo = msg.combatInfo
  785. if msg.backType == 0 then
  786. -- 战斗完 活动已经过期
  787. else
  788. human.db.mozhu.tzCnt = human.db.mozhu.tzCnt + 1
  789. if msg.maxHurt ~= human.db.mozhu.maxHurt then
  790. human.db.mozhu.maxHurt = msg.maxHurt
  791. end
  792. human.db.mozhu.onHero = human.db.mozhu.onHero or {}
  793. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  794. local obj = combatInfo.objList and combatInfo.objList[pos]
  795. if obj and obj.bagIndex then
  796. local hero = human.db.heroBag[obj.bagIndex]
  797. if hero then
  798. human.db.mozhu.onHero[hero.uuid] = 1
  799. end
  800. -- Util.printTable(obj)
  801. end
  802. end
  803. if human.db.mozhu.restCnt == 0 then
  804. local hurtConfig = MoZhuExcel.hurt[human.db.mozhu.tzCnt]
  805. if hurtConfig and #hurtConfig.attackAct > 0 then
  806. combatInfo.rewardItem = combatInfo.rewardItem or {}
  807. for i = 1, #hurtConfig.attackAct do
  808. local itemID = hurtConfig.attackAct[i][1]
  809. local itemCnt = hurtConfig.attackAct[i][2]
  810. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or {}
  811. combatInfo.rewardItem[i] = {itemID, itemCnt}
  812. BagLogic.addItem(human, itemID, itemCnt, "ciYuanMozhu")
  813. end
  814. end
  815. end
  816. end
  817. local msgRet = Msg.gc.GC_MOZHU_FIGHT_END
  818. msgRet.hurt = msg.thisHurt
  819. msgRet.rank = msg.rank
  820. msgRet.oldRank = msg.oldRank
  821. msgRet.unionRank = msg.unionRank
  822. msgRet.oldUnionRank = msg.unionRanked
  823. CombatLogic.fontCombatFinish(msgRet.data, combatInfo)
  824. -- Msg.trace(msgRet)
  825. Msg.send(msgRet, human.fd)
  826. local combatType = CombatDefine.COMABT_TYPE23
  827. local teamType = CombatPosLogic.getTeamType(combatType)
  828. if human.db.combatHero[teamType] then
  829. -- 策划需求 需要保留 魔兽技能
  830. human.db.combatHero[teamType].list = {}
  831. -- human.db.combatHero[teamType].jiban = {}
  832. end
  833. -- CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMABT_TYPE23)
  834. updateDaily(human)
  835. if msg.backType == 0 then
  836. -- 战斗完 活动已经过期
  837. Broadcast.sendErr(human, Lang.ACT_WAS_OVER)
  838. local msgRet = Msg.gc.GC_MOZHU_ACT_OVER
  839. Msg.send(msgRet, human.fd)
  840. end
  841. end
  842. -----------------------------------------fight end - ------------------------
  843. ----------------------------------------- Act Over -------------------------------
  844. local function getRewardByRank(type, rank)
  845. for k, config in ipairs(MoZhuExcel.rank) do
  846. if type == MOZHU_ROLE_RANK_TYPE_1 and config.roleMin <= rank and config.roleMax >= rank then
  847. return k
  848. elseif type == MOZHU_UNION_RANK_TYPE_2 and config.unionMin <= rank and config.unionMax >= rank then
  849. return k
  850. end
  851. end
  852. end
  853. function actOverRank(msg)
  854. if msg.type == 1 then
  855. roleRankOver(msg)
  856. elseif msg.type == 2 then
  857. unionRankOver(msg)
  858. end
  859. end
  860. function roleRankOver(msg)
  861. -- Util.printTable(msg)
  862. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_MOZHU_ROLE_RANK]
  863. local title = mailConfig.title
  864. local senderName = mailConfig.senderName
  865. for uuid, rank in pairs(msg.list) do
  866. local id = getRewardByRank(msg.type, rank)
  867. local config = MoZhuExcel.rank[id]
  868. if config then
  869. local content = Util.format(mailConfig.content, rank)
  870. MailManager.add(MailManager.SYSTEM, uuid, title, content, config.reward, senderName)
  871. end
  872. end
  873. end
  874. function unionRankOver(msg)
  875. -- Util.printTable(msg)
  876. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_MOZHU_UNION_RANK]
  877. local title = mailConfig.title
  878. local senderName = mailConfig.senderName
  879. for unionUuid, rank in pairs(msg.list) do
  880. local id = getRewardByRank(msg.type, rank)
  881. local config = MoZhuExcel.rank[id]
  882. local union = UnionDBLogic.getUnion(unionUuid)
  883. if config and union and union.member then
  884. -- 每个工会随机延迟发放奖励,避免服务器卡顿
  885. local r = math.random(60)
  886. require("core.Timer").addLater(r,function()
  887. local content = Util.format(mailConfig.content, rank)
  888. for uuid in pairs(union.member) do
  889. MailManager.add(MailManager.SYSTEM, uuid, title, content, config.unionReward, senderName)
  890. end
  891. end)
  892. end
  893. end
  894. end