LianyuLogic.lua 45 KB

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