ArchangeEquipInfo.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. ---@class ArchangeEquipInfo
  2. ---@field archangeInfo table<number,table> @大天使装备的信息
  3. ---@field angelSuitAction number[] @天赋大师激活的id
  4. ---@field angelTalenet table @天赋信息
  5. ---@field talentPoint number @天赋点信息
  6. ---@field canBreakthrough table @可突破的装备
  7. ---@field isInitBreakthrough boolean
  8. ---@field isMasterRed boolean @天赋大师红点
  9. ---@field archangeGrailInfo table @装备圣杯信息
  10. ---@field canGrailStrength table @可升级的圣杯
  11. ArchangeEquipInfo = class()
  12. local this = ArchangeEquipInfo
  13. function this:Init()
  14. --self.archangeEquip = {}
  15. self:RegistMessages()
  16. self:Reset()
  17. end
  18. function this:Reset()
  19. self.archangeGrailInfo = {}
  20. self.archangeInfo = {}
  21. if self.masterActionSchedule then
  22. SL:UnSchedule(self.masterActionSchedule)
  23. self.masterActionSchedule = nil
  24. end
  25. if self.timer then
  26. SL:UnSchedule(self.timer)
  27. self.timer = nil
  28. end
  29. self.talentPoint = 0
  30. self.angelTalenet = {}
  31. self.allGrailInfo = {}
  32. self.angelSuitAction = {}
  33. self.canBreakthrough = {}
  34. self.canGrailStrength = {}
  35. self.grailSuitList = {}
  36. self.canBtCount = {}
  37. self.isMasterRed = false
  38. self.isTalent = false
  39. self.isInitBreakthrough = false
  40. end
  41. function this:RegistMessages()
  42. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_ANGEL_EQUIPMENT_ATTR_INFO, self.RES_ALL_ANGEL_EQUIPMENT_ATTR_INFO, self) -- 响应所有天使装备成长属性信息
  43. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ANGEL_TALENT_ACTIVE_INFO, self.RES_ANGEL_TALENT_ACTIVE_INFO, self)-- 响应天赋大师激活的id
  44. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ANGEL_EQUIPMENT_CAN_BREAK, self.RES_ANGEL_EQUIPMENT_CAN_BREAK, self)-- 响应天使装备可以突破
  45. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ANGEL_EQUIPMENT_ATTR_INFO, self.RES_ANGEL_EQUIPMENT_ATTR_INFO, self)-- 响应天使装备成长属性信息
  46. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_DESTROY_ANGEL_EQUIPMENT, self.RES_DESTROY_ANGEL_EQUIPMENT, self) -- 响应天使装备删除
  47. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, self.RES_ANGEL_TALENT_INFO, self)
  48. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_GRAIL_INFO, self.RES_ALL_GRAIL_INFO, self)
  49. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GRAIL_ENTRY_INFO, self.RES_GRAIL_ENTRY_INFO, self)
  50. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ANGEL_EQUIP_EXP_BOOST_INFO, self.RES_ANGEL_EQUIP_EXP_BOOST_INFO, self)
  51. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_EQUIP_OPT_ENTRY_INFO, self.RES_EQUIP_OPT_ENTRY_INFO, self)
  52. SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER, self.LUA_EVENT_BAG_CHANGE_AFTER, self)
  53. SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.LUA_EVENT_BAG_CHANGE_AFTER, self)
  54. SL:RegisterLUAEvent(LUA_EVENT_ENTER_MAP, self.LoginReq, self)
  55. end
  56. -- 响应所有天使装备信息
  57. function this:RES_ALL_ANGEL_EQUIPMENT_ATTR_INFO(_, message)
  58. if message then
  59. if self.isInitBreakthrough then
  60. local messagePanel = GUI:GetUI("dev/outui/Message/Panel/KLHorseRaceLamp/KLHorseRaceLampPanel")
  61. if messagePanel then
  62. for i, v in pairs(message) do
  63. if v.level ~= self.archangeInfo[tonumber(i)].level then
  64. local equip = SL:GetWearEquipByItemId(tonumber(i))
  65. if equip then
  66. local itemTbl = SL:GetConfig("cfg_item", equip.cfgId, "id")
  67. local color = SL:GetConfig("cfg_color", itemTbl.color, "id").color
  68. local text = "<color=\"" .. color .. "\">" .. tostring(itemTbl.name) .. "</color>"
  69. messagePanel:AddArchangelExp(v.level, text)
  70. end
  71. end
  72. end
  73. end
  74. end
  75. for i, v in pairs(message) do
  76. self.archangeInfo[tonumber(i)] = { level = v.level, rank = v.rank, exp = v.exp }
  77. self.archangeGrailInfo[tonumber(i)] = v.grails
  78. end
  79. if self.isInitBreakthrough == false then
  80. self.isInitBreakthrough = true
  81. local equip = SL:GetWearBarsData(9)
  82. for i, v in pairs(equip) do
  83. self:CanBreakthrough(v.id, v.cfgId)
  84. end
  85. if table.count(self.canBreakthrough) > 0 then
  86. SL:RefreshPanelALLRedPoint("KLUISystemLeftPanel")
  87. end
  88. end
  89. --self:RefreshGrailSuitInfo()
  90. --if self.masterActionSchedule then
  91. -- SL:UnSchedule(self.masterActionSchedule)
  92. --end
  93. --self.masterActionSchedule = SL:ScheduleOnce(0.1, function()
  94. -- self.isMasterRed = self:CanMasterAction()
  95. -- if self.isMasterRed then
  96. -- SL:RefreshPanelALLRedPoint("KLUISystemLeftPanel")
  97. -- end
  98. --end)
  99. end
  100. end
  101. -- 响应天赋大师激活的id
  102. function this:RES_ANGEL_TALENT_ACTIVE_INFO(_, message)
  103. if message then
  104. for i, v in pairs(message) do
  105. table.insert(self.angelSuitAction, v)
  106. end
  107. end
  108. SL:onLUAEvent(LUA_ANGEL_TALENT_ACTIVE, self.angelSuitAction)
  109. end
  110. -- 响应天使装备可以突破
  111. function this:RES_ANGEL_EQUIPMENT_CAN_BREAK(_, message)
  112. --SL:onLUAEvent(LUA_ANGEL_EQUIPMENT_CAN_BREAK)
  113. self:CanBreakthrough(message)
  114. SL:RefreshPanelALLRedPoint("KLUISystemLeftPanel")
  115. end
  116. -- 响应天使装备成长属性信息
  117. function this:RES_ANGEL_EQUIPMENT_ATTR_INFO(_, message)
  118. if message then
  119. for i, v in pairs(message) do
  120. self.archangeInfo[tonumber(i)] = v
  121. end
  122. end
  123. end
  124. function this:RES_DESTROY_ANGEL_EQUIPMENT(_, message)
  125. if message then
  126. self.archangeInfo[tonumber(message)] = nil
  127. end
  128. end
  129. function this:RES_ANGEL_TALENT_INFO(_, message)
  130. if message then
  131. self.talentPoint = message.talentPoint
  132. self.angelTalenet = message.talentInfo
  133. end
  134. self.isTalent = self:CanAddTalent()
  135. if self.isTalent then
  136. SL:RefreshPanelALLRedPoint("KLUISystemLeftPanel")
  137. end
  138. end
  139. ---刷新圣杯套装 无参初始化
  140. ---@param cfgId number @变化圣杯道具id
  141. ---@param isPutOn boolean @nil 卸下
  142. function this:RefreshGrailSuitInfo(cfgId, isPutOn)
  143. if not self.grailSuitList then
  144. self.grailSuitList = {}
  145. end
  146. if cfgId then
  147. ---@type cfg_equip_angelGrail_column
  148. local tbl = SL:GetConfig("cfg_equip_angelGrail", cfgId)
  149. if not self.grailSuitList[tbl.grailGrade] then
  150. self.grailSuitList[tbl.grailGrade] = {}
  151. end
  152. if not self.grailSuitList[tbl.grailGrade][tbl.grailQuality] then
  153. self.grailSuitList[tbl.grailGrade][tbl.grailQuality] = 0
  154. end
  155. if isPutOn then
  156. self.grailSuitList[tbl.grailGrade][tbl.grailQuality] = self.grailSuitList[tbl.grailGrade][tbl.grailQuality] + 1
  157. else
  158. self.grailSuitList[tbl.grailGrade][tbl.grailQuality] = self.grailSuitList[tbl.grailGrade][tbl.grailQuality] - 1
  159. end
  160. else
  161. self.grailSuitList = {}
  162. self.grailQualityCount = 4
  163. for _, v in pairs(self.allGrailInfo) do
  164. --for _, k in pairs(v) do
  165. if v.active then
  166. ---@type cfg_equip_angelGrail_column
  167. local tbl = SL:GetConfig("cfg_equip_angelGrail", v.itemConfigId)
  168. if not self.grailSuitList[tbl.grailGrade] then
  169. self.grailSuitList[tbl.grailGrade] = {}
  170. end
  171. if not self.grailSuitList[tbl.grailGrade][tbl.grailQuality] then
  172. self.grailSuitList[tbl.grailGrade][tbl.grailQuality] = 0
  173. end
  174. self.grailSuitList[tbl.grailGrade][tbl.grailQuality] = self.grailSuitList[tbl.grailGrade][tbl.grailQuality] + 1
  175. end
  176. --end
  177. end
  178. end
  179. end
  180. ---刷新总圣杯属性
  181. ---@param info table @镶嵌卸下时发生变化的圣杯属性,缺省刷新全部
  182. ---@param isAdd boolean @true 镶嵌, false 卸下
  183. function this:RefreshAllGrailAttrInfo()
  184. local grailAllAttrList = {}
  185. for _, info in pairs(self.allGrailInfo) do
  186. if info.active then
  187. for _, v in pairs(info.main) do
  188. if not grailAllAttrList[v.attrId] then
  189. grailAllAttrList[v.attrId] = 0
  190. end
  191. grailAllAttrList[v.attrId] = grailAllAttrList[v.attrId] + v.value
  192. end
  193. for _, k in pairs(info.secondary) do
  194. for _, v in pairs(k) do
  195. if not grailAllAttrList[v.attrId] then
  196. grailAllAttrList[v.attrId] = 0
  197. end
  198. grailAllAttrList[v.attrId] = grailAllAttrList[v.attrId] + v.value
  199. end
  200. end
  201. end
  202. end
  203. return grailAllAttrList
  204. end
  205. function this:GetGrailGroupInfo(group)
  206. if self.grailSuitList then
  207. return self.grailSuitList[group]
  208. end
  209. end
  210. function this:GetGrailSuitCount(group, level)
  211. local count = 0
  212. if self.grailSuitList[group] then
  213. for i = 1, self.grailQualityCount do
  214. if self.grailSuitList[group][i] then
  215. if level <= i then
  216. count = count + self.grailSuitList[group][i]
  217. end
  218. end
  219. end
  220. end
  221. return count
  222. end
  223. --- 获取装备的等级信息
  224. ---@param itemId number @装备的唯一ID
  225. ---@return table <string,number> @level = 等级, exp = 经验, rank=等阶
  226. function this:GetEquipLevelInfo(itemId)
  227. if self.archangeInfo and self.archangeInfo[itemId] then
  228. return {
  229. level = self.archangeInfo[itemId].level,
  230. exp = self.archangeInfo[itemId].exp,
  231. rank = self.archangeInfo[itemId].rank,
  232. }
  233. end
  234. return nil
  235. end
  236. --- 获取 全身大天使装备的总等级
  237. ---@return number
  238. function this:GetEquipTotalLevel()
  239. local total = 0
  240. local equip = SL:GetWearBarsData(9)
  241. for i, v in pairs(equip) do
  242. local level = self:GetEquipLevelInfo(v.id).level
  243. total = total + level
  244. end
  245. return total
  246. end
  247. ---根据当前等阶获取等级上限
  248. ---@param rank number @当前等阶
  249. ---@param itemCfgId number @item配置表id
  250. ---@return number @等级上限
  251. function this:GetMaxLevel(rank, itemCfgId)
  252. ---@type cfg_equip_angelAtt_column[]
  253. local tbl = SL:FindConfigs("cfg_equip_angelAtt", "angelGrade", rank)
  254. if tbl ~= nil and table.count(tbl) > 0 then
  255. return tbl[1].angelMaxLv
  256. end
  257. return 0
  258. end
  259. ---根据当前配置id获取等阶上限
  260. ---@param itemCfgId number @item配置表id
  261. ---@return number @等阶
  262. function this:GetMaxRank(itemCfgId)
  263. ---该装备所在的组
  264. local group = SL:GetConfig("cfg_equip_angelGroup", itemCfgId, "id").angelEquipGroup
  265. local basicAttTbl = SL:FindConfigs("cfg_equip_angelAtt", "ornamentsGroup", group)
  266. table.sort(basicAttTbl, function(a, b)
  267. return a.lv > b.lv
  268. end)
  269. return basicAttTbl[1].angelGrade
  270. end
  271. ---判断大师天赋是否已激活
  272. ---@param cfgId number @表id
  273. function this:IsMasterAction(cfgId)
  274. if self.angelSuitAction then
  275. return table.contains(self.angelSuitAction, cfgId)
  276. end
  277. return false
  278. end
  279. ---获取某件装备的满级属性
  280. ---@param cfgId number @表id
  281. ---@return table,number @满级属性,满级时的等级
  282. function this:GetMaxAtt(cfgId)
  283. ---该装备所在的组
  284. local group = SL:GetConfig("cfg_equip_angelGroup", cfgId, "id").angelEquipGroup
  285. local basicAttTbl = SL:FindConfigs("cfg_equip_angelAtt", "ornamentsGroup", group)
  286. table.sort(basicAttTbl, function(a, b)
  287. return a.lv > b.lv
  288. end)
  289. return basicAttTbl[1].basicAtt, basicAttTbl[1].lv
  290. end
  291. ---是否拥有大天使装备
  292. ---@param itemId number @装备的唯一ID
  293. function this:IsHaveArchangeEquip(itemId)
  294. if itemId and self.archangeInfo and self.archangeInfo[itemId] then
  295. return true
  296. end
  297. return false
  298. end
  299. --- 是否可以突破
  300. --- @param itemId number @装备的唯一ID
  301. --- @param cfgId number @装备配置id
  302. --- @return boolean
  303. function this:CanBreakthrough(itemId, cfgId)
  304. local info = self:GetEquipLevelInfo(itemId)
  305. if not itemId then
  306. return false
  307. end
  308. if not cfgId then
  309. local equip = SL:GetWearEquipByItemId(itemId)
  310. if not equip then
  311. return false
  312. end
  313. cfgId = equip.cfgId
  314. end
  315. if not info then
  316. return false
  317. end
  318. local level = info.level -- 装备当前等级
  319. local rank = info.rank -- 装备当前阶数
  320. local maxLv = self:GetMaxLevel(rank, cfgId) -- 装备当前阶数最大等级
  321. local maxRank = self:GetMaxRank(cfgId)
  322. if level == maxLv and rank ~= maxRank then
  323. local group = SL:GetConfig("cfg_equip_angelGroup", cfgId, "id").angelEquipGroup
  324. ---@type cfg_equip_angelAtt_column
  325. local tbl = SL:GetConfigTwoKeys("cfg_equip_angelAtt", info.level, group, "lv", "ornamentsGroup")
  326. for _, cost in pairs(tbl.breakMaterial) do
  327. if SL:GetBagItemCount(cost[1]) < cost[2] then
  328. if not table.contains(self.canBtCount, itemId) then
  329. table.insert(self.canBtCount, itemId)
  330. end
  331. if table.contains(self.canBreakthrough, itemId) then
  332. table.removeByValue(self.canBreakthrough, itemId)
  333. end
  334. return false
  335. end
  336. end
  337. if table.contains(self.canBtCount, itemId) then
  338. table.removeByValue(self.canBtCount, itemId)
  339. end
  340. if not table.contains(self.canBreakthrough, itemId) then
  341. table.insert(self.canBreakthrough, itemId)
  342. end
  343. return true
  344. end
  345. return false
  346. end
  347. --- 获取可以加点的天赋
  348. function this:CanAddTalent()
  349. InfoManager.masterTalentInfo.RedDataList[EMasterTalentType.Archange] = false
  350. if self.talentPoint <= 0 then
  351. return false
  352. end
  353. local careerid = SL:GetConfig("cfg_career", SL:GetMetaValue(EMetaVarGetKey.ME_CAREER_TAB_COLUMN).id, "id").baseCareer
  354. ---@type cfg_equip_angelTalentGroup_column[]
  355. local talentTypeList = SL:FindConfigs("cfg_equip_angelTalentGroup", "Career", careerid)
  356. local talentNum = {}
  357. for i, v in pairs(self.angelTalenet) do
  358. talentNum[i] = 0
  359. for _, talenet in pairs(v) do
  360. talentNum[i] = talenet + talentNum[i]
  361. end
  362. end
  363. ---遍历页签
  364. for i, v in pairs(talentTypeList) do
  365. ---@type cfg_equip_angelTalent_column[]
  366. local talentList = SL:FindConfigs("cfg_equip_angelTalent", "talentGroup", v.talentGroup)
  367. for _, talent in pairs(talentList) do
  368. if self.angelTalenet[v.talentGroup] and self.angelTalenet[v.talentGroup][talent.id] then
  369. --- 该天赋已加点
  370. if self.angelTalenet[v.talentGroup][talent.id] < talent.talentMaxLv then
  371. --- 未达最大等级
  372. --红点
  373. InfoManager.masterTalentInfo.RedDataList[EMasterTalentType.Archange] = true
  374. return true
  375. end
  376. else
  377. local num = talentNum[tostring(i)] and talentNum[tostring(i)] or 0
  378. if num >= talent.talentRequest then
  379. --红点
  380. InfoManager.masterTalentInfo.RedDataList[EMasterTalentType.Archange] = true
  381. return true
  382. end
  383. end
  384. end
  385. end
  386. return false
  387. end
  388. --- 是否有可激活的大天使大师天赋
  389. function this:CanMasterAction()
  390. if table.count(self.archangeInfo) == 0 then
  391. return false
  392. end
  393. local career = SL:GetMetaValue(EMetaVarGetKey.ME_CAREER_TAB_COLUMN)
  394. local equip = SL:GetWearBarsData(9)
  395. ---@type table @<组,装备等级[]>
  396. local equipGroup = {}
  397. for i, equipInfo in pairs(equip) do
  398. local suit = SL:GetConfig("cfg_equip_angelGroup", equipInfo.cfgId, "id").angelEquipSuit
  399. if not equipGroup[suit] then
  400. equipGroup[suit] = {}
  401. end
  402. table.insert(equipGroup[suit], InfoManager.archangeEquipInfo:GetEquipLevelInfo(equipInfo.id).level)
  403. end
  404. --- 给同组的排序
  405. for _, equipGroupInfo in pairs(equipGroup) do
  406. table.sort(equipGroupInfo)
  407. end
  408. ---@type cfg_equip_angelSuit_column[]
  409. local data = SL:FindConfigs("cfg_equip_angelSuit", "type", 2)
  410. for _, v in pairs(data) do
  411. local cfgId = v.id
  412. local actionCount = 0
  413. if v.career == career.baseCareer and not self:IsMasterAction(v.id) then
  414. ---@type cfg_equip_angelSuit_column
  415. local tbl = SL:GetConfig("cfg_equip_angelSuit", cfgId, "id")
  416. local angelLv = table.copy(tbl.angelLv)
  417. --- 循环判断条件
  418. for i, lvInfo in pairs(angelLv) do
  419. if equipGroup[lvInfo[1]] then
  420. --- 找到改组中符合条件的最小的移除
  421. --- 同时符合条件的件数+1
  422. local count = 0
  423. local num = 1
  424. local isEnough = false
  425. while num <= #equipGroup[lvInfo[1]] do
  426. if equipGroup[lvInfo[1]][num] >= lvInfo[3] then
  427. table.remove(equipGroup[lvInfo[1]], num)
  428. actionCount = actionCount + 1
  429. count = count + 1
  430. if count == lvInfo[2] then
  431. isEnough = true
  432. break
  433. end
  434. else
  435. num = num + 1
  436. end
  437. end
  438. if not isEnough then
  439. break
  440. end
  441. end
  442. end
  443. if actionCount == v.wearingCount then
  444. self.isMasterRed = true
  445. return
  446. end
  447. end
  448. end
  449. self.isMasterRed = false
  450. end
  451. function this:LoginReq()
  452. if self.timer then
  453. SL:UnSchedule(self.timer)
  454. self.timer = nil
  455. end
  456. self.timer = SL:ScheduleOnce(2, function()
  457. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_REMAINING_ANGE_GRAIL_INFO)
  458. end)
  459. end
  460. function this:LUA_EVENT_BAG_CHANGE_AFTER(_, message)
  461. self:CanStrengthGrail()
  462. if table.count(self.canBtCount) == 0 then
  463. return
  464. end
  465. local equips = SL:GetWearBarsData(9)
  466. for i, v in pairs(equips) do
  467. self:CanBreakthrough(v.id, v.cfgId)
  468. end
  469. end
  470. ------------------------------------圣杯----------------------------------------
  471. ---
  472. function this:RES_ALL_GRAIL_INFO(_, message)
  473. for i, v in pairs(message) do
  474. self.allGrailInfo[tonumber(i)] = v
  475. end
  476. self:CanStrengthGrail()
  477. self:RefreshGrailSuitInfo()
  478. end
  479. function this:RES_GRAIL_ENTRY_INFO(_, message)
  480. for i, v in pairs(message) do
  481. self.allGrailInfo[tonumber(i)] = v
  482. end
  483. SL:onLUAEvent(LUA_EVENT_GRAIL_INFO_CHANGE)
  484. end
  485. function this:RES_EQUIP_OPT_ENTRY_INFO(_, message)
  486. if message then
  487. for i, v in pairs(message.res) do
  488. self:RefreshGrailSuitInfo(v.itemConfigId, message.opt == 1)
  489. self.allGrailInfo[tonumber(i)] = v.attrInfo
  490. end
  491. end
  492. end
  493. ---改变装备上的圣杯
  494. ---@param equipId number @装备唯一id
  495. ---@param grailPos number @圣杯位置
  496. ---@param grailCfgId number @圣杯配置id
  497. ---@param grailId number @圣杯唯一id 缺省则为卸下
  498. function this:GrailChange(equipId, grailPos, grailCfgId, grailId)
  499. if self.archangeGrailInfo[equipId] then
  500. local index = -1
  501. for i, v in pairs(self.archangeGrailInfo[equipId]) do
  502. if v.grailPosition == grailPos then
  503. index = i
  504. self:GrailInfoChange(tonumber(i))
  505. break
  506. end
  507. end
  508. ---刷新圣杯套装
  509. local cfgId
  510. if not grailCfgId then
  511. cfgId = self.archangeGrailInfo[equipId][index].itemConfigId
  512. else
  513. cfgId = grailCfgId
  514. end
  515. self:RefreshGrailSuitInfo(cfgId, grailId)
  516. self.archangeGrailInfo[equipId][index] = nil
  517. if grailId then
  518. self.archangeGrailInfo[equipId][grailId] = { grailPosition = grailPos, itemConfigId = grailCfgId }
  519. end
  520. else
  521. if grailId then
  522. self.archangeGrailInfo[equipId] = {}
  523. self.archangeGrailInfo[equipId][grailId] = { grailPosition = grailPos, itemConfigId = grailCfgId }
  524. self:RefreshGrailSuitInfo(grailCfgId, grailId)
  525. end
  526. end
  527. self:CanStrengthGrail()
  528. end
  529. ---进入背包和从背包种移除,移除存储中的圣杯(后端唯一id会变,导致内存泄露)
  530. ---@param grailId number @圣杯唯一id
  531. function this:GrailInfoChange(grailId, data)
  532. if self.allGrailInfo[grailId] and not data then
  533. self.allGrailInfo[grailId] = nil
  534. elseif self.allGrailInfo[grailId] and data then
  535. self.allGrailInfo[grailId] = data.attrInfo
  536. end
  537. end
  538. ---获取大天使装备上的圣杯
  539. ---@param itemId @装备的唯一ID
  540. function this:GetEquipGrail(itemId)
  541. if not itemId or not self.archangeGrailInfo[itemId] then
  542. return {}
  543. end
  544. return self.archangeGrailInfo[itemId]
  545. end
  546. ---获取圣杯的信息
  547. ---@param itemId number @装备唯一id
  548. function this:GetGrailInfo(itemId)
  549. if itemId then
  550. if self.allGrailInfo[itemId] then
  551. return self.allGrailInfo[itemId]
  552. end
  553. end
  554. return nil
  555. end
  556. function this:GetGrailStrengthLv(grailId)
  557. local info = self:GetGrailInfo(grailId)
  558. if info then
  559. return info.level
  560. end
  561. return 0
  562. end
  563. function this:GetGrailMaxStrengthLv(cfgId)
  564. local strengthenTbl = SL:GetConfig("cfg_equip_angelStrengthen", cfgId, "id")
  565. if not strengthenTbl then
  566. return nil
  567. end
  568. local strengthenInfo = SL:GetConfigTwoKeys("cfg_equip_angelStrengthenCost", strengthenTbl.costGroup, 0, "AngelstrengthenGroup", "AngelstrengthenSuccessRate")
  569. if not strengthenInfo then
  570. return nil
  571. end
  572. return strengthenInfo.AngelstrengthenLv
  573. end
  574. function this:CanStrengthGrail()
  575. for i, v in pairs(self.archangeGrailInfo) do
  576. if #v == 0 and self.canGrailStrength[i] then
  577. self.canGrailStrength[i] = nil
  578. end
  579. for grailId, grailInfo in pairs(v) do
  580. local info = self:GetGrailInfo(tonumber(grailId))
  581. if info and info.level < self:GetGrailMaxStrengthLv(grailInfo.itemConfigId) and not self:IsGrailEntryMax(info) then
  582. local strengthenTbl = SL:GetConfig("cfg_equip_angelStrengthen", grailInfo.itemConfigId, "id")
  583. local costTbl = SL:GetConfigTwoKeys("cfg_equip_angelStrengthenCost", strengthenTbl.costGroup, info.level, "AngelstrengthenGroup", "AngelstrengthenLv")
  584. local isEnough = true
  585. for _, cost in pairs(costTbl.Angelstrengthencost) do
  586. if SL:GetBagItemCount(cost[1]) < cost[2] then
  587. isEnough = false
  588. break
  589. end
  590. end
  591. if isEnough then
  592. -- 足够
  593. if not self.canGrailStrength[i] then
  594. self.canGrailStrength[i] = {}
  595. end
  596. table.insert(self.canGrailStrength[i], grailInfo.grailPosition)
  597. else
  598. if self.canGrailStrength[i] then
  599. table.removeByValue(self.canGrailStrength[i], grailInfo.grailPosition)
  600. if table.count(self.canGrailStrength[i]) == 0 then
  601. self.canGrailStrength[i] = nil
  602. end
  603. end
  604. end
  605. end
  606. end
  607. end
  608. if table.count(self.canGrailStrength) > 0 then
  609. --- 刷新红点
  610. SL:RefreshPanelALLRedPoint("KLUISystemLeftPanel")
  611. end
  612. end
  613. function this:IsGrailEntryMax(grailInfo)
  614. for i, v in pairs(grailInfo.main) do
  615. if v.isMax == false then
  616. return false
  617. end
  618. end
  619. for i, v in pairs(grailInfo.secondary) do
  620. for _, j in pairs(v) do
  621. if j.isMax == false then
  622. return false
  623. end
  624. end
  625. end
  626. return true
  627. end
  628. function this:CanEquipHaveStrengthenGrail(itemId)
  629. if self.canGrailStrength[itemId] then
  630. return true
  631. else
  632. return false
  633. end
  634. end
  635. function this:CanEquipHaveGrail(itemId)
  636. if table.contains(self.equipRed, itemId) then
  637. return true
  638. else
  639. return false
  640. end
  641. end
  642. function this:CheckEquipRed()
  643. self.equipRed = {}
  644. local info = SL:GetWearBarsData(EEquipWearBarType.Archange)
  645. for i, v in pairs(info) do
  646. local item = v
  647. local id = v.id
  648. --- 判断空的孔
  649. local equipInfo = self:GetEquipLevelInfo(id)
  650. local hole, max = self:GetHole(equipInfo.rank, item.cfgId)
  651. for num = 1, hole do
  652. local isHave = false
  653. if self.archangeGrailInfo[id] then
  654. for _, j in pairs(self.archangeGrailInfo[id]) do
  655. if j.grailPosition == num then
  656. isHave = true
  657. break
  658. end
  659. end
  660. end
  661. if not isHave then
  662. local bagTbl = self:GetBagItem(num, i)
  663. if #bagTbl > 0 then
  664. table.insert(self.equipRed, id)
  665. end
  666. end
  667. end
  668. end
  669. end
  670. --- 筛选背包物品
  671. function this:GetBagItem(holeIndex, pos)
  672. local data = {}
  673. local bagItemTabl = SL:GetMetaValue("BAG_DATA")[1]
  674. if bagItemTabl then
  675. for _, v in pairs(bagItemTabl) do
  676. local tbl = nil
  677. if SL:HasConfig("cfg_equip_angelGrail", v.cfgId, "id") then
  678. tbl = SL:GetConfig("cfg_equip_angelGrail", v.cfgId, "id")
  679. end
  680. if pos then
  681. if tbl and table.contains(tbl.gradePosition, holeIndex) and table.contains(tbl.strPart, pos) then
  682. table.insert(data, v)
  683. end
  684. else
  685. if tbl and table.contains(tbl.gradePosition, holeIndex) then
  686. table.insert(data, v)
  687. end
  688. end
  689. end
  690. end
  691. return data
  692. end
  693. ---@return number,number 解锁的孔位,总孔位
  694. function this:GetHole(rank, cfgId)
  695. if not cfgId then
  696. return 0, 0
  697. end
  698. ---@type cfg_equip_angelGroup_column
  699. local tbl = SL:GetConfig("cfg_equip_angelGroup", cfgId, "id")
  700. if not rank or rank == 0 then
  701. return 0, table.count(tbl.grailOpen)
  702. end
  703. local grailOpen = table.copy(tbl.grailOpen)
  704. table.sort(grailOpen, function(a, b)
  705. return a[1] < b[1]
  706. end)
  707. --local rankIndex = 1
  708. for i, v in pairs(grailOpen) do
  709. if v[1] > rank then
  710. return grailOpen[i - 1][2], table.count(grailOpen)
  711. end
  712. if v[1] == rank then
  713. return grailOpen[i][2], table.count(grailOpen)
  714. end
  715. end
  716. return 0, table.count(grailOpen)
  717. end
  718. ----------------------buff----------------
  719. -- 响应经验加成buff
  720. function this:RES_ANGEL_EQUIP_EXP_BOOST_INFO(_, message)
  721. local data
  722. if message then
  723. for i, v in pairs(message) do
  724. local fuffData
  725. if table.isNullOrEmpty(v) then
  726. local myId = SL:GetMetaValue("MAIN_ACTOR_ID")
  727. local buff_id = tonumber(i)
  728. local bufftbl = SL:GetConfig("cfg_buff", buff_id)
  729. local _buffText = bufftbl.buffText
  730. local time = -1
  731. fuffData = { updateType = 1, buff = { buffTbl = bufftbl, cfgId = buff_id, endTime = time, buffText = _buffText }, roleId = myId }
  732. else
  733. local myId = SL:GetMetaValue("MAIN_ACTOR_ID")
  734. local buff_id = tonumber(i)
  735. local bufftbl = SL:GetConfig("cfg_buff", buff_id)
  736. local _buffText = bufftbl.buffText
  737. local time = v.delayTime
  738. fuffData = { updateType = 0, buff = { buffTbl = bufftbl, cfgId = buff_id, endTime = time, buffText = _buffText }, roleId = myId }
  739. end
  740. SL:onLUAEvent(LUA_EVENT_BUFFCHANHE, fuffData)
  741. end
  742. end
  743. end
  744. function this:SetOtherGrailInfo(grailInfo)
  745. for i, v in pairs(grailInfo) do
  746. self:RefreshOtherAllGrailAttrInfo(v)
  747. end
  748. self:RefreshOtherGrailSuitInfo(grailInfo)
  749. end
  750. ---刷新总圣杯属性
  751. ---@param info table @镶嵌卸下时发生变化的圣杯属性,缺省刷新全部
  752. ---@param isAdd boolean @true 镶嵌, false 卸下
  753. function this:RefreshOtherAllGrailAttrInfo(info, isAdd)
  754. if not self.otherGrailAllAttrList then
  755. self.otherGrailAllAttrList = {}
  756. end
  757. if not info.inlaid then
  758. ---未穿戴返回
  759. return
  760. end
  761. for _, v in pairs(info.main) do
  762. if not self.otherGrailAllAttrList[v.attrId] then
  763. self.otherGrailAllAttrList[v.attrId] = 0
  764. end
  765. self.otherGrailAllAttrList[v.attrId] = self.otherGrailAllAttrList[v.attrId] + v.value
  766. end
  767. for _, k in pairs(info.secondary) do
  768. for _, v in pairs(k) do
  769. if not self.otherGrailAllAttrList[v.attrId] then
  770. self.otherGrailAllAttrList[v.attrId] = 0
  771. end
  772. self.otherGrailAllAttrList[v.attrId] = self.otherGrailAllAttrList[v.attrId] + v.value
  773. end
  774. end
  775. end
  776. ---刷新圣杯套装 无参初始化
  777. ---@param cfgId number @变化圣杯道具id
  778. ---@param isPutOn boolean @nil 卸下
  779. function this:RefreshOtherGrailSuitInfo(grailInfo)
  780. self.otherGrailSuitList = {}
  781. for _, v in pairs(grailInfo) do
  782. ---@type cfg_equip_angelGrail_column
  783. local tbl = SL:GetConfig("cfg_equip_angelGrail", v.itemConfigId)
  784. if not self.otherGrailSuitList[tbl.grailGrade] then
  785. self.otherGrailSuitList[tbl.grailGrade] = {}
  786. end
  787. if not self.otherGrailSuitList[tbl.grailGrade][tbl.grailQuality] then
  788. self.otherGrailSuitList[tbl.grailGrade][tbl.grailQuality] = 0
  789. end
  790. self.otherGrailSuitList[tbl.grailGrade][tbl.grailQuality] = self.otherGrailSuitList[tbl.grailGrade][tbl.grailQuality] + 1
  791. end
  792. end
  793. function this:GetOtherGrailSuitCount(group, level)
  794. local count = 0
  795. if self.otherGrailSuitList[group] then
  796. for i = 1, self.grailQualityCount do
  797. if self.otherGrailSuitList[group][i] then
  798. if level <= i then
  799. count = count + self.otherGrailSuitList[group][i]
  800. end
  801. end
  802. end
  803. end
  804. return count
  805. end
  806. function this:ResetOtherInfo()
  807. self.otherGrailSuitList = {}
  808. self.otherGrailAllAttrList = {}
  809. end