EquipAndAppear.lua 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  1. EquipAndAppear = {}
  2. local this = {}
  3. ---玩家装备信息记录
  4. local ROLE_EQUIP_INFO_RECORDE = "T$role_equip_info_recorde"
  5. local ROLE_EQUIP_STRENGTH_TIMES = "T$role_equip_strength_times"
  6. EquipAndAppear.RecordeType = {
  7. ---全身最大强化等级
  8. MAX_STRENGTH_LEVEL = 1,
  9. ---全身最大追加等级
  10. MAX_APPEND_LEVEL = 2,
  11. ---全身最大卓越词条数量
  12. MAX_ENTRY_COUNT = 3,
  13. ---全身最大首饰等级
  14. MAX_JEWELRY_LEVEL = 4
  15. }
  16. ---装备信息记录数据结构
  17. function this.GetNewEquipInfoRecorde()
  18. local recorde = {
  19. ---全身最大强化等级
  20. max_strength_level = 0,
  21. ---全身最大追加等级
  22. max_append_level = 0,
  23. ---全身最大卓越词条数量
  24. max_entry_count = 0,
  25. ---全身最大首饰等级
  26. max_jewelry_level = 0,
  27. }
  28. return recorde
  29. end
  30. function EquipAndAppear.GetEquipInfoRecorde(actor)
  31. local equipInfoRecorde = getplaydef(actor, ROLE_EQUIP_INFO_RECORDE)
  32. if equipInfoRecorde == nil then
  33. equipInfoRecorde = this.GetNewEquipInfoRecorde()
  34. end
  35. return equipInfoRecorde
  36. end
  37. function this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  38. setplaydef(actor, ROLE_EQUIP_INFO_RECORDE, equipInfoRecorde)
  39. end
  40. -- 保存角色外观(幻化也走这个方法)
  41. function EquipAndAppear.settingequipappear(actor, msgData)
  42. local equipappear = msgData["equipindex"]
  43. local data = {}
  44. for _, value in pairs(equipappear) do
  45. local pos = tonumber(value["slot"])
  46. local cfgId = tonumber(value["cfgId"])
  47. if pos ~= nil then
  48. data[pos] = cfgId
  49. end
  50. end
  51. setitemappeardata(actor, data)
  52. sendluamsg(actor, LuaMessageIdToClient.RES_SETTING_EQUIP_APPEAR, data)
  53. end
  54. -- 初始化角色外观
  55. function initequipppear(actor)
  56. local equipappear = {}
  57. setplaydef(actor, "T$equipappear", equipappear)
  58. end
  59. --获取角色外观
  60. function EquipAndAppear.getequipappear(actor, msgId)
  61. local data = getrolefield(actor, "role.roleappear.appear")
  62. if data == nil then
  63. return
  64. end
  65. local result = {}
  66. for key, value in pairs(data) do
  67. local appear = {}
  68. appear["slot"] = key
  69. appear["cfgId"] = value
  70. table.insert(result, appear)
  71. end
  72. --发送lua消息到客户端
  73. if LuaMessageIdToSever.GET_EQUIP_APPEAR == msgId then
  74. sendluamsg(actor, LuaMessageIdToClient.GET_EQUIP_APPEAR, result)
  75. end
  76. return result
  77. end
  78. -- 外观幻化激活
  79. function EquipAndAppear.equipfashion(actor, msgData)
  80. local cfgIds = msgData["cfgIds"]
  81. local equipFashion = getplaydef(actor, "T$equipfashion")
  82. if equipFashion == nil then
  83. equipFashion = {}
  84. end
  85. for _, cfgId in pairs(cfgIds) do
  86. local isExist = table.contains(equipFashion, cfgId)
  87. if isExist then
  88. --存在已激活的
  89. return
  90. end
  91. end
  92. --计算所有消耗
  93. local allData = getAllEquipAppearCost(cfgIds, 4)
  94. if allData == nil then
  95. return
  96. end
  97. --检查背包是否道具充足
  98. local enough = Bag.checkItemEnough(actor, allData)
  99. if enough == false then
  100. return
  101. end
  102. --扣材料
  103. for _, v in ipairs(allData) do
  104. local cId = v["cfgid"]
  105. local count = v["count"]
  106. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  107. end
  108. --保存幻化
  109. for _, v in pairs(cfgIds) do
  110. table.insert(equipFashion, v)
  111. end
  112. setplaydef(actor, "T$equipfashion", equipFashion)
  113. sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_FASHION, equipFashion)
  114. end
  115. --获取已激活外观
  116. function EquipAndAppear.getallequipfashion(actor)
  117. local equipFashion = getplaydef(actor, "T$equipfashion")
  118. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_FASHION, equipFashion)
  119. end
  120. --激活染色
  121. function EquipAndAppear.actquipcolor(actor, msgData)
  122. local cfgIds = msgData["cfgIds"]
  123. local color = msgData["color"]
  124. --计算消耗材料
  125. local allCost = getAllEquipAppearCost(cfgIds, 5)
  126. if allCost == nil then
  127. return
  128. end
  129. --检查背包是否道具充足
  130. local enough = Bag.checkItemEnough(actor, allCost)
  131. if enough == false then
  132. return
  133. end
  134. --扣材料
  135. for _, v in ipairs(allCost) do
  136. local cId = v["cfgid"]
  137. local count = v["count"]
  138. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  139. end
  140. --染色
  141. local equipcolor = EquipAndAppear.getequipcolor(actor, 0)
  142. for i, v in ipairs(cfgIds) do
  143. local num = 0
  144. for _, val in pairs(equipcolor) do
  145. if val["cfgid"] == v then
  146. table.insert(val["color"], color)
  147. num = num + 1
  148. break
  149. end
  150. end
  151. if num == 0 then
  152. local dt = {}
  153. dt["cfgid"] = v
  154. dt["color"] = {}
  155. table.insert(dt["color"], color)
  156. table.insert(equipcolor, dt)
  157. end
  158. end
  159. setplaydef(actor, "actequipcolor", equipcolor)
  160. end
  161. -- 保存染色
  162. function EquipAndAppear.settingequipcolor(actor, msgData)
  163. local cfgId = msgData["cfgid"]
  164. local color = msgData["color"]
  165. --先校验是否激活该颜色
  166. local actequipcolor = getplaydef(actor, "T$actequipcolor")
  167. local bool = false
  168. for _, v in pairs(actequipcolor) do
  169. local cId = v["cfgid"]
  170. if cId == cfgId then
  171. bool = table.contains(v["color"], color)
  172. break
  173. end
  174. end
  175. if bool ~= true then
  176. return
  177. end
  178. local equipcolor = EquipAndAppear.getequipcolor(actor, 0)
  179. for _, v in ipairs(equipcolor) do
  180. if v["cfgid"] == cfgId then
  181. v["color"] = color
  182. break
  183. end
  184. end
  185. setplaydef(actor, "T$equipcolor", equipcolor)
  186. end
  187. --获取角色染色数据
  188. function EquipAndAppear.getequipcolor(actor, msgId)
  189. local equipcolor = getplaydef(actor, "T$equipcolor")
  190. if equipcolor == nil then
  191. equipcolor = {}
  192. setplaydef(actor, "T$equipcolor", equipcolor)
  193. end
  194. local data = getplaydef(actor, "T$equipcolor")
  195. --发送lua消息到客户端
  196. if msgId == LuaMessageIdToClient.GET_EQUIP_COLOR then
  197. sendluamsg(actor, msgId, data)
  198. end
  199. return data
  200. end
  201. --计算所有消耗
  202. function getAllEquipAppearCost(cfgIds, type)
  203. local allData = {}
  204. for _, cfgId in pairs(cfgIds) do
  205. local cost = ConfigDataManager.getTableValue("cfg_fashion", "deplete", "id", cfgId, "type", type)
  206. if cost == nil then
  207. return nil
  208. end
  209. local data = splitbyshuxianandjinghao(cost)
  210. for _1, v in pairs(data) do
  211. local id = v["cfgid"]
  212. local count = v["count"]
  213. local num = 0;
  214. for _2, val in pairs(allData) do
  215. if val["cfgid"] == id then
  216. val["count"] = val["count"] + count
  217. num = num + 1
  218. break
  219. end
  220. end
  221. if num == 0 then
  222. local element = {}
  223. element["cfgid"] = id
  224. element["count"] = count
  225. table.insert(allData, element)
  226. end
  227. end
  228. end
  229. return allData
  230. end
  231. function EquipAndAppear.playerequipview(actor, otherActor)
  232. if otherActor == nil then
  233. return
  234. end
  235. --发送幻化染色数据
  236. local appear = EquipAndAppear.getequipappear(otherActor, 0)
  237. local title = EquipAndAppear.gettitleinfo(otherActor, 0)
  238. local alldata = {}
  239. alldata["appear"] = appear
  240. alldata["ring"] = EquipAndAppear.getnowwearshapering(otherActor)
  241. local curTitle = 0
  242. if not title.hidden then
  243. curTitle = title.curEquipTitle
  244. end
  245. alldata["title"] = curTitle
  246. local rid = getbaseinfo(otherActor, "rid")
  247. alldata["rid"] = rid
  248. sendluamsg(actor, LuaMessageIdToClient.OTHER_ROLE_APPEAR, alldata)
  249. end
  250. --玩家进入视野时发送玩家装备的强化信息
  251. function EquipAndAppear.playerequipstrength(actor, otherActor)
  252. if otherActor == 0 then
  253. otherActor = actor
  254. end
  255. local alldata = getplaydef(otherActor, "T$luaitemextdata")
  256. local equiplist = getputonequipinfo(otherActor)
  257. local result = {}
  258. local info = {}
  259. for _, equipinfo in pairs(equiplist) do
  260. local itemId = equipinfo.id
  261. local data = alldata[itemId]
  262. local equip = {}
  263. equip.itemid = itemId
  264. if data ~= nil then
  265. if data.strengthlv ~= nil then
  266. equip.strengthlv = data.strengthlv
  267. else
  268. equip.strengthlv = 0
  269. end
  270. else
  271. equip.strengthlv = 0
  272. end
  273. table.insert(info, equip)
  274. end
  275. result.rid = getbaseinfo(otherActor, "rid")
  276. result.equip = info
  277. result = table.valueConvertToString(result)
  278. sendrefluamsg(actor, LuaMessageIdToClient.RES_PLAYER_EQUIP_STRENGTHLV, result)
  279. end
  280. --检查表是否包含某个元素
  281. -- function table.contains(table, element)
  282. -- for _, value in pairs(table) do
  283. -- if value == element then
  284. -- return true
  285. -- end
  286. -- end
  287. -- return false
  288. -- end
  289. -- 分割字符串
  290. function splitbyshuxianandjinghao(str)
  291. local dt = {}
  292. local data = string.split(str, "|")
  293. for _, v in ipairs(data) do
  294. local data2 = string.split(v, "#")
  295. local v2 = {}
  296. v2["cfgid"] = data2[1]
  297. v2["count"] = data2[2]
  298. table.insert(dt, v2)
  299. end
  300. return dt
  301. end
  302. --称号入包
  303. function EquipAndAppear.titleenterbag(actor, configId)
  304. local itemList = ConfigDataManager.getTable("cfg_item", "id", configId)
  305. if itemList == nil then
  306. return
  307. end
  308. local item = itemList[1]
  309. if tonumber(item.type) ~= 2 or tonumber(item.subtype) ~= 15 then
  310. return
  311. end
  312. --计算时间
  313. local fashionList = ConfigDataManager.getTable("cfg_fashion", "id", configId)
  314. if fashionList == nil then
  315. return
  316. end
  317. if table.count(fashionList) == 0 then
  318. return
  319. end
  320. local fashion = fashionList[1]
  321. local titledata = EquipAndAppear.gettitleinfo(actor, 0)
  322. local titles = titledata.title
  323. --不限时
  324. local flag = true
  325. local time = 0
  326. local type = 0
  327. local timeType = tonumber(fashion.timetype)
  328. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  329. if timeType == 1 then
  330. type = 1
  331. for _, value in pairs(titles) do
  332. if value.confId == configId then
  333. value.obtainTime = nowTime --获得时间
  334. value.expiresTime = -1 --到期时间
  335. flag = false
  336. end
  337. end
  338. time = -1
  339. end
  340. --限时
  341. if timeType == 2 then
  342. type = 2
  343. --获取称号的有效期
  344. local times = fashion.time
  345. local timestr = string.split(times, "#")
  346. --总时间
  347. time = tonumber(timestr[1]) * 60 * 60 + tonumber(timestr[2]) * 60 + tonumber(timestr[3])
  348. for _, value in pairs(titles) do
  349. if value.confId == configId then
  350. value.obtainTime = nowTime --获得时间
  351. value.expiresTime = value.obtainTime + time --到期时间
  352. flag = false
  353. end
  354. end
  355. end
  356. --活动限时
  357. if timeType == 3 then
  358. type = 3
  359. --todo 获取称号的有效期
  360. local actId = fashion.time
  361. local actdata = getactivityinfo(actor, actId)
  362. time = math.ceil(actdata.nextopentime / 1000)
  363. for _, value in pairs(titles) do
  364. if value.confId == configId then
  365. value.obtainTime = nowTime --获得时间
  366. value.expiresTime = time --到期时间
  367. flag = false
  368. end
  369. end
  370. end
  371. if flag then
  372. local tt = {}
  373. tt.obtainTime = math.ceil(getbaseinfo("now") / 1000)
  374. if type == 1 or type == 3 then
  375. tt.expiresTime = time
  376. else
  377. tt.expiresTime = tt.obtainTime + time
  378. end
  379. tt.confId = configId
  380. table.insert(titles, tt)
  381. end
  382. setplaydef(actor, "T$titledata", titledata)
  383. --更新称号属性
  384. EquipAndAppear.updatetitleattr(actor)
  385. end
  386. --更新称号属性信息
  387. function EquipAndAppear.updatetitleattr(actor)
  388. local data = getplaydef(actor, "T$titledata")
  389. local titles = data.title
  390. local titleattr = {}
  391. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  392. for _, value in pairs(titles) do
  393. --先校验是否过期
  394. if value.expiresTime == -1 or value.expiresTime > nowTime then
  395. --计算属性
  396. local fashion = ConfigDataManager.getTable("cfg_fashion", "id", value.confId)
  397. local attr = fashion[1].att
  398. local str = string.split(attr, "|")
  399. for _, value in pairs(str) do
  400. local str2 = string.split(value, "#")
  401. local num = titleattr[str2[1]]
  402. local nowNum = str2[2]
  403. if num == nil then
  404. titleattr[str2[1]] = tonumber(nowNum)
  405. else
  406. titleattr[str2[1]] = tonumber(nowNum) + tonumber(num)
  407. end
  408. end
  409. end
  410. end
  411. --更新称号属性
  412. addrolekmlattributes(actor, "titleattr", titleattr)
  413. end
  414. --获取称号详细信息
  415. function EquipAndAppear.gettitleinfo(actor, msgId)
  416. local data = getplaydef(actor, "T$titledata")
  417. if data == nil then
  418. data = EquipAndAppear.inittitledata(actor)
  419. end
  420. if msgId == LuaMessageIdToSever.GET_TITLE then
  421. sendluamsg(actor, LuaMessageIdToClient.GET_TITLE, data)
  422. end
  423. return data
  424. end
  425. --保存称号外观
  426. function EquipAndAppear.settingtitleappear(actor, msgId, msgData)
  427. local data = getplaydef(actor, "T$titledata")
  428. local titleappear = msgData["title"]
  429. data.curEquipTitle = titleappear
  430. setplaydef(actor, "T$titledata", data)
  431. if msgId == LuaMessageIdToSever.SET_TITLE then
  432. sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, titleappear)
  433. local result = {}
  434. result.rid = getbaseinfo(actor, "rid")
  435. result.curEquipTitle = titleappear
  436. sendrefluamsg(actor, LuaMessageIdToClient.RES_TITLE_CHANGE_UPDATE, result)
  437. end
  438. end
  439. --初始化数据
  440. function EquipAndAppear.inittitledata(actor)
  441. local data = {}
  442. data.title = {}
  443. data.hidden = false
  444. data.curEquipTitle = 0
  445. setplaydef(actor, "T$titledata", data)
  446. return data
  447. end
  448. --校验称号的过期时间
  449. function EquipAndAppear.checktitleovertime(actor)
  450. local data = getplaydef(actor, "T$titledata")
  451. if table.count(data) == 0 then
  452. data = EquipAndAppear.inittitledata(actor)
  453. end
  454. local titles = data.title
  455. if table.count(titles) == 0 then
  456. return
  457. end
  458. local curTitle = data.curEquipTitle
  459. local flag = false
  460. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  461. for key, value in pairs(titles) do
  462. --先校验是否过期
  463. --jprint("检查称号过期0",value.expiresTime > nowTime, value.expiresTime, nowTime)
  464. if value.expiresTime ~= -1 and value.expiresTime < nowTime then
  465. table.remove(titles, key)
  466. flag = true
  467. if curTitle == value.confId then
  468. data.curEquipTitle = 0
  469. end
  470. end
  471. end
  472. if flag then
  473. data.title = titles
  474. setplaydef(actor, "T$titledata", data)
  475. EquipAndAppear.updatetitleattr(actor)
  476. --发送消息
  477. sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, 0)
  478. end
  479. end
  480. --获取守护外观
  481. function EquipAndAppear.getguardappear(actor, msgId)
  482. local data = getrolefield(actor, "role.roleEquip.guardAppear")
  483. if data == nil then
  484. sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, {})
  485. return {}
  486. end
  487. local result = {}
  488. for key, value in pairs(data) do
  489. local mm = {}
  490. mm.att = value.attr
  491. mm.getTime = math.floor(value.getTime / 1000)
  492. mm.itemId = key
  493. if value.time ~= -1 then
  494. mm.time = mm.getTime + math.floor(value.time / 1000)
  495. else
  496. mm.time = -1
  497. end
  498. table.insert(result, mm)
  499. end
  500. if msgId == LuaMessageIdToSever.GET_GUARD_APPEAR then
  501. sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, result)
  502. end
  503. return data
  504. end
  505. --获取变身戒指数据
  506. function EquipAndAppear.getshapering(actor, msgId)
  507. local data = getrolefield(actor, "role.roleEquip.shapeRing")
  508. if data == nil then
  509. return {}
  510. end
  511. local nowwear = EquipAndAppear.getnowwearshapering(actor)
  512. local rd = {}
  513. local result = {}
  514. rd.curWearRing = nowwear
  515. for key, value in pairs(data) do
  516. local mm = {}
  517. mm.monsterId = tonumber(key)
  518. mm.ringAttr = value.ringAttr
  519. mm.getTime = math.floor(value.getTime / 1000)
  520. mm.itemId = value.itemId
  521. if value.time ~= -1 then
  522. mm.time = math.floor(value.time / 1000)
  523. else
  524. mm.time = -1
  525. end
  526. table.insert(result, mm)
  527. end
  528. rd.title = result
  529. if msgId == LuaMessageIdToSever.GET_SHAPE_RING then
  530. sendluamsg(actor, LuaMessageIdToClient.GET_SHAPE_RING, rd)
  531. end
  532. return data
  533. end
  534. --穿戴变身戒指
  535. function EquipAndAppear.wearshapering(actor, msgData)
  536. local monsterId = msgData["monsterId"]
  537. setplaydef(actor, "T$wearshapering", monsterId)
  538. setshaperingdata(actor, monsterId)
  539. sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, monsterId)
  540. local result = {}
  541. result.rid = getbaseinfo(actor, "rid")
  542. result.curEquipRing = monsterId
  543. sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  544. end
  545. --获取当前穿戴的变身戒指
  546. function EquipAndAppear.getnowwearshapering(actor)
  547. local data = getplaydef(actor, "T$wearshapering")
  548. if data == nil then
  549. return 0
  550. end
  551. return data
  552. end
  553. --校验变身戒指过期时间
  554. function EquipAndAppear.checkringovertime(actor)
  555. local data = EquipAndAppear.getshapering(actor)
  556. local ringId = EquipAndAppear.getnowwearshapering(actor)
  557. if ringId == 0 then
  558. return
  559. end
  560. local monsterId = ConfigDataManager.getTableValue("cfg_item", "useParam", "id", ringId)
  561. if not monsterId then
  562. return
  563. end
  564. if not data[tostring(monsterId)] then
  565. setplaydef(actor, "T$wearshapering", 0)
  566. sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0)
  567. local result = {}
  568. result.rid = getbaseinfo(actor, "rid")
  569. result.curEquipRing = 0
  570. sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  571. end
  572. -- local nowTime = math.ceil(getbaseinfo("now") / 1000)
  573. -- for index, ring in pairs(data) do
  574. -- if ring ~= -1 then
  575. -- --检查
  576. -- if nowTime > math.floor(ring.time / 1000) then
  577. -- --删除穿戴外观
  578. -- local ringId = EquipAndAppear.getnowwearshapering(actor)
  579. -- if ringId == ring then
  580. -- setplaydef(actor, "T$wearshapering", 0)
  581. -- sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0)
  582. -- local result = {}
  583. -- result.rid = getbaseinfo(actor, "rid")
  584. -- result.curEquipRing = 0
  585. -- sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  586. -- end
  587. -- table.remove(data, index)
  588. -- end
  589. -- end
  590. -- end
  591. end
  592. function EquipAndAppear.initequipluaextdata(alldata, itemid)
  593. local equipdata = {}
  594. equipdata.strengthlv = 0
  595. equipdata.appendlv = 0
  596. equipdata.strengthattr = {}
  597. equipdata.appendattr = {}
  598. alldata[itemid] = equipdata
  599. end
  600. --装备强化
  601. function EquipAndAppear.luastrengthequip(actor, msgData)
  602. local itemid = msgData.itemId
  603. local equip = getequipinfo(actor, itemid, 1)
  604. if equip == nil then
  605. return
  606. end
  607. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  608. local equipdata = alldata[itemid]
  609. if equipdata == nil then
  610. EquipAndAppear.initequipluaextdata(alldata, itemid)
  611. equipdata = alldata[itemid]
  612. end
  613. if equipdata.strengthlv == nil then
  614. equipdata.strengthlv = 0
  615. equipdata.strengthattr = {}
  616. end
  617. local lv = equipdata.strengthlv + 1
  618. local cfgId = equip.cfgid
  619. --首饰的强化等级特殊处理
  620. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  621. if group ~= nil and group ~= "" then
  622. local strengthenmaxLevel = ConfigDataManager.getTableValue("cfg_equip_ornaments", "strengthenmaxLevel","ornamentsGroup", group, "lv", equipdata.ssuplv or 0)
  623. if tonumber(strengthenmaxLevel) < lv then
  624. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级")
  625. return
  626. end
  627. else
  628. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", cfgId)
  629. if tonumber(maxLevel) < lv then
  630. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级")
  631. return
  632. end
  633. end
  634. local costId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "costId", "id", cfgId)
  635. local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", cfgId)
  636. --获取消耗
  637. local coststr = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "cost", "costGroupId", costId, "level", lv)
  638. if coststr == nil then
  639. return
  640. end
  641. local cost = splitbyshuxianandjinghao(coststr)
  642. --校验道具是否足够
  643. local enough = Bag.checkItemEnough(actor, cost)
  644. if enough == false then
  645. TimeLimitGift.checkSpecial2Condition(actor)
  646. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  647. return
  648. end
  649. --扣材料
  650. for _, v in ipairs(cost) do
  651. local cId = v["cfgid"]
  652. local count = v["count"]
  653. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  654. end
  655. TimeLimitGift.checkSpecial2Count(actor)
  656. --获取成功率
  657. local rate = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "rate", "costGroupId", costId, "level", lv)
  658. local randomNumber = math.random(1, 10000)
  659. rate = tonumber(rate)
  660. if rate < randomNumber then
  661. --失败,校验是否等级回退
  662. local failLevel = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "failLevel", "costGroupId", costId, "level", lv)
  663. failLevel = tonumber(failLevel)
  664. if failLevel == equipdata.strengthlv then
  665. --给客户端发强化结果
  666. local dddd = {}
  667. dddd.itemId = itemid
  668. dddd.strengthlv = tonumber(failLevel)
  669. dddd.issuccess = false
  670. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  671. return
  672. end
  673. local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", failLevel)
  674. local attr = splitbyshuxianandjinghao2(att)
  675. equipdata.strengthlv = failLevel
  676. equipdata.strengthattr = attr
  677. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  678. setplaydef(actor, "T$luaitemextdata", alldata)
  679. --更新强化追加等属性
  680. EquipAndAppear.updateluaextattr(actor)
  681. info(actor,"玩家",actor,"强化装备至" .. lv .. "级失败,失败后等级" .. failLevel,"道具id".. itemid,"cfgId:" .. cfgId)
  682. --给客户端发强化结果
  683. local dddd = {}
  684. dddd.itemId = itemid
  685. dddd.strengthlv = tonumber(failLevel)
  686. dddd.issuccess = false
  687. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  688. EquipMaster.strengthMaster(actor)
  689. --装备强化之后发送装备强化信息
  690. EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv)
  691. return
  692. end
  693. --获取属性加成
  694. local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", lv)
  695. local attr = splitbyshuxianandjinghao2(att)
  696. equipdata.strengthlv = lv
  697. equipdata.strengthattr = attr
  698. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  699. setplaydef(actor, "T$luaitemextdata", alldata)
  700. --更新强化追加等属性
  701. EquipAndAppear.updateluaextattr(actor)
  702. local firstRate = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "firstRate", "costGroupId", costId, "level", lv)
  703. firstRate = tonumber(firstRate)
  704. if firstRate == 1 then
  705. --发送跑马灯
  706. local name = getrolefield(actor, "role.basic.name")
  707. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  708. local content = "恭喜" .. name .. "将" .. equipName .. "强化至" .. lv .. "级"
  709. local horseled = {}
  710. horseled.content = content
  711. horseled.cfgId = 109 -- 109是直接写死的
  712. sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled)
  713. end
  714. info(actor,"玩家",actor,"强化装备至" .. lv .. "级成功","道具id".. itemid,"cfgId:" .. cfgId)
  715. --给客户端发强化结果
  716. local dddd = {}
  717. dddd.itemId = itemid
  718. dddd.strengthlv = tonumber(lv)
  719. dddd.issuccess = true
  720. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  721. EquipMaster.strengthMaster(actor)
  722. --记录强化次数
  723. local oldCount = EquipAndAppear.GetEquipStrengthCount(actor)
  724. setplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES, oldCount + 1)
  725. ---触发装备强化任务
  726. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  727. local taskParam = {
  728. part = strPart,
  729. level = lv
  730. }
  731. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.PARTS_STRENGTHEN_LV, taskParam)
  732. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_STRENGTHEN_TIMES, lv)
  733. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL)
  734. --装备强化之后发送装备强化信息
  735. EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv)
  736. end
  737. ---获取玩家装备累计强化次数
  738. function EquipAndAppear.GetEquipStrengthCount(actor)
  739. local totalCount = getplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES)
  740. if totalCount == nil then
  741. totalCount = 0
  742. end
  743. return totalCount
  744. end
  745. function EquipAndAppear.updateequipgmext(actor, itemid, strengthlv)
  746. -- local gmext = getequipgmext(actor,itemid)
  747. -- if gmext == nil or gmext == "null" then
  748. -- gmext = {}
  749. -- end
  750. local gmext = {}
  751. gmext.strengthlv = strengthlv
  752. setequipgmext(actor, itemid, gmext)
  753. end
  754. function splitbyshuxianandjinghao2(str)
  755. local dt = {}
  756. local data = string.split(str, "|")
  757. for _, v in ipairs(data) do
  758. local data2 = string.split(v, "#")
  759. dt[data2[1]] = data2[2]
  760. end
  761. return dt
  762. end
  763. --装备追加
  764. function EquipAndAppear.luaappendequip(actor, msgData)
  765. local itemid = msgData.itemId
  766. local equip = getequipinfo(actor, itemid, 1)
  767. if equip == nil then
  768. return
  769. end
  770. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  771. local equipdata = alldata[itemid]
  772. if equipdata == nil then
  773. EquipAndAppear.initequipluaextdata(alldata, itemid)
  774. equipdata = alldata[itemid]
  775. end
  776. if equipdata.appendlv == nil then
  777. equipdata.appendlv = 0
  778. equipdata.appendattr = {}
  779. end
  780. local lv = equipdata.appendlv + 1
  781. local cfgId = equip.cfgid
  782. --首饰的强化等级特殊处理
  783. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  784. if group ~= nil and group ~= "" then
  785. local appendsmaxLevel = ConfigDataManager.getTableValue("cfg_equip_ornaments", "appendsmaxLevel","ornamentsGroup", group, "lv", equipdata.ssuplv or 0)
  786. if tonumber(appendsmaxLevel) < lv then
  787. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级")
  788. return
  789. end
  790. else
  791. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", cfgId)
  792. if tonumber(maxLevel) < lv then
  793. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级")
  794. return
  795. end
  796. end
  797. local costId = ConfigDataManager.getTableValue("cfg_equip_appends", "costId", "id", cfgId)
  798. local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", cfgId)
  799. --获取消耗
  800. local coststr = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "cost", "costGroupId", costId, "level", lv)
  801. if coststr == nil then
  802. return
  803. end
  804. local cost = splitbyshuxianandjinghao(coststr)
  805. --校验道具是否足够
  806. local enough = Bag.checkItemEnough(actor, cost)
  807. if enough == false then
  808. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  809. return
  810. end
  811. --扣材料
  812. for _, v in ipairs(cost) do
  813. local cId = v["cfgid"]
  814. local count = v["count"]
  815. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  816. end
  817. --获取成功率
  818. local rate = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "rate", "costGroupId", costId, "level", lv)
  819. local randomNumber = math.random(1, 10000)
  820. rate = tonumber(rate)
  821. if rate < randomNumber then
  822. --失败,校验是否等级回退
  823. local failLevel = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "failLevel", "costGroupId", costId, "level", lv)
  824. failLevel = tonumber(failLevel)
  825. if failLevel == equipdata.appendlv then
  826. --给客户端发强化结果
  827. local dddd = {}
  828. dddd.itemId = itemid
  829. dddd.appendlv = tonumber(failLevel)
  830. dddd.issuccess = false
  831. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  832. return
  833. end
  834. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", failLevel)
  835. local attr = splitbyshuxianandjinghao2(att)
  836. equipdata.appendlv = failLevel
  837. equipdata.appendattr = attr
  838. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  839. setplaydef(actor, "T$luaitemextdata", alldata)
  840. --给客户端发强化结果
  841. local dddd = {}
  842. dddd.itemId = itemid
  843. dddd.appendlv = tonumber(failLevel)
  844. dddd.issuccess = false
  845. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  846. EquipMaster.appendMaster(actor)
  847. return
  848. end
  849. --获取属性加成
  850. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", lv)
  851. local attr = splitbyshuxianandjinghao2(att)
  852. equipdata.appendlv = lv
  853. equipdata.appendattr = attr
  854. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  855. setplaydef(actor, "T$luaitemextdata", alldata)
  856. --更新强化追加等属性
  857. EquipAndAppear.updateluaextattr(actor)
  858. local firstRate = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "firstRate", "costGroupId", costId, "level", lv)
  859. firstRate = tonumber(firstRate)
  860. if firstRate == 1 then
  861. --发送跑马灯
  862. local name = getrolefield(actor, "role.basic.name")
  863. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  864. local content = "恭喜" .. name .. "将" .. equipName .. "追加至" .. lv .. "级"
  865. local horseled = {}
  866. horseled.cfgId = 115
  867. horseled.content = content
  868. sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled)
  869. end
  870. --给客户端发强化结果
  871. local dddd = {}
  872. dddd.itemId = itemid
  873. dddd.appendlv = tonumber(lv)
  874. dddd.issuccess = true
  875. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  876. EquipMaster.appendMaster(actor)
  877. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_APPEND_LEVEL)
  878. -- 刷新任务进度
  879. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  880. local taskParam = {
  881. part = strPart,
  882. level = lv
  883. }
  884. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND, taskParam)
  885. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND_TOTAL_LV)
  886. end
  887. --- 获取所有装备数据
  888. function EquipAndAppear.getLuaItemExtData(actor)
  889. local alldata = getplaydef(actor, "T$luaitemextdata")
  890. if alldata == nil then
  891. --说明还没有进行过锻造
  892. setplaydef(actor, "T$luaitemextdata", {})
  893. alldata = getplaydef(actor, "T$luaitemextdata")
  894. end
  895. return alldata
  896. end
  897. --装备属性转移
  898. function EquipAndAppear.luatransferequip(actor, msgData)
  899. local firstId = msgData.firstItem
  900. local secId = msgData.secondItem
  901. local equip1 = getequipinfo(actor, firstId, 1)
  902. if equip1 == nil then
  903. return
  904. end
  905. local equip2 = getequipinfo(actor, secId, 1)
  906. if equip2 == nil then
  907. return
  908. end
  909. local id1 = equip1.cfgid
  910. local id2 = equip2.cfgid
  911. local data1 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id1)
  912. local data2 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id2)
  913. if (data1 == nil) or (data2 == nil) or (data1.transferGroup ~= data2.transferGroup) or (data1.transfer ~= data2.transfer) then
  914. return
  915. end
  916. local ts = msgData.transferStrength -- bool类型
  917. local ta = msgData.transferAppend
  918. local tr = msgData.transferRegeneration
  919. if not ts and not ta and not tr then
  920. return
  921. end
  922. --扩展数据
  923. local extdata = getplaydef(actor, "T$luaitemextdata")
  924. local ext1 = extdata[firstId]
  925. local ext2 = extdata[secId]
  926. if ext2 == nil then
  927. ext2 = {}
  928. ext2.appendattr = {}
  929. ext2.strengthattr = {}
  930. ext2.appendlv = 0
  931. ext2.strengthlv = 0
  932. end
  933. --转移前强化追加
  934. info(actor,"转移前强化追加等级,rid:",actor,"强化等级:",ext1.strengthlv,ext2.strengthlv,"追加等级:",ext1.appendlv,ext2.appendlv,"主装备id:"..firstId.."主装备cfgId:"..id1,"副装备id:"..secId.."副装备cfgId:"..id2)
  935. local allCost = {}
  936. --强化消耗
  937. if ts then
  938. local lv1 = ext1.strengthlv
  939. local lv2 = ext2.strengthlv
  940. if lv2 ~= 0 then
  941. return
  942. end
  943. local costItem = data1[1].strengthencost
  944. local cost = splittransfercoststr(costItem)
  945. local realLv = 0
  946. local realCost = {}
  947. for key, value in pairs(cost) do
  948. if key > realLv and key <= lv1 then
  949. realLv = key
  950. realCost = value
  951. end
  952. end
  953. table.insert(allCost, realCost)
  954. end
  955. if table.count(allCost[1]) == 0 then
  956. allCost[1] = {}
  957. end
  958. --追加消耗
  959. if ta then
  960. local lv1 = ext1.appendlv
  961. local lv2 = ext2.appendlv
  962. if lv2 ~= 0 then
  963. return
  964. end
  965. local costItem = data1[1].appendscost
  966. local cost = splittransfercoststr(costItem)
  967. local realLv = 0
  968. local realCost = {}
  969. for key, value in pairs(cost) do
  970. if key > realLv and key <= lv1 then
  971. realLv = key
  972. realCost = value
  973. end
  974. end
  975. for _, value in pairs(realCost) do
  976. local cId = value["cfgid"]
  977. local num = value["count"]
  978. local n = 0
  979. for _1, v in pairs(allCost[1]) do
  980. if v["cfgid"] == cId then
  981. v["count"] = v["count"] + num
  982. n = n + 1
  983. end
  984. end
  985. if n == 0 then
  986. table.insert(allCost[1], value)
  987. end
  988. end
  989. end
  990. --再生消耗
  991. if tr then
  992. local lv1 = ext1.regenerationlv
  993. local lv2 = ext2.regenerationlv
  994. if lv2 == nil then
  995. ext2.regenerationlv = 0
  996. lv2 = 0
  997. end
  998. if lv2 ~= 0 then
  999. return
  1000. end
  1001. local costItem = data1[1].regenerationcost
  1002. local cost = splittransfercoststr(costItem)
  1003. local realLv = 0
  1004. local realCost = {}
  1005. for key, value in pairs(cost) do
  1006. if key > realLv and key <= lv1 then
  1007. realLv = key
  1008. realCost = value
  1009. end
  1010. end
  1011. for _, value in pairs(realCost) do
  1012. local cId = value["cfgid"]
  1013. local num = value["count"]
  1014. local n = 0
  1015. for _1, v in pairs(allCost[1]) do
  1016. if v["cfgid"] == cId then
  1017. v["count"] = v["count"] + num
  1018. n = n + 1
  1019. end
  1020. end
  1021. if n == 0 then
  1022. table.insert(allCost[1], value)
  1023. end
  1024. end
  1025. end
  1026. --检查道具是否足够
  1027. local enough = Bag.checkItemEnough(actor, allCost[1])
  1028. if not enough then
  1029. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1030. return
  1031. end
  1032. --扣道具
  1033. for _, v in ipairs(allCost[1]) do
  1034. local cId = v["cfgid"]
  1035. local count = v["count"]
  1036. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  1037. end
  1038. --转移强化
  1039. if ts then
  1040. local slv1 = ext1.strengthlv
  1041. ext2.strengthlv = slv1
  1042. ext1.strengthlv = 0
  1043. ext1.strengthattr = {}
  1044. --赋值属性
  1045. local maxLv = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", equip2.cfgid)
  1046. local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", equip2.cfgid)
  1047. if ext2.strengthlv > tonumber(maxLv) then
  1048. ext2.strengthlv = tonumber(maxLv)
  1049. end
  1050. local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", ext2.strengthlv)
  1051. local attr = splitbyshuxianandjinghao2(att)
  1052. ext2.strengthattr = attr
  1053. EquipAndAppear.updateequipgmext(actor, firstId, 0)
  1054. EquipAndAppear.updateequipgmext(actor, secId, ext2.strengthlv)
  1055. end
  1056. --转移追加
  1057. if ta then
  1058. local slv1 = ext1.appendlv
  1059. ext2.appendlv = slv1
  1060. ext1.appendlv = 0
  1061. ext1.appendattr = {}
  1062. --赋值属性
  1063. local maxLv = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", equip2.cfgid)
  1064. local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", equip2.cfgid)
  1065. if ext2.appendlv > tonumber(maxLv) then
  1066. ext2.appendlv = tonumber(maxLv)
  1067. end
  1068. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", ext2.appendlv)
  1069. local attr = splitbyshuxianandjinghao2(att)
  1070. ext2.appendattr = attr
  1071. end
  1072. --转移再生
  1073. if tr then
  1074. local relv = ext1.regenerationlv
  1075. ext2.regenerationlv = relv
  1076. ext1.regenerationlv = 0
  1077. ext2.regenerationattr = {}
  1078. --赋值属性
  1079. local maxLv = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip2.cfgid)
  1080. local groupId = ConfigDataManager.getTableValue("cfg_equip_regeneration", "Group", "id", equip2.cfgid)
  1081. if ext2.regenerationlv > tonumber(maxLv) then
  1082. ext2.regenerationlv = tonumber(maxLv)
  1083. end
  1084. local regeattr = ext1.regenerationattr
  1085. for _, value in pairs(regeattr) do
  1086. local id = value.id
  1087. local regenerationgroup = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  1088. if table.count(regenerationgroup) ~= 0 then
  1089. local sequence = regenerationgroup[1].sequence
  1090. --找对应的表
  1091. local nexttable = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", groupId, "sequence", sequence, "level", ext2.regenerationlv)
  1092. if table.count(nexttable) ~= 0 then
  1093. local att = nexttable[1].att
  1094. local str = string.split(att, "#")
  1095. local dd = {}
  1096. dd[str[1]] = tonumber(str[2])
  1097. dd.id = tonumber(nexttable[1].id)
  1098. ext2.regenerationattr[tostring(table.count(ext2.regenerationattr) + 1)] = dd
  1099. end
  1100. end
  1101. end
  1102. ext1.regenerationattr = {}
  1103. end
  1104. --更新数据
  1105. extdata[firstId] = ext1
  1106. extdata[secId] = ext2
  1107. EquipAndAppear.SetItemExtData(actor, firstId, ext1)
  1108. EquipAndAppear.SetItemExtData(actor, secId, ext2)
  1109. setplaydef(actor, "T$luaitemextdata", extdata)
  1110. EquipAndAppear.updateluaextattr(actor)
  1111. --转移后强化追加
  1112. info(actor,"转移后强化追加等级,rid:",actor,"强化等级:",ext1.strengthlv,ext2.strengthlv,"追加等级:",ext1.appendlv,ext2.appendlv,"主装备id:"..firstId.."主装备cfgId:"..id1,"副装备id:"..secId.."副装备cfgId:"..id2)
  1113. EquipMaster.transferTrigger(actor, equip1, equip2, ts, ta)
  1114. --发送lua消息到客户端
  1115. local data = {}
  1116. data.oldItem = firstId
  1117. data.newItem = secId
  1118. data.issuccess = true
  1119. sendluamsg(actor, LuaMessageIdToClient.RES_TRANSFER_EQUIP, data)
  1120. end
  1121. function EquipAndAppear.checkCanTransfer(actor, firstId, secId)
  1122. if firstId == 0 then
  1123. return
  1124. end
  1125. local data = {}
  1126. data.oldItem = firstId
  1127. data.newItem = secId
  1128. sendluamsg(actor, LuaMessageIdToClient.RES_CAN_TRANSFER, data)
  1129. end
  1130. function splittransfercoststr(str)
  1131. local s = string.split(str, "|")
  1132. local data = {}
  1133. for _, value in pairs(s) do
  1134. local x = string.split(value, "#")
  1135. local len = #x
  1136. local itemList = {}
  1137. if len == 3 then
  1138. local item = {}
  1139. item["cfgid"] = x[2]
  1140. item["count"] = x[3]
  1141. table.insert(itemList, item)
  1142. else
  1143. if len > 3 then
  1144. for i = 1, len do
  1145. local item = {}
  1146. if i == 1 then
  1147. item["cfgid"] = x[i + 1]
  1148. item["count"] = x[i + 2]
  1149. i = i + 3
  1150. else
  1151. item["cfgid"] = x[i]
  1152. item["count"] = x[i + 1]
  1153. i = i + 2
  1154. end
  1155. table.insert(itemList, item)
  1156. end
  1157. end
  1158. end
  1159. data[tonumber(x[1])] = itemList
  1160. end
  1161. return data
  1162. end
  1163. function EquipAndAppear.updateluaextattr(actor)
  1164. local alldata = getplaydef(actor, "T$luaitemextdata")
  1165. local equiplist = getputonequipinfo(actor)
  1166. local allattr = {}
  1167. for _, equipinfo in pairs(equiplist) do
  1168. local itemId = equipinfo.id
  1169. local data = alldata[itemId]
  1170. if data ~= nil then
  1171. --将该装备的属性加到角色身上
  1172. if data.strengthlv ~= nil then
  1173. local strengthattr = data.strengthattr
  1174. table.mergeAdd(allattr, strengthattr)
  1175. end
  1176. if data.appendlv ~= nil then
  1177. local appendattr = data.appendattr
  1178. table.mergeAdd(allattr, appendattr)
  1179. end
  1180. if data.ssuplv ~= nil then
  1181. local ssupattr = data.ssupattr
  1182. local ssactattr = data.ssactattr
  1183. table.mergeAdd(allattr, ssupattr)
  1184. table.mergeAdd(allattr, ssactattr)
  1185. end
  1186. if data.regenerationlv ~= nil then
  1187. local reattr = data.regenerationattr
  1188. local regenerationattr = {}
  1189. for _, att in pairs(reattr) do
  1190. for key, value in pairs(att) do
  1191. if key ~= "id" then
  1192. local num = regenerationattr[key]
  1193. if num == nil then
  1194. num = 0
  1195. end
  1196. regenerationattr[key] = num + value
  1197. end
  1198. end
  1199. end
  1200. table.mergeAdd(allattr, regenerationattr)
  1201. end
  1202. end
  1203. end
  1204. --更新装备记录
  1205. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_ENTRY_COUNT)
  1206. --记录强化追加等属性
  1207. if table.count(allattr) == 0 then
  1208. addrolekmlattributes(actor, "luaextdataforever", {})
  1209. return
  1210. end
  1211. addrolekmlattributes(actor, "luaextdataforever", allattr)
  1212. end
  1213. --首饰升级
  1214. function EquipAndAppear.ssupdate(actor, msgData)
  1215. local itemId = msgData["itemId"]
  1216. local allequip = getplaydef(actor, "T$luaitemextdata")
  1217. local equipext = allequip[itemId]
  1218. if equipext == nil then
  1219. equipext = {}
  1220. end
  1221. if equipext.ssuplv == nil then
  1222. equipext.ssupattr = {}
  1223. equipext.ssuplv = 0
  1224. equipext.ssactlv = {}
  1225. equipext.ssactattr = {}
  1226. end
  1227. local equip = getequipinfo(actor, itemId, 1)
  1228. local cfgId = equip.cfgid
  1229. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  1230. if group == nil then
  1231. return
  1232. end
  1233. local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", equipext.ssuplv)
  1234. if ornaments == nil or table.count(ornaments) == 0 then
  1235. return
  1236. end
  1237. local data = ornaments[1]
  1238. local cost = data.lvdeplete
  1239. local costItem = splitbyshuxianandjinghao(cost)
  1240. --检查背包是否道具充足
  1241. local enough = Bag.checkItemEnough(actor, costItem)
  1242. if enough == false then
  1243. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1244. return
  1245. end
  1246. --扣材料
  1247. for _, v in ipairs(costItem) do
  1248. local cId = v["cfgid"]
  1249. local count = v["count"]
  1250. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  1251. end
  1252. --升级,加属性
  1253. equipext.ssuplv = tonumber(data.lv) + 1
  1254. local att = data.basicatt
  1255. local attr = splitbyshuxianandjinghao2(att)
  1256. equipext.ssupattr = attr
  1257. allequip[itemId] = equipext
  1258. EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  1259. setplaydef(actor, "T$luaitemextdata", allequip)
  1260. --升级成功 回包给客户端
  1261. local result = {}
  1262. result.ssupattr = equipext.ssupattr
  1263. result.ssuplv = tostring(equipext.ssuplv)
  1264. result.ssactlv = equipext.ssactlv
  1265. result.ssactattr = equipext.ssactattr
  1266. result.itemId = itemId
  1267. sendluamsg(actor, LuaMessageIdToClient.RES_UPDATE_EQUIP_ORNAMENTS, result)
  1268. --更新属性
  1269. EquipAndAppear.updateluaextattr(actor)
  1270. --更新等级记录
  1271. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL)
  1272. -- 刷新任务进度
  1273. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.JEWELRY_LV_UP)
  1274. end
  1275. --首饰等级属性激活
  1276. function EquipAndAppear.actssattr(actor, msgData)
  1277. local itemId = msgData["itemId"]
  1278. local lv = msgData["lv"]
  1279. local allequip = getplaydef(actor, "T$luaitemextdata")
  1280. local equipext = allequip[itemId]
  1281. if equipext.ssuplv == nil then
  1282. return
  1283. end
  1284. local equip = getequipinfo(actor, itemId, 1)
  1285. local cfgId = equip.cfgid
  1286. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  1287. local ssuplv = equipext.ssuplv
  1288. if ssuplv < lv then
  1289. return
  1290. end
  1291. if table.contains(equipext.ssactlv, lv) then
  1292. return
  1293. end
  1294. local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", lv)
  1295. if table.count(ornaments) == 0 then
  1296. return
  1297. end
  1298. if ornaments[1].unlockdeplete == nil then
  1299. return
  1300. end
  1301. local unlockDeplete = ornaments[1].unlockdeplete
  1302. if unlockDeplete == nil then
  1303. return
  1304. end
  1305. local costItem = splitbyshuxianandjinghao(unlockDeplete)
  1306. --检查背包是否道具充足
  1307. local enough = Bag.checkItemEnough(actor, costItem)
  1308. if enough == false then
  1309. return
  1310. end
  1311. --扣材料
  1312. for _, v in ipairs(costItem) do
  1313. local cId = v["cfgid"]
  1314. local count = v["count"]
  1315. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  1316. end
  1317. equipext.ssactlv[tostring(lv)] = lv
  1318. local att = ornaments[1].excellenceatt
  1319. local attr = splitbyshuxianandjinghao2(att)
  1320. table.mergeAdd(equipext.ssactattr, attr)
  1321. allequip[itemId] = equipext
  1322. EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  1323. setplaydef(actor, "T$luaitemextdata", allequip)
  1324. --发送回包给客户端
  1325. local result = {}
  1326. result.ssupattr = equipext.ssupattr
  1327. result.ssuplv = equipext.ssuplv
  1328. result.ssactlv = equipext.ssactlv
  1329. result.ssactattr = equipext.ssactattr
  1330. result.itemId = itemId
  1331. sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, result)
  1332. --更新属性
  1333. EquipAndAppear.updateluaextattr(actor)
  1334. end
  1335. function EquipAndAppear.allequipstrengthlv(actor)
  1336. local alldata = getplaydef(actor, "T$luaitemextdata")
  1337. local equiplist = getputonequipinfo(actor)
  1338. local allequipstrengthlv = 0
  1339. for _, equipinfo in pairs(equiplist) do
  1340. local itemId = equipinfo.id
  1341. local data = alldata[itemId]
  1342. if data ~= nil then
  1343. if data.strengthlv ~= nil then
  1344. allequipstrengthlv = allequipstrengthlv + data.strengthlv
  1345. end
  1346. end
  1347. end
  1348. return allequipstrengthlv
  1349. end
  1350. --再生
  1351. function EquipAndAppear.regeneration(actor, msgData)
  1352. local itemId = msgData["itemId"]
  1353. local equip = getequipinfo(actor, itemId, 1)
  1354. local allequip = getplaydef(actor, "T$luaitemextdata")
  1355. local ext = allequip[itemId]
  1356. if ext == nil then
  1357. ext = {}
  1358. ext.regenerationlv = 0
  1359. ext.regenerationattr = {}
  1360. end
  1361. if ext.regenerationlv == nil then
  1362. ext.regenerationlv = 0
  1363. ext.regenerationattr = {}
  1364. end
  1365. local lv = ext.regenerationlv
  1366. local tabledata = ConfigDataManager.getTable("cfg_equip_regeneration", "id", equip.cfgid)
  1367. if table.count(tabledata) == 0 then
  1368. return
  1369. end
  1370. local group = tabledata[1].group
  1371. --获取消耗
  1372. local lockattr = msgData["lockattrpos"]
  1373. local startcost = {}
  1374. local type = 0
  1375. if table.count(ext.regenerationattr) == 0 then
  1376. startcost = tabledata[1].start
  1377. type = 1
  1378. else
  1379. if table.count(lockattr) == 0 then
  1380. startcost = tabledata[1].again
  1381. type = 2
  1382. else
  1383. startcost = tabledata[1].lock
  1384. type = 3
  1385. end
  1386. end
  1387. local cost = getlockcost(startcost, lockattr)
  1388. --校验道具是否足够
  1389. local enough = Bag.checkItemEnough(actor, cost)
  1390. if enough == false then
  1391. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1392. return
  1393. end
  1394. --扣道具
  1395. for _, v in ipairs(cost) do
  1396. local cId = v["cfgid"]
  1397. local count = v["count"]
  1398. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  1399. end
  1400. --随机词条数量
  1401. local attrNum = {}
  1402. if type == 1 then
  1403. attrNum = tabledata[1].startnum
  1404. else
  1405. if type == 2 then
  1406. attrNum = tabledata[1].againnum
  1407. else
  1408. if type == 3 then
  1409. attrNum = tabledata[1].locknum
  1410. end
  1411. end
  1412. end
  1413. local result = random_weighted(attrNum, 1)
  1414. if lv == 0 then
  1415. lv = 1
  1416. end
  1417. --校验词条数是否超过最大值
  1418. local maxAttrNum = tabledata[1].count
  1419. local realNum = result[1] + table.count(lockattr)
  1420. if realNum >= tonumber(maxAttrNum) then
  1421. realNum = tonumber(maxAttrNum) - table.count(lockattr)
  1422. else
  1423. realNum = result[1]
  1424. end
  1425. local attdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "level", lv)
  1426. local entrytable = build_weight_attr(attdata, ext.regenerationattr, lockattr)
  1427. local entryattr = random_weighted(entrytable, realNum)
  1428. --把这次结果临时存一下
  1429. local xilianattr = {}
  1430. for _, key in pairs(lockattr) do
  1431. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1432. end
  1433. for _, key in pairs(entryattr) do
  1434. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1435. end
  1436. local allequiprecord = getplaydef(actor, "T$regeneration")
  1437. if allequiprecord == nil then
  1438. allequiprecord = {}
  1439. end
  1440. local regenerationresult = {}
  1441. regenerationresult.entryAttr = xilianattr
  1442. regenerationresult.itemId = itemId
  1443. allequiprecord[itemId] = regenerationresult
  1444. setplaydef(actor, "T$regeneration", allequiprecord)
  1445. allequip[itemId] = ext
  1446. setplaydef(actor, "T$luaitemextdata", allequip)
  1447. --告诉客户端本次洗练结果
  1448. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_REGENERATION, xilianattr)
  1449. end
  1450. function EquipAndAppear.getupregenerationattr(actor, msgData)
  1451. local itemId = msgData.itemId
  1452. local data = getplaydef(actor, "T$regeneration")
  1453. if data == nil then
  1454. sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, {})
  1455. return
  1456. end
  1457. local result = data[itemId]
  1458. if result == nil then
  1459. result = {}
  1460. end
  1461. sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, result)
  1462. end
  1463. --确认替换词条
  1464. function EquipAndAppear.confirmreplaceentry(actor, msgData)
  1465. -- local lockattr = msgData.lockattrpos
  1466. local itemId = msgData.itemId
  1467. local alldata = getplaydef(actor, "T$regeneration")
  1468. if alldata == nil then
  1469. sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!")
  1470. return
  1471. end
  1472. local data = alldata[itemId]
  1473. if data == nil then
  1474. sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!")
  1475. return
  1476. end
  1477. if data.itemId ~= itemId then
  1478. sendluamsg(actor, LuaMessageIdToClient.TIPS, "两次itemId不一致!")
  1479. return
  1480. end
  1481. local allequip = getplaydef(actor, "T$luaitemextdata")
  1482. local ext = allequip[itemId]
  1483. ext.regenerationattr = {}
  1484. for _, id in pairs(data.entryAttr) do
  1485. local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  1486. if table.count(td) ~= 0 then
  1487. local attr = td[1].att
  1488. local str = string.split(attr, "#")
  1489. local dd = {}
  1490. dd[str[1]] = tonumber(str[2])
  1491. dd.id = id
  1492. ext.regenerationattr[tostring(table.count(ext.regenerationattr) + 1)] = dd
  1493. ext.regenerationlv = tonumber(td[1].level)
  1494. end
  1495. end
  1496. allequip[itemId] = ext
  1497. EquipAndAppear.SetItemExtData(actor, itemId, ext)
  1498. setplaydef(actor, "T$luaitemextdata", allequip)
  1499. alldata[itemId] = {}
  1500. setplaydef(actor, "T$regeneration", alldata)
  1501. --给客户端发替换结果
  1502. sendluamsg(actor, LuaMessageIdToClient.RES_REPLACE_REGENERATION_ATTR, true)
  1503. --更新强化追加等属性
  1504. EquipAndAppear.updateluaextattr(actor)
  1505. end
  1506. --词条强化
  1507. function EquipAndAppear.strengthregenerationattr(actor, msgData)
  1508. local itemId = msgData.itemId
  1509. local allequip = getplaydef(actor, "T$luaitemextdata")
  1510. local ext = allequip[itemId]
  1511. local equip = getequipinfo(actor, itemId, 1)
  1512. local group = ConfigDataManager.getTableValue("cfg_equip_regeneration", "group", "id", equip.cfgid)
  1513. local lv = ext.regenerationlv
  1514. local data = ConfigDataManager.getTable("cfg_equip_regenerationCost", "group", group, "level", lv)
  1515. if table.count(data) == 0 then
  1516. sendluamsg(actor, LuaMessageIdToClient.TIPS, "当前装备词条不能强化!")
  1517. return
  1518. end
  1519. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip.cfgid)
  1520. if tonumber(maxLevel) < lv + 1 then
  1521. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已再生到最大等级")
  1522. return
  1523. end
  1524. local str = data[1].cost
  1525. local cost = splitbyshuxianandjinghao(str)
  1526. --检查材料
  1527. local enough = Bag.checkItemEnough(actor, cost)
  1528. if enough == false then
  1529. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1530. return
  1531. end
  1532. --扣道具
  1533. for _, v in ipairs(cost) do
  1534. local cId = v["cfgid"]
  1535. local count = v["count"]
  1536. removeitemfrombag(actor, cId, count, 0, 9999, '装备外观')
  1537. end
  1538. --计算成功率
  1539. local rate = data[1].rate
  1540. local randomNum = math.random(1, 10000)
  1541. if randomNum > tonumber(rate) then
  1542. --强化失败
  1543. sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, false)
  1544. return
  1545. end
  1546. --强化成功增加属性
  1547. local regenerationattr = ext.regenerationattr
  1548. for i, value in pairs(regenerationattr) do
  1549. local key = value.id
  1550. local data = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", key)
  1551. if table.count(data) ~= 0 then
  1552. local sequence = data[1].sequence
  1553. --查找下一级属性
  1554. local nextdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "sequence", sequence, "level", lv + 1)
  1555. if table.count(nextdata) ~= 0 then
  1556. local att = nextdata[1].att
  1557. local attr = string.split(att, "#")
  1558. local dd = {}
  1559. dd[attr[1]] = tonumber(attr[2])
  1560. dd.id = tonumber(nextdata[1].id)
  1561. ext.regenerationattr[i] = dd
  1562. -- table.remove(ext.regenerationattr,key)
  1563. end
  1564. end
  1565. end
  1566. ext.regenerationlv = lv + 1
  1567. allequip[itemId] = ext
  1568. EquipAndAppear.SetItemExtData(actor, itemId, ext)
  1569. setplaydef(actor, "T$luaitemextdata", allequip)
  1570. --给客户端发消息
  1571. sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, true)
  1572. --更新强化追加等属性
  1573. EquipAndAppear.updateluaextattr(actor)
  1574. --更新洗练未替换的数据
  1575. updateregenoreplaceattr(actor, itemId, ext.regenerationlv, group)
  1576. end
  1577. function updateregenoreplaceattr(actor, itemId, lv, group)
  1578. local alldata = getplaydef(actor, "T$regeneration")
  1579. if alldata == nil then
  1580. return
  1581. end
  1582. local data = alldata[itemId]
  1583. if data == nil then
  1584. return
  1585. end
  1586. local attrs = data.entryAttr
  1587. if attrs == nil then
  1588. return
  1589. end
  1590. for i, id in pairs(data.entryAttr) do
  1591. local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  1592. if table.count(td) ~= 0 then
  1593. local sequence = td[1].sequence
  1594. --查找对应等级属性
  1595. local nextdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "sequence", sequence, "level", lv)
  1596. if table.count(nextdata) ~= 0 then
  1597. attrs[i] = tonumber(nextdata[1].id)
  1598. end
  1599. end
  1600. end
  1601. data.entryAttr = attrs
  1602. alldata[itemId] = data
  1603. setplaydef(actor, "T$regeneration", alldata)
  1604. end
  1605. function mergeitemcost(cost, lockcost)
  1606. for _, item in pairs(lockcost) do
  1607. local flag = true
  1608. for _, value in pairs(cost) do
  1609. if item.cfgid == value.cfgid then
  1610. value.count = value.count + item.count
  1611. flag = false
  1612. end
  1613. end
  1614. if flag then
  1615. table.insert(cost, item)
  1616. end
  1617. end
  1618. return cost
  1619. end
  1620. function getlockcost(cost, lockattr)
  1621. local result = {}
  1622. local locknum = table.count(lockattr)
  1623. local lc = string.split(cost, "|")
  1624. local str = {}
  1625. if locknum ~= 0 then
  1626. str = string.split(lc[locknum], "&")
  1627. for _, value in pairs(str) do
  1628. local item = string.split(value, "#")
  1629. local i = {}
  1630. i.cfgid = item[1]
  1631. i.count = item[2]
  1632. table.insert(result, i)
  1633. end
  1634. else
  1635. result = splitbyshuxianandjinghao(cost)
  1636. end
  1637. return result
  1638. end
  1639. --根据权重随机词条数量
  1640. function random_weighted(weight_str, count)
  1641. local result = {}
  1642. if count <= 0 then
  1643. return result
  1644. end
  1645. local num = string.split(weight_str, "&")
  1646. local weight_total = 0
  1647. for _, value in pairs(num) do
  1648. local sum = string.split(value, "#")
  1649. weight_total = weight_total + tonumber(sum[2])
  1650. end
  1651. local random_weight = math.random(1, weight_total)
  1652. local cumulative_weight = 0
  1653. for _, value in pairs(num) do
  1654. local sum = string.split(value, "#")
  1655. local weight = tonumber(sum[2])
  1656. cumulative_weight = cumulative_weight + weight
  1657. if cumulative_weight >= random_weight then
  1658. table.insert(result, tonumber(sum[1]))
  1659. if table.count(result) == count then
  1660. return result
  1661. end
  1662. end
  1663. end
  1664. end
  1665. --构造随机词条权重库
  1666. function build_weight_attr(attdata, regenenrationattr, lockattr)
  1667. local entrystr = ""
  1668. for i, value in pairs(attdata) do
  1669. local len = #entrystr
  1670. local id = value.id
  1671. local flag = true
  1672. for _, k in pairs(lockattr) do
  1673. if k == id then
  1674. table.remove(attdata, i)
  1675. flag = false
  1676. end
  1677. end
  1678. if flag then
  1679. local weight = 0
  1680. for key, v in pairs(regenenrationattr) do
  1681. if key == id then
  1682. weight = value.weightdown
  1683. end
  1684. end
  1685. if weight == 0 then
  1686. weight = value.weight
  1687. end
  1688. if len == 0 then
  1689. entrystr = id .. "#" .. weight
  1690. else
  1691. entrystr = entrystr .. "&" .. id .. "#" .. weight
  1692. end
  1693. end
  1694. end
  1695. return entrystr
  1696. end
  1697. function getequipssumstrengthlvtest(actor)
  1698. this.GetSumJewelryLv(actor)
  1699. end
  1700. ---获取角色全身装备强化等级
  1701. function EquipAndAppear.GetEquipsSumStrengthLv(actor)
  1702. return this.GetSumLvByType(actor,EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL)
  1703. end
  1704. ---获取角色全身装备追加等级
  1705. function EquipAndAppear.GetEquipsSumAppendLv(actor)
  1706. return this.GetSumLvByType(actor,EquipAndAppear.RecordeType.MAX_APPEND_LEVEL)
  1707. end
  1708. ---获取角色全身装备卓越词条数量(不包含再生词条)
  1709. function EquipAndAppear.GetEquipsSumExcellentEntryCount(actor)
  1710. return this.GetEquipsSumExcellentEntryCount(actor)
  1711. end
  1712. ---获取角色全身装备卓越词条数量(不包含再生词条)
  1713. function this.GetEquipsSumExcellentEntryCount(actor)
  1714. local allEquip = getputonequipinfo(actor)
  1715. if table.isNullOrEmpty(allEquip) then
  1716. return 0
  1717. end
  1718. local sumCount = 0
  1719. for _, equip in pairs(allEquip) do
  1720. local entryAttrMap = equip.entries
  1721. if not table.isNullOrEmpty(entryAttrMap) then
  1722. sumCount = sumCount + table.count(entryAttrMap)
  1723. end
  1724. end
  1725. return sumCount
  1726. end
  1727. ---获取全身首饰等级
  1728. function this.GetSumJewelryLv(actor)
  1729. return this.GetSumLvByType(actor,EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL)
  1730. end
  1731. function this.GetSumLvByType(actor,lvType)
  1732. local equipList = getputonequipinfo(actor)
  1733. if table.isNullOrEmpty(equipList) then
  1734. return 0
  1735. end
  1736. local allEquip = EquipAndAppear.getLuaItemExtData(actor)
  1737. if table.isNullOrEmpty(allEquip) then
  1738. return 0
  1739. end
  1740. local sumLv = 0
  1741. for _, equipInfo in pairs(equipList) do
  1742. local itemId = equipInfo.id
  1743. local equip = allEquip[itemId]
  1744. local lv = this.GetEquipLvByType(equip, lvType)
  1745. if lv ~= 0 then
  1746. sumLv = sumLv + lv
  1747. end
  1748. end
  1749. return sumLv
  1750. end
  1751. function this.GetEquipLvByType(equip, lvType)
  1752. if table.isNullOrEmpty(equip) then
  1753. return 0
  1754. end
  1755. local lv = 0
  1756. if lvType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  1757. lv = equip.strengthlv
  1758. elseif lvType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  1759. lv = equip.appendlv
  1760. elseif lvType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  1761. lv = equip.ssuplv
  1762. end
  1763. if lv == nil then
  1764. return 0
  1765. end
  1766. return tonumber(lv)
  1767. end
  1768. ---更新装备信息记录
  1769. function EquipAndAppear.TryUpdateEquipInfoRecorde(actor, recordeType)
  1770. this.TryUpdateEquipInfoRecorde(actor, recordeType)
  1771. end
  1772. ---更新装备信息记录
  1773. function this.TryUpdateEquipInfoRecorde(actor, recordeType)
  1774. local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor)
  1775. if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  1776. local oldLv = equipInfoRecorde.max_strength_level
  1777. local newLv = EquipAndAppear.GetEquipsSumStrengthLv(actor)
  1778. if newLv > oldLv then
  1779. equipInfoRecorde.max_strength_level = newLv
  1780. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  1781. end
  1782. OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_STRENGTHEN_LV, newLv)
  1783. OpenServerCompetition.updateRankData(actor, CompetitionType.STRENGTHEN, newLv)
  1784. elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  1785. local oldLv = equipInfoRecorde.max_append_level
  1786. local newLv = EquipAndAppear.GetEquipsSumAppendLv(actor)
  1787. if newLv > oldLv then
  1788. equipInfoRecorde.max_append_level = newLv
  1789. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  1790. end
  1791. OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_APPEND_LV, newLv)
  1792. OpenServerCompetition.updateRankData(actor, CompetitionType.APPEND, newLv)
  1793. elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then
  1794. local oldCount = equipInfoRecorde.max_entry_count
  1795. local newCount = this.GetEquipsSumExcellentEntryCount(actor)
  1796. if newCount > oldCount then
  1797. equipInfoRecorde.max_entry_count = newCount
  1798. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  1799. OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.SUPERIOR_ENTRY_COUNT, newCount)
  1800. end
  1801. elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  1802. local oldLv = equipInfoRecorde.max_jewelry_level
  1803. local newLv = this.GetSumJewelryLv(actor)
  1804. if newLv > oldLv then
  1805. equipInfoRecorde.max_jewelry_level = newLv
  1806. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  1807. end
  1808. OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.JEWELRY_LEVEL, newLv)
  1809. end
  1810. end
  1811. function EquipAndAppear.GetEquipInfoRecordeValue(actor, recordeType)
  1812. local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor)
  1813. if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  1814. return equipInfoRecorde.max_strength_level
  1815. elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  1816. return equipInfoRecorde.max_append_level
  1817. elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then
  1818. return equipInfoRecorde.max_entry_count
  1819. elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  1820. return equipInfoRecorde.max_jewelry_level
  1821. end
  1822. return 0
  1823. end
  1824. function EquipAndAppear.CheckPartEquipStrengthLv(actor, part, goalLv)
  1825. local equipList = getputonequipinfo(actor)
  1826. if table.isNullOrEmpty(equipList) then
  1827. return false
  1828. end
  1829. local allData = EquipAndAppear.getLuaItemExtData(actor)
  1830. if table.isNullOrEmpty(allData) then
  1831. return false
  1832. end
  1833. for _, equipInfo in pairs(equipList) do
  1834. local itemId = equipInfo.id
  1835. local cfgId = equipInfo.cfgid
  1836. local equipData = allData[itemId]
  1837. if not table.isNullOrEmpty(equipData) then
  1838. local strengthLv = equipData.strengthlv
  1839. if part == nil and strengthLv >= goalLv then
  1840. return true
  1841. end
  1842. if part ~= nil then
  1843. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  1844. if tonumber(strPart) == part and strengthLv >= goalLv then
  1845. return true
  1846. end
  1847. end
  1848. end
  1849. end
  1850. return false
  1851. end
  1852. function checkspecificstageequipcounttest(actor)
  1853. EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, equipType)
  1854. end
  1855. ---检查阶段装备数量
  1856. function EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, ratingLimit)
  1857. local allEquip = getputonequipinfo(actor)
  1858. if table.isNullOrEmpty(allEquip) then
  1859. return 0
  1860. end
  1861. local sumCount = 0
  1862. for _, equip in pairs(allEquip) do
  1863. local cfgId = equip.cfgid
  1864. local armor = this.IsArmor(cfgId)
  1865. if armor then
  1866. local stage = tonumber(ConfigDataManager.getTableValue("cfg_item", "rank", "id", cfgId))
  1867. if stage ~= nil and (stageLimit == nil or stage >= stageLimit) then
  1868. local rating = EquipAndAppear.GetEquipRating(cfgId)
  1869. if table.isNullOrEmpty(ratingLimit) or ratingLimit == rating or table.contains(ratingLimit, rating) then
  1870. sumCount = sumCount + 1
  1871. end
  1872. end
  1873. end
  1874. end
  1875. return sumCount
  1876. end
  1877. ---获取装备评级
  1878. function EquipAndAppear.GetEquipRating(itemCfgId)
  1879. local ratingScore = tonumber(ConfigDataManager.getTableValue("cfg_equip_entrylib", "initialrating", "id", itemCfgId))
  1880. if ratingScore == nil then
  1881. return 0
  1882. end
  1883. local equipQualityCfgList = ConfigDataManager.getTable("cfg_equip_quality")
  1884. if table.isNullOrEmpty(equipQualityCfgList) then
  1885. return 0
  1886. end
  1887. for rating, equipQualityCfg in pairs(equipQualityCfgList) do
  1888. local stageParam = string.split(equipQualityCfg["stage"], "#")
  1889. if ratingScore >= tonumber(stageParam[1]) and ratingScore <= tonumber(stageParam[2]) then
  1890. return tonumber(rating)
  1891. end
  1892. end
  1893. return 0
  1894. end
  1895. ---是否防具
  1896. function this.IsArmor(cfgId)
  1897. --策划要求代码写死
  1898. local strPart = tonumber(ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId))
  1899. if strPart == nil then
  1900. return false
  1901. end
  1902. if strPart == 4 or strPart == 5 or strPart == 6 or strPart == 7 or strPart == 8 then
  1903. return true
  1904. end
  1905. return false
  1906. end
  1907. function EquipAndAppear.SetItemExtData(actor, itemId, equipData)
  1908. local result = setitemextdata(actor, itemId, equipData)
  1909. if result == nil or result == false then
  1910. gameDebug.assertPrintTrace(false, actor, "setitemextdata失败!", itemId, equipData)
  1911. end
  1912. end
  1913. --
  1914. --
  1915. --function EquipAndAppear.CheckPartEquipStrengthLv(actor, part,goalLv)
  1916. -- EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, "strengthlv")
  1917. --end
  1918. --
  1919. --function EquipAndAppear.CheckPartEquipAppendLv(actor, part, goalLv)
  1920. --
  1921. --end
  1922. --
  1923. --function EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, param)
  1924. -- jprint("--------------1", part, goalLv, param)
  1925. -- local allData = EquipAndAppear.getLuaItemExtData(actor)
  1926. -- if table.isNullOrEmpty(allData) then
  1927. -- return false
  1928. -- end
  1929. -- for itemId, equipData in pairs(allData) do
  1930. -- gameDebug.print("---- equip ----", itemId, equipData)
  1931. -- local strengthLv = equipData[param]
  1932. -- if part == nil and strengthLv >= goalLv then
  1933. -- return true
  1934. -- end
  1935. -- if part ~= nil then
  1936. -- local equip = getequipinfo(actor, itemId,1)
  1937. -- if not table.isNullOrEmpty(equip) then
  1938. -- local cfgId = equip.cfgid
  1939. -- local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  1940. -- if tonumber(strPart) == part and strengthLv >= goalLv then
  1941. -- return true
  1942. -- end
  1943. -- end
  1944. -- end
  1945. -- end
  1946. -- return false
  1947. --end