LianyuLogic.lua 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1205, true) then
  391. return
  392. end
  393. ObjHuman.updateDaily(human)
  394. local msgRet = Msg.gc.GC_LIANYU_QUERY
  395. local dataNet = msgRet.data
  396. local maxLv = getMaxLv(human)
  397. dataNet.maxLv = maxLv
  398. -- 排名相关
  399. local board = BillboardDB.getBoard(BillboardDefine.TYPE_LIANYU)
  400. dataNet.boardList[0] = math.min(#dataNet.boardList, #board.rank2data)
  401. for i = 1, dataNet.boardList[0] do
  402. local rankData = board.rank2data[i]
  403. local boardNet = dataNet.boardList[i]
  404. local db = RoleDBLogic.getDb(rankData.uuid, "name")
  405. boardNet.rank = i
  406. boardNet.name = db and db.name or ""
  407. boardNet.lv = rankData.value1
  408. end
  409. local myRank = BillboardDB.getRank(BillboardDefine.TYPE_LIANYU, human.db._id) or 0
  410. local myRankConfig = getRankConfig(myRank)
  411. dataNet.myRank = myRank
  412. dataNet.myRankItems[0] = myRankConfig and #myRankConfig.rewards or 0
  413. for i = 1, dataNet.myRankItems[0] do
  414. local itemID = myRankConfig.rewards[i][1]
  415. local itemCnt = myRankConfig.rewards[i][2]
  416. Grid.makeItem(dataNet.myRankItems[i], itemID, itemCnt)
  417. end
  418. -- 首通奖励
  419. local firstNeedLv, firstConfig = getNearFirstReward(human)
  420. dataNet.firstNeedLv = firstNeedLv or 0
  421. dataNet.firstItems[0] = firstConfig and #firstConfig.firstrewards or 0
  422. for i = 1, dataNet.firstItems[0] do
  423. local itemID = firstConfig.firstrewards[i][1]
  424. local itemCnt = firstConfig.firstrewards[i][2]
  425. Grid.makeItem(dataNet.firstItems[i], itemID, itemCnt)
  426. end
  427. dataNet.firstLeftCnt = firstNeedLv and math.max(firstNeedLv - maxLv, 0) or 0
  428. dataNet.rewardRed = hasRewardRed(human) and 1 or 0
  429. -- 助战相关
  430. dataNet.helpRed = hasHelpRed(human) and 1 or 0
  431. dataNet.helpByUuid = ""
  432. local targetHelp = getTodayHelp(human)
  433. dataNet.helpHero[0] = 0
  434. if targetHelp and targetHelp.heroGrid then
  435. dataNet.helpByUuid = targetHelp.uuid
  436. dataNet.helpHero[0] = 1
  437. HeroGrid.makeHeroSimple(dataNet.helpHero[1], targetHelp.heroGrid, targetHelp.heroGrid.bagIndex)
  438. end
  439. -- 每日5关奖励
  440. local todayWinLv = getTodayWinLv(human)
  441. dataNet.status = STATUS_START_BUTTON0
  442. if todayWinLv then
  443. dataNet.status = STATUS_START_BUTTON1
  444. if todayWinLv >= PER_FIVELEVEL then
  445. dataNet.status = STATUS_START_BUTTON2
  446. end
  447. end
  448. dataNet.todayStartLv = getTodayStartLv(human)
  449. dataNet.todayWinLv = todayWinLv or 0
  450. -- Msg.trace(msgRet)
  451. Msg.send(msgRet, human.fd)
  452. end
  453. -- 首通奖励查询
  454. function sendFirstRewardQuery(human)
  455. local list = getFirstRewardIDs(human)
  456. local maxLv = getMaxLv(human)
  457. local msgRet = Msg.gc.GC_LIANYU_FIRST_REWARD_QUERY
  458. msgRet.list[0] = list and #list or 0
  459. for i = 1, msgRet.list[0] do
  460. local needLv = list[i]
  461. local net = msgRet.list[i]
  462. local config = LianyuExcel.gamelevel[needLv]
  463. net.needLv = needLv
  464. net.leftLv = math.max(needLv - maxLv, 0)
  465. net.items[0] = #config.firstrewards
  466. for j = 1, net.items[0] do
  467. local itemID = config.firstrewards[j][1]
  468. local itemCnt = config.firstrewards[j][2]
  469. Grid.makeItem(net.items[j], itemID, itemCnt)
  470. end
  471. end
  472. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  473. --Msg.trace(msgRet)
  474. Msg.send(msgRet, human.fd)
  475. end
  476. -- 领取首通奖励
  477. function getFirstReward(human, needLv, getway)
  478. local config = LianyuExcel.gamelevel[needLv]
  479. if not config then
  480. return
  481. end
  482. local maxLv = getMaxLv(human)
  483. if maxLv < needLv then
  484. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  485. end
  486. if isFirstGet(human, needLv) then
  487. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  488. end
  489. setFirstGet(human, needLv)
  490. BagLogic.addItemList(human, config.firstrewards, "lianyu_firstReward")
  491. -- 0-在主界面领取 1-在首通列表领取 2-在战斗内领取
  492. if getway == 0 then
  493. sendQuery(human)
  494. elseif getway == 1 then
  495. sendQuery(human)
  496. sendFirstRewardQuery(human)
  497. elseif getLianyuCache(human) then
  498. -- 战斗过程中领奖励
  499. sendFightInfo(human, true)
  500. end
  501. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  502. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  503. end
  504. -- 每日奖励展示
  505. function sendDailyRewardQuery(human)
  506. local todayStartLv = getTodayStartLv(human)
  507. local msgRet = Msg.gc.GC_LIANYU_DAILY_REWARD_QUERY
  508. msgRet.list[0] = 0
  509. for i = 1, REWARD_SHOW_MAXCNT do
  510. local lv = todayStartLv + i - 1
  511. local config = LianyuExcel.gamelevel[lv]
  512. if not config then
  513. break
  514. end
  515. msgRet.list[0] = msgRet.list[0] + 1
  516. local net = msgRet.list[msgRet.list[0]]
  517. net.needLv = lv
  518. net.items[0] = #config.totalrewards
  519. for j = 1, net.items[0] do
  520. local itemID = config.totalrewards[j][1]
  521. local itemCnt = config.totalrewards[j][2]
  522. Grid.makeItem(net.items[j], itemID, itemCnt)
  523. end
  524. end
  525. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  526. --Msg.trace(msgRet)
  527. Msg.send(msgRet, human.fd)
  528. end
  529. -- 排行榜奖励预览
  530. function sendBoardRewardQuery(human)
  531. local msgRet = Msg.gc.GC_LIANYU_BOARD_REWARD_QUERY
  532. msgRet.list[0] = #LianyuExcel.rankreward
  533. for i = 1, msgRet.list[0] do
  534. local net = msgRet.list[i]
  535. local config = LianyuExcel.rankreward[i]
  536. net.minRank = config.rankMin
  537. net.maxRank = config.rankMax
  538. net.items[0] = #config.rewards
  539. for j = 1, net.items[0] do
  540. local itemID = config.rewards[j][1]
  541. local itemCnt = config.rewards[j][2]
  542. Grid.makeItem(net.items[j], itemID, itemCnt)
  543. end
  544. end
  545. msgRet.rewardRed = hasRewardRed(human) and 1 or 0
  546. --Msg.trace(msgRet)
  547. Msg.send(msgRet, human.fd)
  548. end
  549. -- 查询好友助阵-支援我的
  550. function sendHelpFriendQuery(human)
  551. local lyCommon = getLianyuCommon()
  552. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  553. local maxZhandouli = HeroLogic.getHeroMaxZDL(human) * MAX_HEROCOMBAT_MUL / 100
  554. local msgRet = Msg.gc.GC_LIANYU_HELP_FRIEND_QUERY
  555. msgRet.list[0] = 0
  556. for i = 1, cnt do
  557. if msgRet.list[0] >= #msgRet.list then
  558. break
  559. end
  560. local targetUuid = list[i].uuid
  561. local helpInfo = getHelpInfo(lyCommon, targetUuid)
  562. if helpInfo and helpInfo.heroGrid.zhandouli <= maxZhandouli then
  563. msgRet.list[0] = msgRet.list[0] + 1
  564. local net = msgRet.list[msgRet.list[0]]
  565. net.uuid = targetUuid
  566. net.name = helpInfo.rolebase.name
  567. HeroGrid.makeHeroSimple(net.heroSimple, helpInfo.heroGrid)
  568. end
  569. end
  570. local _, selectUuid = getTodayHelp(human)
  571. msgRet.selectUuid = selectUuid or ""
  572. msgRet.helpRed = hasHelpRed(human) and 1 or 0
  573. --Msg.trace(msgRet)
  574. Msg.send(msgRet, human.fd)
  575. end
  576. -- 选择助战
  577. function selectHelpFriend(human, selectUuid)
  578. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1205, true) then
  579. return
  580. end
  581. if not selectUuid or selectUuid == "" then -- 取消
  582. setTodayHelp(human, nil)
  583. else
  584. if not FriendDBLogic.isFriend(human.db._id, selectUuid) then
  585. return Broadcast.sendErr(human, Lang.LIANYU_HELP_SELECT_ERR_FRIEND)
  586. end
  587. local lyCommon = getLianyuCommon()
  588. local helpInfo = getHelpInfo(lyCommon, selectUuid)
  589. if not helpInfo then
  590. return Broadcast.sendErr(human, Lang.LIANYU_HELP_SELECT_ERR_SET)
  591. end
  592. -- 超出战力不能选择
  593. local maxZhandouli = HeroLogic.getHeroMaxZDL(human)
  594. if helpInfo.heroGrid.zhandouli > maxZhandouli * MAX_HEROCOMBAT_MUL / 100 then
  595. return Broadcast.sendErr(human, Util.format(Lang.LIANYU_MY_SELECT_ERR_ZDL, MAX_HEROCOMBAT_MUL))
  596. end
  597. setTodayHelp(human, selectUuid)
  598. end
  599. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  600. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  601. sendHelpFriendQuery(human)
  602. sendQuery(human)
  603. end
  604. -- 查询好友助阵-我的支援
  605. function sendHelpMyQuery(human)
  606. local lyCommon = getLianyuCommon()
  607. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  608. local msgRet = Msg.gc.GC_LIANYU_HELP_MY_QUERY
  609. msgRet.heroSimple[0] = 0
  610. if helpInfo then
  611. msgRet.heroSimple[0] = 1
  612. HeroGrid.makeHeroSimple(msgRet.heroSimple[1], helpInfo.heroGrid, helpInfo.heroGrid.bagIndex)
  613. end
  614. msgRet.helpRed = hasHelpRed(human) and 1 or 0
  615. --Msg.trace(msgRet)
  616. Msg.send(msgRet, human.fd)
  617. end
  618. -- 派遣英雄,成功后返回GC_LIANYU_HELP_MY_QUERY
  619. function selectMyHelp(human, heroIndex)
  620. local lyCommon = getLianyuCommon()
  621. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  622. if helpInfo then
  623. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_HAD)
  624. end
  625. local heroGrid = human.db.heroBag[heroIndex]
  626. if type(heroGrid) ~= "table" then
  627. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_INDEX)
  628. end
  629. local combatObj = CombatLogic.createHumanObj(human, heroGrid.uuid)
  630. local rolebase = CombatLogic.createRoleBaseByDB(human.db)
  631. if not combatObj or not rolebase then
  632. return Broadcast.sendErr(human, Lang.LIANYU_MY_SELECT_ERR_INDEX)
  633. end
  634. addHelpInfo(lyCommon, human.db._id, heroGrid, combatObj, rolebase)
  635. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  636. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  637. sendHelpMyQuery(human)
  638. sendQuery(human)
  639. end
  640. -- 获取战斗中的累计奖励列表
  641. function getFightItems(human, winLv)
  642. local lianyuCache = getLianyuCache(human)
  643. if not lianyuCache then
  644. return
  645. end
  646. local oldWinLv = lianyuCache.oldWinLv
  647. if oldWinLv >= PER_FIVELEVEL then
  648. return -- 今日已获得过5关累计奖励,就不能继续获得了
  649. end
  650. winLv = winLv or (lianyuCache.winLv or 0)
  651. if winLv <= oldWinLv then
  652. return -- 今日没刷出更好的成绩
  653. end
  654. local items = {}
  655. local startLv = lianyuCache.startLv
  656. for i = oldWinLv + 1, winLv do
  657. local lv = startLv + i - 1
  658. local config = LianyuExcel.gamelevel[lv]
  659. if not config then
  660. break
  661. end
  662. local rewards = config.totalrewards
  663. if i > PER_FIVELEVEL then
  664. -- 每日前5关奖励特别好,后面的就不太好了
  665. rewards = config.fiverewards
  666. end
  667. for _, item in ipairs(rewards) do
  668. local itemID = item[1]
  669. local itemCnt = item[2]
  670. items[itemID] = (items[itemID] or 0) + itemCnt
  671. end
  672. end
  673. return items
  674. end
  675. -- 战斗界面额外信息
  676. function sendFightInfo(human, isFight)
  677. local lianyuCache = getLianyuCache(human)
  678. if not lianyuCache then
  679. return
  680. end
  681. local winLv = lianyuCache.winLv or 0
  682. local maxLv = getMaxLv(human)
  683. if isFight then
  684. if lianyuCache.combatResult == CombatDefine.RESULT_WIN then
  685. winLv = winLv - 1
  686. maxLv = maxLv - 1
  687. end
  688. end
  689. local lv = lianyuCache.startLv + winLv
  690. local itemID = getSelectBuffer(human)
  691. local msgRet = Msg.gc.GC_LIANYU_FIGHT_INFO
  692. local dataNet = msgRet.data
  693. dataNet.lv = lv
  694. Grid.makeItem(dataNet.buffer, itemID, 1)
  695. local items = getFightItems(human, winLv)
  696. dataNet.items[0] = 0
  697. dataNet.isAllGet = 0
  698. dataNet.needLv = 0
  699. dataNet.lastLv = 0
  700. if items then --有累计奖励
  701. for itemID, itemCnt in pairs(items) do
  702. dataNet.items[0] = dataNet.items[0] + 1
  703. local itemNet = dataNet.items[dataNet.items[0]]
  704. Grid.makeItem(itemNet, itemID, itemCnt)
  705. end
  706. else
  707. dataNet.items[0] = 2
  708. -- 发送给前端显示 累计奖励
  709. Grid.makeItem(dataNet.items[1], 111, 0)
  710. Grid.makeItem(dataNet.items[2], 101, 0)
  711. local oldWinLv = lianyuCache.oldWinLv
  712. if oldWinLv < PER_FIVELEVEL and winLv < PER_FIVELEVEL then --后面会有累计奖励
  713. dataNet.needLv = math.max(oldWinLv + 1 - winLv, 0)
  714. dataNet.lastLv = lianyuCache.startLv + PER_FIVELEVEL - 1
  715. else -- 后面不会有累计奖励了
  716. dataNet.isAllGet = 1
  717. end
  718. end
  719. local firstNeedLv, firstConfig = getNearFirstReward(human)
  720. dataNet.firstNeedLv = firstNeedLv or 0
  721. dataNet.firstItems[0] = firstConfig and #firstConfig.firstrewards or 0
  722. for i = 1, dataNet.firstItems[0] do
  723. local itemID = firstConfig.firstrewards[i][1]
  724. local itemCnt = firstConfig.firstrewards[i][2]
  725. Grid.makeItem(dataNet.firstItems[i], itemID, itemCnt)
  726. end
  727. dataNet.firstCanGet = (maxLv >= firstNeedLv) and 1 or 0
  728. --Msg.trace(msgRet)
  729. Msg.send(msgRet, human.fd)
  730. end
  731. -- 助战英雄出战
  732. local HELP_MAIL_ITEMS = {{}}
  733. function setHelpCombatPos(human, pos)
  734. local lianyuCache = getLianyuCache(human)
  735. if not lianyuCache then
  736. lianyuCache = initCombatCache(human)
  737. end
  738. local helpInfo = setCombatHelpPos(human, pos)
  739. if not helpInfo then
  740. return
  741. end
  742. -- 助战给对方奖励
  743. if helpInfo.helpUuids[human.db._id] then
  744. return -- 同一个人助战不给
  745. end
  746. if helpInfo.helpCnt >= FRIEND_DEGREE_MAX then
  747. return -- 超过上限不给
  748. end
  749. setHelpTarget(helpInfo, human.db._id)
  750. HELP_MAIL_ITEMS[1][1] = ItemDefine.ITEM_FRIEND_ID
  751. HELP_MAIL_ITEMS[1][2] = FRIEND_ITEM_CNT
  752. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_LIANYU1]
  753. local title = mailConfig.title
  754. local senderName = mailConfig.senderName
  755. local content = Util.format(mailConfig.content, human.db.name, FRIEND_ITEM_CNT)
  756. MailManager.add(MailManager.SYSTEM, helpInfo.uuid, title, content, HELP_MAIL_ITEMS, senderName)
  757. end
  758. -- 弹出buffer界面
  759. function sendBufferSelect(human)
  760. local lianyuCache = getLianyuCache(human)
  761. if not lianyuCache then
  762. return
  763. end
  764. initCombatObjCache(human)
  765. local formationConfig = CombatPosLogic.getFormationConfig(lianyuCache.formation)
  766. local msgRet = Msg.gc.GC_LIANYU_BUFFER_SELECT_LIST
  767. msgRet.formation = lianyuCache.formation
  768. msgRet.formationName = formationConfig and formationConfig.name or ""
  769. msgRet.lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  770. msgRet.bufferList[0] = #lianyuCache.bufferList
  771. for i, itemID in ipairs(lianyuCache.bufferList) do
  772. Grid.makeItem(msgRet.bufferList[i], itemID, 1)
  773. end
  774. msgRet.heroList[0] = 0
  775. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  776. local combatObj = lianyuCache.objList[index]
  777. if combatObj then
  778. msgRet.heroList[0] = msgRet.heroList[0] + 1
  779. local heroNet = msgRet.heroList[msgRet.heroList[0]]
  780. HeroGrid.makeHeroSimple(heroNet, combatObj, index)
  781. heroNet.hp = getCombatHpRate(human, index)
  782. heroNet.hpMax = MAX_HP_RATE
  783. end
  784. end
  785. --Msg.trace(msgRet)
  786. Msg.send(msgRet, human.fd)
  787. end
  788. -- 选择增益buffer
  789. function selectBuffer(human, bufferIndex)
  790. local lianyuCache = getLianyuCache(human)
  791. if not lianyuCache then
  792. return
  793. end
  794. -- 不能重复选择
  795. if lianyuCache.bufferIndex then
  796. return
  797. end
  798. setBufferIndex(human, bufferIndex)
  799. fight(human)
  800. end
  801. -- 站前加属性
  802. function onFightBegin(human)
  803. local lianyuCache = getLianyuCache(human)
  804. if not lianyuCache then
  805. return
  806. end
  807. local itemID = getSelectBuffer(human)
  808. if not itemID then
  809. return
  810. end
  811. local cmd = ItemDefine.getValue(itemID, "cmd")
  812. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  813. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  814. local atkObj = CombatImpl.objList[atkPos]
  815. if atkObj then
  816. atkObj.isSysAttrChange = true
  817. if cmd[1] == "lianyuAttr" then
  818. local key = cmd[2][1]
  819. local value = cmd[2][2]
  820. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  821. end
  822. end
  823. end
  824. end
  825. -- 回血+设置血量
  826. function recalcHpFightBegin(human, index, atkObj)
  827. local lianyuCache = getLianyuCache(human)
  828. if not lianyuCache then
  829. return
  830. end
  831. -- 援军
  832. local realIndex = lianyuCache.backupPos2index and lianyuCache.backupPos2index[index] or index
  833. local hpRate = getCombatHpRate(human, realIndex)
  834. local itemID = getSelectBuffer(human)
  835. local cmd = itemID and ItemDefine.getValue(itemID, "cmd")
  836. if cmd and cmd[1] == "lianyuHpMp" and (lianyuCache.winLv or 0) % PER_FIVELEVEL == 0 then
  837. local hpRateAdd = cmd[2][1] or 0
  838. hpRate = hpRate + hpRateAdd
  839. end
  840. local hpMax = CombatObj.getHpMax(atkObj)
  841. atkObj.hp = math.ceil(hpMax * hpRate / MAX_HP_RATE)
  842. atkObj.hp = math.min(atkObj.hp, hpMax)
  843. end
  844. -- 检查要不要结束
  845. function checkFinishFight(human)
  846. local lianyuCache = getLianyuCache(human)
  847. if not lianyuCache then
  848. return
  849. end
  850. if lianyuCache.combatResult and lianyuCache.combatResult ~= CombatDefine.RESULT_WIN then
  851. finishFight(human) -- 失败就结束吧
  852. return
  853. end
  854. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  855. local config = LianyuExcel.gamelevel[lv]
  856. if not config then -- 全部通关了也结束
  857. finishFight(human)
  858. return
  859. end
  860. return lv, config
  861. end
  862. -- 战斗开始
  863. function fight(human)
  864. local lianyuCache = getLianyuCache(human)
  865. if not lianyuCache then
  866. lianyuCache = initCombatCache(human)
  867. end
  868. local lv, config = checkFinishFight(human)
  869. if not lv or not config then
  870. return
  871. end
  872. if not lianyuCache.bufferIndex then
  873. -- 发送buffer选择界面
  874. return sendBufferSelect(human)
  875. end
  876. -- 标记今日打过
  877. if getTodayWinLv(human) == nil then
  878. setTodayWinLv(human, 0)
  879. end
  880. -- 战斗界面额外信息
  881. sendFightInfo(human)
  882. -- 调用战斗接口
  883. CombatLogic.combatBegin(human, config.mapID, nil, CombatDefine.COMBAT_TYPE8, lv)
  884. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_8, 1)
  885. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1205)
  886. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  887. YunYingLogic.onCallBack(human, "onLianyu",1)
  888. end
  889. -- 战斗信息
  890. function setCombatBeginInfo(human, combatInfo, lv)
  891. -- 设置一些战斗信息
  892. combatInfo.defender.name = Util.format(Lang.COMBAT_LIANYU_NAME, lv)
  893. end
  894. -- 获取当前地图ID
  895. function getMapID(human, args)
  896. local lianyuCache = getLianyuCache(human)
  897. if not lianyuCache then
  898. lianyuCache = initCombatCache(human)
  899. end
  900. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  901. local config = LianyuExcel.gamelevel[lv]
  902. if not config then -- 全部通关了
  903. return
  904. end
  905. return config.mapID
  906. end
  907. -- 战斗结束回调
  908. function onFightEnd(human, result, combatType, lv, combatInfo)
  909. local lianyuCache = getLianyuCache(human)
  910. if not lianyuCache then
  911. return
  912. end
  913. lianyuCache.combatResult = result
  914. combatInfo.endStatus = CombatLogic.COMBAT_END_STATUS2
  915. combatInfo.noSendFinish = true
  916. if result == CombatDefine.RESULT_WIN then
  917. -- 胜利
  918. lianyuCache.winLv = (lianyuCache.winLv or 0) + 1
  919. if lv > getMaxLv(human) then
  920. setMaxLv(human, lv)
  921. end
  922. -- 每5关重置buffer
  923. if lianyuCache.winLv % PER_FIVELEVEL == 0 then
  924. randBuffers(human)
  925. end
  926. -- 记录血量/技能
  927. lianyuCache.combatHpRates = lianyuCache.combatHpRates or {}
  928. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  929. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  930. local atkObj = combatInfo.objList[atkPos]
  931. if atkObj then
  932. -- 援军
  933. local realIndex = lianyuCache.backupPos2index and lianyuCache.backupPos2index[index] or index
  934. local hpMax = CombatObj.getHpMax(atkObj)
  935. lianyuCache.combatHpRates[realIndex] = atkObj.hp * MAX_HP_RATE / hpMax
  936. if atkObj.backupPos then
  937. local atkBackupPos = CombatLogic.getIndexByPos(CombatDefine.ATTACK_SIDE, atkObj.backupPos)
  938. lianyuCache.backupPos2index = lianyuCache.backupPos2index or {}
  939. lianyuCache.backupPos2index[atkBackupPos] = index
  940. end
  941. end
  942. end
  943. lianyuCache.combatObjSkill = lianyuCache.combatObjSkill or {}
  944. lianyuCache.combatHelpSkill = lianyuCache.combatHelpSkill or {}
  945. for atkPos, atkObj in pairs(combatInfo.objList) do
  946. if atkObj.side == CombatDefine.ATTACK_SIDE then
  947. local realIndex = atkObj.backupPos or atkPos
  948. local skill = {}
  949. skill.skillList = atkObj.skillList
  950. skill.beSkillList = atkObj.beSkillList
  951. lianyuCache.combatObjSkill[realIndex] = skill
  952. end
  953. end
  954. for atkPos, atkObj in pairs(combatInfo.helpList) do
  955. if atkObj.side == CombatDefine.ATTACK_SIDE then
  956. local skill = {}
  957. skill.skillList = atkObj.skillList
  958. skill.beSkillList = atkObj.beSkillList
  959. lianyuCache.combatHelpSkill[atkPos] = skill
  960. end
  961. end
  962. if lv >= #LianyuExcel.gamelevel then -- 全部通关
  963. finishFight(human, combatInfo)
  964. else
  965. if human.fd then
  966. CombatLogic.sendCombatFinish(human, combatInfo)
  967. fight(human)
  968. else
  969. if lianyuCache.bufferIndex == nil then
  970. -- 自动选择BUFFER
  971. selectBuffer(human, 1)
  972. else
  973. fight(human)
  974. end
  975. end
  976. end
  977. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_7, lv)
  978. --TODO:记录绝望深渊
  979. Log.write(Log.LOGID_OSS_BATTLE_DESPAIRABYSS, human.db._id, human.db.account, human.db.name, lv)
  980. else
  981. -- 失败
  982. finishFight(human, combatInfo)
  983. end
  984. end
  985. -- 初始战斗对象信息
  986. function initCombatObjCache(human)
  987. local lianyuCache = getLianyuCache(human)
  988. if not lianyuCache or lianyuCache.objList then
  989. return
  990. end
  991. local objList, helpList, rolebase, formation, jiban = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE8)
  992. local combatHelp, combatHelpPos = getCombatHelp(human)
  993. if combatHelp and combatHelpPos then
  994. if CombatPosLogic.checkPos(formation, combatHelpPos) then
  995. objList[combatHelpPos] = combatHelp.combatObj
  996. end
  997. end
  998. lianyuCache.objList = objList
  999. lianyuCache.helpList = helpList
  1000. lianyuCache.rolebase = rolebase
  1001. lianyuCache.formation = formation
  1002. lianyuCache.jiban = jiban
  1003. end
  1004. -- 玩家战斗信息
  1005. function getCombatObjList(human, side)
  1006. local lianyuCache = getLianyuCache(human)
  1007. if not lianyuCache then
  1008. return
  1009. end
  1010. if side == CombatDefine.DEFEND_SIDE then
  1011. local lv = lianyuCache.startLv + (lianyuCache.winLv or 0)
  1012. local config = LianyuExcel.gamelevel[lv]
  1013. if not config then
  1014. return
  1015. end
  1016. return CombatLogic.getMonsterObjList(config.monsterOutID)
  1017. end
  1018. initCombatObjCache(human)
  1019. local helpList = lianyuCache.helpList
  1020. local rolebase = lianyuCache.rolebase
  1021. local formation = lianyuCache.formation
  1022. local objList = {}
  1023. for index, obj in pairs(lianyuCache.objList) do
  1024. if getCombatHpRate(human, index) > 0 then
  1025. objList[index] = obj
  1026. end
  1027. end
  1028. -- 援军
  1029. if lianyuCache.backupPos2index then
  1030. for backupPos, index in pairs(lianyuCache.backupPos2index) do
  1031. local obj = lianyuCache.objList[index]
  1032. if obj and getCombatHpRate(human, index) > 0 then
  1033. objList[backupPos] = obj
  1034. objList[index] = nil
  1035. end
  1036. end
  1037. end
  1038. return objList, helpList, rolebase, formation, lianyuCache.jiban
  1039. end
  1040. -- 请求结算(战斗结束/中途退出等)
  1041. function finishFight(human, combatInfo, noSend)
  1042. local lianyuCache = getLianyuCache(human)
  1043. if not lianyuCache then
  1044. return
  1045. end
  1046. local items = getFightItems(human)
  1047. -- 刷新每日胜利次数
  1048. if (lianyuCache.winLv or 0) > (getTodayWinLv(human) or 0) then
  1049. setTodayWinLv(human, lianyuCache.winLv)
  1050. end
  1051. cleanCache(human)
  1052. local combatItems = {}
  1053. local msgRet = Msg.gc.GC_LIANYU_FIGHT_FINISH
  1054. msgRet.items[0] = 0
  1055. msgRet.data[0] = 0
  1056. if items then
  1057. for itemID, itemCnt in pairs(items) do
  1058. msgRet.items[0] = msgRet.items[0] + 1
  1059. local itemNet = msgRet.items[msgRet.items[0]]
  1060. Grid.makeItem(itemNet, itemID, itemCnt)
  1061. BagLogic.addItem(human, itemID, itemCnt, "lianyu_win_reward")
  1062. combatItems[#combatItems + 1] = {itemID, itemCnt}
  1063. end
  1064. end
  1065. if not combatInfo then
  1066. local combatCache = CombatLogic.getCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1067. combatInfo = combatCache and combatCache.combatInfo
  1068. CombatLogic.cleanCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1069. end
  1070. if combatInfo then
  1071. if #combatItems > 1 then
  1072. combatInfo.endStatus = nil
  1073. combatInfo.isWin = true
  1074. else
  1075. combatInfo.endStatus = CombatLogic.COMBAT_END_STATUS1
  1076. end
  1077. combatInfo.rewardItem = combatItems
  1078. if not noSend then
  1079. CombatLogic.sendCombatFinish(human, combatInfo)
  1080. end
  1081. CombatLogic.fontCombatFinish(msgRet.data[1], combatInfo)
  1082. msgRet.data[0] = 1
  1083. -- CombatLogic.sendCombatFinish(human, combatInfo)
  1084. end
  1085. -- Msg.trace(msgRet)
  1086. Msg.send(msgRet, human.fd)
  1087. end
  1088. -- 助战英雄数
  1089. function getCombatZhuzhanCnt(human)
  1090. local combatHelp, combatHelpPos = getCombatHelp(human)
  1091. if combatHelp and combatHelpPos then
  1092. return 1
  1093. end
  1094. end
  1095. -- 是否显示跳过战斗按钮
  1096. function isCombatShowJumpBtn(human)
  1097. return true
  1098. end
  1099. -- 继承技能CD
  1100. function setSkillAndBeskill(human, combatInfo)
  1101. local lianyuCache = getLianyuCache(human)
  1102. if not lianyuCache then return end
  1103. for atkPos, atkObj in pairs(CombatImpl.objList) do
  1104. local skill = lianyuCache.combatObjSkill and lianyuCache.combatObjSkill[atkPos]
  1105. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1106. atkObj.skillList = skill.skillList
  1107. atkObj.beSkillList = skill.beSkillList
  1108. end
  1109. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1110. end
  1111. for atkPos, atkObj in pairs(CombatImpl.helpList) do
  1112. local skill = lianyuCache.combatHelpSkill and lianyuCache.combatHelpSkill[atkPos]
  1113. if atkObj.side == CombatDefine.ATTACK_SIDE and skill then
  1114. atkObj.skillList = skill.skillList
  1115. atkObj.beSkillList = skill.beSkillList
  1116. end
  1117. --print("===============", atkPos, skill and skill.skillList, skill and skill.beSkillList)
  1118. end
  1119. end
  1120. -- ============================== 其它 ==================================
  1121. -- 每日重置
  1122. function updateDaily(human)
  1123. if not human.db.lianyu then
  1124. return
  1125. end
  1126. local lianyuDB = human.db.lianyu
  1127. lianyuDB.todayMaxLv = getMaxLv(human)
  1128. lianyuDB.todayWinLv = nil
  1129. lianyuDB.todayHelpUuid = nil
  1130. end
  1131. -- 登出
  1132. function onLogout(human)
  1133. checkFinishFight(human)
  1134. -- 自动选择BUFFER
  1135. selectBuffer(human, 1)
  1136. end
  1137. -- 登陆
  1138. function onLogin(human)
  1139. local lianyuCache = getLianyuCache(human)
  1140. if not lianyuCache then
  1141. return
  1142. end
  1143. local combatCache = CombatLogic.getCombatCache(human.db._id, CombatDefine.COMBAT_TYPE8)
  1144. if combatCache then
  1145. sendFightInfo(human)
  1146. else
  1147. finishFight(human)
  1148. end
  1149. end
  1150. -- 0点结算发奖励
  1151. MAIL_SEND_CACHE = MAIL_SEND_CACHE or nil
  1152. function onZero()
  1153. MAIL_SEND_CACHE = {}
  1154. local maxCnt = LianyuExcel.rankreward[#LianyuExcel.rankreward].rankMax
  1155. local board = BillboardDB.getBoard(BillboardDefine.TYPE_LIANYU)
  1156. if board and board.rank2data then
  1157. maxCnt = maxCnt <= #board.rank2data and maxCnt or #board.rank2data
  1158. for i = 1, maxCnt do
  1159. local rankData = board.rank2data[i]
  1160. MAIL_SEND_CACHE[i] = rankData.uuid
  1161. end
  1162. end
  1163. Timer.addLater(1, boardReward)
  1164. end
  1165. -- 定时器 邮件分开发,预防崩溃
  1166. function boardReward()
  1167. if not MAIL_SEND_CACHE then
  1168. return
  1169. end
  1170. for i = 1, #MAIL_SEND_CACHE do
  1171. local uuid = MAIL_SEND_CACHE[i]
  1172. local rankConfig = getRankConfig(i)
  1173. if not rankConfig then
  1174. MAIL_SEND_CACHE = nil
  1175. return
  1176. end
  1177. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_LIANYU2]
  1178. local title = mailConfig.title
  1179. local senderName = mailConfig.senderName
  1180. local content = Util.format(mailConfig.content, i)
  1181. MailManager.add(MailManager.SYSTEM, uuid, title, content, rankConfig.rewards, senderName)
  1182. end
  1183. MAIL_SEND_CACHE = nil
  1184. end
  1185. -- 设置助战上阵
  1186. local HELP_MAIL_ITEMS = {{}}
  1187. function setCombatZhuzhan(human, pos)
  1188. local lianyuCache = getLianyuCache(human)
  1189. if not lianyuCache then
  1190. lianyuCache = initCombatCache(human)
  1191. end
  1192. local helpInfo = setCombatHelpPos(human, pos)
  1193. if not helpInfo then
  1194. return
  1195. end
  1196. -- 助战给对方奖励
  1197. if helpInfo.helpUuids[human.db._id] then
  1198. return -- 同一个人助战不给
  1199. end
  1200. if helpInfo.helpCnt >= FRIEND_HELP_MAXCNT then
  1201. return -- 超过上限不给
  1202. end
  1203. setHelpTarget(helpInfo, human.db._id)
  1204. HELP_MAIL_ITEMS[1][1] = ItemDefine.ITEM_FRIEND_ID
  1205. HELP_MAIL_ITEMS[1][2] = FRIEND_ITEM_CNT
  1206. local mailConfig = MailExcel.mail[92]
  1207. local title = mailConfig.title
  1208. local senderName = mailConfig.senderName
  1209. local content = Util.format(mailConfig.content, human.db.name, FRIEND_ITEM_CNT)
  1210. MailManager.add(MailManager.SYSTEM, helpInfo.uuid, title, content, HELP_MAIL_ITEMS, senderName)
  1211. end
  1212. function isDot(human)
  1213. local rewardRed = hasRewardRed(human)
  1214. if rewardRed then
  1215. return true
  1216. end
  1217. local lyCommon = getLianyuCommon()
  1218. local helpInfo = getHelpInfo(lyCommon, human.db._id)
  1219. if not helpInfo then
  1220. return true
  1221. end
  1222. local todayWinLv = getTodayWinLv(human)
  1223. if not todayWinLv then
  1224. return true
  1225. end
  1226. return false
  1227. end