LianyuLogic.lua 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. ------------------------------------------
  2. -- 绝望深渊
  3. -- 角色db
  4. -- db.lianyu.maxLv 最大通关数
  5. -- db.lianyu.firstreward 首通奖励领取标记 [id]=true
  6. -- db.lianyu.todayMaxLv [每日重置]今日0点最大通关
  7. -- db.lianyu.todayWinLv [每日重置]今日成功挑战x关
  8. -- db.lianyu.todayHelpUuid [每日重置]助战目标
  9. -- 角色d缓存
  10. -- 角色
  11. -- human.db.lianyuCache
  12. -- lianyuCache.bufferList 可选buffer列表
  13. -- lianyuCache.bufferIndex 已选择buffer
  14. -- lianyuCache.combatHelp 支援对象战斗数据
  15. -- lianyuCache.combatHelpPos 支援对象站位
  16. -- lianyuCache.startLv 起始关
  17. -- lianyuCache.winLv 胜利关数
  18. -- lianyuCache.oldWinLv 老的胜利关数
  19. -- lianyuCache.combatHpRates 剩余血量 [pos]=rate
  20. -- lianyuCache.combatResult 最近战斗结果
  21. -- common db
  22. -- [uuid] = {heroGrid,combatObj,rolebase,helpCnt,helpUuids}
  23. ------------------------------------------
  24. local LianyuExcel = require("excel.lianyu")
  25. local MailExcel = require("excel.mail")
  26. local Util = require("common.Util")
  27. local Lang = require("common.Lang")
  28. local CommonDB = require("common.CommonDB")
  29. local Msg = require("core.Msg")
  30. local ObjHuman = require("core.ObjHuman")
  31. local Broadcast = require("broadcast.Broadcast")
  32. local Grid = require("bag.Grid")
  33. local BagLogic = require("bag.BagLogic")
  34. local ItemDefine = require("bag.ItemDefine")
  35. local BRoleLogic = require("billboard.BRoleLogic")
  36. local BillboardDB = require("billboard.BillboardDB")
  37. local BillboardDefine = require("billboard.BillboardDefine")
  38. local CombatObj = require("combat.CombatObj")
  39. local CombatImpl = require("combat.CombatImpl")
  40. local CombatLogic = require("combat.CombatLogic")
  41. local CombatDefine = require("combat.CombatDefine")
  42. local CombatPosLogic = require("combat.CombatPosLogic")
  43. local RoleAttr = require("role.RoleAttr")
  44. local RoleLogic = require("role.RoleLogic")
  45. local RoleDefine = require("role.RoleDefine")
  46. local RoleDBLogic = require("role.RoleDBLogic")
  47. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  48. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  49. local FriendDBLogic = require("friend.FriendDBLogic")
  50. local HeroGrid = require("hero.HeroGrid")
  51. local HeroLogic = require("hero.HeroLogic")
  52. local MailManager = require("mail.MailManager")
  53. local MailDefine = require("mail.MailIdDefine")
  54. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  55. local Timer = require("core.Timer")
  56. local JibanLogic = require("combat.JibanLogic")
  57. local MengxinLogic = require("present.MengxinLogic")
  58. local Log = require("common.Log")
  59. local YunYingLogic = require("yunying.YunYingLogic")
  60. local BeSkill = require("combat.BeSkill")
  61. local HeroDefine = require("hero.HeroDefine")
  62. local PER_FIVELEVEL = 5 --每隔5关(首通奖励,buffer选择)
  63. local STARTLEVEL_DIFF = 10 --起始关卡差值
  64. local FRIEND_DEGREE_MAX = 10 --活跃度次数上限
  65. local REWARD_SHOW_MAXCNT = 10 --奖励展示数量
  66. local MAX_HEROCOMBAT_MUL = 120 --最大倍数百分比
  67. local MAX_HP_RATE = 10000 --血量万分比
  68. local FRIEND_HELP_MAXCNT = 10 --获得助战奖励次数
  69. local FRIEND_ITEM_CNT = 10 --每次助战获得x点友情点
  70. local STATUS_START_BUTTON0 = 0 -- 开始挑战(红点)
  71. local STATUS_START_BUTTON1 = 1 -- 重新开始
  72. local STATUS_START_BUTTON2 = 2 -- 重新开始(5关奖励全领了)
  73. -- ============================== db ==================================
  74. -- 最大通关数
  75. function getMaxLv(human)
  76. if not human.db.lianyu then
  77. return 0
  78. end
  79. return human.db.lianyu.maxLv or 0
  80. end
  81. function setMaxLv(human, maxLv)
  82. if not human.db.lianyu then
  83. human.db.lianyu = {}
  84. end
  85. human.db.lianyu.maxLv = maxLv
  86. BRoleLogic.updateData(BillboardDefine.TYPE_LIANYU, human.db)
  87. end
  88. -- 首通奖励
  89. function isFirstGet(human, id)
  90. if not human.db.lianyu then
  91. return
  92. end
  93. if not human.db.lianyu.firstreward then
  94. return
  95. end
  96. return human.db.lianyu.firstreward[id]
  97. end
  98. function setFirstGet(human, id)
  99. if not human.db.lianyu then
  100. human.db.lianyu = {}
  101. end
  102. if not human.db.lianyu.firstreward then
  103. human.db.lianyu.firstreward = {}
  104. end
  105. human.db.lianyu.firstreward[id] = true
  106. end
  107. -- 获取本日起始关
  108. function getTodayStartLv(human)
  109. local lianyuDB = human.db.lianyu
  110. if not lianyuDB or not lianyuDB.todayMaxLv then
  111. return 1
  112. end
  113. return math.max(lianyuDB.todayMaxLv - STARTLEVEL_DIFF, 1)
  114. end
  115. -- 本日已胜利关卡
  116. function getTodayWinLv(human)
  117. local lianyuDB = human.db.lianyu
  118. if not lianyuDB then
  119. return
  120. end
  121. return lianyuDB.todayWinLv
  122. end
  123. function setTodayWinLv(human, todayWinLv)
  124. if not human.db.lianyu then
  125. human.db.lianyu = {}
  126. end
  127. human.db.lianyu.todayWinLv = todayWinLv
  128. end
  129. -- 获取助战信息
  130. function getTodayHelp(human)
  131. local lianyuDB = human.db.lianyu
  132. if not lianyuDB then
  133. return
  134. end
  135. local todayHelpUuid = lianyuDB.todayHelpUuid
  136. if not todayHelpUuid then
  137. return
  138. end
  139. if not FriendDBLogic.isFriend(human.db._id, todayHelpUuid) then
  140. lianyuDB.todayHelpUuid = nil
  141. return
  142. end
  143. local lyCommon = getLianyuCommon()
  144. local helpInfo = getHelpInfo(lyCommon, todayHelpUuid)
  145. return helpInfo, todayHelpUuid
  146. end
  147. -- 设置新的助战
  148. function setTodayHelp(human, todayHelpUuid)
  149. if not human.db.lianyu then
  150. human.db.lianyu = {}
  151. end
  152. human.db.lianyu.todayHelpUuid = todayHelpUuid
  153. end
  154. -- ============================== 缓存 ==================================
  155. function cleanCache(human)
  156. human.db.lianyuCache = nil
  157. end
  158. function getLianyuCache(human)
  159. return human.db.lianyuCache
  160. end
  161. -- 初始
  162. function initCombatCache(human)
  163. human.db.lianyuCache = {}
  164. local lianyuCache = human.db.lianyuCache
  165. lianyuCache.startLv = getTodayStartLv(human)
  166. lianyuCache.oldWinLv = getTodayWinLv(human) or 0
  167. lianyuCache.winLv = nil
  168. lianyuCache.bufferList = nil
  169. lianyuCache.bufferIndex = nil
  170. lianyuCache.combatHelp = nil
  171. lianyuCache.combatHelpPos = nil
  172. lianyuCache.combatResult = nil
  173. lianyuCache.combatHpRates = nil
  174. lianyuCache.combatObjSkill = nil
  175. lianyuCache.combatHelpSkill = nil
  176. lianyuCache.objList = nil
  177. lianyuCache.helpList = nil
  178. lianyuCache.rolebase = nil
  179. lianyuCache.formation = nil
  180. lianyuCache.jiban = nil
  181. lianyuCache.backupPos2index = nil -- 援军信息 [战斗位置] = 援军的index
  182. randBuffers(human)
  183. return lianyuCache
  184. end
  185. -- 根据类型随机buffer
  186. local BUFFER_KEY_LIST = {"buff1", "buff2", "buff3"}
  187. function randBufferByType(bufferType)
  188. local keyName = BUFFER_KEY_LIST[bufferType]
  189. if not keyName then
  190. return
  191. end
  192. local list = LianyuExcel.bufferitem[1][keyName]
  193. if not list then
  194. return
  195. end
  196. local weightSum = 0
  197. for _, cf in ipairs(list) do
  198. local weight = cf[1]
  199. weightSum = weightSum + weight
  200. end
  201. if weightSum < 1 then
  202. return
  203. end
  204. local r = math.random(1, weightSum)
  205. for _, cf in ipairs(list) do
  206. local weight = cf[1]
  207. local itemID = cf[2]
  208. if r <= weight then
  209. return itemID
  210. end
  211. r = r - weight
  212. end
  213. end
  214. -- 随机buffer列表
  215. function randBuffers(human)
  216. local lianyuCache = getLianyuCache(human)
  217. if not lianyuCache then
  218. return
  219. end
  220. lianyuCache.bufferList = {}
  221. lianyuCache.bufferIndex = nil
  222. for bufferType = 1, #BUFFER_KEY_LIST do
  223. local len = #lianyuCache.bufferList
  224. local itemID = randBufferByType(bufferType)
  225. lianyuCache.bufferList[len + 1] = itemID
  226. end
  227. end
  228. -- 设置已选择的buffer
  229. function setBufferIndex(human, bufferIndex)
  230. local lianyuCache = getLianyuCache(human)
  231. if not lianyuCache then
  232. return
  233. end
  234. if not lianyuCache.bufferList then
  235. return
  236. end
  237. local itemID = lianyuCache.bufferList[bufferIndex]
  238. if not itemID then
  239. return
  240. end
  241. lianyuCache.bufferIndex = bufferIndex
  242. end
  243. -- 获取已选择的buffer
  244. function getSelectBuffer(human)
  245. local lianyuCache = getLianyuCache(human)
  246. if not lianyuCache then
  247. return
  248. end
  249. local bufferIndex = lianyuCache.bufferIndex
  250. if not bufferIndex then
  251. return
  252. end
  253. return lianyuCache.bufferList[bufferIndex]
  254. end
  255. -- 获取助战对象
  256. function getCombatHelp(human)
  257. local lianyuCache = getLianyuCache(human)
  258. if not lianyuCache then
  259. return
  260. end
  261. return lianyuCache.combatHelp, lianyuCache.combatHelpPos
  262. end
  263. -- 助战上阵
  264. function setCombatHelpPos(human, pos)
  265. local lianyuCache = getLianyuCache(human)
  266. if not lianyuCache then
  267. return
  268. end
  269. if lianyuCache.combatHelpPos then
  270. return
  271. end
  272. local helpInfo = getTodayHelp(human)
  273. if not helpInfo then
  274. return
  275. end
  276. lianyuCache.combatHelp = helpInfo
  277. lianyuCache.combatHelpPos = pos
  278. return lianyuCache.combatHelp
  279. end
  280. -- 获取战斗过程血量
  281. function getCombatHpRate(human, index)
  282. local lianyuCache = getLianyuCache(human)
  283. if not lianyuCache then
  284. return MAX_HP_RATE
  285. end
  286. if not lianyuCache.combatHpRates then
  287. return MAX_HP_RATE
  288. end
  289. return lianyuCache.combatHpRates[index] or MAX_HP_RATE
  290. end
  291. -- ============================== common db ==================================
  292. function getLianyuCommon()
  293. local lyCommon = CommonDB.getValueByKey(CommonDB.KEY_LIANYU)
  294. local nowTime = os.time()
  295. local dayStartTime = Util.getDayStartTime(nowTime)
  296. if not lyCommon or lyCommon.dayStartTime ~= dayStartTime then
  297. lyCommon = {}
  298. lyCommon.dayStartTime = dayStartTime
  299. lyCommon.list = {}
  300. CommonDB.updateValue(CommonDB.KEY_LIANYU, lyCommon)
  301. end
  302. return lyCommon
  303. end
  304. -- 根据uuid获取助战信息
  305. function getHelpInfo(lyCommon, uuid)
  306. if not uuid then
  307. return
  308. end
  309. return lyCommon.list[uuid]
  310. end
  311. -- 设置助战信息
  312. function addHelpInfo(lyCommon, uuid, heroGrid, combatObj, rolebase)
  313. local helpInfo = {}
  314. helpInfo.uuid = uuid
  315. helpInfo.heroGrid = heroGrid
  316. helpInfo.combatObj = combatObj
  317. helpInfo.rolebase = rolebase
  318. helpInfo.helpCnt = 0
  319. helpInfo.helpUuids = {}
  320. lyCommon.list[uuid] = helpInfo
  321. CommonDB.updateValue(CommonDB.KEY_LIANYU, lyCommon)
  322. end
  323. -- 是否助战过
  324. function isHelpTarget(helpInfo, targetUuid)
  325. if helpInfo.helpUuids[targetUuid] then
  326. return true
  327. end
  328. end
  329. -- 记录助战
  330. function setHelpTarget(helpInfo, targetUuid)
  331. helpInfo.helpUuids[targetUuid] = os.time()
  332. helpInfo.helpCnt = helpInfo.helpCnt + 1
  333. local lyCommon = getLianyuCommon()
  334. CommonDB.updateValue(CommonDB.KEY_LIANYU, lyCommon)
  335. end
  336. -- ============================== config ==================================
  337. -- 根据名次获取奖励配置
  338. function getRankConfig(rank)
  339. for _, config in ipairs(LianyuExcel.rankreward) do
  340. if rank < config.rankMin then
  341. break
  342. end
  343. if rank <= config.rankMax then
  344. return config
  345. end
  346. end
  347. end
  348. -- 获取前10关未领取的首通奖励id列表
  349. local FIRST_REWARD_IDS = {}
  350. function getFirstRewardIDs(human)
  351. Util.cleanTable(FIRST_REWARD_IDS)
  352. for id, config in ipairs(LianyuExcel.gamelevel) do
  353. if #config.firstrewards > 0 then
  354. if #FIRST_REWARD_IDS >= REWARD_SHOW_MAXCNT then
  355. break
  356. end
  357. if not isFirstGet(human, id) then
  358. FIRST_REWARD_IDS[#FIRST_REWARD_IDS + 1] = id
  359. end
  360. end
  361. end
  362. return FIRST_REWARD_IDS
  363. end
  364. -- 获取最近需要展示的奖励
  365. function getNearFirstReward(human)
  366. for id, config in ipairs(LianyuExcel.gamelevel) do
  367. if #config.firstrewards > 0 then
  368. if not isFirstGet(human, id) then
  369. return id, config
  370. end
  371. end
  372. end
  373. end
  374. -- ============================== msg ==================================
  375. -- 是否有奖励红点
  376. function hasRewardRed(human)
  377. local firstNeedLv, firstConfig = getNearFirstReward(human)
  378. if not firstNeedLv then
  379. return
  380. end
  381. return getMaxLv(human) >= firstNeedLv
  382. end
  383. -- 是否有助战红点
  384. function hasHelpRed(human)
  385. local lyCommon = getLianyuCommon()
  386. return not getHelpInfo(lyCommon, human.db._id)
  387. end
  388. -- 主界面查询
  389. function sendQuery(human)
  390. local flag, config = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  391. -- if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1205, true) then
  392. -- return
  393. -- end
  394. if not flag then
  395. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NEED_LEVEL, config.lv))
  396. end
  397. ObjHuman.updateDaily(human)
  398. local msgRet = Msg.gc.GC_LIANYU_QUERY
  399. local dataNet = msgRet.data
  400. local maxLv = getMaxLv(human)
  401. dataNet.maxLv = maxLv
  402. -- 排名相关
  403. local board = BillboardDB.getBoard(BillboardDefine.TYPE_LIANYU)
  404. dataNet.boardList[0] = math.min(#dataNet.boardList, #board.rank2data)
  405. for i = 1, dataNet.boardList[0] do
  406. local rankData = board.rank2data[i]
  407. local boardNet = dataNet.boardList[i]
  408. local db = RoleDBLogic.getDb(rankData.uuid, "name")
  409. boardNet.rank = i
  410. boardNet.name = db and db.name or ""
  411. boardNet.lv = rankData.value1
  412. end
  413. local myRank = BillboardDB.getRank(BillboardDefine.TYPE_LIANYU, human.db._id) or 0
  414. local myRankConfig = getRankConfig(myRank)
  415. dataNet.myRank = myRank
  416. dataNet.myRankItems[0] = myRankConfig and #myRankConfig.rewards or 0
  417. for i = 1, dataNet.myRankItems[0] do
  418. local itemID = myRankConfig.rewards[i][1]
  419. local itemCnt = myRankConfig.rewards[i][2]
  420. Grid.makeItem(dataNet.myRankItems[i], itemID, itemCnt)
  421. end
  422. -- 首通奖励
  423. local firstNeedLv, firstConfig = getNearFirstReward(human)
  424. dataNet.firstNeedLv = firstNeedLv or 0
  425. dataNet.firstItems[0] = firstConfig and #firstConfig.firstrewards or 0
  426. for i = 1, dataNet.firstItems[0] do
  427. local itemID = firstConfig.firstrewards[i][1]
  428. local itemCnt = firstConfig.firstrewards[i][2]
  429. Grid.makeItem(dataNet.firstItems[i], itemID, itemCnt)
  430. end
  431. dataNet.firstLeftCnt = firstNeedLv and math.max(firstNeedLv - maxLv, 0) or 0
  432. dataNet.rewardRed = hasRewardRed(human) and 1 or 0
  433. -- 助战相关
  434. dataNet.helpRed = hasHelpRed(human) and 1 or 0
  435. dataNet.helpByUuid = ""
  436. local targetHelp = getTodayHelp(human)
  437. dataNet.helpHero[0] = 0
  438. if targetHelp and targetHelp.heroGrid then
  439. dataNet.helpByUuid = targetHelp.uuid
  440. dataNet.helpHero[0] = 1
  441. HeroGrid.makeHeroSimple(dataNet.helpHero[1], targetHelp.heroGrid, targetHelp.heroGrid.bagIndex)
  442. end
  443. -- 每日5关奖励
  444. local todayWinLv = getTodayWinLv(human)
  445. dataNet.status = STATUS_START_BUTTON0
  446. if todayWinLv then
  447. dataNet.status = STATUS_START_BUTTON1
  448. if todayWinLv >= PER_FIVELEVEL then
  449. dataNet.status = STATUS_START_BUTTON2
  450. end
  451. end
  452. dataNet.todayStartLv = getTodayStartLv(human)
  453. dataNet.todayWinLv = todayWinLv or 0
  454. -- Msg.trace(msgRet)
  455. Msg.send(msgRet, human.fd)
  456. end
  457. -- 首通奖励查询
  458. function sendFirstRewardQuery(human)
  459. local list = getFirstRewardIDs(human)
  460. local maxLv = getMaxLv(human)
  461. local msgRet = Msg.gc.GC_LIANYU_FIRST_REWARD_QUERY
  462. msgRet.list[0] = list and #list or 0
  463. for i = 1, msgRet.list[0] do
  464. local needLv = list[i]
  465. local net = msgRet.list[i]
  466. local config = LianyuExcel.gamelevel[needLv]
  467. net.needLv = needLv
  468. net.leftLv = math.max(needLv - maxLv, 0)
  469. net.items[0] = #config.firstrewards
  470. for j = 1, net.items[0] do
  471. local itemID = config.firstrewards[j][1]
  472. local itemCnt = config.firstrewards[j][2]
  473. Grid.makeItem(net.items[j], itemID, itemCnt)
  474. end
  475. end
  476. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  477. --Msg.trace(msgRet)
  478. Msg.send(msgRet, human.fd)
  479. end
  480. -- 领取首通奖励
  481. function getFirstReward(human, needLv, getway)
  482. local config = LianyuExcel.gamelevel[needLv]
  483. if not config then
  484. return
  485. end
  486. local maxLv = getMaxLv(human)
  487. if maxLv < needLv then
  488. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  489. end
  490. if isFirstGet(human, needLv) then
  491. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  492. end
  493. setFirstGet(human, needLv)
  494. BagLogic.addItemList(human, config.firstrewards, "lianyu_firstReward")
  495. -- 0-在主界面领取 1-在首通列表领取 2-在战斗内领取
  496. if getway == 0 then
  497. sendQuery(human)
  498. elseif getway == 1 then
  499. sendQuery(human)
  500. sendFirstRewardQuery(human)
  501. elseif getLianyuCache(human) then
  502. -- 战斗过程中领奖励
  503. sendFightInfo(human, true)
  504. end
  505. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  506. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  507. end
  508. -- 每日奖励展示
  509. function sendDailyRewardQuery(human)
  510. local todayStartLv = getTodayStartLv(human)
  511. local msgRet = Msg.gc.GC_LIANYU_DAILY_REWARD_QUERY
  512. msgRet.list[0] = 0
  513. for i = 1, REWARD_SHOW_MAXCNT do
  514. local lv = todayStartLv + i - 1
  515. local config = LianyuExcel.gamelevel[lv]
  516. if not config then
  517. break
  518. end
  519. msgRet.list[0] = msgRet.list[0] + 1
  520. local net = msgRet.list[msgRet.list[0]]
  521. net.needLv = lv
  522. net.items[0] = #config.totalrewards
  523. for j = 1, net.items[0] do
  524. local itemID = config.totalrewards[j][1]
  525. local itemCnt = config.totalrewards[j][2]
  526. Grid.makeItem(net.items[j], itemID, itemCnt)
  527. end
  528. end
  529. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  530. --Msg.trace(msgRet)
  531. Msg.send(msgRet, human.fd)
  532. end
  533. -- 排行榜奖励预览
  534. function sendBoardRewardQuery(human)
  535. local msgRet = Msg.gc.GC_LIANYU_BOARD_REWARD_QUERY
  536. msgRet.list[0] = #LianyuExcel.rankreward
  537. for i = 1, msgRet.list[0] do
  538. local net = msgRet.list[i]
  539. local config = LianyuExcel.rankreward[i]
  540. net.minRank = config.rankMin
  541. net.maxRank = config.rankMax
  542. net.items[0] = #config.rewards
  543. for j = 1, net.items[0] do
  544. local itemID = config.rewards[j][1]
  545. local itemCnt = config.rewards[j][2]
  546. Grid.makeItem(net.items[j], itemID, itemCnt)
  547. end
  548. end
  549. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  550. --Msg.trace(msgRet)
  551. Msg.send(msgRet, human.fd)
  552. end
  553. -- 查询好友助阵-支援我的
  554. function sendHelpFriendQuery(human)
  555. local lyCommon = getLianyuCommon()
  556. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  557. local maxZhandouli = HeroLogic.getHeroMaxZDL(human) * MAX_HEROCOMBAT_MUL / 100
  558. local msgRet = Msg.gc.GC_LIANYU_HELP_FRIEND_QUERY
  559. msgRet.list[0] = 0
  560. for i = 1, cnt do
  561. if msgRet.list[0] >= #msgRet.list then
  562. break
  563. end
  564. local targetUuid = list[i].uuid
  565. local helpInfo = getHelpInfo(lyCommon, targetUuid)
  566. if helpInfo and helpInfo.heroGrid.zhandouli <= maxZhandouli then
  567. msgRet.list[0] = msgRet.list[0] + 1
  568. local net = msgRet.list[msgRet.list[0]]
  569. net.uuid = targetUuid
  570. net.name = helpInfo.rolebase.name
  571. HeroGrid.makeHeroSimple(net.heroSimple, helpInfo.heroGrid)
  572. end
  573. end
  574. local _, selectUuid = getTodayHelp(human)
  575. msgRet.selectUuid = selectUuid or ""
  576. msgRet.helpRed = hasHelpRed(human) and 1 or 0
  577. --Msg.trace(msgRet)
  578. Msg.send(msgRet, human.fd)
  579. end
  580. -- 选择助战
  581. function selectHelpFriend(human, selectUuid)
  582. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1205, true) then
  583. return
  584. end
  585. if not selectUuid or selectUuid == "" then -- 取消
  586. setTodayHelp(human, nil)
  587. else
  588. if not FriendDBLogic.isFriend(human.db._id, selectUuid) then
  589. return Broadcast.sendErr(human, Lang.LIANYU_HELP_SELECT_ERR_FRIEND)
  590. end
  591. local lyCommon = getLianyuCommon()
  592. local helpInfo = getHelpInfo(lyCommon, selectUuid)
  593. if not helpInfo then
  594. return Broadcast.sendErr(human, Lang.LIANYU_HELP_SELECT_ERR_SET)
  595. end
  596. -- 超出战力不能选择
  597. local maxZhandouli = HeroLogic.getHeroMaxZDL(human)
  598. if helpInfo.heroGrid.zhandouli > maxZhandouli * MAX_HEROCOMBAT_MUL / 100 then
  599. return Broadcast.sendErr(human, Util.format(Lang.LIANYU_MY_SELECT_ERR_ZDL, MAX_HEROCOMBAT_MUL))
  600. end
  601. setTodayHelp(human, selectUuid)
  602. end
  603. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  604. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  605. sendHelpFriendQuery(human)
  606. sendQuery(human)
  607. end
  608. -- 查询好友助阵-我的支援
  609. function sendHelpMyQuery(human)
  610. local lyCommon = getLianyuCommon()
  611. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  612. local msgRet = Msg.gc.GC_LIANYU_HELP_MY_QUERY
  613. msgRet.heroSimple[0] = 0
  614. if helpInfo then
  615. msgRet.heroSimple[0] = 1
  616. HeroGrid.makeHeroSimple(msgRet.heroSimple[1], helpInfo.heroGrid, helpInfo.heroGrid.bagIndex)
  617. end
  618. msgRet.helpRed = hasHelpRed(human) and 1 or 0
  619. --Msg.trace(msgRet)
  620. Msg.send(msgRet, human.fd)
  621. end
  622. -- 派遣英雄,成功后返回GC_LIANYU_HELP_MY_QUERY
  623. function selectMyHelp(human, heroIndex)
  624. local lyCommon = getLianyuCommon()
  625. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  626. if helpInfo then
  627. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_HAD)
  628. end
  629. local heroGrid = human.db.heroBag[heroIndex]
  630. if type(heroGrid) ~= "table" then
  631. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_INDEX)
  632. end
  633. local combatObj = CombatLogic.createHumanObj(human, heroGrid.uuid)
  634. local rolebase = CombatLogic.createRoleBaseByDB(human.db)
  635. if not combatObj or not rolebase then
  636. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_INDEX)
  637. end
  638. addHelpInfo(lyCommon, human.db._id, heroGrid, combatObj, rolebase)
  639. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  640. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  641. sendHelpMyQuery(human)
  642. sendQuery(human)
  643. end
  644. -- 获取战斗中的累计奖励列表
  645. function getFightItems(human, winLv)
  646. local lianyuCache = getLianyuCache(human)
  647. if not lianyuCache then
  648. return
  649. end
  650. local oldWinLv = lianyuCache.oldWinLv
  651. if oldWinLv >= PER_FIVELEVEL then
  652. return -- 今日已获得过5关累计奖励,就不能继续获得了
  653. end
  654. winLv = winLv or (lianyuCache.winLv or 0)
  655. if winLv <= oldWinLv then
  656. return -- 今日没刷出更好的成绩
  657. end
  658. local items = {}
  659. local startLv = lianyuCache.startLv
  660. for i = oldWinLv + 1, winLv do
  661. local lv = startLv + i - 1
  662. local config = LianyuExcel.gamelevel[lv]
  663. if not config then
  664. break
  665. end
  666. local rewards = config.totalrewards
  667. if i > PER_FIVELEVEL then
  668. -- 每日前5关奖励特别好,后面的就不太好了
  669. rewards = config.fiverewards
  670. end
  671. for _, item in ipairs(rewards) do
  672. local itemID = item[1]
  673. local itemCnt = item[2]
  674. items[itemID] = (items[itemID] or 0) + itemCnt
  675. end
  676. end
  677. return items
  678. end
  679. -- 战斗界面额外信息
  680. function sendFightInfo(human, isFight)
  681. local lianyuCache = getLianyuCache(human)
  682. if not lianyuCache then
  683. return
  684. end
  685. local winLv = lianyuCache.winLv or 0
  686. local maxLv = getMaxLv(human)
  687. if isFight then
  688. if lianyuCache.combatResult == CombatDefine.RESULT_WIN then
  689. winLv = winLv - 1
  690. maxLv = maxLv - 1
  691. end
  692. end
  693. local lv = lianyuCache.startLv + winLv
  694. local itemID = getSelectBuffer(human)
  695. local msgRet = Msg.gc.GC_LIANYU_FIGHT_INFO
  696. local dataNet = msgRet.data
  697. dataNet.lv = lv
  698. Grid.makeItem(dataNet.buffer, itemID, 1)
  699. local items = getFightItems(human, winLv)
  700. dataNet.items[0] = 0
  701. dataNet.isAllGet = 0
  702. dataNet.needLv = 0
  703. dataNet.lastLv = 0
  704. if items then --有累计奖励
  705. for itemID, itemCnt in pairs(items) do
  706. dataNet.items[0] = dataNet.items[0] + 1
  707. local itemNet = dataNet.items[dataNet.items[0]]
  708. Grid.makeItem(itemNet, itemID, itemCnt)
  709. end
  710. else
  711. dataNet.items[0] = 2
  712. -- 发送给前端显示 累计奖励
  713. Grid.makeItem(dataNet.items[1], 111, 0)
  714. Grid.makeItem(dataNet.items[2], 101, 0)
  715. local oldWinLv = lianyuCache.oldWinLv
  716. if oldWinLv < PER_FIVELEVEL and winLv < PER_FIVELEVEL then --后面会有累计奖励
  717. dataNet.needLv = math.max(oldWinLv + 1 - winLv, 0)
  718. dataNet.lastLv = lianyuCache.startLv + PER_FIVELEVEL - 1
  719. else -- 后面不会有累计奖励了
  720. dataNet.isAllGet = 1
  721. end
  722. end
  723. local firstNeedLv, firstConfig = getNearFirstReward(human)
  724. dataNet.firstNeedLv = firstNeedLv or 0
  725. dataNet.firstItems[0] = firstConfig and #firstConfig.firstrewards or 0
  726. for i = 1, dataNet.firstItems[0] do
  727. local itemID = firstConfig.firstrewards[i][1]
  728. local itemCnt = firstConfig.firstrewards[i][2]
  729. Grid.makeItem(dataNet.firstItems[i], itemID, itemCnt)
  730. end
  731. dataNet.firstCanGet = (maxLv >= firstNeedLv) and 1 or 0
  732. --Msg.trace(msgRet)
  733. Msg.send(msgRet, human.fd)
  734. end
  735. -- 助战英雄出战
  736. local HELP_MAIL_ITEMS = {{}}
  737. function setHelpCombatPos(human, pos)
  738. local lianyuCache = getLianyuCache(human)
  739. if not lianyuCache then
  740. lianyuCache = initCombatCache(human)
  741. end
  742. local helpInfo = setCombatHelpPos(human, pos)
  743. if not helpInfo then
  744. return
  745. end
  746. -- 助战给对方奖励
  747. if helpInfo.helpUuids[human.db._id] then
  748. return -- 同一个人助战不给
  749. end
  750. if helpInfo.helpCnt >= FRIEND_DEGREE_MAX then
  751. return -- 超过上限不给
  752. end
  753. setHelpTarget(helpInfo, human.db._id)
  754. HELP_MAIL_ITEMS[1][1] = ItemDefine.ITEM_FRIEND_ID
  755. HELP_MAIL_ITEMS[1][2] = FRIEND_ITEM_CNT
  756. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_LIANYU1]
  757. local title = mailConfig.title
  758. local senderName = mailConfig.senderName
  759. local content = Util.format(mailConfig.content, human.db.name, FRIEND_ITEM_CNT)
  760. MailManager.add(MailManager.SYSTEM, helpInfo.uuid, title, content, HELP_MAIL_ITEMS, senderName)
  761. end
  762. -- 弹出buffer界面
  763. function sendBufferSelect(human)
  764. local lianyuCache = getLianyuCache(human)
  765. if not lianyuCache then
  766. return
  767. end
  768. initCombatObjCache(human)
  769. local formationConfig = CombatPosLogic.getFormationConfig(lianyuCache.formation)
  770. local msgRet = Msg.gc.GC_LIANYU_BUFFER_SELECT_LIST
  771. msgRet.formation = lianyuCache.formation
  772. msgRet.formationName = formationConfig and formationConfig.name or ""
  773. msgRet.lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  774. msgRet.bufferList[0] = #lianyuCache.bufferList
  775. for i, itemID in ipairs(lianyuCache.bufferList) do
  776. Grid.makeItem(msgRet.bufferList[i], itemID, 1)
  777. end
  778. msgRet.heroList[0] = 0
  779. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  780. local combatObj = lianyuCache.objList[index]
  781. if combatObj then
  782. msgRet.heroList[0] = msgRet.heroList[0] + 1
  783. local heroNet = msgRet.heroList[msgRet.heroList[0]]
  784. HeroGrid.makeHeroSimple(heroNet, combatObj, index)
  785. heroNet.hp = getCombatHpRate(human, index)
  786. heroNet.hpMax = MAX_HP_RATE
  787. end
  788. end
  789. --Msg.trace(msgRet)
  790. Msg.send(msgRet, human.fd)
  791. end
  792. -- 选择增益buffer
  793. function selectBuffer(human, bufferIndex)
  794. local lianyuCache = getLianyuCache(human)
  795. if not lianyuCache then
  796. return
  797. end
  798. -- 不能重复选择
  799. if lianyuCache.bufferIndex then
  800. return
  801. end
  802. setBufferIndex(human, bufferIndex)
  803. fight(human)
  804. end
  805. -- 站前加属性
  806. function onFightBegin(human)
  807. local lianyuCache = getLianyuCache(human)
  808. if not lianyuCache then
  809. return
  810. end
  811. local itemID = getSelectBuffer(human)
  812. if not itemID then
  813. return
  814. end
  815. local cmd = ItemDefine.getValue(itemID, "cmd")
  816. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  817. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  818. local atkObj = CombatImpl.objList[atkPos]
  819. if atkObj then
  820. atkObj.isSysAttrChange = true
  821. if cmd[1] == "lianyuAttr" then
  822. local key = cmd[2][1]
  823. local value = cmd[2][2]
  824. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  825. end
  826. end
  827. end
  828. end
  829. -- 回血+设置血量
  830. function recalcHpFightBegin(human, index, atkObj)
  831. local lianyuCache = getLianyuCache(human)
  832. if not lianyuCache then
  833. return
  834. end
  835. -- 援军
  836. local realIndex = lianyuCache.backupPos2index and lianyuCache.backupPos2index[index] or index
  837. local hpRate = getCombatHpRate(human, realIndex)
  838. local itemID = getSelectBuffer(human)
  839. local cmd = itemID and ItemDefine.getValue(itemID, "cmd")
  840. if cmd and cmd[1] == "lianyuHpMp" and (lianyuCache.winLv or 0) % PER_FIVELEVEL == 0 then
  841. local hpRateAdd = cmd[2][1] or 0
  842. hpRate = hpRate + hpRateAdd
  843. end
  844. local hpMax = CombatObj.getHpMax(atkObj)
  845. atkObj.hp = math.ceil(hpMax * hpRate / MAX_HP_RATE)
  846. atkObj.hp = math.min(atkObj.hp, hpMax)
  847. end
  848. -- 检查要不要结束
  849. function checkFinishFight(human)
  850. local lianyuCache = getLianyuCache(human)
  851. if not lianyuCache then
  852. return
  853. end
  854. if lianyuCache.combatResult and lianyuCache.combatResult ~= CombatDefine.RESULT_WIN then
  855. finishFight(human) -- 失败就结束吧
  856. return
  857. end
  858. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  859. local config = LianyuExcel.gamelevel[lv]
  860. if not config then -- 全部通关了也结束
  861. finishFight(human)
  862. return
  863. end
  864. return lv, config
  865. end
  866. -- 战斗开始
  867. function fight(human)
  868. local lianyuCache = getLianyuCache(human)
  869. if not lianyuCache then
  870. lianyuCache = initCombatCache(human)
  871. end
  872. local lv, config = checkFinishFight(human)
  873. if not lv or not config then
  874. return
  875. end
  876. if not lianyuCache.bufferIndex then
  877. -- 发送buffer选择界面
  878. return sendBufferSelect(human)
  879. end
  880. -- 标记今日打过
  881. if getTodayWinLv(human) == nil then
  882. setTodayWinLv(human, 0)
  883. end
  884. -- 战斗界面额外信息
  885. sendFightInfo(human)
  886. -- 调用战斗接口
  887. CombatLogic.combatBegin(human, config.mapID, nil, CombatDefine.COMBAT_TYPE8, lv)
  888. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_8, 1)
  889. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  890. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  891. YunYingLogic.onCallBack(human, "onLianyu",1)
  892. end
  893. -- 战斗信息
  894. function setCombatBeginInfo(human, combatInfo, lv)
  895. -- 设置一些战斗信息
  896. combatInfo.defender.name = Util.format(Lang.COMBAT_LIANYU_NAME, lv)
  897. end
  898. -- 获取当前地图ID
  899. function getMapID(human, args)
  900. local lianyuCache = getLianyuCache(human)
  901. if not lianyuCache then
  902. lianyuCache = initCombatCache(human)
  903. end
  904. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  905. local config = LianyuExcel.gamelevel[lv]
  906. if not config then -- 全部通关了
  907. return
  908. end
  909. return config.mapID
  910. end
  911. -- 战斗结束回调
  912. function onFightEnd(human, result, combatType, lv, combatInfo)
  913. local lianyuCache = getLianyuCache(human)
  914. if not lianyuCache then
  915. return
  916. end
  917. lianyuCache.combatResult = result
  918. combatInfo.endStatus = CombatLogic.COMBAT_END_STATUS2
  919. combatInfo.noSendFinish = true
  920. if result == CombatDefine.RESULT_WIN then
  921. -- 胜利
  922. lianyuCache.winLv = (lianyuCache.winLv or 0) + 1
  923. if lv > getMaxLv(human) then
  924. setMaxLv(human, lv)
  925. end
  926. -- 每5关重置buffer
  927. if lianyuCache.winLv % PER_FIVELEVEL == 0 then
  928. randBuffers(human)
  929. end
  930. -- 记录血量/技能
  931. lianyuCache.combatHpRates = lianyuCache.combatHpRates or {}
  932. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  933. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  934. local atkObj = combatInfo.objList[atkPos]
  935. if atkObj then
  936. -- 援军
  937. local realIndex = lianyuCache.backupPos2index and lianyuCache.backupPos2index[index] or index
  938. local hpMax = CombatObj.getHpMax(atkObj)
  939. lianyuCache.combatHpRates[realIndex] = atkObj.hp * MAX_HP_RATE / hpMax
  940. if atkObj.backupPos then
  941. local atkBackupPos = CombatLogic.getIndexByPos(CombatDefine.ATTACK_SIDE, atkObj.backupPos)
  942. lianyuCache.backupPos2index = lianyuCache.backupPos2index or {}
  943. lianyuCache.backupPos2index[atkBackupPos] = index
  944. end
  945. end
  946. end
  947. lianyuCache.combatObjSkill = lianyuCache.combatObjSkill or {}
  948. lianyuCache.combatHelpSkill = lianyuCache.combatHelpSkill or {}
  949. for atkPos, atkObj in pairs(combatInfo.objList) do
  950. if atkObj.side == CombatDefine.ATTACK_SIDE then
  951. local realIndex = atkObj.backupPos or atkPos
  952. local skill = {}
  953. skill.skillList = atkObj.skillList
  954. skill.beSkillList = atkObj.beSkillList
  955. lianyuCache.combatObjSkill[realIndex] = skill
  956. end
  957. end
  958. for atkPos, atkObj in pairs(combatInfo.helpList) do
  959. if atkObj.side == CombatDefine.ATTACK_SIDE then
  960. local skill = {}
  961. skill.skillList = atkObj.skillList
  962. skill.beSkillList = atkObj.beSkillList
  963. lianyuCache.combatHelpSkill[atkPos] = skill
  964. end
  965. end
  966. if lv >= #LianyuExcel.gamelevel then -- 全部通关
  967. finishFight(human, combatInfo)
  968. else
  969. if human.fd then
  970. CombatLogic.sendCombatFinish(human, combatInfo)
  971. fight(human)
  972. else
  973. if lianyuCache.bufferIndex == nil then
  974. -- 自动选择BUFFER
  975. selectBuffer(human, 1)
  976. else
  977. fight(human)
  978. end
  979. end
  980. end
  981. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_7, lv)
  982. --TODO:记录绝望深渊
  983. --Log.write(Log.LOGID_OSS_BATTLE_DESPAIRABYSS, human.db._id, human.db.account, human.db.name, lv)
  984. Log.write(Log.LOGID_OSS_BATTLE_DESPAIRABYSS, human.db._id, human.db.newUniqueTag, human.db.name, lv)
  985. else
  986. -- 失败
  987. finishFight(human, combatInfo)
  988. end
  989. end
  990. -- 初始战斗对象信息
  991. function initCombatObjCache(human)
  992. local lianyuCache = getLianyuCache(human)
  993. if not lianyuCache or lianyuCache.objList then
  994. return
  995. end
  996. local objList, helpList, rolebase, formation, jiban = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE8)
  997. local combatHelp, combatHelpPos = getCombatHelp(human)
  998. if combatHelp and combatHelpPos then
  999. if CombatPosLogic.checkPos(formation, combatHelpPos) then
  1000. objList[combatHelpPos] = combatHelp.combatObj
  1001. end
  1002. end
  1003. lianyuCache.objList = objList
  1004. lianyuCache.helpList = helpList
  1005. lianyuCache.rolebase = rolebase
  1006. lianyuCache.formation = formation
  1007. lianyuCache.jiban = jiban
  1008. end
  1009. -- 玩家战斗信息
  1010. function getCombatObjList(human, side)
  1011. local lianyuCache = getLianyuCache(human)
  1012. if not lianyuCache then
  1013. return
  1014. end
  1015. if side == CombatDefine.DEFEND_SIDE then
  1016. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  1017. local config = LianyuExcel.gamelevel[lv]
  1018. if not config then
  1019. return
  1020. end
  1021. return CombatLogic.getMonsterObjList(config.monsterOutID)
  1022. end
  1023. initCombatObjCache(human)
  1024. local helpList = lianyuCache.helpList
  1025. local rolebase = lianyuCache.rolebase
  1026. local formation = lianyuCache.formation
  1027. local objList = {}
  1028. for index, obj in pairs(lianyuCache.objList) do
  1029. if getCombatHpRate(human, index) > 0 then
  1030. objList[index] = obj
  1031. end
  1032. end
  1033. -- 援军
  1034. if lianyuCache.backupPos2index then
  1035. for backupPos, index in pairs(lianyuCache.backupPos2index) do
  1036. local obj = lianyuCache.objList[index]
  1037. if obj and getCombatHpRate(human, index) > 0 then
  1038. objList[backupPos] = obj
  1039. objList[index] = nil
  1040. end
  1041. end
  1042. end
  1043. return objList, helpList, rolebase, formation, lianyuCache.jiban
  1044. end
  1045. -- 请求结算(战斗结束/中途退出等)
  1046. function finishFight(human, combatInfo, noSend)
  1047. local lianyuCache = getLianyuCache(human)
  1048. if not lianyuCache then
  1049. return
  1050. end
  1051. local items = getFightItems(human)
  1052. -- 刷新每日胜利次数
  1053. if (lianyuCache.winLv or 0) > (getTodayWinLv(human) or 0) then
  1054. setTodayWinLv(human, lianyuCache.winLv)
  1055. end
  1056. cleanCache(human)
  1057. local combatItems = {}
  1058. local msgRet = Msg.gc.GC_LIANYU_FIGHT_FINISH
  1059. msgRet.items[0] = 0
  1060. msgRet.data[0] = 0
  1061. if items then
  1062. for itemID, itemCnt in pairs(items) do
  1063. msgRet.items[0] = msgRet.items[0] + 1
  1064. local itemNet = msgRet.items[msgRet.items[0]]
  1065. Grid.makeItem(itemNet, itemID, itemCnt)
  1066. BagLogic.addItem(human, itemID, itemCnt, "lianyu_win_reward")
  1067. combatItems[#combatItems + 1] = {itemID, itemCnt}
  1068. end
  1069. end
  1070. if not combatInfo then
  1071. local combatCache = CombatLogic.getCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1072. combatInfo = combatCache and combatCache.combatInfo
  1073. CombatLogic.cleanCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1074. end
  1075. if combatInfo then
  1076. if #combatItems > 1 then
  1077. combatInfo.endStatus = nil
  1078. combatInfo.isWin = true
  1079. else
  1080. combatInfo.endStatus = CombatLogic.COMBAT_END_STATUS1
  1081. end
  1082. combatInfo.rewardItem = combatItems
  1083. if not noSend then
  1084. CombatLogic.sendCombatFinish(human, combatInfo)
  1085. end
  1086. CombatLogic.fontCombatFinish(msgRet.data[1], combatInfo)
  1087. msgRet.data[0] = 1
  1088. -- CombatLogic.sendCombatFinish(human, combatInfo)
  1089. end
  1090. -- Msg.trace(msgRet)
  1091. Msg.send(msgRet, human.fd)
  1092. end
  1093. -- 助战英雄数
  1094. function getCombatZhuzhanCnt(human)
  1095. local combatHelp, combatHelpPos = getCombatHelp(human)
  1096. if combatHelp and combatHelpPos then
  1097. return 1
  1098. end
  1099. end
  1100. -- 是否显示跳过战斗按钮
  1101. function isCombatShowJumpBtn(human)
  1102. return true
  1103. end
  1104. -- 继承技能CD
  1105. function setSkillAndBeskill(human, combatInfo)
  1106. local lianyuCache = getLianyuCache(human)
  1107. if not lianyuCache then return end
  1108. for atkPos, atkObj in pairs(CombatImpl.objList) do
  1109. local skill = lianyuCache.combatObjSkill and lianyuCache.combatObjSkill[atkPos]
  1110. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1111. atkObj.skillList = skill.skillList
  1112. atkObj.beSkillList = skill.beSkillList
  1113. end
  1114. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1115. end
  1116. for atkPos, atkObj in pairs(CombatImpl.helpList) do
  1117. local skill = lianyuCache.combatHelpSkill and lianyuCache.combatHelpSkill[atkPos]
  1118. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1119. atkObj.skillList = skill.skillList
  1120. atkObj.beSkillList = skill.beSkillList
  1121. end
  1122. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1123. end
  1124. end
  1125. -- ============================== 其它 ==================================
  1126. -- 每日重置
  1127. function updateDaily(human)
  1128. if not human.db.lianyu then
  1129. return
  1130. end
  1131. local lianyuDB = human.db.lianyu
  1132. lianyuDB.todayMaxLv = getMaxLv(human)
  1133. lianyuDB.todayWinLv = nil
  1134. lianyuDB.todayHelpUuid = nil
  1135. end
  1136. -- 登出
  1137. function onLogout(human)
  1138. checkFinishFight(human)
  1139. -- 自动选择BUFFER
  1140. selectBuffer(human, 1)
  1141. end
  1142. -- 登陆
  1143. function onLogin(human)
  1144. local lianyuCache = getLianyuCache(human)
  1145. if not lianyuCache then
  1146. return
  1147. end
  1148. local combatCache = CombatLogic.getCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1149. if combatCache then
  1150. sendFightInfo(human)
  1151. else
  1152. finishFight(human)
  1153. end
  1154. end
  1155. -- 0点结算发奖励
  1156. MAIL_SEND_CACHE = MAIL_SEND_CACHE or nil
  1157. function onZero()
  1158. MAIL_SEND_CACHE = {}
  1159. local maxCnt = LianyuExcel.rankreward[#LianyuExcel.rankreward].rankMax
  1160. local board = BillboardDB.getBoard(BillboardDefine.TYPE_LIANYU)
  1161. if board and board.rank2data then
  1162. maxCnt = maxCnt <= #board.rank2data and maxCnt or #board.rank2data
  1163. for i = 1, maxCnt do
  1164. local rankData = board.rank2data[i]
  1165. MAIL_SEND_CACHE[i] = rankData.uuid
  1166. end
  1167. end
  1168. Timer.addLater(1, boardReward)
  1169. end
  1170. -- 定时器 邮件分开发,预防崩溃
  1171. function boardReward()
  1172. if not MAIL_SEND_CACHE then
  1173. return
  1174. end
  1175. for i = 1, #MAIL_SEND_CACHE do
  1176. local uuid = MAIL_SEND_CACHE[i]
  1177. local rankConfig = getRankConfig(i)
  1178. if not rankConfig then
  1179. MAIL_SEND_CACHE = nil
  1180. return
  1181. end
  1182. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_LIANYU2]
  1183. local title = mailConfig.title
  1184. local senderName = mailConfig.senderName
  1185. local content = Util.format(mailConfig.content, i)
  1186. MailManager.add(MailManager.SYSTEM, uuid, title, content, rankConfig.rewards, senderName)
  1187. end
  1188. MAIL_SEND_CACHE = nil
  1189. end
  1190. -- 设置助战上阵
  1191. local HELP_MAIL_ITEMS = {{}}
  1192. function setCombatZhuzhan(human, pos)
  1193. local lianyuCache = getLianyuCache(human)
  1194. if not lianyuCache then
  1195. lianyuCache = initCombatCache(human)
  1196. end
  1197. local helpInfo = setCombatHelpPos(human, pos)
  1198. if not helpInfo then
  1199. return
  1200. end
  1201. -- 助战给对方奖励
  1202. if helpInfo.helpUuids[human.db._id] then
  1203. return -- 同一个人助战不给
  1204. end
  1205. if helpInfo.helpCnt >= FRIEND_HELP_MAXCNT then
  1206. return -- 超过上限不给
  1207. end
  1208. setHelpTarget(helpInfo, human.db._id)
  1209. HELP_MAIL_ITEMS[1][1] = ItemDefine.ITEM_FRIEND_ID
  1210. HELP_MAIL_ITEMS[1][2] = FRIEND_ITEM_CNT
  1211. local mailConfig = MailExcel.mail[92]
  1212. local title = mailConfig.title
  1213. local senderName = mailConfig.senderName
  1214. local content = Util.format(mailConfig.content, human.db.name, FRIEND_ITEM_CNT)
  1215. MailManager.add(MailManager.SYSTEM, helpInfo.uuid, title, content, HELP_MAIL_ITEMS, senderName)
  1216. end
  1217. function isDot(human)
  1218. local rewardRed = hasRewardRed(human)
  1219. if rewardRed then
  1220. return true
  1221. end
  1222. local lyCommon = getLianyuCommon()
  1223. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  1224. if not helpInfo then
  1225. return true
  1226. end
  1227. local todayWinLv = getTodayWinLv(human)
  1228. if not todayWinLv then
  1229. return true
  1230. end
  1231. return false
  1232. end