LianyuLogic.lua 45 KB

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