XingYaoGongMing.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. -- 星曜之门-星耀共鸣
  2. local ObjHuman = require("core.ObjHuman")
  3. local Util = require("common.Util")
  4. local Msg = require("core.Msg")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local Lang = require("common.Lang")
  7. local BagLogic = require("bag.BagLogic")
  8. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  9. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  10. local XingYaoMenExcel = require("excel.xingYaoMen")
  11. local HeroGrid = require("hero.HeroGrid")
  12. local Grid = require("bag.Grid")
  13. local HeroLogic = require("hero.HeroLogic")
  14. local HeroEquip = require("hero.HeroEquip")
  15. local FuwenLogic = require("fuwen.FuwenLogic")
  16. local ItemDefine = require("bag.ItemDefine")
  17. local Log = require("common.Log")
  18. local LogDefine = require("common.LogDefine")
  19. -- human.db.xingYaoGongMing = {
  20. -- defList = nil --守卫者
  21. -- gridList = nil --保存格子信息
  22. -- xingYaoHe = nil --星耀之核
  23. -- }
  24. -- gridList[index] = {
  25. -- heroIndex = nil
  26. -- cdTime = nil --冷却时间
  27. -- }
  28. -- defList[heroIndex] = heroIndex
  29. XINGYAO_GONGMING_DEFMAX = 5 -- 5个守护者
  30. XYHERO_LV = 1
  31. XYHERO_RESET = 2
  32. local function makeXyGmGridsByIndex(human,net,gridIndex,gridData)
  33. net.index = gridIndex
  34. net.oldLV = 0
  35. net.hero[0] = 0
  36. local heroIndex = gridData.heroIndex
  37. if heroIndex then
  38. local heroGrid = human.db.heroBag[heroIndex]
  39. if heroGrid then
  40. net.hero[0] = 1
  41. HeroGrid.makeHeroSimple(net.hero[1], heroGrid, heroIndex, human)
  42. net.oldLV = heroGrid.oldLV or 0
  43. end
  44. end
  45. net.leftTime = 0
  46. if gridData.cdTime then
  47. net.leftTime = math.max(gridData.cdTime - os.time(),0)
  48. end
  49. end
  50. local function makeXyGmGrids(human,net,conf)
  51. net[0] = 0
  52. if not human.db.xingYaoGongMing or not human.db.xingYaoGongMing.gridList then return end
  53. for index,data in pairs(human.db.xingYaoGongMing.gridList) do
  54. net[0] = net[0] + 1
  55. local index = net[0]
  56. makeXyGmGridsByIndex(human,net[index],index,data)
  57. end
  58. end
  59. local function gongMingGridHeroOff(human,heroGrid,heroIndex)
  60. local oldLv = heroGrid.oldLV or 0
  61. Log.write(Log.LOGID_TEST, "XingYaoGongMing gongMingGridHeroOff hero OldLv: "..oldLv.." Lv: "..heroGrid.lv.." humanUuid: ", human.db._id)
  62. makeLvQuality(heroGrid)
  63. HeroEquip.putOffQuick(human, heroGrid.id, heroIndex, true)
  64. FuwenLogic.putOffQuick(human, heroGrid.id, heroIndex, true)
  65. ObjHuman.doCalcHero(human, heroIndex)
  66. HeroLogic.sendHeroGridDynamic(human, heroGrid, heroIndex)
  67. end
  68. local function makeGongMingDef(human)
  69. local maxIndex = nil
  70. local maxLV = nil
  71. local maxZhanDouLi = nil
  72. for i = 1, human.db.heroBag[0] do
  73. local heroGrid = human.db.heroBag[i]
  74. local defList = human.db.xingYaoGongMing.defList
  75. if heroGrid then
  76. if not defList or not defList[i] then
  77. local lv = heroGrid.lv
  78. if heroGrid.oldLV then
  79. lv = heroGrid.oldLV
  80. end
  81. local set = nil
  82. if not maxLV and not maxZhanDouLi then
  83. set = true
  84. else
  85. if maxLV < lv then
  86. set = true
  87. elseif maxLV == lv and maxZhanDouLi < heroGrid.zhandouli then
  88. set = true
  89. end
  90. end
  91. --print("i,maxLV,lv,maxZhanDouLi,zhandouli,set",i,maxLV,lv,maxZhanDouLi,heroGrid.zhandouli,set)
  92. if set then
  93. maxLV = lv
  94. maxIndex = i
  95. maxZhanDouLi = heroGrid.zhandouli
  96. end
  97. end
  98. end
  99. end
  100. if not maxIndex then return end
  101. local gridIndex = isGongMing(human,maxIndex)
  102. if gridIndex then
  103. local gridList = human.db.xingYaoGongMing.gridList
  104. if gridList then
  105. gridList[gridIndex].heroIndex = nil
  106. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  107. end
  108. local heroGrid = human.db.heroBag[maxIndex]
  109. gongMingGridHeroOff(human,heroGrid,maxIndex)
  110. end
  111. human.db.xingYaoGongMing.defList = human.db.xingYaoGongMing.defList or {}
  112. human.db.xingYaoGongMing.defList[maxIndex] = maxIndex
  113. end
  114. local function checkGongMingDB(human)
  115. --if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  116. --return
  117. --end
  118. if human.db.xingYaoGongMing then return end
  119. human.db.xingYaoGongMing = {}
  120. human.db.xingYaoGongMing.gridList = {}
  121. human.db.xingYaoGongMing.gridList[1] = {}
  122. for i=1,XINGYAO_GONGMING_DEFMAX do
  123. makeGongMingDef(human)
  124. end
  125. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  126. end
  127. function CG_XINGYAOMEN_GONGMING_QUERY(human)
  128. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  129. return
  130. end
  131. checkGongMingDB(human)
  132. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_QUERY
  133. local conf = XingYaoMenExcel.gongMing[1]
  134. makeXyGmGrids(human,msgRet.grid,conf)
  135. msgRet.maxGrid = conf.gridMax
  136. msgRet.defList[0] = 0
  137. local db = human.db.xingYaoGongMing
  138. if db and db.defList then
  139. for heroIndex in pairs(db.defList) do
  140. local heroGrid = human.db.heroBag[heroIndex]
  141. if heroGrid then
  142. msgRet.defList[0] = msgRet.defList[0] + 1
  143. local index = msgRet.defList[0]
  144. HeroGrid.makeHeroSimple(msgRet.defList[index], heroGrid, heroIndex, human)
  145. end
  146. end
  147. end
  148. Grid.makeItem(msgRet.cdClean,conf.cdClean[1],conf.cdClean[2])
  149. --Msg.trace(msgRet)
  150. Msg.send(msgRet,human.fd)
  151. GC_XINGYAOMEN_GONGMING_REDS(human)
  152. end
  153. local function gridCanOpen(human,gridIndex,send,checkItem)
  154. checkGongMingDB(human)
  155. local db = human.db.xingYaoGongMing
  156. if not db or not db.gridList then return end
  157. if gridIndex ~= 1 and not db.gridList[gridIndex - 1] then
  158. if send then
  159. Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_OPEN_ERR1)
  160. end
  161. return
  162. elseif db.gridList[gridIndex] then
  163. if send then
  164. Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_OPEN_ERR2)
  165. end
  166. return
  167. end
  168. if checkItem then
  169. local gongMingConf = XingYaoMenExcel.gongMing[1]
  170. local conf = XingYaoMenExcel.gongMingGrid
  171. local needItem = gongMingConf.openGridCostItem
  172. local needCnt = 0
  173. if gridIndex > #conf then
  174. needCnt = conf[#conf].openCost
  175. else
  176. needCnt = conf[gridIndex].openCost
  177. end
  178. local now = BagLogic.getItemCnt(human, ItemDefine.ITEM_XINGYAOGONGMING_ID)
  179. if now < needCnt then
  180. if send then
  181. Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_OPEN_ERR)
  182. end
  183. return
  184. end
  185. end
  186. return true
  187. end
  188. function CG_XINGYAOMEN_GONGMING_OPEN_QUERY(human,gridIndex)
  189. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  190. return
  191. end
  192. local gongMingConf = XingYaoMenExcel.gongMing[1]
  193. if gridIndex > gongMingConf.gridMax then
  194. return Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_OPEN_ERR3)
  195. end
  196. if not gridCanOpen(human,gridIndex,true) then return end
  197. local conf = XingYaoMenExcel.gongMingGrid
  198. local needItem = gongMingConf.openGridCostItem
  199. local needCnt = 0
  200. if gridIndex > #conf then
  201. needCnt = conf[#conf].openCost
  202. else
  203. needCnt = conf[gridIndex].openCost
  204. end
  205. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_OPEN_QUERY
  206. Grid.makeItem(msgRet.cost, needItem, needCnt)
  207. msgRet.now = BagLogic.getItemCnt(human, ItemDefine.ITEM_XINGYAOGONGMING_ID)
  208. --Msg.trace(msgRet)
  209. Msg.send(msgRet,human.fd)
  210. end
  211. function CG_XINGYAOMEN_GONGMING_OPEN_DO(human,gridIndex)
  212. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  213. return
  214. end
  215. local gongMingConf = XingYaoMenExcel.gongMing[1]
  216. if gridIndex > gongMingConf.gridMax then return end
  217. if not gridCanOpen(human,gridIndex,true,true) then return end
  218. local conf = XingYaoMenExcel.gongMingGrid
  219. local needItem = gongMingConf.openGridCostItem
  220. local needCnt = 0
  221. if gridIndex > #conf then
  222. needCnt = conf[#conf].openCost
  223. else
  224. needCnt = conf[gridIndex].openCost
  225. end
  226. local now = BagLogic.getItemCnt(human, ItemDefine.ITEM_XINGYAOGONGMING_ID)
  227. if now < needCnt then
  228. return
  229. end
  230. BagLogic.delItem(human, ItemDefine.ITEM_XINGYAOGONGMING_ID, needCnt, "xingyao_gongming")
  231. human.db.xingYaoGongMing.gridList[gridIndex] = {}
  232. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_OPEN_DO
  233. msgRet.gridIndex = gridIndex
  234. --Msg.trace(msgRet)
  235. Msg.send(msgRet,human.fd)
  236. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  237. GC_XINGYAOMEN_GONGMING_REDS(human)
  238. end
  239. function CG_XINGYAOMEN_GONGMING_PUTON(human,heroIndex,gridIndex)
  240. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  241. return
  242. end
  243. checkGongMingDB(human)
  244. local db = human.db.xingYaoGongMing
  245. if not db then return end
  246. local conf = XingYaoMenExcel.gongMing[1]
  247. if gridIndex > conf.gridMax then return end
  248. local mingLV,mingIndex = getGongMingLV(human)
  249. if mingLV == 0 then
  250. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_DEF_ERR)
  251. end
  252. local heroGrid = human.db.heroBag[heroIndex]
  253. local mingGrid = human.db.heroBag[mingIndex]
  254. if not heroGrid or not mingGrid then return end
  255. if db.defList[heroIndex] then
  256. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_DEF_ERR)
  257. end
  258. if heroGrid.lv >= mingLV then
  259. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_ON_ERR5)
  260. end
  261. if not db.gridList or not db.gridList[gridIndex] then
  262. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_GRID_OPEN_ERR)
  263. end
  264. local gridData = db.gridList[gridIndex]
  265. if gridData then
  266. if gridData.heroIndex then
  267. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_ON_ERR2)
  268. elseif gridData.cdTime then
  269. local leftTime = math.max(gridData.cdTime - os.time(),0)
  270. if leftTime > 0 then
  271. return Broadcast.sendErr(human, Util.format(Lang.XINGYAOMEN_GONGMING_ON_ERR3,leftTime))
  272. end
  273. end
  274. end
  275. for _,data in pairs(db.gridList) do
  276. if data.heroIndex == heroIndex then
  277. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_ON_ERR1)
  278. end
  279. end
  280. human.db.xingYaoGongMing.gridList[gridIndex].heroIndex = heroIndex
  281. makeLvQuality(heroGrid,mingGrid)
  282. HeroLogic.sendHeroGridDynamic(human, heroGrid, heroIndex)
  283. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_PUTON
  284. msgRet.heroIndex = heroIndex
  285. msgRet.gridIndex = gridIndex
  286. HeroGrid.makeHeroSimple(msgRet.hero,heroGrid,heroIndex,human)
  287. makeXyGmGridsByIndex(human,msgRet.grid,gridIndex,human.db.xingYaoGongMing.gridList[gridIndex])
  288. Msg.send(msgRet,human.fd)
  289. ObjHuman.doCalcHero(human, heroIndex)
  290. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  291. end
  292. function CG_XINGYAOMEN_GONGMING_PUTOFF(human,gridIndex)
  293. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  294. return
  295. end
  296. checkGongMingDB(human)
  297. local db = human.db.xingYaoGongMing
  298. if not db then return end
  299. if not db.gridList or not db.gridList[gridIndex] then
  300. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_GRID_OPEN_ERR)
  301. end
  302. if not db.gridList[gridIndex].heroIndex then
  303. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_GRID_HERO_NO)
  304. end
  305. local heroIndex = db.gridList[gridIndex].heroIndex
  306. db.gridList[gridIndex].heroIndex = nil
  307. local heroGrid = human.db.heroBag[heroIndex]
  308. if not heroGrid then end
  309. local now = os.time()
  310. local conf = XingYaoMenExcel.gongMing[1]
  311. db.gridList[gridIndex].cdTime = now + conf.cdTime
  312. gongMingGridHeroOff(human,heroGrid,heroIndex)
  313. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_PUTOFF
  314. msgRet.gridIndex = gridIndex
  315. msgRet.leftTime = math.max(db.gridList[gridIndex].cdTime - now,0)
  316. --Msg.trace(msgRet)
  317. Msg.send(msgRet,human.fd)
  318. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  319. end
  320. function CG_XINGYAOMEN_GONGMING_CDCLEAN(human,gridIndex)
  321. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302,true) then
  322. return
  323. end
  324. local db = human.db.xingYaoGongMing
  325. if not db then return end
  326. if not db.gridList or not db.gridList[gridIndex] then
  327. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_GRID_OPEN_ERR)
  328. end
  329. if not db.gridList[gridIndex].cdTime then return end
  330. local leftTime = math.max(db.gridList[gridIndex].cdTime - os.time(),0)
  331. if leftTime <= 0 then
  332. return Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_CD_CLEAN)
  333. end
  334. local conf = XingYaoMenExcel.gongMing[1]
  335. if not BagLogic.checkItemCnt(human,conf.cdClean[1],conf.cdClean[2]) then
  336. return
  337. end
  338. BagLogic.delItem(human,conf.cdClean[1],conf.cdClean[2],"xingyao_gongming")
  339. db.gridList[gridIndex].cdTime = nil
  340. Broadcast.sendErr(human, Lang.XINGYAOMEN_GONGMING_CD_CLEAN_OK)
  341. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_CDCLEAN
  342. msgRet.gridIndex = gridIndex
  343. --Msg.trace(msgRet)
  344. Msg.send(msgRet,human.fd)
  345. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  346. end
  347. function getGongMingLV(human)
  348. local db = human.db.xingYaoGongMing
  349. if not db or not db.defList then return 0,0,0 end
  350. local mingLV = nil
  351. local mingIndex = nil
  352. local defCnt = 0
  353. for index in pairs(db.defList) do
  354. local heroGrid = human.db.heroBag[index]
  355. if heroGrid then
  356. defCnt = defCnt + 1
  357. if not mingLV or mingLV > heroGrid.lv then
  358. mingLV = heroGrid.lv
  359. mingIndex = index
  360. end
  361. end
  362. end
  363. if defCnt < XINGYAO_GONGMING_DEFMAX then
  364. return 0,0,0
  365. end
  366. return mingLV,mingIndex,defCnt
  367. end
  368. -- 是否正在共鸣 则不能做常规升级
  369. function isGongMing(human,heroIndex,sendType)
  370. if not human or not human.db.xingYaoGongMing or not human.db.xingYaoGongMing.gridList then return end
  371. for index,data in pairs(human.db.xingYaoGongMing.gridList) do
  372. if data.heroIndex and heroIndex == data.heroIndex then
  373. if sendType and sendType == XYHERO_LV then
  374. Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_LVUP_ERR)
  375. elseif sendType and sendType == XYHERO_RESET then
  376. Broadcast.sendErr(human,Lang.XINGYAOMEN_GONGMING_RESET_ERR)
  377. end
  378. return index
  379. end
  380. end
  381. end
  382. --刷新入驻英雄共鸣等级
  383. function refreshGongMing(human)
  384. if not human.db.xingYaoGongMing or not human.db.xingYaoGongMing.gridList then return end
  385. local mingLV,mingIndex = getGongMingLV(human)
  386. if mingLV == 0 then return end
  387. for i,data in pairs(human.db.xingYaoGongMing.gridList) do
  388. if data.heroIndex then
  389. local heroGrid = human.db.heroBag[data.heroIndex]
  390. local mingGrid = human.db.heroBag[mingIndex]
  391. if heroGrid and mingGrid then
  392. local send = nil
  393. if mingLV ~= heroGrid.lv then
  394. heroGrid.lv = mingLV
  395. send = true
  396. end
  397. if heroGrid.quality ~= mingGrid.quality then
  398. heroGrid.quality = mingGrid.quality
  399. send = true
  400. end
  401. if send then
  402. ObjHuman.doCalcHero(human, data.heroIndex)
  403. HeroLogic.sendHeroGridDynamic(human, heroGrid, data.heroIndex)
  404. end
  405. end
  406. end
  407. end
  408. end
  409. --增加新的英雄,是否影响到守卫和共鸣等级 heroIndex新增英雄背包index
  410. function onAddHero(human,heroGrid,heroIndex)
  411. --if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  412. --return
  413. --end
  414. --print("onAddHero lv heroIndex",heroGrid.lv,heroIndex)
  415. checkGongMingDB(human)
  416. local mingLV,minIndex,defCnt = getGongMingLV(human)
  417. human.db.xingYaoGongMing.defList = human.db.xingYaoGongMing.defList or {}
  418. local defList = human.db.xingYaoGongMing.defList
  419. if defList[heroIndex] then return end
  420. if defCnt >= XINGYAO_GONGMING_DEFMAX then
  421. if heroGrid.lv > mingLV then
  422. defList[minIndex] = nil
  423. defList[heroIndex] = heroIndex
  424. end
  425. refreshGongMing(human)
  426. else
  427. human.db.xingYaoGongMing.defList[heroIndex] = heroIndex
  428. end
  429. end
  430. --删除英雄,是否影响到守卫和共鸣等级 heroIndex原英雄背包index
  431. function onDelHero(human, heroGrid, heroIndex)
  432. --if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  433. --return
  434. --end
  435. checkGongMingDB(human)
  436. local defList = human.db.xingYaoGongMing.defList
  437. if not defList or not defList[heroIndex] then --删除的英雄不是守卫者,走卸下入驻逻辑
  438. putOff(human,heroGrid,heroIndex)
  439. return
  440. end
  441. defList[heroIndex] = nil
  442. makeGongMingDef(human)
  443. refreshGongMing(human)
  444. end
  445. --英雄升级,是否影响到守卫和共鸣等级 heroIndex原英雄背包index
  446. function onHeroLvUp(human,heroGrid,heroIndex)
  447. --if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  448. --return
  449. --end
  450. --print("onHeroLvUp lv heroIndex",heroGrid.lv,heroIndex)
  451. checkGongMingDB(human)
  452. local mingLV,minIndex,defCnt = getGongMingLV(human)
  453. local defList = human.db.xingYaoGongMing.defList
  454. if not defList then return end
  455. if defList[heroIndex] then
  456. refreshGongMing(human)
  457. else
  458. if heroGrid.lv > mingLV then
  459. human.db.xingYaoGongMing.defList[minIndex] = nil
  460. human.db.xingYaoGongMing.defList[heroIndex] = heroIndex
  461. refreshGongMing(human)
  462. end
  463. end
  464. end
  465. --英雄升阶
  466. function onHeroUpgrade(human,heroGrid,heroIndex)
  467. --if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  468. --return
  469. --end
  470. checkGongMingDB(human)
  471. local defList = human.db.xingYaoGongMing.defList
  472. if not defList then return end
  473. if not defList[heroIndex] then return end
  474. refreshGongMing(human)
  475. end
  476. --英雄分解重生觉醒等等操作,下阵入驻英雄
  477. function putOff(human,heroGrid,heroIndex)
  478. local gridIndex = isGongMing(human,heroIndex)
  479. if not gridIndex then return end
  480. local oldLv = heroGrid.oldLV or 0
  481. Log.write(Log.LOGID_TEST, "XingYaoGongMing putOff hero OldLv: "..oldLv.." Lv: "..heroGrid.lv.." humanUuid: ", human.db._id)
  482. makeLvQuality(heroGrid)
  483. human.db.xingYaoGongMing.gridList[gridIndex] = {}
  484. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_302)
  485. end
  486. --征战扫荡掉落
  487. local function onSaoDang(human,items)
  488. local conf = XingYaoMenExcel.gongMing[1]
  489. local battleExtraItem = conf.battleExtraItem
  490. local battleExtraSaoDang = conf.battleExtraSaoDang
  491. local randomCnt = math.random(battleExtraSaoDang[1],battleExtraSaoDang[2])
  492. items[battleExtraItem] = (items[battleExtraItem] or 0) + randomCnt
  493. end
  494. --征战挂机收益
  495. function getItemOut(human,items,outCnt)
  496. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  497. return
  498. end
  499. checkGongMingDB(human)
  500. if not outCnt then
  501. onSaoDang(human,items)
  502. return
  503. end
  504. local conf = XingYaoMenExcel.gongMing[1]
  505. local battleExtraItem = conf.battleExtraItem
  506. local battleExtraCnt = conf.battleExtraCnt
  507. local cnt = math.ceil(math.random(battleExtraCnt[1] * outCnt,battleExtraCnt[2] * outCnt))
  508. if cnt > 0 then
  509. items[battleExtraItem] = (items[battleExtraItem] or 0) + cnt
  510. end
  511. end
  512. --扫荡奖励列表
  513. function getItemOutsShow(human,items)
  514. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_302) then
  515. return
  516. end
  517. checkGongMingDB(human)
  518. local conf = XingYaoMenExcel.gongMing[1]
  519. local battleExtraItem = conf.battleExtraItem
  520. items[battleExtraItem] = 1
  521. end
  522. function getGongMingLVByIndex(human,heroIndex)
  523. if not human then return 0 end
  524. if not isGongMing(human,heroIndex) then return 0 end
  525. local mingLV = getGongMingLV(human)
  526. return mingLV or 0
  527. end
  528. function GC_XINGYAOMEN_GONGMING_REDS(human)
  529. local msgRet = Msg.gc.GC_XINGYAOMEN_GONGMING_REDS
  530. msgRet.nextGridRed = 0
  531. local db = human.db.xingYaoGongMing
  532. if not db or not db.gridList then return end
  533. local conf = XingYaoMenExcel.gongMing[1]
  534. local nextGrid = math.min(#db.gridList + 1,conf.gridMax)
  535. if not db.gridList[nextGrid] then
  536. if gridCanOpen(human,nextGrid,nil,true) then
  537. msgRet.nextGridRed = 1
  538. end
  539. end
  540. --Msg.trace(msgRet)
  541. Msg.send(msgRet,human.fd)
  542. end
  543. function makeLvQuality(heroGrid,targetGrid)
  544. if targetGrid then
  545. heroGrid.oldLV = heroGrid.lv
  546. heroGrid.lv = targetGrid.lv
  547. heroGrid.oldQuality = heroGrid.quality
  548. heroGrid.quality = targetGrid.quality
  549. else
  550. heroGrid.lv = heroGrid.oldLV
  551. heroGrid.oldLV = nil
  552. heroGrid.quality = heroGrid.oldQuality
  553. heroGrid.oldQuality = nil
  554. end
  555. end
  556. function isDot(human)
  557. if not human.db.xingYaoGongMing
  558. or not human.db.xingYaoGongMing.gridList
  559. then return true
  560. end
  561. local gridList = human.db.xingYaoGongMing.gridList
  562. local conf = XingYaoMenExcel.gongMing[1]
  563. local nextGrid = math.min(#gridList + 1,conf.gridMax)
  564. if not gridList[nextGrid] then
  565. if gridCanOpen(human,nextGrid,nil,true) then
  566. return true
  567. end
  568. end
  569. end