MoZhuLogic.lua 32 KB

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