MoZhuLogic.lua 34 KB

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