JibanLogic.lua 9.2 KB

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