JibanLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. local Msg = require("core.Msg")
  2. local Util = require("common.Util")
  3. local CombatPosLogic = require("combat.CombatPosLogic")
  4. local HeroGrid = require("hero.HeroGrid")
  5. local BeSkill = require("combat.BeSkill")
  6. local CombatDefine = require("combat.CombatDefine")
  7. local JibanExcel = require("excel.jiban")
  8. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  9. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local Lang = require("common.Lang")
  12. local HeroLogic = require("hero.HeroLogic")
  13. local GuideLogic = require("guide.GuideLogic")
  14. local CombatExcel = require("excel.combat")
  15. local Json = require("common.Json")
  16. local HeroConfig = require("excel.hero").hero
  17. local AnotherWorldBattleNS
  18. local HeroBook
  19. CMD1 = 1 -- 主线通关
  20. CMD2 = 2 -- 获得英雄
  21. CMD3 = 3 -- 通关通天塔
  22. CMD4 = 4 -- 等级
  23. FATHER2ID = nil
  24. HERO2ID = nil
  25. CMD2POS = nil
  26. JIBATEMP = nil
  27. local function getDB(human)
  28. human.db.jiban = human.db.jiban or {[1] = 1}
  29. return human.db.jiban
  30. end
  31. -- 获取全部设置的羁绊位置英雄ID
  32. local function getDB_AllJibanHeroID(human)
  33. human.db.jibanheroid = human.db.jibanheroid or {}
  34. return human.db.jibanheroid
  35. end
  36. -- 获取某个羁绊位置英雄ID
  37. local function getDB_JibanHeroIDByIndex(human, nIndex)
  38. local jibanheroid = getDB_AllJibanHeroID(human)
  39. return jibanheroid[nIndex] and jibanheroid[nIndex] or -1
  40. end
  41. -- 设置羁绊位置英雄ID
  42. local function setDB_JibanHeroID(human, nIndex, nHeroID)
  43. local jibanheroid = getDB_AllJibanHeroID(human)
  44. jibanheroid[nIndex] = nHeroID
  45. end
  46. local function fontJibanInfo(net,id)
  47. local conf = JibanExcel.jiban[id]
  48. net.id = id
  49. net.name = conf.name
  50. net.desc = conf.desc
  51. net.quality = conf.quality
  52. local len = 0
  53. for _,v in ipairs(conf.hero) do
  54. len = len + 1
  55. HeroGrid.makeHeroSimpleByID(net.heroList[len], v)
  56. end
  57. net.heroList[0] = len
  58. end
  59. function initAfterHot()
  60. -- 同一father下的羁绊互斥
  61. --[[
  62. FATHER2ID = {
  63. [jibanCfg.father] = {
  64. jibanCfg.id,
  65. } -- array
  66. }
  67. ]]
  68. FATHER2ID = {}
  69. HERO2ID = {}
  70. --[[
  71. temp = {
  72. {jibanCfg.quality,jibanCfg.id},
  73. } -- array
  74. ]]
  75. JIBATEMP = {}
  76. for k,v in ipairs(JibanExcel.jiban) do
  77. JIBATEMP[#JIBATEMP + 1] = {v.quality,k}
  78. for _,v1 in ipairs(v.hero) do
  79. HERO2ID[v1] = HERO2ID[v1] or {}
  80. HERO2ID[v1][#HERO2ID[v1] + 1] = k
  81. end
  82. end
  83. table.sort(JIBATEMP,function(a,b)
  84. if a[1] > b[1] then
  85. return true
  86. elseif a[1] == b[1] and a[2] < b[2] then
  87. return true
  88. else
  89. return false
  90. end
  91. end)
  92. local msgRet = Msg.gc.GC_JIBAN_PREVIEW
  93. local len = 0
  94. for k,v in ipairs(JIBATEMP) do
  95. local conf = JibanExcel.jiban[v[2]]
  96. FATHER2ID[conf.father] = FATHER2ID[conf.father] or {}
  97. FATHER2ID[conf.father][#FATHER2ID[conf.father] + 1] = v[2]
  98. -- len = len + 1
  99. -- local net = msgRet.list[len]
  100. -- fontJibanInfo(net,k)
  101. end
  102. -- msgRet.list[0] = len
  103. CMD2POS = {}
  104. for k,v in ipairs(JibanExcel.pos) do
  105. if v.cmd > 0 then
  106. CMD2POS[v.cmd] = k
  107. end
  108. end
  109. end
  110. function query(human,combatType,heroID, extraArgs)
  111. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_207)
  112. if flag ~= true then
  113. return
  114. end
  115. local msgRet = Msg.gc.GC_JIBAN_QUERY
  116. local len = 0
  117. if HERO2ID[heroID] then
  118. for k,v in ipairs(HERO2ID[heroID]) do
  119. len = len + 1
  120. local net = msgRet.jibanList[len]
  121. fontJibanInfo(net,v)
  122. end
  123. end
  124. msgRet.jibanList[0] = len
  125. len = 0
  126. local db = getDB(human)
  127. local combatHeroDB
  128. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  129. AnotherWorldBattleNS = AnotherWorldBattleNS or require("anotherWorldBattle.AnotherWorldBattleNS")
  130. local v1,v2, v3
  131. v1, v2, v3, combatHeroDB = AnotherWorldBattleNS.getCombatHeros(human, combatType, extraArgs)
  132. combatHeroDB = combatHeroDB or {}
  133. else
  134. combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  135. end
  136. local jibanDB = combatHeroDB.jiban or {}
  137. for k,v in ipairs(JibanExcel.pos) do
  138. len = len + 1
  139. local net = msgRet.posList[len]
  140. net.id = k
  141. net.tip = v.tip
  142. net.isOpen = db[k] or 0
  143. net.sort = v.sort
  144. local heroGrid
  145. if jibanDB[k] and jibanDB[k] ~= "" and jibanDB[k] ~= "0" then
  146. heroGrid = HeroLogic.getHeroGridByUuid(human, jibanDB[k])
  147. end
  148. if not heroGrid then
  149. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  150. if -1 ~= nHeroID then
  151. local heroGridList = HeroLogic.getHeroListById(human, nHeroID)
  152. if nil ~= _G.next(heroGridList) then
  153. local nHeroIndex = heroGridList[1]
  154. heroGrid = HeroLogic.getHeroGrid(human, nHeroID, nHeroIndex)
  155. end
  156. end
  157. end
  158. local index = heroGrid and heroGrid.bagIndex or 0
  159. HeroGrid.makeHeroSimple(net.hero, heroGrid, index)
  160. end
  161. msgRet.posList[0] = len
  162. Msg.send(msgRet,human.fd)
  163. end
  164. --
  165. function sendQuery(human,combatType, teamType)
  166. local msgRet = Msg.gc.GC_JIBAN_QUERY_ALL
  167. local len = 0
  168. local db = getDB(human)
  169. msgRet.type = teamType
  170. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  171. local jibanDB = combatHeroDB.jiban or {}
  172. for k,v in ipairs(JibanExcel.pos) do
  173. len = len + 1
  174. local net = msgRet.posList[len]
  175. net.id = k
  176. net.tip = v.tip
  177. net.isOpen = db[k] or 0
  178. net.sort = v.sort
  179. local heroGrid
  180. if jibanDB[k] and jibanDB[k] ~= "" and jibanDB[k] ~= "0" then
  181. heroGrid = HeroLogic.getHeroGridByUuid(human, jibanDB[k])
  182. end
  183. if not heroGrid then
  184. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  185. if -1 ~= nHeroID then
  186. local heroGridList = HeroLogic.getHeroListById(human, nHeroID)
  187. if nil ~= _G.next(heroGridList) then
  188. local nHeroIndex = heroGridList[1]
  189. heroGrid = HeroLogic.getHeroGrid(human, nHeroID, nHeroIndex)
  190. end
  191. end
  192. end
  193. local index = heroGrid and heroGrid.bagIndex or 0
  194. HeroGrid.makeHeroSimple(net.hero, heroGrid, index)
  195. end
  196. msgRet.posList[0] = len
  197. Msg.send(msgRet,human.fd)
  198. end
  199. function preview(human)
  200. local msgRet = Msg.gc.GC_JIBAN_PREVIEW
  201. msgRet.list[0] = 0
  202. msgRet.isend = 0
  203. local len = 0
  204. for k,v in ipairs(JIBATEMP) do
  205. len = len + 1
  206. local net = msgRet.list[len]
  207. fontJibanInfo(net,k)
  208. if len >=20 then
  209. msgRet.list[0] = len
  210. Msg.send(msgRet,human.fd)
  211. len = 0
  212. end
  213. end
  214. msgRet.list[0] = len
  215. msgRet.isend = 1
  216. Msg.send(msgRet,human.fd)
  217. end
  218. function getPosList(human)
  219. return getDB(human)
  220. end
  221. function onCallback(human,cmd,arg)
  222. local pos = CMD2POS[cmd]
  223. local db = getDB(human)
  224. if db[pos] then
  225. return
  226. end
  227. local conf = JibanExcel.pos[pos]
  228. if arg >= conf.arg then
  229. db[pos] = 1
  230. end
  231. end
  232. function getJiban(objList,jibanList)
  233. local objHero = {}
  234. local jibanHero = {}
  235. for i = 1,CombatDefine.COMBAT_HERO_CNT - 1 do
  236. local obj = objList[i]
  237. -- 不是玩家不计算羁绊
  238. if obj and obj.type == CombatDefine.COMBAT_OBJ_TYPE1 then
  239. objHero[obj.id] = objHero[obj.id] or 0
  240. objHero[obj.id] = objHero[obj.id] + 1
  241. end
  242. end
  243. if jibanList then
  244. -- for k,v in pairs(jibanList) do
  245. -- if v > 0 then
  246. -- objHero[v] = objHero[v] or 0
  247. -- objHero[v] = objHero[v] + 1
  248. -- end
  249. -- end
  250. for _, heroInfo in pairs(jibanList) do
  251. local heroID = heroInfo.heroID
  252. if heroID > 0 then
  253. jibanHero[heroID] = heroInfo
  254. end
  255. end
  256. end
  257. -- local jiban = {}
  258. -- for _,v in pairs(FATHER2ID) do
  259. -- for _,v1 in ipairs(v) do
  260. -- local conf = JibanExcel.jiban[v1]
  261. -- local canUse = true
  262. -- for _,v2 in ipairs(conf.hero) do
  263. -- if not objHero[v2] then
  264. -- canUse = false
  265. -- break
  266. -- end
  267. -- end
  268. -- if canUse then
  269. -- jiban[v1] = 1
  270. -- break
  271. -- end
  272. -- end
  273. -- end
  274. -- return jiban
  275. local jiban = {}
  276. for _,v in pairs(FATHER2ID) do
  277. for _,v1 in ipairs(v) do
  278. local conf = JibanExcel.jiban[v1]
  279. local canUse = true
  280. local jbHeroList = {}
  281. for _,v2 in ipairs(conf.hero) do
  282. if not objHero[v2] and not jibanHero[v2] then
  283. canUse = false
  284. break
  285. end
  286. if jibanHero[v2] then
  287. jbHeroList[v2] = 1
  288. end
  289. end
  290. if canUse then
  291. jiban[v1] = {}
  292. for jbHeroID in pairs(jbHeroList) do
  293. jiban[v1][jbHeroID] = jibanHero[jbHeroID]
  294. end
  295. end
  296. end
  297. end
  298. return jiban
  299. end
  300. function getJibanHero(human,combatHeroDB)
  301. local jibanHero = {}
  302. local jibanheroid = getDB_AllJibanHeroID(human)
  303. if combatHeroDB.jiban or (jibanheroid and next(jibanheroid)) then
  304. -- for k, uuid in pairs(combatHeroDB.jiban) do
  305. -- if uuid ~= "0" and uuid ~= "" then
  306. -- local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  307. -- if heroGrid then
  308. -- jibanHero[k] = heroGrid.id
  309. -- else
  310. -- local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  311. -- if -1 ~= nHeroID then
  312. -- jibanHero[k] = nHeroID
  313. -- end
  314. -- end
  315. -- end
  316. -- end
  317. for k, uuid in pairs(combatHeroDB.jiban) do
  318. if uuid ~= "0" and uuid ~= "" then
  319. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  320. if heroGrid then
  321. local heroCfg = HeroConfig[heroGrid.id]
  322. jibanHero[k] = {
  323. heroID = heroGrid.id,
  324. icon = heroGrid.head or (heroCfg and heroCfg.head or 0),
  325. star = heroGrid.star or 1,
  326. camp = heroCfg and heroCfg.camp or 1,
  327. grade = heroGrid.grade or (heroCfg and heroCfg.grade or 1),
  328. }
  329. else
  330. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  331. if -1 ~= nHeroID then
  332. local heroCfg = HeroConfig[nHeroID]
  333. jibanHero[k] = {
  334. heroID = nHeroID,
  335. icon = heroCfg and heroCfg.head or 0,
  336. star = 1,
  337. camp = heroCfg and heroCfg.camp or 1,
  338. grade = heroCfg.grade or 1,
  339. }
  340. end
  341. end
  342. end
  343. end
  344. local startIdx = CombatDefine.COMBAT_HERO_CNT + 1
  345. for _, nHeroID in pairs(jibanheroid or {}) do
  346. if -1 ~= nHeroID then
  347. local heroCfg = HeroConfig[nHeroID]
  348. jibanHero[startIdx] = {
  349. heroID = nHeroID,
  350. icon = heroCfg and heroCfg.head or 0,
  351. star = 1,
  352. camp = heroCfg and heroCfg.camp or 1,
  353. grade = heroCfg.grade or 1,
  354. }
  355. startIdx = startIdx + 1
  356. end
  357. end
  358. end
  359. return jibanHero
  360. end
  361. function getDesc(jiban)
  362. -- local desc = {}
  363. -- local len = 0
  364. -- for k,v in pairs(jiban) do
  365. -- local conf = JibanExcel.jiban[k]
  366. -- if len > 0 then
  367. -- len = len + 1
  368. -- desc[len] = "|"
  369. -- end
  370. -- len = len + 1
  371. -- desc[len] = conf.name
  372. -- len = len + 1
  373. -- desc[len] = ","
  374. -- len = len + 1
  375. -- desc[len] = conf.desc
  376. -- len = len + 1
  377. -- desc[len] = ","
  378. -- len = len + 1
  379. -- desc[len] = conf.quality
  380. -- end
  381. -- local descStr = table.concat(desc)
  382. -- return descStr
  383. local len = 0
  384. local JiBanInfo = {}
  385. for k, jbHeroInfo in pairs(jiban) do
  386. local conf = JibanExcel.jiban[k]
  387. len = len + 1
  388. JiBanInfo[len] = {
  389. name = conf.name,
  390. desc = conf.desc,
  391. quality = conf.quality,
  392. hero = conf.hero,
  393. }
  394. if next(jbHeroInfo) then
  395. JiBanInfo[len].jbHeroInfo = {}
  396. local info = JiBanInfo[len].jbHeroInfo
  397. for jbHeroId, data in pairs(jbHeroInfo) do
  398. info[jbHeroId] = data
  399. end
  400. end
  401. end
  402. return Json.Encode(JiBanInfo)
  403. end
  404. function setBeSkill(objList,jiban)
  405. if not jiban then return end
  406. local skillList = {}
  407. for k in pairs(jiban) do
  408. local conf = JibanExcel.jiban[k]
  409. local skillID = conf.skill
  410. if skillID > 0 then
  411. for i = 1,CombatDefine.COMBAT_HERO_CNT - 1 do
  412. local obj = objList[i]
  413. if obj then
  414. BeSkill.setBeSkillID(obj,skillID)
  415. end
  416. end
  417. end
  418. end
  419. end
  420. -- 更新羁绊
  421. function update(human,combatType,jibanListStr, heroIdStr, extraArgs)
  422. local conf = CombatExcel.combat[combatType]
  423. if not conf then return end
  424. local posList = getPosList(human)
  425. local jibanList = Util.split(jibanListStr,",")
  426. local jibanHeroIdArr = Util.split(heroIdStr,",", true)
  427. local combatHeroDB
  428. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  429. AnotherWorldBattleNS = AnotherWorldBattleNS or require("anotherWorldBattle.AnotherWorldBattleNS")
  430. local v1,v2, v3
  431. v1, v2, v3, combatHeroDB = AnotherWorldBattleNS.getCombatHeros(human, combatType, extraArgs)
  432. if not combatHeroDB then
  433. return
  434. end
  435. else
  436. combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  437. end
  438. HeroBook = HeroBook or require("hero.HeroBook")
  439. for k,v in ipairs(jibanList) do
  440. local uuid = v or "0"
  441. local heroId = jibanHeroIdArr[k] or 0
  442. if uuid ~= "" and uuid ~= "0" and heroId ~= 0 then
  443. --检测有没有再阵容上
  444. for _, combatUuid in ipairs(combatHeroDB.list) do
  445. if uuid == combatUuid then return end
  446. end
  447. if not posList[k] then return end
  448. -- local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  449. -- if not heroGrid then return end
  450. -- setDB_JibanHeroID(human, k, heroGrid.id)
  451. local res = HeroBook.isGetHero(human, heroId)
  452. if not res or res == HeroBook.LIEZHUAN_REWARD_NO then
  453. return
  454. end
  455. setDB_JibanHeroID(human, k, heroId)
  456. end
  457. end
  458. combatHeroDB.jiban = jibanList
  459. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  460. return query(human, combatType, 0, extraArgs)
  461. end
  462. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_JIBAN_GROUP)
  463. sendQuery(human,combatType, conf.teamType)
  464. end