MoZhuLogic.lua 33 KB

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