EquipFunc.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. ---@class EquipFunc
  2. EquipFunc = {}
  3. local this = EquipFunc
  4. function this.Init()
  5. this.otherEquips = nil
  6. this.RegistEvents()
  7. end
  8. function this.Reset()
  9. this.UnRegistEvents()
  10. this.otherEquips = nil
  11. end
  12. function this.RegistEvents()
  13. SL:RegisterLUAEvent(LUA_EVENT_ROLE_INFO, this.ResOtherRoleInfoMessage)
  14. SL:RegisterLUAEvent(LUA_EVENT_ROLE_PROPERTY_CHANGE,this.LUA_EVENT_ROLE_PROPERTY_CHANGE)
  15. end
  16. function this.UnRegistEvents()
  17. SL:UnRegisterLUAEvent(LUA_EVENT_ROLE_INFO,this.ResOtherRoleInfoMessage)
  18. SL:UnRegisterLUAEvent(LUA_EVENT_ROLE_PROPERTY_CHANGE,this.LUA_EVENT_ROLE_PROPERTY_CHANGE)
  19. end
  20. ------------------------用来显示别人的装备信息-----------start--------------------------------------
  21. ---@param message UserProtos.OtherRoleInfoRes
  22. function this.ResOtherRoleInfoMessage(_, message)
  23. if message.type == 4 and tostring(message.role.rid) == this.otherRid then
  24. local equips = {}
  25. for _, v in pairs(message.equipIndex) do
  26. local wearBar, pos = SL:GetWearBarAndPosBaseEquipIndex(v.index)
  27. if not equips[wearBar] then
  28. equips[wearBar] = {}
  29. end
  30. equips[wearBar][pos] = v.equip
  31. end
  32. this.otherEquips = equips
  33. end
  34. end
  35. function this.OtherGetEquipWearBarIdPos(id)
  36. local index = this.GetEquipIndexByItemId(id)
  37. if not index then
  38. return
  39. end
  40. local wearBarId, pos = SL:GetWearBarAndPosBaseEquipIndex(index)
  41. return wearBarId, pos
  42. end
  43. function this.GetEquipIndexByItemId(itemId)
  44. if not this.otherEquips then
  45. return
  46. end
  47. for wearBar , posEquipInfo in pairs(this.otherEquips) do
  48. for pos, equip in pairs(posEquipInfo) do
  49. if(equip.id == itemId) then
  50. return this.GetIdxOfEquip(pos,wearBar)
  51. end
  52. end
  53. end
  54. end
  55. function this.checkOtherEquips()
  56. if not this.otherEquips then
  57. return false
  58. end
  59. return true
  60. end
  61. ------------------------用来显示别人的装备信息-------end------------------------------------------
  62. function this.GetIdxOfEquip(pos,gemWearCellId)
  63. if not gemWearCellId then
  64. return pos
  65. end
  66. return gemWearCellId << 16 | pos
  67. end
  68. -- 获取装备名字颜色
  69. function this.GetEquipNameColor(cfgId)
  70. local colorid = SL:GetConfig('cfg_item', cfgId).color
  71. return SL:GetConfigMultiKeys('cfg_color', colorid, 'id').color
  72. end
  73. -- 获取装备强化等级
  74. function this.GetEquipStrengthLevel(item)
  75. local strengthLevel = 0
  76. if item.luaExtData ~= "null" and item.luaExtData ~= "" then
  77. strengthLevel = SL:JsonDecode(item.luaExtData).strengthlv or 0
  78. end
  79. return strengthLevel
  80. end
  81. ---装备是否可强化
  82. function this.EquipIsCanStrength(equip)
  83. if equip then
  84. if SL:HasConfig('cfg_equip_strengthen', equip['cfgId']) then
  85. ---@type cfg_equip_strengthen_column
  86. local strength_tbl = SL:GetConfig('cfg_equip_strengthen', equip['cfgId'])
  87. local nowLv = this.GetEquipStrengthLevel(equip)
  88. local maxLevel = strength_tbl.maxLevel
  89. ---首饰换表处理
  90. local ornament_tbl = SL:HasConfig('cfg_equip_ornamentsMain', equip['cfgId'])
  91. if ornament_tbl then
  92. maxLevel = InfoManager.equipJewelryInfo:GetCurLevelMaxStrength(equip)
  93. end
  94. local lv = nowLv + 1
  95. if nowLv >= maxLevel then
  96. return false
  97. end
  98. if SL:HasConfigTwoKeys('cfg_equip_strengthenCost', strength_tbl.costId, lv, 'costGroupId', 'level') then
  99. ---@type cfg_equip_strengthenCost_column
  100. local strengthenCostCfg = SL:GetConfigTwoKeys('cfg_equip_strengthenCost', strength_tbl.costId, lv, 'costGroupId', 'level')
  101. for _, v in ipairs(strengthenCostCfg.cost) do
  102. local cfgId = v[1]
  103. local needCount = v[2]
  104. local bagCount = SL:GetBagItemCount(cfgId)
  105. if needCount > bagCount then
  106. return false
  107. end
  108. end
  109. else
  110. return false
  111. end
  112. else
  113. return false
  114. end
  115. else
  116. return false
  117. end
  118. return true
  119. end
  120. ---装备是否可追加
  121. function this.EquipIsCanAppend(equip)
  122. if equip then
  123. if SL:HasConfig('cfg_equip_appends', equip['cfgId']) then
  124. ---@type cfg_equip_appends_column
  125. local strength_tbl = SL:GetConfig('cfg_equip_appends', equip['cfgId'])
  126. local nowLv = this.GetEquipAppendLevel(equip)
  127. local maxLevel = strength_tbl.maxLevel
  128. ---首饰换表处理
  129. local ornament_tbl = SL:HasConfig('cfg_equip_ornamentsMain', equip['cfgId'])
  130. if ornament_tbl then
  131. maxLevel = InfoManager.equipJewelryInfo:GetCurLevelMaxAppend(equip)
  132. end
  133. local lv = nowLv + 1
  134. if nowLv >= maxLevel then
  135. return false
  136. end
  137. if SL:HasConfigTwoKeys('cfg_equip_appendsCost', strength_tbl.costId, lv, 'costGroupId', 'level') then
  138. ---@type cfg_equip_appendsCost_column
  139. local strengthenCostCfg = SL:GetConfigTwoKeys('cfg_equip_appendsCost', strength_tbl.costId, lv, 'costGroupId', 'level')
  140. for _, v in ipairs(strengthenCostCfg.cost) do
  141. local cfgId = v[1]
  142. local needCount = v[2]
  143. local bagCount = SL:GetBagItemCount(cfgId)
  144. if needCount > bagCount then
  145. return false
  146. end
  147. end
  148. else
  149. return false
  150. end
  151. else
  152. return false
  153. end
  154. else
  155. return false
  156. end
  157. return true
  158. end
  159. -- 获取全身装备强化等级
  160. function this.GetAllStrengthLevel()
  161. local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  162. if not next(equipAll) or not next(equipAll[1]) then
  163. return 0
  164. end
  165. local allLevel = 0
  166. for _, v in pairs(equipAll[1]) do
  167. local level = this.GetEquipStrengthLevel(v)
  168. allLevel = allLevel + level
  169. end
  170. return allLevel
  171. end
  172. -- 获取装备追加等级
  173. function this.GetEquipAppendLevel(item)
  174. local strengthLevel = 0
  175. if item.luaExtData ~= "null" and item.luaExtData ~= "" then
  176. strengthLevel = SL:JsonDecode(item.luaExtData).appendlv or 0
  177. end
  178. return strengthLevel
  179. end
  180. -- 获取全身装备追加等级
  181. function this.GetAllAppendLevel()
  182. local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  183. if not next(equipAll) or not next(equipAll[1]) then
  184. return 0
  185. end
  186. local allLevel = 0
  187. for _, v in pairs(equipAll[1]) do
  188. local level = this.GetEquipAppendLevel(v)
  189. allLevel = allLevel + level
  190. end
  191. return allLevel
  192. end
  193. -- 获取装备流光id
  194. function this.GetEquipLiuGuangId(item,strengthlv)
  195. if not SL:HasConfig('cfg_equip_strengthen', item.cfgId) then
  196. return
  197. end
  198. local stream = SL:GetConfig('cfg_equip_strengthen', item.cfgId).stream
  199. local ret
  200. if stream then
  201. local strengthLevel =strengthlv or EquipFunc.GetEquipStrengthLevel(item)
  202. for _, streamInfo in ipairs(stream) do
  203. local nowStrengthLevel = streamInfo[1]
  204. if strengthLevel >= nowStrengthLevel then
  205. ret = streamInfo[2]
  206. else
  207. return ret
  208. end
  209. end
  210. end
  211. return ret
  212. end
  213. -- 获取装备强化数据
  214. function this.GetEquipStrengthAttr(item)
  215. local strengthenTbl = SL:GetConfig('cfg_equip_strengthen', item.cfgId)
  216. if strengthenTbl then
  217. local groupId = SL:GetConfig('cfg_equip_strengthen', item.cfgId).groupId
  218. local strengthLevel = this.GetEquipStrengthLevel(item)
  219. local nowAttrInfo = SL:GetConfigTwoKeys('cfg_equip_strengthenGroup', groupId, strengthLevel, 'group', 'lv')
  220. if nowAttrInfo then
  221. return nowAttrInfo.att
  222. end
  223. end
  224. return {}
  225. end
  226. -- 获取装备追加数据
  227. function this.GetEquipAppendAttr(item)
  228. local strengthenTbl = SL:GetConfig('cfg_equip_appends', item.cfgId)
  229. if strengthenTbl then
  230. local groupId = SL:GetConfig('cfg_equip_appends', item.cfgId).groupId
  231. local strengthLevel = this.GetEquipAppendLevel(item)
  232. local nowAttrInfo = SL:GetConfigTwoKeys('cfg_equip_appendsGroup', groupId, strengthLevel, 'group', 'lv')
  233. if nowAttrInfo then
  234. return nowAttrInfo.att
  235. end
  236. end
  237. return {}
  238. end
  239. -- 获取装备再生等级
  240. function this.GetEquipRegenerateLevel(item)
  241. local regenerationLevel = 0
  242. if item.luaExtData ~= "null" and item.luaExtData ~= "" then
  243. regenerationLevel = SL:JsonDecode(item.luaExtData).regenerationlv or 0
  244. end
  245. return tonumber(regenerationLevel)
  246. end
  247. -- 获取装备再生属性
  248. function this.GetEquipRegenerate(item)
  249. if not SL:HasConfig('cfg_equip_regeneration', item.cfgId) then
  250. return
  251. end
  252. local regenerateTbl = SL:GetConfig('cfg_equip_regeneration', item.cfgId)
  253. if regenerateTbl then
  254. if item.luaExtData ~= "null" and item.luaExtData ~= "" then
  255. local tab = SL:JsonDecode(item.luaExtData).regenerationattr
  256. return tab
  257. end
  258. end
  259. end
  260. function this.GetEquipRegenerateAttr(item)
  261. local message = this.GetEquipRegenerate(item)
  262. if message then
  263. local all_attr_id = {}
  264. for i=1,10,1 do
  265. if message[tostring(i)] then
  266. table.insert(all_attr_id,message[tostring(i)].id)
  267. else
  268. break
  269. end
  270. end
  271. local att_list = {}
  272. for _, v in ipairs(all_attr_id) do
  273. local str = SL:GetConfig('cfg_equip_regenerationGroup', v).att
  274. local oneList = string.split(str,'#')
  275. table.insert(att_list,{type=tonumber(oneList[1]),num=tonumber(oneList[2])})
  276. end
  277. return att_list
  278. end
  279. end
  280. ---@param item CommonProtos.Item
  281. ---@param strengthenState number
  282. ---@param appendState number
  283. ---@param rebornState number
  284. function this.GetTransferCost(item, strengthenState, appendState, rebornState)
  285. local strengthenCost = {}
  286. local appendCost = {}
  287. local rebornCost = {}
  288. local strengthenLevel = EquipFunc.GetEquipStrengthLevel(item)
  289. local appendLevel = EquipFunc.GetEquipAppendLevel(item)
  290. local rebornLevel = EquipFunc.GetEquipRegenerateLevel(item)
  291. ---@type cfg_equip_transfer_column
  292. local sourceTbl = SL:GetConfig("cfg_equip_transfer", item.cfgId)
  293. if strengthenState == "1" then
  294. for _, v in ipairs(sourceTbl.strengthenCost) do
  295. if strengthenLevel >= v[1] then
  296. strengthenCost["id"] = v[2]
  297. strengthenCost["num"] = v[3]
  298. else
  299. break
  300. end
  301. end
  302. end
  303. if appendState == "1" then
  304. for _, v in ipairs(sourceTbl.appendsCost) do
  305. if appendLevel >= v[1] then
  306. appendCost["id"] = v[2]
  307. appendCost["num"] = v[3]
  308. else
  309. break
  310. end
  311. end
  312. end
  313. if rebornState == "1" then
  314. for _, v in ipairs(sourceTbl.regenerationCost) do
  315. if rebornLevel >= v[1] then
  316. rebornCost["id"] = v[2]
  317. rebornCost["num"] = v[3]
  318. else
  319. break
  320. end
  321. end
  322. end
  323. local totalCost = { id = 0, num = 0 }
  324. if strengthenCost.id then
  325. totalCost.id = strengthenCost.id
  326. totalCost.num = strengthenCost.num + totalCost.num
  327. end
  328. if appendCost.id then
  329. totalCost.id = appendCost.id
  330. totalCost.num = appendCost.num + totalCost.num
  331. end
  332. if rebornCost.id then
  333. totalCost.id = rebornCost.id
  334. totalCost.num = rebornCost.num + totalCost.num
  335. end
  336. return totalCost
  337. end
  338. ---@param sourceItem CommonProtos.Item @转移装备
  339. ---@param targetItem CommonProtos.Item @继承装备
  340. function this.CheckEquipCanTransfer(sourceItem, targetItem)
  341. if sourceItem then
  342. ---继承装备未曾锻造过
  343. if EquipFunc.GetEquipStrengthLevel(targetItem) == 0 and EquipFunc.GetEquipAppendLevel(targetItem) == 0 then
  344. ---目标装备无再生属性
  345. local targetRegenerate = EquipFunc.GetEquipRegenerate(targetItem)
  346. if targetRegenerate and next(targetRegenerate) then
  347. return false
  348. end
  349. ---转移装备有属性可转移
  350. if EquipFunc.GetEquipStrengthLevel(sourceItem) > 0 or EquipFunc.GetEquipAppendLevel(sourceItem) > 0 then
  351. ---@type cfg_equip_transfer_column
  352. local sourceTbl = SL:GetConfig("cfg_equip_transfer", sourceItem.cfgId)
  353. ---@type cfg_equip_transfer_column
  354. local targetTbl = SL:GetConfig("cfg_equip_transfer", targetItem.cfgId)
  355. if targetTbl and sourceTbl then
  356. ---隶属同一转移组可转移
  357. if targetTbl.transferGroup == sourceTbl.transferGroup then
  358. local regenerate = EquipFunc.GetEquipRegenerate(sourceItem)
  359. ---有再生追加判断再生组
  360. if regenerate and next(regenerate) then
  361. if targetTbl.regenerationGroup == sourceTbl.regenerationGroup then
  362. return true
  363. end
  364. else
  365. return true
  366. end
  367. end
  368. end
  369. end
  370. end
  371. end
  372. return false
  373. end
  374. function this.LUA_EVENT_ROLE_PROPERTY_CHANGE()
  375. local strength = SL:GetMetaValue("GET_ATTR_VALUE_BY_ID", EMUCharacterAttrType.strength)
  376. local agility = SL:MeData_GetSpecialAttrValue(EMUCharacterAttrType.agility)
  377. local intelligence = SL:MeData_GetSpecialAttrValue(EMUCharacterAttrType.intelligence)
  378. local itemList_1 = SL:GetWearBarsData(EEquipWearBarType.BaseEquip)
  379. local all_take_off = {}
  380. if itemList_1 then
  381. for _, item in pairs(itemList_1) do
  382. local is_off = false
  383. local cfg_id = item.cfgId
  384. local useAttLimit = SL:GetEquipValue(EMetaVarGetKey.EQUIP_WEAR_LIMIT, "", cfg_id)
  385. for _, att in ipairs(useAttLimit) do
  386. local att_type = att[1]
  387. local att_num = att[2]
  388. if att_type == EMUCharacterAttrType.strength then
  389. if strength < att_num then
  390. is_off = true
  391. break
  392. end
  393. elseif att_type == EMUCharacterAttrType.agility then
  394. if agility < att_num then
  395. is_off = true
  396. break
  397. end
  398. elseif att_type == EMUCharacterAttrType.intelligence then
  399. if intelligence < att_num then
  400. is_off = true
  401. break
  402. end
  403. end
  404. end
  405. if is_off then
  406. table.insert(all_take_off,item)
  407. end
  408. end
  409. end
  410. if table.count(all_take_off) > 0 then
  411. local all_str = ""
  412. for idx, item in ipairs(all_take_off) do
  413. local tab = SL:GetConfig("cfg_item",item.cfgId)
  414. local name = tab.name
  415. local color_id = tab.color
  416. local color_str = SL:GetConfig("cfg_color",color_id).color
  417. local one_str = "<color=" .. color_str .. ">" .. name .. "</color>"
  418. if idx < #all_take_off then
  419. one_str = one_str .. ","
  420. end
  421. all_str = all_str .. one_str
  422. local wearBarId, pos = SL:GetEquipWearBarIdPos(item.id)
  423. SL:TakeOffEquip(wearBarId, pos)
  424. end
  425. local str_cfg = SL:GetConfig("cfg_string",28001).text
  426. local str = string.format(str_cfg,all_str)
  427. SL:CommonTipsMessage({ showTips = str, sureBtnText = "确定"})
  428. end
  429. end
  430. ---替换装备背包界面按钮图片
  431. function this:ReplaceEquipBagButton(list)
  432. for i, v in ipairs(list) do
  433. ---@type cfg_bagButton_column
  434. local cfg = SL:GetConfig("cfg_bagButton",i)
  435. GUI:Image_loadTexture(v, cfg.icon, "Atlas/UIBagPanel_Out.spriteatlas")
  436. GUI:setPosition(v,cfg.position[1],cfg.position[2])
  437. GUI:setPositionZ(v,cfg.position[3])
  438. GUI:setVisible(v,cfg.show == 1)
  439. end
  440. end