JibanLogic.lua 12 KB

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