MoZhuLogic.lua 33 KB

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