JibanLogic.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. CMD1 = 1 -- 主线通关
  16. CMD2 = 2 -- 获得英雄
  17. CMD3 = 3 -- 通关通天塔
  18. CMD4 = 4 -- 等级
  19. FATHER2ID = nil
  20. HERO2ID = nil
  21. CMD2POS = nil
  22. local function getDB(human)
  23. human.db.jiban = human.db.jiban or {[1] = 1}
  24. return human.db.jiban
  25. end
  26. -- 获取全部设置的羁绊位置英雄ID
  27. local function getDB_AllJibanHeroID(human)
  28. human.db.jibanheroid = human.db.jibanheroid or {}
  29. return human.db.jibanheroid
  30. end
  31. -- 获取某个羁绊位置英雄ID
  32. local function getDB_JibanHeroIDByIndex(human, nIndex)
  33. local jibanheroid = getDB_AllJibanHeroID(human)
  34. return jibanheroid[nIndex] and jibanheroid[nIndex] or -1
  35. end
  36. -- 设置羁绊位置英雄ID
  37. local function setDB_JibanHeroID(human, nIndex, nHeroID)
  38. local jibanheroid = getDB_AllJibanHeroID(human)
  39. jibanheroid[nIndex] = nHeroID
  40. end
  41. local function fontJibanInfo(net,id)
  42. local conf = JibanExcel.jiban[id]
  43. net.id = id
  44. net.name = conf.name
  45. net.desc = conf.desc
  46. net.quality = conf.quality
  47. local len = 0
  48. for _,v in ipairs(conf.hero) do
  49. len = len + 1
  50. HeroGrid.makeHeroSimpleByID(net.heroList[len], v)
  51. end
  52. net.heroList[0] = len
  53. end
  54. function initAfterHot()
  55. -- 同一father下的羁绊互斥
  56. --[[
  57. FATHER2ID = {
  58. [jibanCfg.father] = {
  59. jibanCfg.id,
  60. } -- array
  61. }
  62. ]]
  63. FATHER2ID = {}
  64. HERO2ID = {}
  65. --[[
  66. temp = {
  67. {jibanCfg.quality,jibanCfg.id},
  68. } -- array
  69. ]]
  70. local temp = {}
  71. for k,v in ipairs(JibanExcel.jiban) do
  72. temp[#temp + 1] = {v.quality,k}
  73. for _,v1 in ipairs(v.hero) do
  74. HERO2ID[v1] = HERO2ID[v1] or {}
  75. HERO2ID[v1][#HERO2ID[v1] + 1] = k
  76. end
  77. end
  78. table.sort(temp,function(a,b)
  79. if a[1] > b[1] then
  80. return true
  81. elseif a[1] == b[1] and a[2] < b[2] then
  82. return true
  83. else
  84. return false
  85. end
  86. end)
  87. local msgRet = Msg.gc.GC_JIBAN_PREVIEW
  88. local len = 0
  89. for k,v in ipairs(temp) do
  90. local conf = JibanExcel.jiban[v[2]]
  91. FATHER2ID[conf.father] = FATHER2ID[conf.father] or {}
  92. FATHER2ID[conf.father][#FATHER2ID[conf.father] + 1] = v[2]
  93. len = len + 1
  94. local net = msgRet.list[len]
  95. fontJibanInfo(net,k)
  96. end
  97. msgRet.list[0] = len
  98. CMD2POS = {}
  99. for k,v in ipairs(JibanExcel.pos) do
  100. if v.cmd > 0 then
  101. CMD2POS[v.cmd] = k
  102. end
  103. end
  104. end
  105. function query(human,combatType,heroID)
  106. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_207)
  107. if flag ~= true then
  108. return
  109. end
  110. local msgRet = Msg.gc.GC_JIBAN_QUERY
  111. local len = 0
  112. if HERO2ID[heroID] then
  113. for k,v in ipairs(HERO2ID[heroID]) do
  114. len = len + 1
  115. local net = msgRet.jibanList[len]
  116. fontJibanInfo(net,v)
  117. end
  118. end
  119. msgRet.jibanList[0] = len
  120. len = 0
  121. local db = getDB(human)
  122. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  123. local jibanDB = combatHeroDB.jiban or {}
  124. for k,v in ipairs(JibanExcel.pos) do
  125. len = len + 1
  126. local net = msgRet.posList[len]
  127. net.id = k
  128. net.tip = v.tip
  129. net.isOpen = db[k] or 0
  130. net.sort = v.sort
  131. local heroGrid
  132. if jibanDB[k] and jibanDB[k] ~= "" and jibanDB[k] ~= "0" then
  133. heroGrid = HeroLogic.getHeroGridByUuid(human, jibanDB[k])
  134. end
  135. if not heroGrid then
  136. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  137. if -1 ~= nHeroID then
  138. local heroGridList = HeroLogic.getHeroListById(human, nHeroID)
  139. if nil ~= _G.next(heroGridList) then
  140. local nHeroIndex = heroGridList[1]
  141. heroGrid = HeroLogic.getHeroGrid(human, nHeroID, nHeroIndex)
  142. end
  143. end
  144. end
  145. local index = heroGrid and heroGrid.bagIndex or 0
  146. HeroGrid.makeHeroSimple(net.hero, heroGrid, index)
  147. end
  148. msgRet.posList[0] = len
  149. Msg.send(msgRet,human.fd)
  150. end
  151. --
  152. function sendQuery(human,combatType, teamType)
  153. local msgRet = Msg.gc.GC_JIBAN_QUERY_ALL
  154. local len = 0
  155. local db = getDB(human)
  156. msgRet.type = teamType
  157. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  158. local jibanDB = combatHeroDB.jiban or {}
  159. for k,v in ipairs(JibanExcel.pos) do
  160. len = len + 1
  161. local net = msgRet.posList[len]
  162. net.id = k
  163. net.tip = v.tip
  164. net.isOpen = db[k] or 0
  165. net.sort = v.sort
  166. local heroGrid
  167. if jibanDB[k] and jibanDB[k] ~= "" and jibanDB[k] ~= "0" then
  168. heroGrid = HeroLogic.getHeroGridByUuid(human, jibanDB[k])
  169. end
  170. if not heroGrid then
  171. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  172. if -1 ~= nHeroID then
  173. local heroGridList = HeroLogic.getHeroListById(human, nHeroID)
  174. if nil ~= _G.next(heroGridList) then
  175. local nHeroIndex = heroGridList[1]
  176. heroGrid = HeroLogic.getHeroGrid(human, nHeroID, nHeroIndex)
  177. end
  178. end
  179. end
  180. local index = heroGrid and heroGrid.bagIndex or 0
  181. HeroGrid.makeHeroSimple(net.hero, heroGrid, index)
  182. end
  183. msgRet.posList[0] = len
  184. Msg.send(msgRet,human.fd)
  185. end
  186. function preview(human)
  187. local msgRet = Msg.gc.GC_JIBAN_PREVIEW
  188. Msg.send(msgRet,human.fd)
  189. end
  190. function getPosList(human)
  191. return getDB(human)
  192. end
  193. function onCallback(human,cmd,arg)
  194. local pos = CMD2POS[cmd]
  195. local db = getDB(human)
  196. if db[pos] then
  197. return
  198. end
  199. local conf = JibanExcel.pos[pos]
  200. if arg >= conf.arg then
  201. db[pos] = 1
  202. end
  203. end
  204. function getJiban(objList,jibanList)
  205. local objHero = {}
  206. local jibanHero = {}
  207. for i = 1,CombatDefine.COMBAT_HERO_CNT - 1 do
  208. local obj = objList[i]
  209. -- 不是玩家不计算羁绊
  210. if obj and obj.type == CombatDefine.COMBAT_OBJ_TYPE1 then
  211. objHero[obj.id] = objHero[obj.id] or 0
  212. objHero[obj.id] = objHero[obj.id] + 1
  213. end
  214. end
  215. if jibanList then
  216. for k,v in pairs(jibanList) do
  217. if v > 0 then
  218. objHero[v] = objHero[v] or 0
  219. objHero[v] = objHero[v] + 1
  220. end
  221. end
  222. end
  223. local jiban = {}
  224. for _,v in pairs(FATHER2ID) do
  225. for _,v1 in ipairs(v) do
  226. local conf = JibanExcel.jiban[v1]
  227. local canUse = true
  228. for _,v2 in ipairs(conf.hero) do
  229. if not objHero[v2] then
  230. canUse = false
  231. break
  232. end
  233. end
  234. if canUse then
  235. jiban[v1] = 1
  236. break
  237. end
  238. end
  239. end
  240. return jiban
  241. end
  242. function getJibanHero(human,combatHeroDB)
  243. local jibanHero = {}
  244. if combatHeroDB.jiban then
  245. for k, uuid in pairs(combatHeroDB.jiban) do
  246. if uuid ~= "0" and uuid ~= "" then
  247. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  248. if heroGrid then
  249. jibanHero[k] = heroGrid.id
  250. else
  251. local nHeroID = getDB_JibanHeroIDByIndex(human, k)
  252. if -1 ~= nHeroID then
  253. jibanHero[k] = nHeroID
  254. end
  255. end
  256. end
  257. end
  258. end
  259. return jibanHero
  260. end
  261. function getDesc(jiban)
  262. local desc = {}
  263. local len = 0
  264. for k,v in pairs(jiban) do
  265. local conf = JibanExcel.jiban[k]
  266. if len > 0 then
  267. len = len + 1
  268. desc[len] = "|"
  269. end
  270. len = len + 1
  271. desc[len] = conf.name
  272. len = len + 1
  273. desc[len] = ","
  274. len = len + 1
  275. desc[len] = conf.desc
  276. len = len + 1
  277. desc[len] = ","
  278. len = len + 1
  279. desc[len] = conf.quality
  280. end
  281. local descStr = table.concat(desc)
  282. return descStr
  283. end
  284. function setBeSkill(objList,jiban)
  285. if not jiban then return end
  286. local skillList = {}
  287. for k in pairs(jiban) do
  288. local conf = JibanExcel.jiban[k]
  289. local skillID = conf.skill
  290. if skillID > 0 then
  291. for i = 1,CombatDefine.COMBAT_HERO_CNT - 1 do
  292. local obj = objList[i]
  293. if obj then
  294. BeSkill.setBeSkillID(obj,skillID)
  295. end
  296. end
  297. end
  298. end
  299. end
  300. function update(human,combatType,jibanListStr)
  301. local conf = CombatExcel.combat[combatType]
  302. if not conf then return end
  303. local posList = getPosList(human)
  304. local jibanList = Util.split(jibanListStr,",")
  305. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,combatType)
  306. for k,v in ipairs(jibanList) do
  307. local uuid = v or "0"
  308. if uuid ~= "" and uuid ~= "0" then
  309. --检测有没有再阵容上
  310. for _, combatUuid in ipairs(combatHeroDB.list) do
  311. if uuid == combatUuid then return end
  312. end
  313. if not posList[k] then return end
  314. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  315. if not heroGrid then return end
  316. setDB_JibanHeroID(human, k, heroGrid.id)
  317. end
  318. end
  319. combatHeroDB.jiban = jibanList
  320. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_JIBAN_GROUP)
  321. sendQuery(human,combatType, conf.teamType)
  322. end