JibanLogic.lua 7.4 KB

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