MoZhuLogic.lua 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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. -- 新修改:一键领取所有可领取奖励
  411. local msgInner = {} -- InnerMsg.lw.LW_MOZHU_UNION_GET
  412. msgInner.uuid = human.db._id
  413. msgInner.unionUuid = human.db.unionUuid
  414. -- msgInner.id = id
  415. --InnerMsg.sendMsg(0, msgInner)
  416. MozhuMiddleLogic.LW_MOZHU_UNION_GET(0,msgInner)
  417. end
  418. function unionGetWL(human, msg)
  419. -- Util.printTable(msg)
  420. if msg.ret == 0 then
  421. return
  422. end
  423. -- local config = MoZhuExcel.hurt[msg.id]
  424. -- if not config then return end
  425. -- BagLogic.addItemList(human, config.reward, "ciYuanMozhu")
  426. -- human.db.mozhu.unionGet = msg.id
  427. local len = 0
  428. local itemVec = {}
  429. local getIdx = human.db.mozhu.unionGet or 0
  430. for _, idx in ipairs(msg.rewardIdxList) do
  431. local config = MoZhuExcel.hurt[idx]
  432. if config and idx > getIdx then
  433. for _, item in ipairs(config.reward) do
  434. len = len + 1
  435. itemVec[len] = item
  436. getIdx = idx
  437. -- human.db.mozhu.unionGet = idx
  438. end
  439. end
  440. end
  441. if len == 0 then
  442. return
  443. end
  444. human.db.mozhu.unionGet = getIdx
  445. BagLogic.addItemList(human, itemVec, "ciYuanMozhu")
  446. local msgRet = Msg.gc.GC_MOZHU_REWARD_GET
  447. -- msgRet.id = msg.id
  448. msgRet.id = human.db.mozhu.unionGet
  449. Msg.send(msgRet, human.fd)
  450. end
  451. function jijie(human, str)
  452. if not human.db.unionUuid or human.db.unionUuid == "" then return end
  453. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  454. if not union then return end
  455. -- 检测官职 能否满足要求
  456. local member = UnionDBLogic.getUnionMember(union, human.db._id)
  457. if not member
  458. or (member.post ~= UnionDefine.POST_PRESIDENT and member.post ~= UnionDefine.POST_OFFICIAL) then
  459. return Broadcast.sendErr(human, Lang.UNION_HAVE_NO_POWER)
  460. end
  461. local mozhuTime = union.mozhuJijie or 0
  462. local now = os.time()
  463. local config = MoZhuExcel.mozhu[1]
  464. if now - mozhuTime <= config.jijie then
  465. return
  466. end
  467. union.mozhuJijie = now
  468. UnionDBLogic.updateUnionData(union)
  469. -- 发送 聊天 到公会
  470. if ChatUnion.chatUnionEctype(human, str) == 1 then
  471. return
  472. end
  473. local msgRet = Msg.gc.GC_MOZHU_JIJIE_DO
  474. msgRet.jijieTime = config.jijie
  475. Msg.send(msgRet, human.fd)
  476. Broadcast.sendErr(human, Lang.UNION_ECTYPE_JIJIE_SUCCESS)
  477. end
  478. function rest(human)
  479. if human.db.mozhu.tzCnt < 3 then
  480. return
  481. end
  482. local retstCnt = human.db.mozhu.restCnt + 1
  483. local config = MoZhuExcel.mozhu[1]
  484. if retstCnt > #config.rest then
  485. return
  486. end
  487. if not ObjHuman.checkRMB(human, config.rest[retstCnt]) then
  488. return
  489. end
  490. ObjHuman.decZuanshi(human,-config.rest[retstCnt],"ciYuanMozhu")
  491. human.db.mozhu.restCnt = human.db.mozhu.restCnt + 1
  492. human.db.mozhu.tzCnt = 0
  493. human.db.mozhu.hurt = 0
  494. human.db.mozhu.onHero = nil
  495. local msgRet = Msg.gc.GC_MOZHU_RESET
  496. msgRet.tzCnt = MOZHU_TIAOZHAN_CNT - human.db.mozhu.tzCnt
  497. msgRet.restCnt = #config.rest - human.db.mozhu.restCnt
  498. msgRet.restNeed = config.rest[retstCnt + 1] or 0
  499. Msg.send(msgRet, human.fd)
  500. end
  501. function buffUp(human)
  502. if not human.db.unionUuid or human.db.unionUuid == "" then return end
  503. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  504. if not union then return end
  505. local now = os.time()
  506. local lv = union.mozhuBufLv or 0
  507. local endTime = union.mozhuBufTime or now
  508. if endTime ~= 0 and now >= endTime then
  509. lv = 0
  510. endTime = now
  511. end
  512. if lv + 1 > #MoZhuExcel.buff then
  513. return
  514. end
  515. local config = MoZhuExcel.buff[lv + 1]
  516. if not ObjHuman.checkRMB(human, config.need) then
  517. return
  518. end
  519. ObjHuman.decZuanshi(human,-config.need,"ciYuanMozhu")
  520. union.mozhuBufLv = lv + 1
  521. union.mozhuBufTime = endTime + config.time
  522. UnionDBLogic.updateUnionData(union)
  523. local msgRet = Msg.gc.GC_MOZHU_BUFF_UP
  524. fontBuff(union, msgRet)
  525. Msg.send(msgRet, human.fd)
  526. end
  527. function ciTiaoQuery(human)
  528. if MOZHU_CITIAO then
  529. local msgRet = Msg.gc.GC_MOZHU_CITIAO_QUERY
  530. msgRet.time = MOZHU_CITIAO_TIME
  531. local len = 0
  532. for id in pairs(MOZHU_CITIAO) do
  533. len = len + 1
  534. local config = MoZhuExcel.citiao[id]
  535. local net = msgRet.list[len]
  536. net.id = id
  537. net.name = config.citiao
  538. net.desc = config.miaoshu
  539. end
  540. msgRet.list[0] = len
  541. Msg.send(msgRet, human.fd)
  542. end
  543. end
  544. -- 封装 BOSS 技能详情
  545. function fontDragonSkill(msgRet, monsterOutID)
  546. local monsterID
  547. for _, v in ipairs(MonsterExcel.monsterOut[monsterOutID].member) do
  548. if v and v[1] ~= 0 then
  549. monsterID = v[1]
  550. break
  551. end
  552. end
  553. local monsterConfig = MonsterExcel.monster[monsterID]
  554. local len = 1
  555. HeroLogic.makeSkillNet(msgRet.skillList[len], monsterConfig.normalAtkID)
  556. for k, v in ipairs(monsterConfig.skillList) do
  557. len = len + 1
  558. HeroLogic.makeSkillNet(msgRet.skillList[len], v)
  559. end
  560. for k , v in ipairs(monsterConfig.beSkillList) do
  561. if len < 4 then
  562. len = len + 1
  563. HeroLogic.makeSkillNet(msgRet.skillList[len], v)
  564. end
  565. end
  566. msgRet.skillList[0] = len
  567. end
  568. -- BOSS查询
  569. function bossQuery(human)
  570. local msgRet = Msg.gc.GC_MOZHU_BOSS_QUERY
  571. local config = MoZhuExcel.mozhu[1]
  572. msgRet.id = 1
  573. msgRet.desc = config.desc
  574. fontDragonSkill(msgRet, config.monsterOutID)
  575. Msg.send(msgRet, human.fd)
  576. end
  577. ----------------------------------- combat ------------------------------------------------------------------------
  578. function getCombatMonsterOutID(human, side, args)
  579. if side ~= CombatDefine.DEFEND_SIDE then return end
  580. local config = MoZhuExcel.mozhu[1]
  581. return config.monsterOutID
  582. end
  583. function getMapID()
  584. local config = MoZhuExcel.mozhu[1]
  585. return config.mapID
  586. end
  587. function getCombatObjList(human, side, args)
  588. if side ~= CombatDefine.DEFEND_SIDE then return end
  589. local monsterOutID = getCombatMonsterOutID(human, side)
  590. local objList, _, _,formation,jiban, elfList = CombatLogic.getMonsterObjList(monsterOutID, CombatDefine.COMBAT_OBJ_TYPE3 , args)
  591. local rolebase = CombatLogic.createRoleBaseDefault()
  592. local monsterConfig = MonsterExcel.monster[monsterOutID]
  593. if monsterConfig then
  594. rolebase.name = monsterConfig.name
  595. rolebase.lv = monsterLv or 1
  596. rolebase.head = monsterConfig.head
  597. rolebase.zhandouli = zhandouli or 0
  598. end
  599. return objList, nil, rolebase,formation,jiban, elfList
  600. end
  601. function onFightBegin(human)
  602. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  603. if not union then
  604. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  605. end
  606. local lv = union.mozhuBufLv
  607. local endTime = union.mozhuBufTime
  608. if not lv or not endTime then return end
  609. local now = os.time()
  610. if now < endTime then
  611. local bufConfig = MoZhuExcel.buff[lv]
  612. if not bufConfig then return end
  613. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  614. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  615. local atkObj = CombatImpl.objList[atkPos]
  616. if atkObj then
  617. for k, v in ipairs(bufConfig.attrs) do
  618. local key = v[1]
  619. local value = v[2]
  620. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  621. atkObj.isSysAttrChange = true
  622. end
  623. end
  624. end
  625. end
  626. end
  627. -- 不合适的下阵
  628. function updateCombatPosCheck(human)
  629. if human.db.mozhu and human.db.mozhu.onHero then
  630. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMABT_TYPE23)
  631. if not combatHero then return false end
  632. human.db.mozhu.onHero = human.db.mozhu.onHero or {}
  633. for pos, uuid in pairs(combatHero) do
  634. if human.db.mozhu.onHero[uuid] then
  635. combatHero[pos] = nil
  636. end
  637. end
  638. local len = 0
  639. for pos, uuid in pairs(combatHero) do
  640. len = len + 1
  641. end
  642. if len == 0 then
  643. return false
  644. end
  645. end
  646. return true
  647. end
  648. function fight(human, uuid)
  649. local startTime, endTime = getActTime()
  650. local now = os.time()
  651. if now < startTime or now >= endTime then
  652. Broadcast.sendErr(human, Lang.ACT_WAS_OVER)
  653. local msgRet = Msg.gc.GC_MOZHU_ACT_OVER
  654. Msg.send(msgRet, human.fd)
  655. return
  656. end
  657. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  658. if not union then
  659. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  660. end
  661. if human.db.mozhu and human.db.mozhu.tzCnt >= MOZHU_TIAOZHAN_CNT then
  662. return
  663. end
  664. --已经阵亡的英雄不能下阵
  665. if human.db.mozhu and human.db.mozhu.onHero then
  666. for it_uuid, _ in pairs(human.db.mozhu.onHero) do
  667. if uuid == it_uuid then
  668. Broadcast.sendErr(human, Lang.YJTREASURE_YAOJI_CURE_ERR2)
  669. return
  670. end
  671. end
  672. end
  673. local state = updateCombatPosCheck(human)
  674. if not state then
  675. return
  676. end
  677. local config = MoZhuExcel.mozhu[1]
  678. CombatLogic.combatBegin(human, config.mapID, 1 , CombatDefine.COMABT_TYPE23)
  679. end
  680. function setSkillAndBeskill(human,combatInfo)
  681. local myList = {}
  682. local bossList = {}
  683. for k in pairs(MOZHU_CITIAO) do
  684. local config = MoZhuExcel.citiao[k]
  685. if config.shengxiao == DragonNestLogic.CITIAO_BY_ATTACK then
  686. myList[#myList+1] = config.skillID
  687. elseif config.shengxiao == DragonNestLogic.CITIAO_BY_DEFEND then
  688. bossList[#bossList+1] = config.skillID
  689. end
  690. end
  691. if #myList > 0 then
  692. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE]) do
  693. local obj = CombatImpl.objList[pos]
  694. if obj then
  695. for _, skillID in ipairs(myList) do
  696. local skillConfig = SkillExcel[skillID]
  697. if skillConfig.beSkillType == BeSkill.BESKILL_TYPE24 then
  698. for _,skillID in ipairs(skillConfig.args) do
  699. local skillConfig = SkillExcel[skillID]
  700. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  701. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  702. skillID,
  703. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  704. skillConfig.cd[2] or 0, 0}
  705. end
  706. else
  707. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  708. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  709. skillID,
  710. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  711. skillConfig.cd[2] or 0, 0}
  712. end
  713. end
  714. end
  715. end
  716. end
  717. if #bossList > 0 then
  718. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.DEFEND_SIDE]) do
  719. local obj = CombatImpl.objList[pos]
  720. if obj then
  721. for _, skillID in ipairs(bossList) do
  722. local skillConfig = SkillExcel[skillID]
  723. if skillConfig.beSkillType == BeSkill.BESKILL_TYPE24 then
  724. for _,skillID in ipairs(skillConfig.args) do
  725. local skillConfig = SkillExcel[skillID]
  726. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  727. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  728. skillID,
  729. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  730. skillConfig.cd[2] or 0, 0}
  731. end
  732. else
  733. obj.beSkillList[skillConfig.beSkillType] = obj.beSkillList[skillConfig.beSkillType] or {}
  734. obj.beSkillList[skillConfig.beSkillType][#obj.beSkillList[skillConfig.beSkillType] + 1] = {
  735. skillID,
  736. skillConfig.beSkillLimit > 0 and skillConfig.beSkillLimit,skillConfig.cd[1] or 0,
  737. skillConfig.cd[2] or 0, 0}
  738. end
  739. end
  740. end
  741. end
  742. end
  743. end
  744. function makeBaseInfo(human, roleBase, unionBase)
  745. roleBase.uuid = human.db._id
  746. roleBase.name = human.db.name
  747. roleBase.lv = human.db.lv
  748. roleBase.unionUuid = human.db.unionUuid or ""
  749. roleBase.head = human.db.head or 0
  750. roleBase.headFrame = human.db.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  751. roleBase.bannerID = 0
  752. roleBase.svrName = Config.SVR_NAME
  753. roleBase.svrIndex = Config.SVR_INDEX
  754. if human.db.unionUuid then
  755. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  756. if union then
  757. roleBase.bannerID = union.bannerID
  758. unionBase.unionName = union.name
  759. unionBase.lv = union.lv
  760. unionBase.bannerID = union.bannerID
  761. unionBase.svrName = Config.SVR_NAME
  762. unionBase.svrIndex = Config.SVR_INDEX
  763. end
  764. end
  765. end
  766. function onFightEnd(human,result, combatType, cbParam , combatInfo)
  767. local atkHurt = 0
  768. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  769. local obj = combatInfo.objList and combatInfo.objList[pos]
  770. if obj then
  771. atkHurt = atkHurt + obj.result[1]
  772. -- local hero = human.db.heroBag[obj.bagIndex]
  773. -- Util.printTable(obj)
  774. end
  775. end
  776. -- 魔兽 造成伤害
  777. for _,pos in ipairs(CombatDefine.SIDE2HELPPOS[CombatDefine.ATTACK_SIDE]) do
  778. local pet = combatInfo.helpList and combatInfo.helpList[pos]
  779. if pet and pet.isPet then
  780. atkHurt = atkHurt + pet.result[1]
  781. end
  782. end
  783. -- 精灵 造成伤害
  784. for _,pos in ipairs(CombatDefine.SIDE2ELFPOS[CombatDefine.ATTACK_SIDE]) do
  785. local elf = combatInfo.elfList and combatInfo.elfList[pos]
  786. if elf then
  787. atkHurt = atkHurt + elf.result[1]
  788. end
  789. end
  790. if atkHurt <= 0 then
  791. atkHurt = 0
  792. end
  793. human.db.mozhu.hurt = human.db.mozhu.hurt or 0
  794. human.db.mozhu.hurt = human.db.mozhu.hurt + atkHurt
  795. --local msgInner = InnerMsg.lw.LW_MOZHU_FIGHT_END
  796. local msgInner = {}
  797. msgInner.uuid = human.db._id
  798. msgInner.unionUuid = human.db.unionUuid or ""
  799. msgInner.maxHurt = human.db.mozhu.hurt
  800. msgInner.combatInfo = {}
  801. msgInner.roleBase = {}
  802. msgInner.unionBase = {}
  803. msgInner.combatInfo = combatInfo
  804. makeBaseInfo(human, msgInner.roleBase, msgInner.unionBase)
  805. --InnerMsg.sendMsg(0, msgInner)
  806. MozhuMiddleLogic.LW_MOZHU_FIGHT_END(0,msgInner)
  807. YunYingLogic.onCallBack(human, "MoZhuCombat", 1)
  808. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_10, 1)
  809. TriggerLogic.PublishEvent(TriggerDefine.MOZHU_CHALLENGE, human.db._id, 1)
  810. end
  811. function onfightEndWL(human, msg)
  812. initHuman(human)
  813. -- Util.printTable(msg)
  814. --
  815. if msg.maxHurt ~= human.db.mozhu.maxHurt then
  816. human.db.mozhu.maxHurt = msg.maxHurt
  817. end
  818. local combatInfo = msg.combatInfo
  819. if msg.backType == 0 then
  820. -- 战斗完 活动已经过期
  821. else
  822. human.db.mozhu.tzCnt = human.db.mozhu.tzCnt + 1
  823. if msg.maxHurt ~= human.db.mozhu.maxHurt then
  824. human.db.mozhu.maxHurt = msg.maxHurt
  825. end
  826. human.db.mozhu.onHero = human.db.mozhu.onHero or {}
  827. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  828. local obj = combatInfo.objList and combatInfo.objList[pos]
  829. if obj and obj.bagIndex then
  830. local hero = human.db.heroBag[obj.bagIndex]
  831. if hero then
  832. human.db.mozhu.onHero[hero.uuid] = 1
  833. end
  834. -- Util.printTable(obj)
  835. end
  836. end
  837. if human.db.mozhu.restCnt == 0 then
  838. local hurtConfig = MoZhuExcel.hurt[human.db.mozhu.tzCnt]
  839. if hurtConfig and #hurtConfig.attackAct > 0 then
  840. combatInfo.rewardItem = combatInfo.rewardItem or {}
  841. for i = 1, #hurtConfig.attackAct do
  842. local itemID = hurtConfig.attackAct[i][1]
  843. local itemCnt = hurtConfig.attackAct[i][2]
  844. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or {}
  845. combatInfo.rewardItem[i] = {itemID, itemCnt}
  846. BagLogic.addItem(human, itemID, itemCnt, "ciYuanMozhu")
  847. end
  848. end
  849. end
  850. end
  851. local msgRet = Msg.gc.GC_MOZHU_FIGHT_END
  852. msgRet.hurt = msg.thisHurt
  853. msgRet.rank = msg.rank
  854. msgRet.oldRank = msg.oldRank
  855. msgRet.unionRank = msg.unionRank
  856. msgRet.oldUnionRank = msg.unionRanked
  857. CombatLogic.fontCombatFinish(msgRet.data, combatInfo)
  858. -- Msg.trace(msgRet)
  859. Msg.send(msgRet, human.fd)
  860. local combatType = CombatDefine.COMABT_TYPE23
  861. local teamType = CombatPosLogic.getTeamType(combatType)
  862. if human.db.combatHero[teamType] then
  863. -- 策划需求 需要保留 魔兽技能
  864. human.db.combatHero[teamType].list = {}
  865. -- human.db.combatHero[teamType].jiban = {}
  866. end
  867. -- CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMABT_TYPE23)
  868. updateDaily(human)
  869. if msg.backType == 0 then
  870. -- 战斗完 活动已经过期
  871. Broadcast.sendErr(human, Lang.ACT_WAS_OVER)
  872. local msgRet = Msg.gc.GC_MOZHU_ACT_OVER
  873. Msg.send(msgRet, human.fd)
  874. end
  875. end
  876. -----------------------------------------fight end - ------------------------
  877. ----------------------------------------- Act Over -------------------------------
  878. local function getRewardByRank(type, rank)
  879. for k, config in ipairs(MoZhuExcel.rank) do
  880. if type == MOZHU_ROLE_RANK_TYPE_1 and config.roleMin <= rank and config.roleMax >= rank then
  881. return k
  882. elseif type == MOZHU_UNION_RANK_TYPE_2 and config.unionMin <= rank and config.unionMax >= rank then
  883. return k
  884. end
  885. end
  886. end
  887. function actOverRank(msg)
  888. if msg.type == 1 then
  889. roleRankOver(msg)
  890. elseif msg.type == 2 then
  891. unionRankOver(msg)
  892. end
  893. end
  894. function roleRankOver(msg)
  895. -- Util.printTable(msg)
  896. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_MOZHU_ROLE_RANK]
  897. local title = mailConfig.title
  898. local senderName = mailConfig.senderName
  899. for uuid, rank in pairs(msg.list) do
  900. local id = getRewardByRank(msg.type, rank)
  901. local config = MoZhuExcel.rank[id]
  902. if config then
  903. local content = Util.format(mailConfig.content, rank)
  904. MailManager.add(MailManager.SYSTEM, uuid, title, content, config.reward, senderName)
  905. end
  906. end
  907. end
  908. function unionRankOver(msg)
  909. -- Util.printTable(msg)
  910. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_MOZHU_UNION_RANK]
  911. local title = mailConfig.title
  912. local senderName = mailConfig.senderName
  913. for unionUuid, rank in pairs(msg.list) do
  914. local id = getRewardByRank(msg.type, rank)
  915. local config = MoZhuExcel.rank[id]
  916. local union = UnionDBLogic.getUnion(unionUuid)
  917. if config and union and union.member then
  918. -- 每个工会随机延迟发放奖励,避免服务器卡顿
  919. local r = math.random(60)
  920. require("core.Timer").addLater(r,function()
  921. local content = Util.format(mailConfig.content, rank)
  922. for uuid in pairs(union.member) do
  923. MailManager.add(MailManager.SYSTEM, uuid, title, content, config.unionReward, senderName)
  924. end
  925. end)
  926. end
  927. end
  928. end