LianyuLogic.lua 44 KB

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