JibanLogic.lua 7.7 KB

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