UIEquipJewelryInfo.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ---@class UIEquipJewelryInfo
  2. UIEquipJewelryInfo = class()
  3. local this = UIEquipJewelryInfo
  4. function this:ctor()
  5. end
  6. function this:Reset()
  7. --[[ if self.coHide1 ~= nil then
  8. Coroutine.Stop(self.coHide1)
  9. end
  10. if self.coHide2 ~= nil then
  11. Coroutine.Stop(self.coHide2)
  12. end]]
  13. end
  14. function this:Init()
  15. self:InitData()
  16. self:RegistMessages()
  17. self.OutEquipData = {}
  18. self.OrnamentsGroupList = {}
  19. local ornamentsTbl = SL:GetConfigTable('cfg_equip_ornaments')
  20. for _, v in pairs(ornamentsTbl) do
  21. if not self.OrnamentsGroupList[v.ornamentsGroup] then
  22. self.OrnamentsGroupList[v.ornamentsGroup] = {}
  23. end
  24. table.insert(self.OrnamentsGroupList[v.ornamentsGroup], v)
  25. end
  26. end
  27. function this:InitData()
  28. end
  29. function this:RegistMessages()
  30. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_UPDATE_EQUIP_ORNAMENTS, self.RES_UPDATE_EQUIP_ORNAMENTS, self)
  31. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, self.RES_ACT_EQUIP_ORNAMENTS, self)
  32. SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER, self.LUA_EVENT_BAG_CHANGE_AFTER, self)
  33. end
  34. function this:LUA_EVENT_BAG_CHANGE_AFTER(_, itemList)
  35. if itemList then
  36. SL:RefreshPanelALLRedPoint("KLEquipJewelryActivePanel")
  37. SL:RefreshPanelALLRedPoint("KLEquipJewelryPanel")
  38. end
  39. end
  40. ---@param message RES_UPDATE_EQUIP_ORNAMENTS
  41. function this:RES_ACT_EQUIP_ORNAMENTS(_, message)
  42. if message then
  43. SL:RefreshPanelALLRedPoint("KLEquipJewelryActivePanel")
  44. end
  45. end
  46. ---@param message RES_UPDATE_EQUIP_ORNAMENTS
  47. function this:RES_UPDATE_EQUIP_ORNAMENTS(_, message)
  48. if message then
  49. SL:RefreshPanelALLRedPoint("KLEquipJewelryPanel")
  50. end
  51. end
  52. function this:IsShowLevelRedDot()
  53. local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  54. if not equipAll or not next(equipAll) or not equipAll[1] or not next(equipAll[1]) then
  55. return false
  56. end
  57. for i, v in pairs(equipAll[1]) do
  58. for _, j in pairs(E_JewelryEquipType) do
  59. if i == j then
  60. ---@type RES_UPDATE_EQUIP_ORNAMENTS
  61. self.OutEquipData = SL:JsonDecode(v.luaExtData,false)
  62. local preLevel = 0
  63. if self.OutEquipData ~= nil and self.OutEquipData.ssuplv then
  64. preLevel = self.OutEquipData.ssuplv --当前首饰等级
  65. end
  66. local PreOrnament_Tbl, NextOrnament_Tbl = self:GetJewelryTblInfoByLevel(v.cfgId, preLevel)
  67. if NextOrnament_Tbl then
  68. --没升满 判断材料是否足够
  69. if next(PreOrnament_Tbl.lvDeplete) then
  70. for _, attrValue in pairs(PreOrnament_Tbl.lvDeplete) do
  71. local haveCount = SL:GetBagItemCount(tonumber(attrValue[1]))
  72. local needCount = tonumber(attrValue[2])
  73. if haveCount >= needCount then
  74. return true
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end
  81. end
  82. return false
  83. end
  84. ---首饰是否可升级
  85. function this:IsJewelryCanUpLevel(v)
  86. if not v then
  87. return false
  88. end
  89. ---@type RES_UPDATE_EQUIP_ORNAMENTS
  90. local outEquipData = SL:JsonDecode(v.luaExtData,false)
  91. local preLevel = 0
  92. if outEquipData and outEquipData.ssuplv then
  93. preLevel = outEquipData.ssuplv --当前首饰等级
  94. end
  95. local PreOrnament_Tbl, NextOrnament_Tbl = self:GetJewelryTblInfoByLevel(v.cfgId, preLevel)
  96. if NextOrnament_Tbl then
  97. --没升满 判断材料是否足够
  98. if next(PreOrnament_Tbl.lvDeplete) then
  99. for _, attrValue in pairs(PreOrnament_Tbl.lvDeplete) do
  100. local haveCount = SL:GetBagItemCount(tonumber(attrValue[1]))
  101. local needCount = tonumber(attrValue[2])
  102. if haveCount >= needCount then
  103. return true
  104. end
  105. end
  106. end
  107. end
  108. return false
  109. end
  110. ---首饰是否可激活
  111. function this:IsJewelryCanActive(v)
  112. if not v then
  113. return false
  114. end
  115. ---@type RES_UPDATE_EQUIP_ORNAMENTS
  116. local outEquipData = SL:JsonDecode(v.luaExtData,false)
  117. local OrnamentsGroup = self:GetOrnamentsGroup(v.cfgId)
  118. local maxActiveLv = 0 ---激活最大等级
  119. local preLevel = 0
  120. if outEquipData and outEquipData.ssuplv then
  121. preLevel = outEquipData.ssuplv --当前首饰等级
  122. end
  123. if outEquipData ~= nil and outEquipData.ssactlv then
  124. for _, actlv in pairs(outEquipData.ssactlv) do
  125. if maxActiveLv < actlv then
  126. --已激活的
  127. maxActiveLv = actlv
  128. end
  129. end
  130. end
  131. ---@type cfg_equip_ornaments_column
  132. local NextActiveTbl = nil ---下一个激活信息
  133. if OrnamentsGroup then
  134. for i, Group in pairs(OrnamentsGroup) do
  135. if next(Group.excellenceAtt) then
  136. if Group.lv > maxActiveLv then
  137. NextActiveTbl = Group
  138. break
  139. end
  140. end
  141. end
  142. end
  143. if not NextActiveTbl then
  144. return false
  145. else
  146. if next(NextActiveTbl.unlockDeplete) and preLevel >= NextActiveTbl.lv then
  147. for _, unlockDeplete in pairs(NextActiveTbl.unlockDeplete) do
  148. local haveCount = SL:GetBagItemCount(tonumber(unlockDeplete[1]))
  149. local needCount = tonumber(unlockDeplete[2])
  150. if haveCount >= needCount then
  151. return true
  152. else
  153. return false
  154. end
  155. end
  156. end
  157. end
  158. return false
  159. end
  160. function this:IsShowActiveRedDot()
  161. local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  162. if not equipAll or not next(equipAll) or not equipAll[1] or not next(equipAll[1]) then
  163. return false
  164. end
  165. for i, type in pairs(E_JewelryEquipType) do
  166. if equipAll[1][type] then
  167. local v = equipAll[1][type]
  168. ---@type RES_UPDATE_EQUIP_ORNAMENTS
  169. self.OutEquipData = SL:JsonDecode(v.luaExtData,false)
  170. local OrnamentsGroup = self:GetOrnamentsGroup(v.cfgId)
  171. local maxActiveLv = 0 ---激活最大等级
  172. local preLevel = 0
  173. if self.OutEquipData and self.OutEquipData.ssuplv then
  174. preLevel = self.OutEquipData.ssuplv --当前首饰等级
  175. end
  176. if self.OutEquipData ~= nil and self.OutEquipData.ssactlv then
  177. for _, actlv in pairs(self.OutEquipData.ssactlv) do
  178. if maxActiveLv < actlv then
  179. --已激活的
  180. maxActiveLv = actlv
  181. end
  182. end
  183. end
  184. ---@type cfg_equip_ornaments_column
  185. local NextActiveTbl = nil ---下一个激活信息
  186. if OrnamentsGroup then
  187. for z, Group in pairs(OrnamentsGroup) do
  188. if next(Group.excellenceAtt) then
  189. if Group.lv > maxActiveLv then
  190. NextActiveTbl = Group
  191. break
  192. end
  193. end
  194. end
  195. end
  196. if NextActiveTbl and next(NextActiveTbl.unlockDeplete) and preLevel >= NextActiveTbl.lv then
  197. for _, unlockDeplete in pairs(NextActiveTbl.unlockDeplete) do
  198. local haveCount = SL:GetBagItemCount(tonumber(unlockDeplete[1]))
  199. local needCount = tonumber(unlockDeplete[2])
  200. if haveCount >= needCount then
  201. return true
  202. end
  203. end
  204. end
  205. end
  206. end
  207. return false
  208. end
  209. function this:GetOrnamentsGroup(cfgId)
  210. if not SL:HasConfig('cfg_equip_ornamentsMain', cfgId) then
  211. return
  212. end
  213. ---@type cfg_equip_ornamentsMain_column
  214. local ornament_tbl = SL:GetConfig('cfg_equip_ornamentsMain', cfgId)
  215. if ornament_tbl.ornamentsGroup and self.OrnamentsGroupList[ornament_tbl.ornamentsGroup] then
  216. return self.OrnamentsGroupList[ornament_tbl.ornamentsGroup]
  217. end
  218. return nil
  219. end
  220. ---@return cfg_equip_ornaments_column
  221. function this:GetJewelryTblInfoByLevel(cfgId, Level)
  222. local PreOrnament_Tbl = nil
  223. local NextOrnament_Tbl = nil
  224. if SL:HasConfig('cfg_equip_ornamentsMain', cfgId) then
  225. ---@type cfg_equip_ornamentsMain_column
  226. local ornament_tbl = SL:GetConfig('cfg_equip_ornamentsMain', cfgId)
  227. if ornament_tbl.ornamentsGroup and self.OrnamentsGroupList[ornament_tbl.ornamentsGroup] then
  228. for _, v in pairs(self.OrnamentsGroupList[ornament_tbl.ornamentsGroup]) do
  229. if v.lv == Level then
  230. PreOrnament_Tbl = v
  231. end
  232. if v.lv == Level + 1 then
  233. NextOrnament_Tbl = v
  234. end
  235. end
  236. end
  237. end
  238. return PreOrnament_Tbl, NextOrnament_Tbl
  239. end
  240. ---获得当前首饰等级最大可强化等级
  241. function this:GetCurLevelMaxStrength(equipInfo)
  242. local cfgId = equipInfo.cfgId
  243. if not next(equipInfo) then
  244. return false
  245. end
  246. local Level = 0
  247. self.OutEquipData = SL:JsonDecode(equipInfo.luaExtData,false)
  248. if self.OutEquipData ~= nil and self.OutEquipData.ssuplv then
  249. Level = tonumber(self.OutEquipData.ssuplv) --当前首饰等级
  250. end
  251. local PreOrnament_Tbl,NextOrnament_Tbl = self:GetJewelryTblInfoByLevel(cfgId,Level)
  252. if PreOrnament_Tbl then
  253. return PreOrnament_Tbl.strengthenmaxLevel
  254. end
  255. return Level
  256. end
  257. ---获得当前首饰等级最大可追加等级
  258. function this:GetCurLevelMaxAppend(equipInfo)
  259. local cfgId = equipInfo.cfgId
  260. if not next(equipInfo) then
  261. return false
  262. end
  263. local Level = 0
  264. self.OutEquipData = SL:JsonDecode(equipInfo.luaExtData,false)
  265. if self.OutEquipData ~= nil and self.OutEquipData.ssuplv then
  266. Level = tonumber(self.OutEquipData.ssuplv) --当前首饰等级
  267. end
  268. local PreOrnament_Tbl,NextOrnament_Tbl = self:GetJewelryTblInfoByLevel(cfgId,Level)
  269. if PreOrnament_Tbl then
  270. return PreOrnament_Tbl.appendsmaxLevel
  271. end
  272. return Level
  273. end
  274. ESpecialAttrID=
  275. {
  276. minAtk=200011,
  277. maxAtk=200021
  278. }
  279. function this:IsSpecialAttrId(attrId)
  280. for _,v in pairs(ESpecialAttrID) do
  281. if v == attrId then
  282. return true
  283. end
  284. end
  285. return false
  286. end
  287. function this:GetAttrJewelSpecialTbl(minAttrId, MaxAttrId, PreOrnament_Tbl, NextOrnament_Tbl,name)
  288. local tbl=nil
  289. if NextOrnament_Tbl then
  290. tbl=self:GetAttrSpecial(minAttrId,MaxAttrId,PreOrnament_Tbl.basicAtt, NextOrnament_Tbl.basicAtt,name)
  291. else
  292. tbl=self:GetAttrSpecial(minAttrId,MaxAttrId,PreOrnament_Tbl.basicAtt, nil,name)
  293. end
  294. return tbl
  295. end
  296. function this:GetAttrSpecial(minAttrId, MaxAttrId, preAttrList, nextAttrList,name)
  297. local pre_attr_map = {}
  298. local next_attr_map = {}
  299. local arrowShow = false
  300. for _, nowAttr in pairs(preAttrList) do
  301. pre_attr_map[nowAttr[1]] = nowAttr[2]
  302. end
  303. if nextAttrList then
  304. for _, nowAttr in pairs(nextAttrList) do
  305. next_attr_map[nowAttr[1]] = nowAttr[2]
  306. end
  307. arrowShow = true
  308. else
  309. arrowShow = false
  310. end
  311. local tbl = nil
  312. local minAtk = pre_attr_map[minAttrId]
  313. local maxAtk = pre_attr_map[MaxAttrId]
  314. local nextValue = nil
  315. local name = name
  316. if arrowShow then
  317. local minAtkNext = next_attr_map[minAttrId]
  318. local maxAtkNext = next_attr_map[MaxAttrId]
  319. if minAtkNext and maxAtkNext then
  320. nextValue = minAtkNext .. '~' .. maxAtkNext
  321. end
  322. end
  323. if minAtk and maxAtk and nextValue then
  324. tbl = {
  325. attrName = name,
  326. preValue = minAtk .. '~' .. maxAtk,
  327. nextValue = nextValue,
  328. arrowShow = arrowShow
  329. }
  330. end
  331. return tbl
  332. end