MoZhuLogic.lua 32 KB

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