MoZhuLogic.lua 33 KB

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