MoZhuLogic.lua 32 KB

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