EquipAndAppear.lua 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683
  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. ---装备bind数据修复
  31. local EQUIP_BIND_DATA_REPAIR = "T$equipbinddatarepair"
  32. local EQUIP_UP_DATA_REPAIR = "T$equipssupdatarepair"
  33. function EquipAndAppear.login(actor)
  34. RepairRoleData.action(
  35. actor,
  36. EQUIP_BIND_DATA_REPAIR,
  37. 202503192016,
  38. EquipAndAppear.repairEquipBindData2025_03_19,
  39. actor
  40. )
  41. RepairRoleData.action(
  42. actor,
  43. EQUIP_UP_DATA_REPAIR,
  44. 202503241400,
  45. EquipAndAppear.repairEquipSsupData2025_03_24,
  46. actor
  47. )
  48. EquipAndAppear.UpdateWear(actor)
  49. end
  50. function EquipAndAppear.onLogout(actor)
  51. local rid = getbaseinfo(actor, "rid")
  52. local list = getnarplayer(actor)
  53. for k, v in pairs(list) do
  54. local targetActor = getactor(actor, v.rid)
  55. sendluamsg(
  56. targetActor,
  57. 10000500,
  58. {
  59. playerid = rid
  60. }
  61. )
  62. end
  63. end
  64. function EquipAndAppear.repairEquipBindData2025_03_19(actor)
  65. local allData = EquipAndAppear.getLuaItemExtData(actor)
  66. local infos = getallequipinfo(actor)
  67. for _, equip in pairs(infos) do
  68. if this.checkEquipData(actor, allData, equip.id) then
  69. changeitembindstate(actor, equip.id, 1)
  70. end
  71. end
  72. info(actor, "修复bind数据成功")
  73. end
  74. ---装备首饰升级数据修复
  75. function EquipAndAppear.repairEquipSsupData2025_03_24(actor)
  76. local allData = EquipAndAppear.getLuaItemExtData(actor)
  77. local infos = getallequipinfo(actor)
  78. for _, equip in pairs(infos) do
  79. local cfgId = equip.cfgid
  80. local itemId = tonumber(equip.id)
  81. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  82. if group ~= nil and group ~= "" then
  83. local equipext = allData[itemId]
  84. if equipext then
  85. local ssUpLv = equipext.ssuplv or 0
  86. local ornaments =
  87. ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", ssUpLv)
  88. if (ornaments == nil) and ssUpLv > 0 then
  89. -- 修复数据
  90. for i = ssUpLv - 1, 1, -1 do
  91. local newNaments =
  92. ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", i)
  93. if newNaments and table.count(newNaments) > 0 then
  94. equipext.ssuplv = i
  95. local att = newNaments[1].basicatt
  96. local attr = splitbyshuxianandjinghao2(att)
  97. equipext.ssupattr = attr
  98. EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  99. allData[itemId] = equipext
  100. setplaydef(actor, "T$luaitemextdata", allData)
  101. break
  102. end
  103. end
  104. end
  105. end
  106. end
  107. end
  108. info(actor, "修复首饰升级数据成功")
  109. end
  110. function this.checkEquipData(actor, allData, itemId)
  111. local equipData = allData[tonumber(itemId)]
  112. if not equipData then
  113. return false
  114. end
  115. if equipData.strengthlv ~= 0 then
  116. return true
  117. end
  118. if equipData.appendlv ~= 0 then
  119. return true
  120. end
  121. local equip = getequipinfo(actor, itemId, 1)
  122. if table.count(equip.entries) > 2 then
  123. return true
  124. end
  125. return false
  126. end
  127. function EquipAndAppear.GetEquipInfoRecorde(actor)
  128. local equipInfoRecorde = getplaydef(actor, ROLE_EQUIP_INFO_RECORDE)
  129. if equipInfoRecorde == nil then
  130. equipInfoRecorde = this.GetNewEquipInfoRecorde()
  131. end
  132. return equipInfoRecorde
  133. end
  134. function this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  135. setplaydef(actor, ROLE_EQUIP_INFO_RECORDE, equipInfoRecorde)
  136. end
  137. -- 保存角色外观(幻化也走这个方法)
  138. function EquipAndAppear.settingequipappear(actor, msgData)
  139. local equipappear = msgData["equipindex"]
  140. local data = {}
  141. for _, value in pairs(equipappear) do
  142. local pos = tonumber(value["slot"])
  143. local cfgId = tonumber(value["cfgId"])
  144. if pos ~= nil then
  145. data[pos] = cfgId
  146. end
  147. end
  148. setitemappeardata(actor, data)
  149. sendluamsg(actor, LuaMessageIdToClient.RES_SETTING_EQUIP_APPEAR, data)
  150. NewEquipWear.UpdateWear(actor, data)
  151. EquipAndAppear.UpdateWear(actor)
  152. end
  153. -- 初始化角色外观
  154. function initequipppear(actor)
  155. local equipappear = {}
  156. setplaydef(actor, "T$equipappear", equipappear)
  157. end
  158. -- 获取角色外观
  159. function EquipAndAppear.getequipappear(actor, msgId)
  160. local data = getrolefield(actor, "role.roleappear.appear")
  161. if data == nil then
  162. return
  163. end
  164. -- local lv = API.GetItemData(actor,itemId,"strengthlv") or 0
  165. -- local infos = getallequipinfo(actor)
  166. local infos = getputonequipinfo(actor)
  167. local result = {}
  168. local tmpEquipSlots = {}
  169. for k, v in pairs(infos) do
  170. local equip = infos[k]
  171. local pos = gameequip.pos(equip.equipindex)
  172. tmpEquipSlots[pos] = API.GetItemData(actor, equip.id, "strengthlv") or 0
  173. end
  174. for key, value in pairs(data) do
  175. local appear = {}
  176. appear["slot"] = key
  177. appear["cfgId"] = value
  178. appear["lv"] = tmpEquipSlots[key] or 0
  179. table.insert(result, appear)
  180. end
  181. -- 发送lua消息到客户端
  182. if LuaMessageIdToSever.GET_EQUIP_APPEAR == msgId then
  183. sendluamsg(actor, LuaMessageIdToClient.GET_EQUIP_APPEAR, result)
  184. end
  185. return result
  186. end
  187. function EquipAndAppear.UpdateWear(actor)
  188. -- local data = getrolefield(actor, "role.roleappear.appear")
  189. -- if data == nil then
  190. -- return
  191. -- end
  192. -- local infos = getallequipinfo(actor)
  193. -- local result = {}
  194. -- local tmpEquipSlots = {}
  195. -- for k, v in pairs(infos) do
  196. -- local equip = infos[k]
  197. -- local pos = gameequip.pos(equip.equipindex)
  198. -- tmpEquipSlots[pos] = API.GetItemData(actor, equip.id, "strengthlv") or 0
  199. -- end
  200. -- for key, value in pairs(data) do
  201. -- local appear = {}
  202. -- appear["slot"] = key
  203. -- appear["cfgId"] = value
  204. -- appear["lv"] = tmpEquipSlots[key] or 0
  205. -- table.insert(result, appear)
  206. -- end
  207. -- local rid = getbaseinfo(actor, "rid")
  208. -- local list = getnarplayer(actor)
  209. -- for k, v in pairs(list) do
  210. -- sendluamsg(v.rid, LuaMessageIdToSever.UpdateWear, {rid = rid, data = result, oriData = data})
  211. -- end
  212. -- 发送幻化染色数据
  213. local appear = EquipAndAppear.getequipappear(actor, 0)
  214. local title = EquipAndAppear.gettitleinfo(actor, 0)
  215. local alldata = {}
  216. alldata["appear"] = appear
  217. alldata["ring"] = EquipAndAppear.getnowwearshapering(actor)
  218. local curTitle = 0
  219. if not title.hidden then
  220. curTitle = title.curEquipTitle
  221. end
  222. alldata["title"] = curTitle
  223. local rid = getbaseinfo(actor, "rid")
  224. alldata["rid"] = rid
  225. local isTransfet = APIGetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET")
  226. if isTransfet ~= nil and isTransfet > 0 then
  227. -- local isTransfet = APIGetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET")
  228. APISetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET", 0)
  229. return
  230. end
  231. local list = getnarplayer(actor)
  232. for k, v in pairs(list) do
  233. local targetActor = getactor(actor, v.rid)
  234. sendluamsg(targetActor, LuaMessageIdToClient.OTHER_ROLE_APPEAR, alldata)
  235. end
  236. end
  237. -- 外观幻化激活
  238. function EquipAndAppear.equipfashion(actor, msgData)
  239. local cfgIds = msgData["cfgIds"]
  240. local equipFashion = getplaydef(actor, "T$equipfashion")
  241. if equipFashion == nil then
  242. equipFashion = {}
  243. end
  244. for _, cfgId in pairs(cfgIds) do
  245. local isExist = table.contains(equipFashion, cfgId)
  246. if isExist then
  247. -- 存在已激活的
  248. return
  249. end
  250. end
  251. -- 计算所有消耗
  252. local allData = getAllEquipAppearCost(cfgIds, 4)
  253. if allData == nil then
  254. return
  255. end
  256. -- 检查背包是否道具充足
  257. local enough = Bag.checkItemEnough(actor, allData)
  258. if enough == false then
  259. return
  260. end
  261. -- 扣材料
  262. for _, v in ipairs(allData) do
  263. local cId = v["cfgid"]
  264. local count = v["count"]
  265. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  266. end
  267. -- 保存幻化
  268. for _, v in pairs(cfgIds) do
  269. table.insert(equipFashion, v)
  270. end
  271. setplaydef(actor, "T$equipfashion", equipFashion)
  272. sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_FASHION, equipFashion)
  273. end
  274. -- 获取已激活外观
  275. function EquipAndAppear.getallequipfashion(actor)
  276. local equipFashion = getplaydef(actor, "T$equipfashion")
  277. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_FASHION, equipFashion)
  278. end
  279. -- 激活染色
  280. function EquipAndAppear.actquipcolor(actor, msgData)
  281. local cfgIds = msgData["cfgIds"]
  282. local color = msgData["color"]
  283. -- 计算消耗材料
  284. local allCost = getAllEquipAppearCost(cfgIds, 5)
  285. if allCost == nil then
  286. return
  287. end
  288. -- 检查背包是否道具充足
  289. local enough = Bag.checkItemEnough(actor, allCost)
  290. if enough == false then
  291. return
  292. end
  293. -- 扣材料
  294. for _, v in ipairs(allCost) do
  295. local cId = v["cfgid"]
  296. local count = v["count"]
  297. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  298. end
  299. -- 染色
  300. local equipcolor = EquipAndAppear.getequipcolor(actor, 0)
  301. for i, v in ipairs(cfgIds) do
  302. local num = 0
  303. for _, val in pairs(equipcolor) do
  304. if val["cfgid"] == v then
  305. table.insert(val["color"], color)
  306. num = num + 1
  307. break
  308. end
  309. end
  310. if num == 0 then
  311. local dt = {}
  312. dt["cfgid"] = v
  313. dt["color"] = {}
  314. table.insert(dt["color"], color)
  315. table.insert(equipcolor, dt)
  316. end
  317. end
  318. setplaydef(actor, "actequipcolor", equipcolor)
  319. end
  320. -- 保存染色
  321. function EquipAndAppear.settingequipcolor(actor, msgData)
  322. local cfgId = msgData["cfgid"]
  323. local color = msgData["color"]
  324. -- 先校验是否激活该颜色
  325. local actequipcolor = getplaydef(actor, "T$actequipcolor")
  326. local bool = false
  327. for _, v in pairs(actequipcolor) do
  328. local cId = v["cfgid"]
  329. if cId == cfgId then
  330. bool = table.contains(v["color"], color)
  331. break
  332. end
  333. end
  334. if bool ~= true then
  335. return
  336. end
  337. local equipcolor = EquipAndAppear.getequipcolor(actor, 0)
  338. for _, v in ipairs(equipcolor) do
  339. if v["cfgid"] == cfgId then
  340. v["color"] = color
  341. break
  342. end
  343. end
  344. setplaydef(actor, "T$equipcolor", equipcolor)
  345. end
  346. -- 获取角色染色数据
  347. function EquipAndAppear.getequipcolor(actor, msgId)
  348. local equipcolor = getplaydef(actor, "T$equipcolor")
  349. if equipcolor == nil then
  350. equipcolor = {}
  351. setplaydef(actor, "T$equipcolor", equipcolor)
  352. end
  353. local data = getplaydef(actor, "T$equipcolor")
  354. -- 发送lua消息到客户端
  355. if msgId == LuaMessageIdToClient.GET_EQUIP_COLOR then
  356. sendluamsg(actor, msgId, data)
  357. end
  358. return data
  359. end
  360. -- 计算所有消耗
  361. function getAllEquipAppearCost(cfgIds, type)
  362. local allData = {}
  363. for _, cfgId in pairs(cfgIds) do
  364. local cost = ConfigDataManager.getTableValue("cfg_fashion", "deplete", "id", cfgId, "type", type)
  365. if cost == nil then
  366. return nil
  367. end
  368. local data = splitbyshuxianandjinghao(cost)
  369. for _1, v in pairs(data) do
  370. local id = v["cfgid"]
  371. local count = v["count"]
  372. local num = 0
  373. for _2, val in pairs(allData) do
  374. if val["cfgid"] == id then
  375. val["count"] = val["count"] + count
  376. num = num + 1
  377. break
  378. end
  379. end
  380. if num == 0 then
  381. local element = {}
  382. element["cfgid"] = id
  383. element["count"] = count
  384. table.insert(allData, element)
  385. end
  386. end
  387. end
  388. return allData
  389. end
  390. function EquipAndAppear.playerequipview(actor, otherActor)
  391. if otherActor == nil then
  392. return
  393. end
  394. -- 发送幻化染色数据
  395. local appear = EquipAndAppear.getequipappear(otherActor, 0)
  396. local title = EquipAndAppear.gettitleinfo(otherActor, 0)
  397. local alldata = {}
  398. alldata["appear"] = appear
  399. alldata["ring"] = EquipAndAppear.getnowwearshapering(otherActor)
  400. local curTitle = 0
  401. if not title.hidden then
  402. curTitle = title.curEquipTitle
  403. end
  404. alldata["title"] = curTitle
  405. local rid = getbaseinfo(otherActor, "rid")
  406. alldata["rid"] = rid
  407. sendluamsg(actor, LuaMessageIdToClient.OTHER_ROLE_APPEAR, alldata)
  408. end
  409. -- 玩家进入视野时发送玩家装备的强化信息
  410. function EquipAndAppear.playerequipstrength(actor, otherActor)
  411. if otherActor == 0 then
  412. otherActor = actor
  413. end
  414. local alldata = getplaydef(otherActor, "T$luaitemextdata")
  415. local equiplist = getputonequipinfo(otherActor)
  416. local result = {}
  417. local info = {}
  418. for _, equipinfo in pairs(equiplist) do
  419. local itemId = equipinfo.id
  420. local data = alldata[itemId]
  421. local equip = {}
  422. equip.itemid = itemId
  423. if data ~= nil then
  424. if data.strengthlv ~= nil then
  425. equip.strengthlv = data.strengthlv
  426. else
  427. equip.strengthlv = 0
  428. end
  429. else
  430. equip.strengthlv = 0
  431. end
  432. table.insert(info, equip)
  433. end
  434. result.rid = getbaseinfo(otherActor, "rid")
  435. result.equip = info
  436. result = table.valueConvertToString(result)
  437. sendrefluamsg(actor, LuaMessageIdToClient.RES_PLAYER_EQUIP_STRENGTHLV, result)
  438. end
  439. -- 检查表是否包含某个元素
  440. -- function table.contains(table, element)
  441. -- for _, value in pairs(table) do
  442. -- if value == element then
  443. -- return true
  444. -- end
  445. -- end
  446. -- return false
  447. -- end
  448. -- 分割字符串
  449. function splitbyshuxianandjinghao(str)
  450. local dt = {}
  451. local data = string.split(str, "|")
  452. for _, v in ipairs(data) do
  453. local data2 = string.split(v, "#")
  454. local v2 = {}
  455. v2["cfgid"] = data2[1]
  456. v2["count"] = data2[2]
  457. table.insert(dt, v2)
  458. end
  459. return dt
  460. end
  461. -- 称号入包
  462. function EquipAndAppear.titleenterbag(actor, configId)
  463. local itemList = ConfigDataManager.getTable("cfg_item", "id", configId)
  464. if itemList == nil then
  465. return
  466. end
  467. local item = itemList[1]
  468. if tonumber(item.type) ~= 2 or tonumber(item.subtype) ~= 15 then
  469. return
  470. end
  471. -- 计算时间
  472. local fashionList = ConfigDataManager.getTable("cfg_fashion", "id", configId)
  473. if fashionList == nil then
  474. return
  475. end
  476. if table.count(fashionList) == 0 then
  477. return
  478. end
  479. local fashion = fashionList[1]
  480. local titledata = EquipAndAppear.gettitleinfo(actor, 0)
  481. local titles = titledata.title
  482. -- 不限时
  483. local flag = true
  484. local time = 0
  485. local type = 0
  486. local timeType = tonumber(fashion.timetype)
  487. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  488. if timeType == 1 then
  489. type = 1
  490. for _, value in pairs(titles) do
  491. if value.confId == configId then
  492. value.obtainTime = nowTime -- 获得时间
  493. value.expiresTime = -1 -- 到期时间
  494. flag = false
  495. end
  496. end
  497. time = -1
  498. end
  499. -- 限时
  500. if timeType == 2 then
  501. type = 2
  502. -- 获取称号的有效期
  503. local times = fashion.time
  504. local timestr = string.split(times, "#")
  505. -- 总时间
  506. time = tonumber(timestr[1]) * 60 * 60 + tonumber(timestr[2]) * 60 + tonumber(timestr[3])
  507. for _, value in pairs(titles) do
  508. if value.confId == configId then
  509. value.obtainTime = nowTime -- 获得时间
  510. value.expiresTime = value.obtainTime + time -- 到期时间
  511. flag = false
  512. end
  513. end
  514. end
  515. -- 活动限时
  516. if timeType == 3 then
  517. type = 3
  518. -- todo 获取称号的有效期
  519. local actId = fashion.time
  520. local actdata = getactivityinfo(actor, actId)
  521. time = math.ceil(actdata.nextopentime / 1000)
  522. for _, value in pairs(titles) do
  523. if value.confId == configId then
  524. value.obtainTime = nowTime -- 获得时间
  525. value.expiresTime = time -- 到期时间
  526. flag = false
  527. end
  528. end
  529. end
  530. if flag then
  531. local tt = {}
  532. tt.obtainTime = math.ceil(getbaseinfo("now") / 1000)
  533. if type == 1 or type == 3 then
  534. tt.expiresTime = time
  535. else
  536. tt.expiresTime = tt.obtainTime + time
  537. end
  538. tt.confId = configId
  539. table.insert(titles, tt)
  540. end
  541. setplaydef(actor, "T$titledata", titledata)
  542. -- 更新称号属性
  543. EquipAndAppear.updatetitleattr(actor)
  544. end
  545. -- 更新称号属性信息
  546. function EquipAndAppear.updatetitleattr(actor)
  547. local data = getplaydef(actor, "T$titledata")
  548. local titles = data.title
  549. local titleattr = {}
  550. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  551. for _, value in pairs(titles) do
  552. -- 先校验是否过期
  553. if value.expiresTime == -1 or value.expiresTime > nowTime then
  554. -- 计算属性
  555. local fashion = ConfigDataManager.getTable("cfg_fashion", "id", value.confId)
  556. local attr = fashion[1].att
  557. local str = string.split(attr, "|")
  558. for _, value in pairs(str) do
  559. local str2 = string.split(value, "#")
  560. local num = titleattr[str2[1]]
  561. local nowNum = str2[2]
  562. if num == nil then
  563. titleattr[str2[1]] = tonumber(nowNum)
  564. else
  565. titleattr[str2[1]] = tonumber(nowNum) + tonumber(num)
  566. end
  567. end
  568. end
  569. end
  570. -- 更新称号属性
  571. addrolekmlattributes(actor, "titleattr", titleattr)
  572. end
  573. -- 获取称号详细信息
  574. function EquipAndAppear.gettitleinfo(actor, msgId)
  575. local data = getplaydef(actor, "T$titledata")
  576. if data == nil then
  577. data = EquipAndAppear.inittitledata(actor)
  578. end
  579. if msgId == LuaMessageIdToSever.GET_TITLE then
  580. sendluamsg(actor, LuaMessageIdToClient.GET_TITLE, data)
  581. end
  582. return data
  583. end
  584. -- 保存称号外观
  585. function EquipAndAppear.settingtitleappear(actor, msgId, msgData)
  586. local data = getplaydef(actor, "T$titledata")
  587. local titleappear = msgData["title"]
  588. data.curEquipTitle = titleappear
  589. setplaydef(actor, "T$titledata", data)
  590. if msgId == LuaMessageIdToSever.SET_TITLE then
  591. sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, titleappear)
  592. local result = {}
  593. result.rid = getbaseinfo(actor, "rid")
  594. result.curEquipTitle = titleappear
  595. sendrefluamsg(actor, LuaMessageIdToClient.RES_TITLE_CHANGE_UPDATE, result)
  596. end
  597. end
  598. -- 初始化数据
  599. function EquipAndAppear.inittitledata(actor)
  600. local data = {}
  601. data.title = {}
  602. data.hidden = false
  603. data.curEquipTitle = 0
  604. setplaydef(actor, "T$titledata", data)
  605. return data
  606. end
  607. -- 校验称号的过期时间
  608. function EquipAndAppear.checktitleovertime(actor)
  609. local data = getplaydef(actor, "T$titledata")
  610. if table.count(data) == 0 then
  611. data = EquipAndAppear.inittitledata(actor)
  612. end
  613. local titles = data.title
  614. if table.count(titles) == 0 then
  615. return
  616. end
  617. local curTitle = data.curEquipTitle
  618. local flag = false
  619. local nowTime = math.ceil(getbaseinfo("now") / 1000)
  620. for key, value in pairs(titles) do
  621. -- 先校验是否过期
  622. -- jprint("检查称号过期0",value.expiresTime > nowTime, value.expiresTime, nowTime)
  623. if value.expiresTime ~= -1 and value.expiresTime < nowTime then
  624. table.remove(titles, key)
  625. flag = true
  626. if curTitle == value.confId then
  627. data.curEquipTitle = 0
  628. end
  629. end
  630. end
  631. if flag then
  632. data.title = titles
  633. setplaydef(actor, "T$titledata", data)
  634. EquipAndAppear.updatetitleattr(actor)
  635. -- 发送消息
  636. sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, 0)
  637. end
  638. end
  639. -- 获取守护外观
  640. function EquipAndAppear.getguardappear(actor, msgId)
  641. local data = getrolefield(actor, "role.roleEquip.guardAppear")
  642. if data == nil then
  643. sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, {})
  644. return {}
  645. end
  646. local result = {}
  647. for key, value in pairs(data) do
  648. local mm = {}
  649. mm.att = value.attr
  650. mm.getTime = math.floor(value.getTime / 1000)
  651. mm.itemId = key
  652. if value.time ~= -1 then
  653. mm.time = mm.getTime + math.floor(value.time / 1000)
  654. else
  655. mm.time = -1
  656. end
  657. table.insert(result, mm)
  658. end
  659. if msgId == LuaMessageIdToSever.GET_GUARD_APPEAR then
  660. sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, result)
  661. end
  662. return data
  663. end
  664. -- 获取变身戒指数据
  665. function EquipAndAppear.getshapering(actor, msgId)
  666. local data = getrolefield(actor, "role.roleEquip.shapeRing")
  667. if data == nil then
  668. return {}
  669. end
  670. local nowwear = EquipAndAppear.getnowwearshapering(actor)
  671. local rd = {}
  672. local result = {}
  673. rd.curWearRing = nowwear
  674. for key, value in pairs(data) do
  675. local mm = {}
  676. mm.monsterId = tonumber(key)
  677. mm.ringAttr = value.ringAttr
  678. mm.getTime = math.floor(value.getTime / 1000)
  679. mm.itemId = value.itemId
  680. if value.time ~= -1 then
  681. mm.time = math.floor(value.time / 1000)
  682. else
  683. mm.time = -1
  684. end
  685. table.insert(result, mm)
  686. end
  687. rd.title = result
  688. if msgId == LuaMessageIdToSever.GET_SHAPE_RING then
  689. sendluamsg(actor, LuaMessageIdToClient.GET_SHAPE_RING, rd)
  690. end
  691. return data
  692. end
  693. -- 穿戴变身戒指
  694. function EquipAndAppear.wearshapering(actor, msgData)
  695. local monsterId = msgData["monsterId"]
  696. setplaydef(actor, "T$wearshapering", monsterId)
  697. setshaperingdata(actor, monsterId)
  698. sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, monsterId)
  699. local result = {}
  700. result.rid = getbaseinfo(actor, "rid")
  701. result.curEquipRing = monsterId
  702. sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  703. end
  704. -- 获取当前穿戴的变身戒指
  705. function EquipAndAppear.getnowwearshapering(actor)
  706. local data = getplaydef(actor, "T$wearshapering")
  707. if data == nil then
  708. return 0
  709. end
  710. return data
  711. end
  712. -- 校验变身戒指过期时间
  713. function EquipAndAppear.checkringovertime(actor)
  714. local data = EquipAndAppear.getshapering(actor)
  715. local ringId = EquipAndAppear.getnowwearshapering(actor)
  716. if ringId == 0 then
  717. return
  718. end
  719. local monsterId = ConfigDataManager.getTableValue("cfg_item", "useParam", "id", ringId)
  720. if not monsterId then
  721. return
  722. end
  723. if not data[tostring(monsterId)] then
  724. setplaydef(actor, "T$wearshapering", 0)
  725. sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0)
  726. local result = {}
  727. result.rid = getbaseinfo(actor, "rid")
  728. result.curEquipRing = 0
  729. sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  730. end
  731. -- local nowTime = math.ceil(getbaseinfo("now") / 1000)
  732. -- for index, ring in pairs(data) do
  733. -- if ring ~= -1 then
  734. -- --检查
  735. -- if nowTime > math.floor(ring.time / 1000) then
  736. -- --删除穿戴外观
  737. -- local ringId = EquipAndAppear.getnowwearshapering(actor)
  738. -- if ringId == ring then
  739. -- setplaydef(actor, "T$wearshapering", 0)
  740. -- sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0)
  741. -- local result = {}
  742. -- result.rid = getbaseinfo(actor, "rid")
  743. -- result.curEquipRing = 0
  744. -- sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result)
  745. -- end
  746. -- table.remove(data, index)
  747. -- end
  748. -- end
  749. -- end
  750. end
  751. function EquipAndAppear.initequipluaextdata(alldata, itemid)
  752. local equipdata = {}
  753. equipdata.strengthlv = 0
  754. equipdata.appendlv = 0
  755. equipdata.strengthattr = {}
  756. equipdata.appendattr = {}
  757. alldata[itemid] = equipdata
  758. end
  759. -- 装备强化
  760. function EquipAndAppear.luastrengthequip(actor, msgData)
  761. local itemid = msgData.itemId
  762. local equip = getequipinfo(actor, itemid, 1)
  763. if equip == nil then
  764. return
  765. end
  766. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  767. local equipdata = alldata[itemid]
  768. if equipdata == nil then
  769. EquipAndAppear.initequipluaextdata(alldata, itemid)
  770. equipdata = alldata[itemid]
  771. end
  772. if equipdata.strengthlv == nil then
  773. equipdata.strengthlv = 0
  774. equipdata.strengthattr = {}
  775. end
  776. local lv = equipdata.strengthlv + 1
  777. local cfgId = equip.cfgid
  778. -- 首饰的强化等级特殊处理
  779. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  780. if group ~= nil and group ~= "" then
  781. local strengthenmaxLevel =
  782. ConfigDataManager.getTableValue(
  783. "cfg_equip_ornaments",
  784. "strengthenmaxLevel",
  785. "ornamentsGroup",
  786. group,
  787. "lv",
  788. equipdata.ssuplv or 0
  789. )
  790. if tonumber(strengthenmaxLevel) < lv then
  791. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级")
  792. return
  793. end
  794. else
  795. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", cfgId)
  796. if tonumber(maxLevel) < lv then
  797. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级")
  798. return
  799. end
  800. end
  801. local costId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "costId", "id", cfgId)
  802. local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", cfgId)
  803. -- 获取消耗
  804. local coststr =
  805. ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "cost", "costGroupId", costId, "level", lv)
  806. if coststr == nil then
  807. return
  808. end
  809. local cost = splitbyshuxianandjinghao(coststr)
  810. -- 校验道具是否足够
  811. local enough = Bag.checkItemEnough(actor, cost)
  812. if enough == false then
  813. TimeLimitGift.checkSpecial2Condition(actor)
  814. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  815. return
  816. end
  817. -- 扣材料
  818. for _, v in ipairs(cost) do
  819. local cId = v["cfgid"]
  820. local count = v["count"]
  821. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  822. end
  823. TimeLimitGift.checkSpecial2Count(actor)
  824. -- 获取成功率
  825. local rate = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "rate", "costGroupId", costId, "level", lv)
  826. local randomNumber = math.random(1, 10000)
  827. rate = tonumber(rate)
  828. if rate < randomNumber then
  829. -- 失败,校验是否等级回退
  830. local failLevel =
  831. ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "failLevel", "costGroupId", costId, "level", lv)
  832. failLevel = tonumber(failLevel)
  833. -- if not equip.isbind then
  834. -- changeitembindstate(actor,itemid,1)
  835. -- local res = {itemId = itemid,bindId = true}
  836. -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res)
  837. -- end
  838. if failLevel == equipdata.strengthlv then
  839. -- 给客户端发强化结果
  840. local dddd = {}
  841. dddd.itemId = itemid
  842. dddd.strengthlv = tonumber(failLevel)
  843. dddd.issuccess = false
  844. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  845. return
  846. end
  847. local att =
  848. ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", failLevel)
  849. local attr = splitbyshuxianandjinghao2(att)
  850. equipdata.strengthlv = failLevel
  851. equipdata.strengthattr = attr
  852. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  853. setplaydef(actor, "T$luaitemextdata", alldata)
  854. -- 更新强化追加等属性
  855. EquipAndAppear.updateluaextattr(actor)
  856. info(actor, "玩家", actor, "强化装备至" .. lv .. "级失败,失败后等级" .. failLevel, "道具id" .. itemid, "cfgId:" .. cfgId)
  857. -- 给客户端发强化结果
  858. local dddd = {}
  859. dddd.itemId = itemid
  860. dddd.strengthlv = tonumber(failLevel)
  861. dddd.issuccess = false
  862. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  863. EquipMaster.strengthMaster(actor)
  864. -- 装备强化之后发送装备强化信息
  865. EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv)
  866. return
  867. end
  868. -- 获取属性加成
  869. local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", lv)
  870. local attr = splitbyshuxianandjinghao2(att)
  871. equipdata.strengthlv = lv
  872. equipdata.strengthattr = attr
  873. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  874. setplaydef(actor, "T$luaitemextdata", alldata)
  875. -- 更新强化追加等属性
  876. EquipAndAppear.updateluaextattr(actor)
  877. local firstRate =
  878. ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "firstRate", "costGroupId", costId, "level", lv)
  879. firstRate = tonumber(firstRate)
  880. if firstRate == 1 then
  881. -- 发送跑马灯
  882. local name = getrolefield(actor, "role.basic.name")
  883. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  884. local content = "恭喜" .. name .. "将" .. equipName .. "强化至" .. lv .. "级"
  885. local horseled = {}
  886. horseled.content = content
  887. horseled.cfgId = 109 -- 109是直接写死的
  888. sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled)
  889. end
  890. info(actor, "玩家", actor, "强化装备至" .. lv .. "级成功", "道具id" .. itemid, "cfgId:" .. cfgId)
  891. -- if not equip.isbind then
  892. -- changeitembindstate(actor,itemid,1)
  893. -- local res = {itemId = itemid,bindId = true}
  894. -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res)
  895. -- end
  896. -- 给客户端发强化结果
  897. local dddd = {}
  898. dddd.itemId = itemid
  899. dddd.strengthlv = tonumber(lv)
  900. dddd.issuccess = true
  901. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd)
  902. EquipMaster.strengthMaster(actor)
  903. -- 记录强化次数
  904. local oldCount = EquipAndAppear.GetEquipStrengthCount(actor)
  905. setplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES, oldCount + 1)
  906. ---触发装备强化任务
  907. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  908. local taskParam = {
  909. part = strPart,
  910. level = lv
  911. }
  912. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.PARTS_STRENGTHEN_LV, taskParam)
  913. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_STRENGTHEN_TIMES, lv)
  914. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL)
  915. -- 装备强化之后发送装备强化信息
  916. EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv)
  917. LogManager.RoleStrenthenEquip(actor)
  918. end
  919. ---获取玩家装备累计强化次数
  920. function EquipAndAppear.GetEquipStrengthCount(actor)
  921. local totalCount = getplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES)
  922. if totalCount == nil then
  923. totalCount = 0
  924. end
  925. return totalCount
  926. end
  927. function EquipAndAppear.updateequipgmext(actor, itemid, strengthlv)
  928. -- local gmext = getequipgmext(actor,itemid)
  929. -- if gmext == nil or gmext == "null" then
  930. -- gmext = {}
  931. -- end
  932. local gmext = {}
  933. gmext.strengthlv = strengthlv
  934. setequipgmext(actor, itemid, gmext)
  935. end
  936. function splitbyshuxianandjinghao2(str)
  937. local dt = {}
  938. local data = string.split(str, "|")
  939. for _, v in ipairs(data) do
  940. local data2 = string.split(v, "#")
  941. dt[data2[1]] = data2[2]
  942. end
  943. return dt
  944. end
  945. -- 装备追加
  946. function EquipAndAppear.luaappendequip(actor, msgData)
  947. local itemid = msgData.itemId
  948. local equip = getequipinfo(actor, itemid, 1)
  949. if equip == nil then
  950. return
  951. end
  952. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  953. local equipdata = API.GetItemDataSrc(actor, itemid)
  954. if equipdata == nil then
  955. EquipAndAppear.initequipluaextdata(alldata, itemid)
  956. equipdata = alldata[itemid]
  957. end
  958. if equipdata.appendlv == nil then
  959. equipdata.appendlv = 0
  960. equipdata.appendattr = {}
  961. end
  962. local lv = equipdata.appendlv + 1
  963. local cfgId = equip.cfgid
  964. -- 首饰的强化等级特殊处理
  965. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  966. if group ~= nil and group ~= "" then
  967. local appendsmaxLevel =
  968. ConfigDataManager.getTableValue(
  969. "cfg_equip_ornaments",
  970. "appendsmaxLevel",
  971. "ornamentsGroup",
  972. group,
  973. "lv",
  974. equipdata.ssuplv or 0
  975. )
  976. if tonumber(appendsmaxLevel) < lv then
  977. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级")
  978. return
  979. end
  980. else
  981. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", cfgId)
  982. if tonumber(maxLevel) < lv then
  983. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级")
  984. return
  985. end
  986. end
  987. local costId = ConfigDataManager.getTableValue("cfg_equip_appends", "costId", "id", cfgId)
  988. local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", cfgId)
  989. -- 获取消耗
  990. local coststr = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "cost", "costGroupId", costId, "level", lv)
  991. if coststr == nil then
  992. return
  993. end
  994. local cost = splitbyshuxianandjinghao(coststr)
  995. -- 校验道具是否足够
  996. local enough = Bag.checkItemEnough(actor, cost)
  997. if enough == false then
  998. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  999. return
  1000. end
  1001. -- 扣材料
  1002. for _, v in ipairs(cost) do
  1003. local cId = v["cfgid"]
  1004. local count = v["count"]
  1005. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  1006. end
  1007. -- 获取成功率
  1008. local rate = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "rate", "costGroupId", costId, "level", lv)
  1009. local randomNumber = math.random(1, 10000)
  1010. rate = tonumber(rate)
  1011. if rate < randomNumber then
  1012. -- 失败,校验是否等级回退
  1013. local failLevel =
  1014. ConfigDataManager.getTableValue("cfg_equip_appendsCost", "failLevel", "costGroupId", costId, "level", lv)
  1015. failLevel = tonumber(failLevel)
  1016. -- if not equip.isbind then
  1017. -- changeitembindstate(actor,itemid,1)
  1018. -- local res = {itemId = itemid,bindId = true}
  1019. -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res)
  1020. -- end
  1021. if failLevel == equipdata.appendlv then
  1022. -- 给客户端发强化结果
  1023. local dddd = {}
  1024. dddd.itemId = itemid
  1025. dddd.appendlv = tonumber(failLevel)
  1026. dddd.issuccess = false
  1027. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  1028. return
  1029. end
  1030. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", failLevel)
  1031. local attr = splitbyshuxianandjinghao2(att)
  1032. equipdata.appendlv = failLevel
  1033. equipdata.appendattr = attr
  1034. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  1035. setplaydef(actor, "T$luaitemextdata", alldata)
  1036. info(actor, "玩家", actor, "追加装备至" .. lv .. "级失败,失败后等级" .. failLevel, "道具id" .. itemid, "cfgId:" .. cfgId)
  1037. -- 给客户端发强化结果
  1038. local dddd = {}
  1039. dddd.itemId = itemid
  1040. dddd.appendlv = tonumber(failLevel)
  1041. dddd.issuccess = false
  1042. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  1043. EquipMaster.appendMaster(actor)
  1044. return
  1045. end
  1046. -- 获取属性加成
  1047. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", lv)
  1048. local attr = splitbyshuxianandjinghao2(att)
  1049. equipdata.appendlv = lv
  1050. equipdata.appendattr = attr
  1051. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  1052. setplaydef(actor, "T$luaitemextdata", alldata)
  1053. -- 更新强化追加等属性
  1054. EquipAndAppear.updateluaextattr(actor)
  1055. local firstRate =
  1056. ConfigDataManager.getTableValue("cfg_equip_appendsCost", "firstRate", "costGroupId", costId, "level", lv)
  1057. firstRate = tonumber(firstRate)
  1058. if firstRate == 1 then
  1059. -- 发送跑马灯
  1060. local name = getrolefield(actor, "role.basic.name")
  1061. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  1062. -- local content = "恭喜" .. name .. "将" .. equipName .. "追加至" .. lv .. "级"
  1063. -- local horseled = {}
  1064. -- horseled.cfgId = 115
  1065. -- horseled.content = content
  1066. -- sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled)
  1067. noticeTip.noticeinfo(actor, 115, name, equipName, lv)
  1068. end
  1069. -- 给客户端发强化结果
  1070. local dddd = {}
  1071. dddd.itemId = itemid
  1072. dddd.appendlv = tonumber(lv)
  1073. dddd.issuccess = true
  1074. sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd)
  1075. info(actor, "玩家", actor, "追加装备至" .. lv .. "级成功", "道具id" .. itemid, "cfgId:" .. cfgId)
  1076. -- if not equip.isbind then
  1077. -- changeitembindstate(actor,itemid,1)
  1078. -- local res = {itemId = itemid,bindId = true}
  1079. -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res)
  1080. -- end
  1081. EquipMaster.appendMaster(actor)
  1082. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_APPEND_LEVEL)
  1083. -- 刷新任务进度
  1084. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  1085. local taskParam = {
  1086. part = strPart,
  1087. level = lv
  1088. }
  1089. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND, taskParam)
  1090. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND_TOTAL_LV)
  1091. LogManager.RoleAppendEquip(actor)
  1092. end
  1093. function EquipAndAppear.setAppendLv(actor, itemid, lv)
  1094. local equip = getequipinfo(actor, itemid, 1)
  1095. if equip == nil then
  1096. return
  1097. end
  1098. local cfgId = equip.cfgid
  1099. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  1100. local equipdata = API.GetItemDataSrc(actor, itemid)
  1101. if equipdata == nil then
  1102. EquipAndAppear.initequipluaextdata(alldata, itemid)
  1103. equipdata = alldata[itemid]
  1104. end
  1105. if equipdata.appendlv == nil then
  1106. equipdata.appendlv = 0
  1107. equipdata.appendattr = {}
  1108. end
  1109. local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", cfgId)
  1110. -- 获取属性加成
  1111. local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", lv)
  1112. local attr = splitbyshuxianandjinghao2(att)
  1113. equipdata.appendlv = lv
  1114. equipdata.appendattr = attr
  1115. EquipAndAppear.SetItemExtData(actor, itemid, equipdata)
  1116. setplaydef(actor, "T$luaitemextdata", alldata)
  1117. -- 更新强化追加等属性
  1118. EquipAndAppear.updateluaextattr(actor)
  1119. end
  1120. --- 获取所有装备数据
  1121. function EquipAndAppear.getLuaItemExtData(actor)
  1122. local alldata = getplaydef(actor, "T$luaitemextdata")
  1123. if alldata == nil then
  1124. -- 说明还没有进行过锻造
  1125. setplaydef(actor, "T$luaitemextdata", {})
  1126. alldata = getplaydef(actor, "T$luaitemextdata")
  1127. end
  1128. return alldata
  1129. end
  1130. -- 装备属性转移
  1131. function EquipAndAppear.luatransferequip(actor, msgData)
  1132. local firstId = msgData.firstItem
  1133. local secId = msgData.secondItem
  1134. local equip1 = getequipinfo(actor, firstId, 1)
  1135. if equip1 == nil then
  1136. return
  1137. end
  1138. local equip2 = getequipinfo(actor, secId, 1)
  1139. if equip2 == nil then
  1140. return
  1141. end
  1142. local id1 = equip1.cfgid
  1143. local id2 = equip2.cfgid
  1144. local data1 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id1)
  1145. local data2 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id2)
  1146. if
  1147. (data1 == nil) or (data2 == nil) or (data1.transferGroup ~= data2.transferGroup) or
  1148. (data1.transfer ~= data2.transfer)
  1149. then
  1150. return
  1151. end
  1152. local ts = msgData.transferStrength -- bool类型
  1153. local ta = msgData.transferAppend
  1154. local tr = msgData.transferRegeneration
  1155. if not ts and not ta and not tr then
  1156. return
  1157. end
  1158. -- 扩展数据
  1159. local extdata = getplaydef(actor, "T$luaitemextdata")
  1160. local ext1 = extdata[firstId]
  1161. local ext2 = extdata[secId]
  1162. if ext2 == nil then
  1163. ext2 = {}
  1164. ext2.appendattr = {}
  1165. ext2.strengthattr = {}
  1166. ext2.appendlv = 0
  1167. ext2.strengthlv = 0
  1168. end
  1169. -- 转移前强化追加
  1170. info(
  1171. actor,
  1172. "转移前强化追加等级,rid:",
  1173. actor,
  1174. "强化等级:",
  1175. ext1.strengthlv,
  1176. ext2.strengthlv,
  1177. "追加等级:",
  1178. ext1.appendlv,
  1179. ext2.appendlv,
  1180. "主装备id:" .. firstId .. "主装备cfgId:" .. id1,
  1181. "副装备id:" .. secId .. "副装备cfgId:" .. id2
  1182. )
  1183. local allCost = {}
  1184. -- 强化消耗
  1185. if ts then
  1186. local lv1 = ext1.strengthlv
  1187. local lv2 = ext2.strengthlv
  1188. if lv2 ~= 0 then
  1189. return
  1190. end
  1191. local costItem = data1[1].strengthencost
  1192. local cost = splittransfercoststr(costItem)
  1193. local realLv = 0
  1194. local realCost = {}
  1195. for key, value in pairs(cost) do
  1196. if key > realLv and key <= lv1 then
  1197. realLv = key
  1198. realCost = value
  1199. end
  1200. end
  1201. table.insert(allCost, realCost)
  1202. end
  1203. if table.count(allCost[1]) == 0 then
  1204. allCost[1] = {}
  1205. end
  1206. -- 追加消耗
  1207. if ta then
  1208. local lv1 = ext1.appendlv
  1209. local lv2 = ext2.appendlv
  1210. if lv2 ~= 0 then
  1211. return
  1212. end
  1213. local costItem = data1[1].appendscost
  1214. local cost = splittransfercoststr(costItem)
  1215. local realLv = 0
  1216. local realCost = {}
  1217. for key, value in pairs(cost) do
  1218. if key > realLv and key <= lv1 then
  1219. realLv = key
  1220. realCost = value
  1221. end
  1222. end
  1223. for _, value in pairs(realCost) do
  1224. local cId = value["cfgid"]
  1225. local num = value["count"]
  1226. local n = 0
  1227. for _1, v in pairs(allCost[1]) do
  1228. if v["cfgid"] == cId then
  1229. v["count"] = v["count"] + num
  1230. n = n + 1
  1231. end
  1232. end
  1233. if n == 0 then
  1234. table.insert(allCost[1], value)
  1235. end
  1236. end
  1237. end
  1238. -- 再生消耗
  1239. if tr then
  1240. local lv1 = ext1.regenerationlv
  1241. local lv2 = ext2.regenerationlv
  1242. if lv2 == nil then
  1243. ext2.regenerationlv = 0
  1244. lv2 = 0
  1245. end
  1246. if lv2 ~= 0 then
  1247. return
  1248. end
  1249. local costItem = data1[1].regenerationcost
  1250. local cost = splittransfercoststr(costItem)
  1251. local realLv = 0
  1252. local realCost = {}
  1253. for key, value in pairs(cost) do
  1254. if key > realLv and key <= lv1 then
  1255. realLv = key
  1256. realCost = value
  1257. end
  1258. end
  1259. for _, value in pairs(realCost) do
  1260. local cId = value["cfgid"]
  1261. local num = value["count"]
  1262. local n = 0
  1263. for _1, v in pairs(allCost[1]) do
  1264. if v["cfgid"] == cId then
  1265. v["count"] = v["count"] + num
  1266. n = n + 1
  1267. end
  1268. end
  1269. if n == 0 then
  1270. table.insert(allCost[1], value)
  1271. end
  1272. end
  1273. end
  1274. -- 检查道具是否足够
  1275. local enough = Bag.checkItemEnough(actor, allCost[1])
  1276. if not enough then
  1277. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1278. return
  1279. end
  1280. -- 扣道具
  1281. for _, v in ipairs(allCost[1]) do
  1282. local cId = v["cfgid"]
  1283. local count = v["count"]
  1284. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  1285. end
  1286. -- 转移强化
  1287. if ts then
  1288. local slv1 = ext1.strengthlv
  1289. ext2.strengthlv = slv1
  1290. ext1.strengthlv = 0
  1291. ext1.strengthattr = {}
  1292. -- 赋值属性
  1293. local maxLv = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", equip2.cfgid)
  1294. local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", equip2.cfgid)
  1295. if ext2.strengthlv > tonumber(maxLv) then
  1296. ext2.strengthlv = tonumber(maxLv)
  1297. end
  1298. local att =
  1299. ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", ext2.strengthlv)
  1300. local attr = splitbyshuxianandjinghao2(att)
  1301. ext2.strengthattr = attr
  1302. EquipAndAppear.updateequipgmext(actor, firstId, 0)
  1303. EquipAndAppear.updateequipgmext(actor, secId, ext2.strengthlv)
  1304. end
  1305. -- 转移追加
  1306. if ta then
  1307. local slv1 = ext1.appendlv
  1308. ext2.appendlv = slv1
  1309. ext1.appendlv = 0
  1310. ext1.appendattr = {}
  1311. -- 赋值属性
  1312. local maxLv = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", equip2.cfgid)
  1313. local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", equip2.cfgid)
  1314. if ext2.appendlv > tonumber(maxLv) then
  1315. ext2.appendlv = tonumber(maxLv)
  1316. end
  1317. local att =
  1318. ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", ext2.appendlv)
  1319. local attr = splitbyshuxianandjinghao2(att)
  1320. ext2.appendattr = attr
  1321. end
  1322. -- 转移再生
  1323. if tr then
  1324. local relv = ext1.regenerationlv
  1325. ext2.regenerationlv = relv
  1326. ext1.regenerationlv = 0
  1327. ext2.regenerationattr = {}
  1328. -- 赋值属性
  1329. local maxLv = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip2.cfgid)
  1330. local groupId = ConfigDataManager.getTableValue("cfg_equip_regeneration", "Group", "id", equip2.cfgid)
  1331. if ext2.regenerationlv > tonumber(maxLv) then
  1332. ext2.regenerationlv = tonumber(maxLv)
  1333. end
  1334. local regeattr = ext1.regenerationattr
  1335. for _, value in pairs(regeattr) do
  1336. local id = value.id
  1337. local regenerationgroup = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  1338. if table.count(regenerationgroup) ~= 0 then
  1339. local sequence = regenerationgroup[1].sequence
  1340. -- 找对应的表
  1341. local nexttable =
  1342. ConfigDataManager.getTable(
  1343. "cfg_equip_regenerationGroup",
  1344. "group",
  1345. groupId,
  1346. "sequence",
  1347. sequence,
  1348. "level",
  1349. ext2.regenerationlv
  1350. )
  1351. if table.count(nexttable) ~= 0 then
  1352. local att = nexttable[1].att
  1353. local str = string.split(att, "#")
  1354. local dd = {}
  1355. dd[str[1]] = tonumber(str[2])
  1356. dd.id = tonumber(nexttable[1].id)
  1357. ext2.regenerationattr[tostring(table.count(ext2.regenerationattr) + 1)] = dd
  1358. end
  1359. end
  1360. end
  1361. ext1.regenerationattr = {}
  1362. end
  1363. -- 更新数据
  1364. extdata[firstId] = ext1
  1365. extdata[secId] = ext2
  1366. EquipAndAppear.SetItemExtData(actor, firstId, ext1)
  1367. EquipAndAppear.SetItemExtData(actor, secId, ext2)
  1368. setplaydef(actor, "T$luaitemextdata", extdata)
  1369. EquipAndAppear.updateluaextattr(actor)
  1370. -- 转移后强化追加
  1371. info(
  1372. actor,
  1373. "转移后强化追加等级,rid:",
  1374. actor,
  1375. "强化等级:",
  1376. ext1.strengthlv,
  1377. ext2.strengthlv,
  1378. "追加等级:",
  1379. ext1.appendlv,
  1380. ext2.appendlv,
  1381. "主装备id:" .. firstId .. "主装备cfgId:" .. id1,
  1382. "副装备id:" .. secId .. "副装备cfgId:" .. id2
  1383. )
  1384. if not equip2.isbind then
  1385. changeitembindstate(actor, secId, 1)
  1386. local res = {
  1387. itemId = secId,
  1388. bindId = true
  1389. }
  1390. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE, res)
  1391. end
  1392. -- 检查主装备是否还有强化追加属性
  1393. if this.checkEquipStrengthAndAppend(actor, firstId) then
  1394. -- 变为非绑定
  1395. changeitembindstate(actor, firstId, 0)
  1396. local res = {
  1397. itemId = firstId,
  1398. bindId = false
  1399. }
  1400. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE, res)
  1401. end
  1402. EquipMaster.transferTrigger(actor, equip1, equip2, ts, ta)
  1403. -- 发送lua消息到客户端
  1404. local data = {}
  1405. data.oldItem = firstId
  1406. data.newItem = secId
  1407. data.issuccess = true
  1408. sendluamsg(actor, LuaMessageIdToClient.RES_TRANSFER_EQUIP, data)
  1409. end
  1410. function this.checkEquipStrengthAndAppend(actor, itemId)
  1411. local allData = EquipAndAppear.getLuaItemExtData(actor)
  1412. local equipData = allData[tonumber(itemId)]
  1413. if not equipData then
  1414. return true
  1415. end
  1416. local strengthlv = equipData.strengthlv
  1417. local appendlv = equipData.appendlv
  1418. if (strengthlv == 0) and (appendlv == 0) then
  1419. return true
  1420. end
  1421. return false
  1422. end
  1423. function EquipAndAppear.checkCanTransfer(actor, firstId, secId)
  1424. if firstId == 0 then
  1425. return
  1426. end
  1427. local data = {}
  1428. data.oldItem = firstId
  1429. data.newItem = secId
  1430. sendluamsg(actor, LuaMessageIdToClient.RES_CAN_TRANSFER, data)
  1431. end
  1432. function splittransfercoststr(str)
  1433. local s = string.split(str, "|")
  1434. local data = {}
  1435. for _, value in pairs(s) do
  1436. local x = string.split(value, "#")
  1437. local len = #x
  1438. local itemList = {}
  1439. if len == 3 then
  1440. local item = {}
  1441. item["cfgid"] = x[2]
  1442. item["count"] = x[3]
  1443. table.insert(itemList, item)
  1444. else
  1445. if len > 3 then
  1446. for i = 1, len do
  1447. local item = {}
  1448. if i == 1 then
  1449. item["cfgid"] = x[i + 1]
  1450. item["count"] = x[i + 2]
  1451. i = i + 3
  1452. else
  1453. item["cfgid"] = x[i]
  1454. item["count"] = x[i + 1]
  1455. i = i + 2
  1456. end
  1457. table.insert(itemList, item)
  1458. end
  1459. end
  1460. end
  1461. data[tonumber(x[1])] = itemList
  1462. end
  1463. return data
  1464. end
  1465. function EquipAndAppear.updateluaextattr(actor)
  1466. local alldata = getplaydef(actor, "T$luaitemextdata")
  1467. local equiplist = getputonequipinfo(actor)
  1468. local allattr = {}
  1469. for _, equipinfo in pairs(equiplist) do
  1470. local itemId = equipinfo.id
  1471. local data = alldata[itemId]
  1472. if data ~= nil then
  1473. -- 将该装备的属性加到角色身上
  1474. if data.strengthlv ~= nil then
  1475. local strengthattr = EquipFunc.getEquipStrengthWearAddAttr(actor, itemId)
  1476. table.mergeAdd(allattr, strengthattr)
  1477. end
  1478. if data.appendlv ~= nil then
  1479. local appendattr = data.appendattr
  1480. if appendattr == nil then
  1481. local groupId =
  1482. ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", equipinfo.cfgid)
  1483. local att =
  1484. ConfigDataManager.getTableValue(
  1485. "cfg_equip_appendsGroup",
  1486. "att",
  1487. "group",
  1488. groupId,
  1489. "lv",
  1490. data.appendlv
  1491. )
  1492. local attr = splitbyshuxianandjinghao2(att)
  1493. appendattr = attr
  1494. end
  1495. table.mergeAdd(allattr, appendattr)
  1496. end
  1497. if data.ssuplv ~= nil then
  1498. local ssupattr = data.ssupattr
  1499. local ssactattr = data.ssactattr
  1500. table.mergeAdd(allattr, ssupattr)
  1501. table.mergeAdd(allattr, ssactattr)
  1502. end
  1503. if data.regenerationlv ~= nil then
  1504. local reattr = data.regenerationattr
  1505. local regenerationattr = {}
  1506. for _, att in pairs(reattr) do
  1507. for key, value in pairs(att) do
  1508. if key ~= "id" then
  1509. local num = regenerationattr[key]
  1510. if num == nil then
  1511. num = 0
  1512. end
  1513. regenerationattr[key] = num + value
  1514. end
  1515. end
  1516. end
  1517. table.mergeAdd(allattr, regenerationattr)
  1518. end
  1519. end
  1520. end
  1521. -- 更新装备记录
  1522. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_ENTRY_COUNT)
  1523. -- 记录强化追加等属性
  1524. if table.count(allattr) == 0 then
  1525. addrolekmlattributes(actor, "luaextdataforever", {})
  1526. return
  1527. end
  1528. addrolekmlattributes(actor, "luaextdataforever", allattr)
  1529. end
  1530. -- 首饰升级
  1531. function EquipAndAppear.ssupdate(actor, msgData)
  1532. local itemId = msgData["itemId"]
  1533. local allequip = getplaydef(actor, "T$luaitemextdata")
  1534. local equipext = allequip[itemId]
  1535. if equipext == nil then
  1536. equipext = {}
  1537. end
  1538. if equipext.ssuplv == nil then
  1539. equipext.ssupattr = {}
  1540. equipext.ssuplv = 0
  1541. equipext.ssactlv = {}
  1542. equipext.ssactattr = {}
  1543. end
  1544. local equip = getequipinfo(actor, itemId, 1)
  1545. local cfgId = equip.cfgid
  1546. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  1547. if group == nil then
  1548. return
  1549. end
  1550. local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", equipext.ssuplv)
  1551. if ornaments == nil or table.count(ornaments) == 0 then
  1552. return
  1553. end
  1554. local ornaments2 =
  1555. ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", (equipext.ssuplv or 0) + 1)
  1556. if ornaments2 == nil or table.count(ornaments2) == 0 then
  1557. sendluamsg(actor, LuaMessageIdToClient.TIPS, "已经是最大等级!")
  1558. return
  1559. end
  1560. local data = ornaments2[1]
  1561. local cost = ornaments[1].lvdeplete
  1562. local costItem = splitbyshuxianandjinghao(cost)
  1563. -- 检查背包是否道具充足
  1564. local enough = Bag.checkItemEnough(actor, costItem)
  1565. if enough == false then
  1566. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1567. return
  1568. end
  1569. -- 扣材料
  1570. for _, v in ipairs(costItem) do
  1571. local cId = v["cfgid"]
  1572. local count = v["count"]
  1573. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  1574. end
  1575. -- 升级,加属性
  1576. equipext.ssuplv = tonumber(data.lv)
  1577. local att = data.basicatt
  1578. local attr = splitbyshuxianandjinghao2(att)
  1579. equipext.ssupattr = attr
  1580. allequip[itemId] = equipext
  1581. EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  1582. setplaydef(actor, "T$luaitemextdata", allequip)
  1583. -- 升级成功 回包给客户端
  1584. local result = {}
  1585. result.ssupattr = equipext.ssupattr
  1586. result.ssuplv = tostring(equipext.ssuplv)
  1587. result.ssactlv = equipext.ssactlv
  1588. result.ssactattr = equipext.ssactattr
  1589. result.itemId = itemId
  1590. sendluamsg(actor, LuaMessageIdToClient.RES_UPDATE_EQUIP_ORNAMENTS, result)
  1591. -- 更新属性
  1592. EquipAndAppear.updateluaextattr(actor)
  1593. -- 更新等级记录
  1594. this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL)
  1595. -- 刷新任务进度
  1596. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.JEWELRY_LV_UP)
  1597. end
  1598. -- 首饰等级属性激活
  1599. function EquipAndAppear.actssattr(actor, msgData)
  1600. local itemId = msgData["itemId"]
  1601. local lv = msgData["lv"]
  1602. local allequip = getplaydef(actor, "T$luaitemextdata")
  1603. local equipext = allequip[itemId]
  1604. if equipext.ssuplv == nil then
  1605. return
  1606. end
  1607. local equip = getequipinfo(actor, itemId, 1)
  1608. local cfgId = equip.cfgid
  1609. local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId)
  1610. local ssuplv = equipext.ssuplv
  1611. if ssuplv < lv then
  1612. return
  1613. end
  1614. if table.contains(equipext.ssactlv, lv) then
  1615. return
  1616. end
  1617. local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", lv)
  1618. if table.count(ornaments) == 0 then
  1619. return
  1620. end
  1621. if ornaments[1].unlockdeplete == nil then
  1622. return
  1623. end
  1624. local unlockDeplete = ornaments[1].unlockdeplete
  1625. if unlockDeplete == nil then
  1626. return
  1627. end
  1628. local costItem = splitbyshuxianandjinghao(unlockDeplete)
  1629. -- 检查背包是否道具充足
  1630. local enough = Bag.checkItemEnough(actor, costItem)
  1631. if enough == false then
  1632. return
  1633. end
  1634. -- 扣材料
  1635. for _, v in ipairs(costItem) do
  1636. local cId = v["cfgid"]
  1637. local count = v["count"]
  1638. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  1639. end
  1640. equipext.ssactlv[tostring(lv)] = lv
  1641. local att = ornaments[1].excellenceatt
  1642. local attr = splitbyshuxianandjinghao2(att)
  1643. table.mergeAdd(equipext.ssactattr, attr)
  1644. allequip[itemId] = equipext
  1645. EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  1646. setplaydef(actor, "T$luaitemextdata", allequip)
  1647. -- 发送回包给客户端
  1648. local result = {}
  1649. result.ssupattr = equipext.ssupattr
  1650. result.ssuplv = equipext.ssuplv
  1651. result.ssactlv = equipext.ssactlv
  1652. result.ssactattr = equipext.ssactattr
  1653. result.itemId = itemId
  1654. sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, result)
  1655. -- 更新属性
  1656. EquipAndAppear.updateluaextattr(actor)
  1657. end
  1658. function EquipAndAppear.allequipstrengthlv(actor)
  1659. local alldata = getplaydef(actor, "T$luaitemextdata")
  1660. local equiplist = getputonequipinfo(actor)
  1661. local allequipstrengthlv = 0
  1662. for _, equipinfo in pairs(equiplist) do
  1663. local itemId = equipinfo.id
  1664. local data = alldata[itemId]
  1665. if data ~= nil then
  1666. if data.strengthlv ~= nil then
  1667. allequipstrengthlv = allequipstrengthlv + data.strengthlv
  1668. end
  1669. end
  1670. end
  1671. return allequipstrengthlv
  1672. end
  1673. function EquipAndAppear.allequipappendlv(actor)
  1674. local alldata = getplaydef(actor, "T$luaitemextdata")
  1675. local equiplist = getputonequipinfo(actor)
  1676. local allequipstrengthlv = 0
  1677. for _, equipinfo in pairs(equiplist) do
  1678. local itemId = equipinfo.id
  1679. local data = alldata[itemId]
  1680. if data ~= nil then
  1681. if data.appendlv ~= nil then
  1682. allequipstrengthlv = allequipstrengthlv + data.appendlv
  1683. end
  1684. end
  1685. end
  1686. return allequipstrengthlv
  1687. end
  1688. function rand_cfgs_weight(cfgs)
  1689. local weightTotal = 0
  1690. for i, v in ipairs(cfgs) do
  1691. weightTotal = weightTotal + tonumber(v.weight)
  1692. end
  1693. local randWeight = math.random(1, weightTotal)
  1694. for i, v in ipairs(cfgs) do
  1695. local weight = tonumber(v.weight)
  1696. if randWeight < weight then
  1697. return v
  1698. end
  1699. randWeight = randWeight - weight
  1700. end
  1701. return cfgs[1]
  1702. end
  1703. -- 再生
  1704. function EquipAndAppear.regeneration(actor, msgData)
  1705. local itemId = msgData["itemId"]
  1706. local isUseProtect = msgData.useProtect == true
  1707. local isGemCost = msgData.isGemCost == true
  1708. local equip = getequipinfo(actor, itemId, 1)
  1709. local regenerationlv = API.GetItemData(actor, itemId, "regenerationlv") or 0
  1710. local regenerationattr = API.GetItemData(actor, itemId, "regenerationattr") or {}
  1711. local lv = regenerationlv
  1712. local tabledata = ConfigDataManager.getTable("cfg_equip_regeneration", "id", equip.cfgid)
  1713. if table.count(tabledata) == 0 then
  1714. return
  1715. end
  1716. local group = tabledata[1].group
  1717. -- 获取消耗
  1718. local lockattr = msgData["lockattrpos"]
  1719. local startcost = {}
  1720. local type = 0
  1721. if table.count(regenerationattr) == 0 then
  1722. startcost = tabledata[1].start
  1723. type = 1
  1724. else
  1725. if table.count(lockattr) == 0 then
  1726. startcost = tabledata[1].again
  1727. type = 2
  1728. else
  1729. startcost = tabledata[1].lock
  1730. type = 3
  1731. end
  1732. end
  1733. if type ~= 3 and isGemCost == true then
  1734. startcost = tabledata[1].gemcost
  1735. end
  1736. local cost = getlockcost(startcost, lockattr)
  1737. -- 校验道具是否足够
  1738. local enough = Bag.checkItemEnough(actor, cost)
  1739. if enough and isUseProtect then
  1740. enough = Bag.checkItemEnough(actor, {{cfgid = "21000110", count = "1"}})
  1741. end
  1742. if enough == false then
  1743. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1744. return
  1745. end
  1746. -- 扣道具
  1747. for _, v in ipairs(cost) do
  1748. local cId = v["cfgid"]
  1749. local count = v["count"]
  1750. removeitemfrombag(actor, cId, count, 0, 9999, "装备再生")
  1751. end
  1752. if isUseProtect then
  1753. removeitemfrombag(actor, 21000110, 1, 0, 9999, "装备再生")
  1754. end
  1755. -- 随机词条数量
  1756. local attrNum = {}
  1757. if type == 1 then
  1758. attrNum = tabledata[1].startnum
  1759. else
  1760. if type == 2 then
  1761. attrNum = tabledata[1].againnum
  1762. else
  1763. if type == 3 then
  1764. attrNum = tabledata[1].locknum
  1765. end
  1766. end
  1767. end
  1768. local result = random_weighted(attrNum, 1)
  1769. if lv == 0 then
  1770. lv = 1
  1771. end
  1772. -- 校验词条数是否超过最大值
  1773. local maxAttrNum = tabledata[1].count
  1774. local realNum = result[1] + table.count(lockattr)
  1775. if realNum >= tonumber(maxAttrNum) then
  1776. realNum = tonumber(maxAttrNum) - table.count(lockattr)
  1777. else
  1778. realNum = result[1]
  1779. end
  1780. -- local attdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "level", lv)
  1781. local attdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group)
  1782. local entrytable = build_weight_attr(attdata, regenerationattr, lockattr)
  1783. local entryattr = random_attr(entrytable, realNum)
  1784. -- 把这次结果临时存一下
  1785. local xilianattr = {}
  1786. for _, key in pairs(lockattr) do
  1787. -- xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1788. local cfg = ConfigDataManager.getById("cfg_equip_regenerationGroup", key)
  1789. if cfg == nil then
  1790. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1791. else
  1792. local cfgs =
  1793. ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", cfg.group, "sequence", cfg.sequence)
  1794. local cfgRand = rand_cfgs_weight(cfgs)
  1795. if cfgRand == nil then
  1796. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1797. else
  1798. if isUseProtect then
  1799. if tonumber(cfgRand.level) > tonumber(cfg.level) then
  1800. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(cfgRand.id)
  1801. else
  1802. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1803. end
  1804. else
  1805. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(cfgRand.id)
  1806. end
  1807. end
  1808. end
  1809. end
  1810. if table.count(lockattr) == 0 then
  1811. for _, key in pairs(entryattr) do
  1812. xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key)
  1813. end
  1814. end
  1815. local allequiprecord = getplaydef(actor, "T$regeneration")
  1816. if allequiprecord == nil then
  1817. allequiprecord = {}
  1818. end
  1819. local regenerationresult = {}
  1820. regenerationresult.entryAttr = xilianattr
  1821. regenerationresult.itemId = itemId
  1822. allequiprecord[itemId] = regenerationresult
  1823. setplaydef(actor, "T$regeneration", allequiprecord)
  1824. local msg = {}
  1825. msg.id = itemId
  1826. msg.attrs = {}
  1827. msg.attrs.entryAttr = xilianattr
  1828. -- 告诉客户端本次洗练结果
  1829. sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_REGENERATION, msg)
  1830. end
  1831. function EquipAndAppear.getupregenerationattr(actor, msgData)
  1832. local itemId = msgData.itemId
  1833. local data = getplaydef(actor, "T$regeneration")
  1834. if data == nil then
  1835. sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, {})
  1836. return
  1837. end
  1838. local result = data[itemId]
  1839. if result == nil then
  1840. result = {}
  1841. end
  1842. local equipData = {}
  1843. equipData.id = itemId
  1844. equipData.attrs = result
  1845. sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, equipData)
  1846. end
  1847. -- 确认替换词条
  1848. function EquipAndAppear.confirmreplaceentry(actor, msgData)
  1849. -- local lockattr = msgData.lockattrpos
  1850. local itemId = msgData.itemId
  1851. local alldata = getplaydef(actor, "T$regeneration")
  1852. if alldata == nil then
  1853. sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!")
  1854. return
  1855. end
  1856. local data = alldata[itemId]
  1857. if data == nil then
  1858. sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!")
  1859. return
  1860. end
  1861. if data.itemId ~= itemId then
  1862. sendluamsg(actor, LuaMessageIdToClient.TIPS, "两次itemId不一致!")
  1863. return
  1864. end
  1865. local regenerationattr = {}
  1866. local regenerationlv = 1
  1867. for _, id in pairs(data.entryAttr) do
  1868. local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  1869. if table.count(td) ~= 0 then
  1870. local attr = td[1].att
  1871. local str = string.split(attr, "#")
  1872. local dd = {}
  1873. dd[str[1]] = tonumber(str[2])
  1874. dd.id = id
  1875. regenerationattr[tostring(table.count(regenerationattr) + 1)] = dd
  1876. regenerationlv = tonumber(td[1].level)
  1877. end
  1878. end
  1879. -- EquipAndAppear.SetItemExtData(actor, itemId, ext)
  1880. -- setplaydef(actor, "T$luaitemextdata", allequip)
  1881. API.SetItemData(actor, itemId, "regenerationlv", regenerationlv)
  1882. API.SetItemData(actor, itemId, "regenerationattr", regenerationattr)
  1883. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  1884. local equipdata = alldata[itemId]
  1885. if equipdata == nil then
  1886. EquipAndAppear.initequipluaextdata(alldata, itemId)
  1887. equipdata = alldata[itemId]
  1888. end
  1889. equipdata.regenerationlv = regenerationlv
  1890. equipdata.regenerationattr = regenerationattr
  1891. setplaydef(actor, "T$luaitemextdata", alldata)
  1892. alldata[itemId] = nil
  1893. setplaydef(actor, "T$regeneration", alldata)
  1894. -- 给客户端发替换结果
  1895. sendluamsg(actor, LuaMessageIdToClient.RES_REPLACE_REGENERATION_ATTR, true)
  1896. -- 更新强化追加等属性
  1897. EquipAndAppear.updateluaextattr(actor)
  1898. end
  1899. -- 再生词条转移
  1900. function EquipAndAppear.regenerationMove(actor, msgData)
  1901. local itemId1 = msgData.itemId1
  1902. local itemId2 = msgData.itemId2
  1903. local cfgid = msgData.cfgid
  1904. if itemId1 == nil or itemId2 == nil or cfgid == nil then
  1905. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1906. return
  1907. end
  1908. local cfg = ConfigDataManager.getById("cfg_equip_regenerationMoveCost", cfgid)
  1909. if cfg == nil then
  1910. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1911. return
  1912. end
  1913. local equip1 = getequipinfo(actor, itemId1, 1)
  1914. local equip2 = getequipinfo(actor, itemId2, 1)
  1915. if equip1 == nil or equip2 == nil then
  1916. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1917. return
  1918. end
  1919. local regenerationattr = API.GetItemData(actor, itemId1, "regenerationattr") or {}
  1920. if table.count(regenerationattr) == 0 then
  1921. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1922. return
  1923. end
  1924. local cfgRegeneration1 = ConfigDataManager.getById("cfg_equip_regeneration", equip1.cfgid)
  1925. local cfgRegeneration2 = ConfigDataManager.getById("cfg_equip_regeneration", equip2.cfgid)
  1926. if cfgRegeneration1 == nil or cfgRegeneration2 == nil then
  1927. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1928. return
  1929. end
  1930. if cfgRegeneration1.group ~= cfgRegeneration2.group then
  1931. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1932. return
  1933. end
  1934. local cfgItem1 = ConfigDataManager.getById("cfg_item", equip1.cfgid)
  1935. local cfgItem2 = ConfigDataManager.getById("cfg_item", equip2.cfgid)
  1936. local strPart1 = (not string.isNullOrEmpty(cfgItem1.strpart) and string.split(cfgItem1.strpart, "#") or {})
  1937. local strPart2 = (not string.isNullOrEmpty(cfgItem2.strpart) and string.split(cfgItem2.strpart, "#") or {})
  1938. local isFind = false
  1939. for i, v in ipairs(strPart1) do
  1940. local findIndex, cfg =
  1941. table.findByCondi(
  1942. strPart2,
  1943. function(a)
  1944. if tonumber(a) <= 3 and tonumber(v) <= 3 then
  1945. return true
  1946. end
  1947. return tonumber(a) == tonumber(v)
  1948. end
  1949. )
  1950. if findIndex ~= nil then
  1951. isFind = true
  1952. break
  1953. end
  1954. end
  1955. if isFind == false then
  1956. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备选择错误")
  1957. return
  1958. end
  1959. local costs = {}
  1960. local strCosts = string.split(cfg.costs, "|")
  1961. for i, v in ipairs(strCosts) do
  1962. local strItem = string.split(v, "#")
  1963. table.insert(costs, {cfgid = strItem[1], count = strItem[2]})
  1964. end
  1965. -- 校验道具是否足够
  1966. local enough = Bag.checkItemEnough(actor, costs)
  1967. if enough == false then
  1968. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  1969. return
  1970. end
  1971. -- 扣道具
  1972. for _, v in ipairs(costs) do
  1973. local cId = v["cfgid"]
  1974. local count = v["count"]
  1975. removeitemfrombag(actor, cId, count, 0, 9999, "装备再生")
  1976. end
  1977. API.SetItemData(actor, itemId1, "regenerationlv", 0)
  1978. API.SetItemData(actor, itemId1, "regenerationattr", {})
  1979. API.SetItemData(actor, itemId2, "regenerationlv", 1)
  1980. API.SetItemData(actor, itemId2, "regenerationattr", regenerationattr)
  1981. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  1982. local equipdata2 = alldata[itemId2]
  1983. if equipdata2 == nil then
  1984. EquipAndAppear.initequipluaextdata(alldata, itemId2)
  1985. equipdata2 = alldata[itemId2]
  1986. end
  1987. equipdata2.regenerationlv = 1
  1988. equipdata2.regenerationattr = regenerationattr
  1989. local equipdata1 = alldata[itemId1]
  1990. if equipdata1 == nil then
  1991. EquipAndAppear.initequipluaextdata(alldata, itemId1)
  1992. equipdata1 = alldata[itemId1]
  1993. end
  1994. equipdata1.regenerationlv = 0
  1995. equipdata1.regenerationattr = {}
  1996. setplaydef(actor, "T$luaitemextdata", alldata)
  1997. local alldata2 = getplaydef(actor, "T$regeneration")
  1998. if alldata2 ~= nil then
  1999. alldata2[itemId1] = nil
  2000. alldata2[itemId2] = nil
  2001. end
  2002. setplaydef(actor, "T$regeneration", alldata2)
  2003. sendluamsg(actor, LuaMessageIdToSever.RES_EQUIP_REGENERATION_MOVE, {})
  2004. end
  2005. -- 词条强化
  2006. function EquipAndAppear.strengthregenerationattr(actor, msgData)
  2007. local itemId = msgData.itemId
  2008. local allequip = getplaydef(actor, "T$luaitemextdata")
  2009. local ext = allequip[itemId]
  2010. local equip = getequipinfo(actor, itemId, 1)
  2011. local group = ConfigDataManager.getTableValue("cfg_equip_regeneration", "group", "id", equip.cfgid)
  2012. local lv = ext.regenerationlv
  2013. local data = ConfigDataManager.getTable("cfg_equip_regenerationCost", "group", group, "level", lv)
  2014. if table.count(data) == 0 then
  2015. sendluamsg(actor, LuaMessageIdToClient.TIPS, "当前装备词条不能强化!")
  2016. return
  2017. end
  2018. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip.cfgid)
  2019. if tonumber(maxLevel) < lv + 1 then
  2020. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已再生到最大等级")
  2021. return
  2022. end
  2023. local str = data[1].cost
  2024. local cost = splitbyshuxianandjinghao(str)
  2025. -- 检查材料
  2026. local enough = Bag.checkItemEnough(actor, cost)
  2027. if enough == false then
  2028. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
  2029. return
  2030. end
  2031. -- 扣道具
  2032. for _, v in ipairs(cost) do
  2033. local cId = v["cfgid"]
  2034. local count = v["count"]
  2035. removeitemfrombag(actor, cId, count, 0, 9999, "装备外观")
  2036. end
  2037. -- 计算成功率
  2038. local rate = data[1].rate
  2039. local randomNum = math.random(1, 10000)
  2040. if randomNum > tonumber(rate) then
  2041. -- 强化失败
  2042. sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, false)
  2043. return
  2044. end
  2045. -- 强化成功增加属性
  2046. local regenerationattr = ext.regenerationattr
  2047. for i, value in pairs(regenerationattr) do
  2048. local key = value.id
  2049. local data = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", key)
  2050. if table.count(data) ~= 0 then
  2051. local sequence = data[1].sequence
  2052. -- 查找下一级属性
  2053. local nextdata =
  2054. ConfigDataManager.getTable(
  2055. "cfg_equip_regenerationGroup",
  2056. "group",
  2057. group,
  2058. "sequence",
  2059. sequence,
  2060. "level",
  2061. lv + 1
  2062. )
  2063. if table.count(nextdata) ~= 0 then
  2064. local att = nextdata[1].att
  2065. local attr = string.split(att, "#")
  2066. local dd = {}
  2067. dd[attr[1]] = tonumber(attr[2])
  2068. dd.id = tonumber(nextdata[1].id)
  2069. ext.regenerationattr[i] = dd
  2070. -- table.remove(ext.regenerationattr,key)
  2071. end
  2072. end
  2073. end
  2074. ext.regenerationlv = lv + 1
  2075. allequip[itemId] = ext
  2076. EquipAndAppear.SetItemExtData(actor, itemId, ext)
  2077. setplaydef(actor, "T$luaitemextdata", allequip)
  2078. -- 给客户端发消息
  2079. sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, true)
  2080. -- 更新强化追加等属性
  2081. EquipAndAppear.updateluaextattr(actor)
  2082. -- 更新洗练未替换的数据
  2083. updateregenoreplaceattr(actor, itemId, ext.regenerationlv, group)
  2084. end
  2085. function updateregenoreplaceattr(actor, itemId, lv, group)
  2086. local alldata = getplaydef(actor, "T$regeneration")
  2087. if alldata == nil then
  2088. return
  2089. end
  2090. local data = alldata[itemId]
  2091. if data == nil then
  2092. return
  2093. end
  2094. local attrs = data.entryAttr
  2095. if attrs == nil then
  2096. return
  2097. end
  2098. for i, id in pairs(data.entryAttr) do
  2099. local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id)
  2100. if table.count(td) ~= 0 then
  2101. local sequence = td[1].sequence
  2102. -- 查找对应等级属性
  2103. local nextdata =
  2104. ConfigDataManager.getTable(
  2105. "cfg_equip_regenerationGroup",
  2106. "group",
  2107. group,
  2108. "sequence",
  2109. sequence,
  2110. "level",
  2111. lv
  2112. )
  2113. if table.count(nextdata) ~= 0 then
  2114. attrs[i] = tonumber(nextdata[1].id)
  2115. end
  2116. end
  2117. end
  2118. data.entryAttr = attrs
  2119. alldata[itemId] = data
  2120. setplaydef(actor, "T$regeneration", alldata)
  2121. end
  2122. function mergeitemcost(cost, lockcost)
  2123. for _, item in pairs(lockcost) do
  2124. local flag = true
  2125. for _, value in pairs(cost) do
  2126. if item.cfgid == value.cfgid then
  2127. value.count = value.count + item.count
  2128. flag = false
  2129. end
  2130. end
  2131. if flag then
  2132. table.insert(cost, item)
  2133. end
  2134. end
  2135. return cost
  2136. end
  2137. function getlockcost(cost, lockattr)
  2138. local result = {}
  2139. local locknum = table.count(lockattr)
  2140. local lc = string.split(cost, "|")
  2141. local str = {}
  2142. if locknum ~= 0 then
  2143. str = string.split(lc[locknum], "&")
  2144. for _, value in pairs(str) do
  2145. local item = string.split(value, "#")
  2146. local i = {}
  2147. i.cfgid = item[1]
  2148. i.count = item[2]
  2149. table.insert(result, i)
  2150. end
  2151. else
  2152. result = splitbyshuxianandjinghao(cost)
  2153. end
  2154. return result
  2155. end
  2156. -- 根据权重随机词条数量
  2157. function random_weighted(weight_str, count)
  2158. local result = {}
  2159. if count <= 0 then
  2160. return result
  2161. end
  2162. local num = string.split(weight_str, "&")
  2163. local weight_total = 0
  2164. for _, value in pairs(num) do
  2165. local sum = string.split(value, "#")
  2166. weight_total = weight_total + tonumber(sum[2])
  2167. end
  2168. local random_weight = math.random(1, weight_total)
  2169. local cumulative_weight = 0
  2170. for _, value in pairs(num) do
  2171. local sum = string.split(value, "#")
  2172. local weight = tonumber(sum[2])
  2173. cumulative_weight = cumulative_weight + weight
  2174. if cumulative_weight >= random_weight then
  2175. table.insert(result, tonumber(sum[1]))
  2176. if table.count(result) == count then
  2177. return result
  2178. end
  2179. end
  2180. end
  2181. end
  2182. function random_weighted_one(attrsWeighteds, weightedTotal)
  2183. local random_weight = math.random(1, weightedTotal)
  2184. for i, v in ipairs(attrsWeighteds) do
  2185. if random_weight <= v.weighted then
  2186. return v
  2187. end
  2188. random_weight = random_weight - v.weighted
  2189. end
  2190. return attrsWeighteds[1]
  2191. end
  2192. function random_attr(attr_str, count)
  2193. local attrs = string.split(attr_str, "&")
  2194. local attrsWeighteds = {}
  2195. local weightedTotal = 0
  2196. for i, v in ipairs(attrs) do
  2197. local attr = string.split(v, "#")
  2198. local attrId = attr[1]
  2199. local attrWeighted = tonumber(attr[2])
  2200. weightedTotal = weightedTotal + attrWeighted
  2201. table.insert(attrsWeighteds, {attrId = attrId, weighted = attrWeighted})
  2202. end
  2203. local results = {}
  2204. for i = 1, count do
  2205. local attr = random_weighted_one(attrsWeighteds, weightedTotal)
  2206. if attr ~= nil then
  2207. table.insert(results, tonumber(attr.attrId))
  2208. end
  2209. end
  2210. return results
  2211. end
  2212. -- 构造随机词条权重库
  2213. function build_weight_attr(attdata, regenenrationattr, lockattr)
  2214. local entrystr = ""
  2215. local sequences = {}
  2216. for k, v in pairs(regenenrationattr) do
  2217. -- local sequence = ConfigDataManager.getTableValue("cfg_equip_regenerationGroup","Countkey","parameter",operateActivityId,"type",_rechargeType())
  2218. local cfgRegeneration = ConfigDataManager.getById("cfg_equip_regenerationGroup", v.id)
  2219. if cfgRegeneration ~= nil and not string.isNullOrEmpty(cfgRegeneration) then
  2220. sequences[cfgRegeneration.sequence] = tonumber(cfgRegeneration.weightdown)
  2221. end
  2222. end
  2223. for i, value in pairs(attdata) do
  2224. local len = #entrystr
  2225. local id = value.id
  2226. local flag = true
  2227. for _, k in pairs(lockattr) do
  2228. if k == id then
  2229. table.remove(attdata, i)
  2230. flag = false
  2231. end
  2232. end
  2233. if flag then
  2234. local weight = 0
  2235. local sequence = ConfigDataManager.getTableValue("cfg_equip_regenerationGroup", "sequence", "id", id)
  2236. if sequences[sequence] ~= nil then
  2237. weight = sequences[sequence]
  2238. end
  2239. if weight == 0 then
  2240. weight = value.weight
  2241. end
  2242. if len == 0 then
  2243. entrystr = id .. "#" .. weight
  2244. else
  2245. entrystr = entrystr .. "&" .. id .. "#" .. weight
  2246. end
  2247. end
  2248. end
  2249. return entrystr
  2250. end
  2251. function getequipssumstrengthlvtest(actor)
  2252. this.GetSumJewelryLv(actor)
  2253. end
  2254. ---获取角色全身装备强化等级
  2255. function EquipAndAppear.GetEquipsSumStrengthLv(actor)
  2256. return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL)
  2257. end
  2258. ---获取角色全身装备追加等级
  2259. function EquipAndAppear.GetEquipsSumAppendLv(actor)
  2260. return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_APPEND_LEVEL)
  2261. end
  2262. ---获取角色全身装备卓越词条数量(不包含再生词条)
  2263. function EquipAndAppear.GetEquipsSumExcellentEntryCount(actor)
  2264. return this.GetEquipsSumExcellentEntryCount(actor)
  2265. end
  2266. ---获取角色全身装备卓越词条数量(不包含再生词条)
  2267. function this.GetEquipsSumExcellentEntryCount(actor)
  2268. local allEquip = getputonequipinfo(actor)
  2269. if table.isNullOrEmpty(allEquip) then
  2270. return 0
  2271. end
  2272. local sumCount = 0
  2273. for _, equip in pairs(allEquip) do
  2274. local entryAttrMap = equip.entries
  2275. if not table.isNullOrEmpty(entryAttrMap) then
  2276. sumCount = sumCount + table.count(entryAttrMap)
  2277. end
  2278. end
  2279. return sumCount
  2280. end
  2281. ---获取全身首饰等级
  2282. function this.GetSumJewelryLv(actor)
  2283. return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL)
  2284. end
  2285. function this.GetSumLvByType(actor, lvType)
  2286. local equipList = getputonequipinfo(actor)
  2287. if table.isNullOrEmpty(equipList) then
  2288. return 0
  2289. end
  2290. local allEquip = EquipAndAppear.getLuaItemExtData(actor)
  2291. if table.isNullOrEmpty(allEquip) then
  2292. return 0
  2293. end
  2294. local sumLv = 0
  2295. for _, equipInfo in pairs(equipList) do
  2296. local itemId = equipInfo.id
  2297. local equip = allEquip[itemId]
  2298. local lv = this.GetEquipLvByType(equip, lvType)
  2299. if lv ~= 0 then
  2300. sumLv = sumLv + lv
  2301. end
  2302. end
  2303. return sumLv
  2304. end
  2305. function this.GetEquipLvByType(equip, lvType)
  2306. if table.isNullOrEmpty(equip) then
  2307. return 0
  2308. end
  2309. local lv = 0
  2310. if lvType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  2311. lv = equip.strengthlv
  2312. elseif lvType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  2313. lv = equip.appendlv
  2314. elseif lvType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  2315. lv = equip.ssuplv
  2316. end
  2317. if lv == nil then
  2318. return 0
  2319. end
  2320. return tonumber(lv)
  2321. end
  2322. ---更新装备信息记录
  2323. function EquipAndAppear.TryUpdateEquipInfoRecorde(actor, recordeType)
  2324. this.TryUpdateEquipInfoRecorde(actor, recordeType)
  2325. end
  2326. ---更新装备信息记录
  2327. function this.TryUpdateEquipInfoRecorde(actor, recordeType)
  2328. local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor)
  2329. if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  2330. local oldLv = equipInfoRecorde.max_strength_level
  2331. local newLv = EquipAndAppear.GetEquipsSumStrengthLv(actor)
  2332. if newLv > oldLv then
  2333. equipInfoRecorde.max_strength_level = newLv
  2334. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  2335. end
  2336. OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_STRENGTHEN_LV, newLv)
  2337. OpenServerCompetition.updateRankData(actor, CompetitionType.STRENGTHEN, newLv)
  2338. elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  2339. local oldLv = equipInfoRecorde.max_append_level
  2340. local newLv = EquipAndAppear.GetEquipsSumAppendLv(actor)
  2341. if newLv > oldLv then
  2342. equipInfoRecorde.max_append_level = newLv
  2343. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  2344. end
  2345. OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_APPEND_LV, newLv)
  2346. OpenServerCompetition.updateRankData(actor, CompetitionType.APPEND, newLv)
  2347. elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then
  2348. local oldCount = equipInfoRecorde.max_entry_count
  2349. local newCount = this.GetEquipsSumExcellentEntryCount(actor)
  2350. if newCount > oldCount then
  2351. equipInfoRecorde.max_entry_count = newCount
  2352. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  2353. OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.SUPERIOR_ENTRY_COUNT, newCount)
  2354. end
  2355. elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  2356. local oldLv = equipInfoRecorde.max_jewelry_level
  2357. local newLv = this.GetSumJewelryLv(actor)
  2358. if newLv > oldLv then
  2359. equipInfoRecorde.max_jewelry_level = newLv
  2360. this.SaveEquipInfoRecorde(actor, equipInfoRecorde)
  2361. end
  2362. OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.JEWELRY_LEVEL, newLv)
  2363. end
  2364. end
  2365. function EquipAndAppear.GetEquipInfoRecordeValue(actor, recordeType)
  2366. local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor)
  2367. if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then
  2368. return equipInfoRecorde.max_strength_level
  2369. elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then
  2370. return equipInfoRecorde.max_append_level
  2371. elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then
  2372. return equipInfoRecorde.max_entry_count
  2373. elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then
  2374. return equipInfoRecorde.max_jewelry_level
  2375. end
  2376. return 0
  2377. end
  2378. function EquipAndAppear.CheckPartEquipStrengthLv(actor, part, goalLv)
  2379. local equipList = getputonequipinfo(actor)
  2380. if table.isNullOrEmpty(equipList) then
  2381. return false
  2382. end
  2383. local allData = EquipAndAppear.getLuaItemExtData(actor)
  2384. if table.isNullOrEmpty(allData) then
  2385. return false
  2386. end
  2387. for _, equipInfo in pairs(equipList) do
  2388. local itemId = equipInfo.id
  2389. local cfgId = equipInfo.cfgid
  2390. local equipData = allData[itemId]
  2391. if not table.isNullOrEmpty(equipData) then
  2392. local strengthLv = equipData.strengthlv
  2393. if part == nil and strengthLv >= goalLv then
  2394. return true
  2395. end
  2396. if part ~= nil then
  2397. local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  2398. if tonumber(strPart) == part and strengthLv >= goalLv then
  2399. return true
  2400. end
  2401. end
  2402. end
  2403. end
  2404. return false
  2405. end
  2406. function checkspecificstageequipcounttest(actor)
  2407. EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, equipType)
  2408. end
  2409. ---检查阶段装备数量
  2410. function EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, ratingLimit)
  2411. local allEquip = getputonequipinfo(actor)
  2412. if table.isNullOrEmpty(allEquip) then
  2413. return 0
  2414. end
  2415. local sumCount = 0
  2416. for _, equip in pairs(allEquip) do
  2417. local cfgId = equip.cfgid
  2418. local armor = this.IsArmor(cfgId)
  2419. if armor then
  2420. local stage = tonumber(ConfigDataManager.getTableValue("cfg_item", "rank", "id", cfgId))
  2421. if stage ~= nil and (stageLimit == nil or stage >= stageLimit) then
  2422. local rating = EquipAndAppear.GetEquipRating(cfgId)
  2423. if table.isNullOrEmpty(ratingLimit) or ratingLimit == rating or table.contains(ratingLimit, rating) then
  2424. sumCount = sumCount + 1
  2425. end
  2426. end
  2427. end
  2428. end
  2429. return sumCount
  2430. end
  2431. ---获取装备评级
  2432. function EquipAndAppear.GetEquipRating(itemCfgId)
  2433. local ratingScore =
  2434. tonumber(ConfigDataManager.getTableValue("cfg_equip_entrylib", "initialrating", "id", itemCfgId))
  2435. if ratingScore == nil then
  2436. return 0
  2437. end
  2438. local equipQualityCfgList = ConfigDataManager.getTable("cfg_equip_quality")
  2439. if table.isNullOrEmpty(equipQualityCfgList) then
  2440. return 0
  2441. end
  2442. for rating, equipQualityCfg in pairs(equipQualityCfgList) do
  2443. local stageParam = string.split(equipQualityCfg["stage"], "#")
  2444. if ratingScore >= tonumber(stageParam[1]) and ratingScore <= tonumber(stageParam[2]) then
  2445. return tonumber(rating)
  2446. end
  2447. end
  2448. return 0
  2449. end
  2450. ---是否防具
  2451. function this.IsArmor(cfgId)
  2452. -- 策划要求代码写死
  2453. local strPart = tonumber(ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId))
  2454. if strPart == nil then
  2455. return false
  2456. end
  2457. if strPart == 4 or strPart == 5 or strPart == 6 or strPart == 7 or strPart == 8 then
  2458. return true
  2459. end
  2460. return false
  2461. end
  2462. function EquipAndAppear.SetItemExtData(actor, itemId, equipData)
  2463. local result = setitemextdata(actor, itemId, equipData)
  2464. if result == nil or result == false then
  2465. gameDebug.assertPrintTrace(false, actor, "setitemextdata失败!", itemId, equipData)
  2466. end
  2467. end
  2468. --
  2469. --
  2470. -- function EquipAndAppear.CheckPartEquipStrengthLv(actor, part,goalLv)
  2471. -- EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, "strengthlv")
  2472. -- end
  2473. --
  2474. -- function EquipAndAppear.CheckPartEquipAppendLv(actor, part, goalLv)
  2475. --
  2476. -- end
  2477. --
  2478. -- function EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, param)
  2479. -- jprint("--------------1", part, goalLv, param)
  2480. -- local allData = EquipAndAppear.getLuaItemExtData(actor)
  2481. -- if table.isNullOrEmpty(allData) then
  2482. -- return false
  2483. -- end
  2484. -- for itemId, equipData in pairs(allData) do
  2485. -- gameDebug.print("---- equip ----", itemId, equipData)
  2486. -- local strengthLv = equipData[param]
  2487. -- if part == nil and strengthLv >= goalLv then
  2488. -- return true
  2489. -- end
  2490. -- if part ~= nil then
  2491. -- local equip = getequipinfo(actor, itemId,1)
  2492. -- if not table.isNullOrEmpty(equip) then
  2493. -- local cfgId = equip.cfgid
  2494. -- local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)
  2495. -- if tonumber(strPart) == part and strengthLv >= goalLv then
  2496. -- return true
  2497. -- end
  2498. -- end
  2499. -- end
  2500. -- end
  2501. -- return false
  2502. -- end
  2503. -- 新道具入包
  2504. function EquipAndAppear.ItemAdd(actor, itemId, itemCfgId)
  2505. -- 必须是装备
  2506. local type = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
  2507. if tonumber(type) ~= ItemType.EQUIP then
  2508. return
  2509. end
  2510. local itemExtData = getitemextdata(actor, itemId)
  2511. if itemExtData == nil then
  2512. return
  2513. end
  2514. local allequip = getplaydef(actor, "T$luaitemextdata") or {}
  2515. allequip[itemId] = itemExtData
  2516. setplaydef(actor, "T$luaitemextdata", allequip)
  2517. end
  2518. -- 喇叭使用,跑马灯
  2519. function EquipAndAppear.Horn(actor, msgData)
  2520. info("MS => EquipAndAppear.Horn", msgData)
  2521. -- 检查消息内容
  2522. local content = msgData.content
  2523. if not content or content == "" then
  2524. tipinfo(actor, "消息内容不能为空")
  2525. return
  2526. end
  2527. -- 喇叭道具ID
  2528. local hornItemId = 23000008
  2529. -- 检测背包是否有喇叭道具
  2530. local hornCount = getbagitemcountbyid(actor, hornItemId)
  2531. if not hornCount or tonumber(hornCount) < 1 then
  2532. tipinfo(actor, "背包中没有喇叭道具")
  2533. return
  2534. end
  2535. -- 消耗一个喇叭道具
  2536. local removeResult = removeitemfrombag(actor, hornItemId, 1, 0, 9999, "使用喇叭")
  2537. if not removeResult then
  2538. tipinfo(actor, "消耗喇叭道具失败")
  2539. return
  2540. end
  2541. -- 获取玩家名称
  2542. local playerName = getbaseinfo(actor, "rolename")
  2543. info("MS => playerName", playerName)
  2544. if not playerName then
  2545. playerName = "未知玩家"
  2546. end
  2547. -- 构建跑马灯消息内容
  2548. local finalContent = "[" .. playerName .. "]: " .. content
  2549. -- 发送跑马灯消息给所有玩家
  2550. local allPlayers = getallplayer()
  2551. if allPlayers and #allPlayers > 0 then
  2552. for _, playerId in pairs(allPlayers) do
  2553. local playerActor = getactor(playerId)
  2554. if playerActor then
  2555. local horseled = {}
  2556. horseled.cfgId = 109
  2557. horseled.content = finalContent
  2558. sendluamsg(playerActor, LuaMessageIdToClient.HORSE_LAMP, horseled)
  2559. end
  2560. end
  2561. end
  2562. -- 发送成功提示给使用喇叭的玩家
  2563. tipinfo(actor, "喇叭消息发送成功")
  2564. info("MS => 喇叭消息发送成功", "玩家", playerName, "内容", content)
  2565. end
  2566. -- 新增消耗道具逻辑
  2567. function EquipAndAppear.addbuffcostitem(actor, itemConfigId, count)
  2568. local itemId = itemConfigId
  2569. local uid = getbaseinfo(actor, "uid")
  2570. info("EquipAndAppear.addbuffcostitem: " .. uid .. " " .. itemConfigId .. " " .. count)
  2571. if itemConfigId == 60080001 then
  2572. info("魔剑士id:" .. itemConfigId)
  2573. unlockusercareer(actor, 4, uid)
  2574. info("魔剑士已解锁")
  2575. return
  2576. elseif itemConfigId == 60080002 then
  2577. info("圣导师id:" .. itemConfigId)
  2578. unlockusercareer(actor, 5, uid)
  2579. info("圣导师已解锁")
  2580. return
  2581. elseif itemConfigId == 60080003 then
  2582. info("召唤师id:" .. itemConfigId)
  2583. local result = unlockusercareer(actor, 6, uid)
  2584. info("召唤师已解锁")
  2585. info("召唤师解锁结果:" .. result)
  2586. return
  2587. end
  2588. -- 检测战旗/纪念戒指词条重置符
  2589. if itemId == "60090007" or itemId == 60090007 then
  2590. -- 检测战旗/纪念戒指属性重置符
  2591. info("使用纪念戒指重置符")
  2592. -- 战旗/纪念戒指词条重置符处理
  2593. -- 获取玩家背包中的战旗或纪念戒指
  2594. local equipItems = getallequipinfo(actor)
  2595. if table.isNullOrEmpty(equipItems) then
  2596. sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置词条的装备(纪念戒指或战旗)")
  2597. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2598. return
  2599. end
  2600. local targetItems = {}
  2601. for _, equip in pairs(equipItems) do
  2602. local equipCfgId = equip.cfgid
  2603. -- 检查是否为纪念戒指(23000003)或战旗(23000002)
  2604. if equipCfgId == 23000003 or equipCfgId == 23000002 then
  2605. table.insert(targetItems, equip)
  2606. end
  2607. end
  2608. -- 如果没有找到目标装备,提示玩家
  2609. if #targetItems == 0 then
  2610. sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置词条的装备(纪念戒指或战旗)")
  2611. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2612. return
  2613. end
  2614. -- 如果只有一个目标装备,直接处理
  2615. if #targetItems == 1 then
  2616. -- this.resetEquipEntryWithRandomAttrs(actor, 23000003, itemId, count)
  2617. this.resetEquipEntryWithRandomAttrs(actor, targetItems[1].id, itemId, count)
  2618. return
  2619. end
  2620. -- 如果有多个目标装备,需要玩家选择
  2621. -- 这里我们默认选择第一个找到的装备进行处理
  2622. -- 需要弹出选择界面
  2623. this.resetEquipEntryWithRandomAttrs(actor, targetItems[1].id, itemId, count)
  2624. return
  2625. elseif itemId == "60090008" or itemId == 60090008 then
  2626. info("使用战旗/纪念戒指属性重置符")
  2627. -- 战旗/纪念戒指属性重置符处理
  2628. -- 获取玩家背包中的战旗或纪念戒指
  2629. local equipItems = getallequipinfo(actor)
  2630. if table.isNullOrEmpty(equipItems) then
  2631. sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置属性的装备(纪念戒指或战旗)")
  2632. if itemId and count then
  2633. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  2634. end
  2635. return
  2636. end
  2637. local targetItems = {}
  2638. for _, equip in pairs(equipItems) do
  2639. local equipCfgId = equip.cfgid
  2640. -- 检查是否为纪念戒指(23000003)或战旗(23000002)
  2641. if equipCfgId == 23000003 or equipCfgId == 23000002 then
  2642. table.insert(targetItems, equip)
  2643. end
  2644. end
  2645. -- 如果没有找到目标装备,提示玩家
  2646. if #targetItems == 0 then
  2647. sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置属性的装备(纪念戒指或战旗)")
  2648. if itemId and count then
  2649. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  2650. end
  2651. return
  2652. end
  2653. -- 如果只有一个目标装备,直接处理
  2654. if #targetItems == 1 then
  2655. this.resetEquipPropertyWithFourRandomAttrs(actor, targetItems[1].id, itemId, count)
  2656. return
  2657. end
  2658. -- 如果有多个目标装备,选择第一个找到的装备进行处理
  2659. this.resetEquipPropertyWithFourRandomAttrs(actor, targetItems[1].id, itemId, count)
  2660. return
  2661. end
  2662. -- 使用大天使属性重置符
  2663. if itemId == "60090009" or itemId == 60090009 then
  2664. info("使用大天使属性重置符")
  2665. -- sendluamsg(actor, LuaMessageIdToClient.REQ_RESET_ANGEL_TALENT_POINT, {})
  2666. local result = this.useAngelEquipResetItem(actor, itemId, count)
  2667. if not result then
  2668. -- 如果使用失败,恢复道具
  2669. Bag.addItemToBag(actor, itemId, count, 0, 9999, "大天使属性重置符使用失败")
  2670. end
  2671. return
  2672. end
  2673. -- 检查是否为血色城堡通行证
  2674. if itemId == "50010013" then
  2675. -- 检查是否为赤色要塞通行证
  2676. local result = this.useBloodyCastleTicket(actor, itemId, count)
  2677. if not result then
  2678. -- 如果使用失败,恢复道具
  2679. Bag.addItemToBag(actor, itemId, count, 0, 9999, "血色城堡门票使用失败")
  2680. end
  2681. return
  2682. elseif itemId == "50010014" then
  2683. -- 检查是否为卡利玛神庙通行证
  2684. local result = this.useRedFortressTicket(actor, itemId, count)
  2685. if not result then
  2686. -- 如果使用失败,恢复道具
  2687. Bag.addItemToBag(actor, itemId, count, 0, 9999, "赤色要塞门票使用失败")
  2688. end
  2689. return
  2690. elseif itemId == "50010015" then
  2691. local result = this.useKalimaTempleTicket(actor, itemId, count)
  2692. if not result then
  2693. -- 如果使用失败,恢复道具
  2694. Bag.addItemToBag(actor, itemId, count, 0, 9999, "卡利玛神庙门票使用失败")
  2695. end
  2696. return
  2697. end
  2698. -- 检查是否为大师天赋洗点果实
  2699. if itemId == "60090006" then
  2700. local result = this.useMasterTalentResetFruit(actor, itemId, count)
  2701. if not result then
  2702. -- 如果使用失败,恢复道具
  2703. Bag.addItemToBag(actor, itemId, count, 0, 9999, "大师天赋洗点果实使用失败")
  2704. end
  2705. return
  2706. end
  2707. end
  2708. -- 使用大天使属性重置符
  2709. function this.useAngelEquipResetItem(actor, itemId, count)
  2710. -- 检查道具数量
  2711. local hasCount = getbagitemcountbyid(actor, itemId)
  2712. if hasCount == nil or tonumber(hasCount) < count then
  2713. sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具数量不足,无法使用大天使属性重置符")
  2714. return false
  2715. end
  2716. -- 获取玩家身上穿戴的大天使装备(武器、项链、戒指、旗帜)
  2717. local angelEquips = {}
  2718. local equipInfo = getputonequipinfo(actor)
  2719. if not table.isNullOrEmpty(equipInfo) then
  2720. for _, equip in pairs(equipInfo) do
  2721. local equipCfgId = equip["cfgid"]
  2722. -- 检查是否为大天使装备
  2723. if AngelMajorEquipment.isAngelEquip(equipCfgId) then
  2724. -- 检查是否为武器(1)、项链(2)、戒指(3)、旗帜(11)
  2725. local strPart = ConfigDataManager.getTableValue("cfg_item", "strPart", "id", equipCfgId)
  2726. if strPart == 1 or strPart == 2 or strPart == 3 or strPart == 11 then
  2727. table.insert(angelEquips, equip)
  2728. end
  2729. end
  2730. end
  2731. end
  2732. -- 如果没有找到符合条件的大天使装备
  2733. if #angelEquips == 0 then
  2734. noticeTip.noticeinfo(actor, "您身上没有穿戴可重置的大天使装备(武器、项链、戒指、旗帜)")
  2735. return false
  2736. end
  2737. -- 扣除道具
  2738. removeitemfrombag(actor, itemId, count, 0, 9999, "大天使属性重置符")
  2739. -- 重置每件装备的属性
  2740. for _, equip in pairs(angelEquips) do
  2741. this.resetAngelEquipRandomAttrs(actor, equip["id"], equip["cfgid"])
  2742. end
  2743. noticeTip.noticeinfo(actor, "成功重置大天使装备属性,生成了3-6条随机属性")
  2744. return true
  2745. end
  2746. -- 重置大天使装备的随机属性
  2747. function this.resetAngelEquipRandomAttrs(actor, equipId, equipCfgId)
  2748. -- 获取装备属性信息
  2749. local equipAttr = getplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA)
  2750. if table.isNullOrEmpty(equipAttr) then
  2751. equipAttr = {}
  2752. end
  2753. local equipInfo = equipAttr[equipId]
  2754. if table.isNullOrEmpty(equipInfo) then
  2755. equipInfo = {}
  2756. end
  2757. -- 获取装备当前等级
  2758. local level = equipInfo["level"] or 1
  2759. -- 获取装备组ID
  2760. local groupId = ConfigDataManager.getTableValue("cfg_equip_angelGroup", "angelEquipGroup", "id", equipCfgId)
  2761. if not groupId then
  2762. return false
  2763. end
  2764. -- 获取该等级的属性配置
  2765. local attrConfig = ConfigDataManager.getTable("cfg_equip_angelAtt", "ornamentsGroup", groupId, "lv", level)
  2766. if table.isNullOrEmpty(attrConfig) then
  2767. return false
  2768. end
  2769. -- 随机生成3-6条属性
  2770. local minAttrs = 3
  2771. local maxAttrs = 6
  2772. local attrCount = math.random(minAttrs, maxAttrs)
  2773. -- 获取所有可用的属性条目(从词条库中)
  2774. local allEntries = ConfigDataManager.getTable("cfg_equip_angelEntry")
  2775. if table.isNullOrEmpty(allEntries) then
  2776. return false
  2777. end
  2778. -- 筛选出合适的属性组(根据装备类型)
  2779. local validEntries = {}
  2780. -- 根据装备配置ID判断装备类型并选择合适的属性组范围
  2781. local groupStart = 101 -- 1级绿色品质属性组
  2782. local groupEnd = 804 -- 8级金色品质属性组
  2783. for _, entry in pairs(allEntries) do
  2784. if entry.group >= groupStart and entry.group <= groupEnd then
  2785. table.insert(validEntries, entry)
  2786. end
  2787. end
  2788. -- 随机选择属性条目并生成属性值
  2789. local selectedAttrs = {}
  2790. for i = 1, math.min(attrCount, #validEntries) do
  2791. if #validEntries <= 0 then
  2792. break
  2793. end
  2794. local randomIndex = math.random(1, #validEntries)
  2795. local entry = validEntries[randomIndex]
  2796. table.remove(validEntries, randomIndex)
  2797. -- 从该条目中随机选择一个属性
  2798. local attList = entry.att
  2799. if not table.isNullOrEmpty(attList) then
  2800. local randomAttIndex = math.random(1, #attList)
  2801. local att = attList[randomAttIndex]
  2802. -- 生成属性值(在配置的范围内随机)
  2803. local attrId = att[1]
  2804. local minValue = att[2]
  2805. local maxValue = att[3]
  2806. local value = math.random(minValue, maxValue)
  2807. -- 累加相同属性的值
  2808. selectedAttrs[attrId] = (selectedAttrs[attrId] or 0) + value
  2809. end
  2810. end
  2811. -- 构造属性字符串
  2812. local attrString = ""
  2813. local attrIndex = 1
  2814. for attrId, value in pairs(selectedAttrs) do
  2815. if attrIndex > 1 then
  2816. attrString = attrString .. "|"
  2817. end
  2818. attrString = attrString .. attrId .. "#" .. value
  2819. attrIndex = attrIndex + 1
  2820. end
  2821. -- 更新装备属性信息
  2822. equipInfo["level"] = level
  2823. equipInfo["exp"] = equipInfo["exp"] or 0
  2824. equipInfo["rank"] = equipInfo["rank"] or 0
  2825. equipInfo["grails"] = equipInfo["grails"] or {}
  2826. equipAttr[equipId] = equipInfo
  2827. setplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA, equipAttr)
  2828. -- 移除旧属性
  2829. local attrKey = string.format(RoleAttrKey.ANGEL_MAJOR_EQUIPMENT, equipId)
  2830. RoleAttr.clearRoleAttrAndDB(actor, attrKey)
  2831. -- 添加新属性
  2832. if attrString ~= "" then
  2833. local attrTable = string.split(attrString, "|")
  2834. local temp = {}
  2835. for _, attr in pairs(attrTable) do
  2836. local tmps = string.split(attr, "#")
  2837. local attrId = tmps[1]
  2838. local attrValue = tmps[2]
  2839. if tonumber(attrValue) ~= 0 then
  2840. temp[tonumber(attrId)] = tonumber(attrValue)
  2841. end
  2842. end
  2843. RoleAttr.addAndSaveRoleAttr(actor, attrKey, temp)
  2844. end
  2845. -- 发送更新后的属性信息给客户端
  2846. local res = {}
  2847. res[equipId] = equipInfo
  2848. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_ANGEL_EQUIPMENT_ATTR_INFO, res)
  2849. return true
  2850. end
  2851. -- 重置装备词条为随机属性(排除减伤属性)
  2852. function this.resetEquipEntryWithRandomAttrs(actor, equipId, itemId, count)
  2853. info("使用战旗/纪念戒指词条重置符,重置装备ID:", equipId)
  2854. -- 获取装备信息
  2855. local equipInfo = getequipinfo(actor, equipId, 1)
  2856. -- info("装备信息:", equipInfo)
  2857. if not equipInfo or equipInfo == nil then
  2858. sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取装备信息")
  2859. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2860. return
  2861. end
  2862. info("装备信息:", equipInfo)
  2863. -- 获取所有词条配置
  2864. local allEntries = ConfigDataManager.getTable("cfg_equip_att")
  2865. -- local allEntries = ConfigDataManager.getTable("cfg_att_info")
  2866. info("所有词条配置数量:", allEntries and #allEntries or 0)
  2867. if not allEntries or allEntries == nil then
  2868. sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取词条配置")
  2869. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2870. return
  2871. end
  2872. -- 定义减伤属性ID(需要排除)
  2873. local excludedEntryId = 26
  2874. info("总词条数量:", #allEntries)
  2875. -- 过滤可用的词条(排除减伤属性)并构建带权重的列表
  2876. local availableEntries = {}
  2877. local totalWeight = 0
  2878. for _, entry in ipairs(allEntries) do
  2879. -- 确保不包含减伤属性
  2880. if entry.id ~= excludedEntryId and entry.id ~= 36 and entry.id ~= 37 and entry.id ~= 38 then
  2881. local attrParts = string.split(entry.att, "#")
  2882. local weight = 1 -- 默认权重
  2883. if #attrParts >= 4 then
  2884. weight = tonumber(attrParts[4]) or 1 -- 获取权重,如果不存在则为1
  2885. end
  2886. table.insert(
  2887. availableEntries,
  2888. {
  2889. entry = entry,
  2890. weight = weight
  2891. }
  2892. )
  2893. totalWeight = totalWeight + weight
  2894. end
  2895. end
  2896. if #availableEntries == 0 then
  2897. sendluamsg(actor, LuaMessageIdToClient.TIPS, "没有可用的词条")
  2898. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2899. return
  2900. end
  2901. info("可用词条数量:", #availableEntries, "总权重:", totalWeight)
  2902. -- 根据阶梯状概率选择词条数量(2条:3条:4条 = 60%:30%:10%)
  2903. local entryCountWeights = {
  2904. {
  2905. count = 2,
  2906. weight = 60
  2907. },
  2908. {
  2909. count = 3,
  2910. weight = 30
  2911. },
  2912. {
  2913. count = 4,
  2914. weight = 10
  2915. }
  2916. }
  2917. local totalCountWeight = 0
  2918. for _, cw in ipairs(entryCountWeights) do
  2919. totalCountWeight = totalCountWeight + cw.weight
  2920. end
  2921. local randomCountValue = math.random(1, totalCountWeight)
  2922. local cumulativeCountWeight = 0
  2923. local entryCount = 2 -- 默认2条
  2924. for _, cw in ipairs(entryCountWeights) do
  2925. cumulativeCountWeight = cumulativeCountWeight + cw.weight
  2926. if randomCountValue <= cumulativeCountWeight then
  2927. entryCount = cw.count
  2928. break
  2929. end
  2930. end
  2931. info("选择的词条数量:", entryCount)
  2932. local selectedEntries = {}
  2933. -- 生成新的词条列表(使用加权随机选择)
  2934. local tempAvailableEntries = {}
  2935. for i, weightedEntry in ipairs(availableEntries) do
  2936. tempAvailableEntries[i] = {
  2937. entry = weightedEntry.entry,
  2938. weight = weightedEntry.weight
  2939. }
  2940. end
  2941. local tempTotalWeight = totalWeight
  2942. -- 根据权重随机选择词条
  2943. for i = 1, entryCount do
  2944. if #tempAvailableEntries <= 0 or tempTotalWeight <= 0 then
  2945. break
  2946. end
  2947. -- 生成一个基于当前总权重的随机数
  2948. local randomValue = math.random(1, tempTotalWeight)
  2949. local currentWeight = 0
  2950. local selectedIndex = 1
  2951. -- 找到对应的词条
  2952. for j, weightedEntry in ipairs(tempAvailableEntries) do
  2953. currentWeight = currentWeight + weightedEntry.weight
  2954. if randomValue <= currentWeight then
  2955. selectedIndex = j
  2956. break
  2957. end
  2958. end
  2959. local selectedWeightedEntry = tempAvailableEntries[selectedIndex]
  2960. local entryCfg = selectedWeightedEntry.entry
  2961. info(string.format("选择的第%d条词条: ID=%d, 权重=%d", i, entryCfg.id, selectedWeightedEntry.weight))
  2962. local attrParts = string.split(entryCfg.att, "#")
  2963. local attrId = attrParts[1]
  2964. local minValue = attrParts[2]
  2965. local maxValue = attrParts[3]
  2966. info(
  2967. string.format(
  2968. "原始属性值: attrId=%s, minValue=%s, maxValue=%s",
  2969. tostring(attrId),
  2970. tostring(minValue),
  2971. tostring(maxValue)
  2972. )
  2973. )
  2974. -- 转换为数字
  2975. minValue = tonumber(minValue)
  2976. maxValue = tonumber(maxValue)
  2977. -- 创建词条对象
  2978. local entry = {
  2979. entryid = entryCfg.id,
  2980. attrid = attrId,
  2981. value = math.random(minValue, maxValue)
  2982. }
  2983. info("生成的词条对象:", entry)
  2984. table.insert(selectedEntries, entry)
  2985. -- 从可选列表中移除已选的词条,避免重复
  2986. tempTotalWeight = tempTotalWeight - selectedWeightedEntry.weight
  2987. table.remove(tempAvailableEntries, selectedIndex)
  2988. end
  2989. info("随机生成的词条:", selectedEntries)
  2990. -- 应用新的词条到装备
  2991. local result = resetequipentry(actor, equipId, selectedEntries)
  2992. -- info("resetequipentry结果:", result)
  2993. if not result then
  2994. sendluamsg(actor, LuaMessageIdToClient.TIPS, "词条重置失败")
  2995. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指词条重置符使用失败")
  2996. return
  2997. end
  2998. -- 删除使用的道具
  2999. local bagIdx = gainbagidxbyitemid(actor, itemId)
  3000. if bagIdx and bagIdx > 0 then
  3001. removeitembyidxlist(actor, {bagIdx}, 0, "词条重置")
  3002. end
  3003. -- 发送成功消息
  3004. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备词条重置成功!")
  3005. return true
  3006. end
  3007. -- 重置装备属性为四个随机属性(专门用于60090008道具,仅限四属性的战旗和纪念戒指)
  3008. function this.resetEquipPropertyWithFourRandomAttrs(actor, equipId, itemId, count)
  3009. info("使用战旗/纪念戒指属性重置符,重置装备ID:", equipId)
  3010. -- 获取装备信息
  3011. local equipInfo = getequipinfo(actor, equipId, 1)
  3012. info("装备信息:", equipInfo)
  3013. if not equipInfo or equipInfo == nil then
  3014. sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取装备信息")
  3015. if itemId and count then
  3016. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3017. end
  3018. return
  3019. end
  3020. -- 检查装备是否为四属性装备(纪念戒指23000003或战旗23000002)
  3021. local equipCfgId = equipInfo.cfgid
  3022. if equipCfgId ~= 23000003 and equipCfgId ~= 23000002 then
  3023. sendluamsg(actor, LuaMessageIdToClient.TIPS, "只能对纪念戒指或战旗使用此道具")
  3024. if itemId and count then
  3025. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3026. end
  3027. return
  3028. end
  3029. -- 检查装备当前是否具有四个属性
  3030. local entries = equipInfo.entries
  3031. if not entries or table.count(entries) ~= 4 then
  3032. sendluamsg(actor, LuaMessageIdToClient.TIPS, "只能对具有四个属性的装备使用此道具")
  3033. if itemId and count then
  3034. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3035. end
  3036. return
  3037. end
  3038. -- 获取所有词条配置
  3039. local allEntries = ConfigDataManager.getTable("cfg_equip_att")
  3040. info("所有词条配置数量:", allEntries and #allEntries or 0)
  3041. if not allEntries or allEntries == nil then
  3042. sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取词条配置")
  3043. if itemId and count then
  3044. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3045. end
  3046. return
  3047. end
  3048. -- 定义减伤属性ID(需要排除)
  3049. local excludedEntryId = 312012
  3050. -- 过滤可用的词条(排除减伤属性)并构建带权重的列表
  3051. local availableEntries = {}
  3052. local totalWeight = 0
  3053. for _, entry in ipairs(allEntries) do
  3054. -- 确保不包含减伤属性
  3055. if entry.id ~= excludedEntryId then
  3056. local attrParts = string.split(entry.att, "#")
  3057. local weight = 1 -- 默认权重
  3058. if #attrParts >= 4 then
  3059. weight = tonumber(attrParts[4]) or 1 -- 获取权重,如果不存在则为1
  3060. end
  3061. table.insert(
  3062. availableEntries,
  3063. {
  3064. entry = entry,
  3065. weight = weight
  3066. }
  3067. )
  3068. totalWeight = totalWeight + weight
  3069. end
  3070. end
  3071. info("可用词条数量:", #availableEntries, "总权重:", totalWeight)
  3072. if #availableEntries == 0 then
  3073. sendluamsg(actor, LuaMessageIdToClient.TIPS, "没有可用的词条")
  3074. if itemId and count then
  3075. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3076. end
  3077. return
  3078. end
  3079. -- 固定选择4个属性
  3080. local propertyCount = 4
  3081. local selectedProperties = {}
  3082. -- 创建一个副本来避免重复选择
  3083. local tempAvailableEntries = {}
  3084. for i, weightedEntry in ipairs(availableEntries) do
  3085. tempAvailableEntries[i] = {
  3086. entry = weightedEntry.entry,
  3087. weight = weightedEntry.weight
  3088. }
  3089. end
  3090. local tempTotalWeight = totalWeight
  3091. -- 生成4个随机属性(使用加权随机选择)
  3092. for i = 1, propertyCount do
  3093. if #tempAvailableEntries <= 0 or tempTotalWeight <= 0 then
  3094. break
  3095. end
  3096. -- 生成一个基于当前总权重的随机数
  3097. local randomValue = math.random(1, tempTotalWeight)
  3098. local currentWeight = 0
  3099. local selectedIndex = 1
  3100. -- 找到对应的词条
  3101. for j, weightedEntry in ipairs(tempAvailableEntries) do
  3102. currentWeight = currentWeight + weightedEntry.weight
  3103. if randomValue <= currentWeight then
  3104. selectedIndex = j
  3105. break
  3106. end
  3107. end
  3108. local selectedWeightedEntry = tempAvailableEntries[selectedIndex]
  3109. local entryCfg = selectedWeightedEntry.entry
  3110. info(string.format("选择的第%d个词条: ID=%d, 权重=%d", i, entryCfg.id, selectedWeightedEntry.weight))
  3111. local attrParts = string.split(entryCfg.att, "#")
  3112. local attrId = attrParts[1]
  3113. local minValue = attrParts[2]
  3114. local maxValue = attrParts[3]
  3115. info(
  3116. string.format(
  3117. "属性值范围: attrId=%s, minValue=%s, maxValue=%s",
  3118. tostring(attrId),
  3119. tostring(minValue),
  3120. tostring(maxValue)
  3121. )
  3122. )
  3123. -- 转换为数字
  3124. minValue = tonumber(minValue)
  3125. maxValue = tonumber(maxValue)
  3126. -- 确保最小值不大于最大值
  3127. if minValue > maxValue then
  3128. info(string.format("词条%d最小值大于最大值,交换值: %d > %d", entryCfg.id, minValue, maxValue))
  3129. minValue, maxValue = maxValue, minValue
  3130. end
  3131. -- 生成随机值
  3132. local randomValue
  3133. local success, errorMsg =
  3134. pcall(
  3135. function()
  3136. randomValue = math.random(minValue, maxValue)
  3137. return true
  3138. end
  3139. )
  3140. if not success then
  3141. info(string.format("生成随机值失败: %s, 范围: %d - %d", tostring(errorMsg), minValue, maxValue))
  3142. sendluamsg(actor, LuaMessageIdToClient.TIPS, "生成随机值失败")
  3143. if itemId and count then
  3144. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3145. end
  3146. return
  3147. end
  3148. info(string.format("生成的随机值: %d", randomValue))
  3149. -- 创建属性对象
  3150. local propertyEntry = {
  3151. entryid = entryCfg.id, -- 词条ID
  3152. attrid = attrId, -- 属性ID
  3153. value = randomValue -- 随机生成的值
  3154. }
  3155. info("创建的属性对象:", propertyEntry)
  3156. table.insert(selectedProperties, propertyEntry)
  3157. info(string.format("已添加第%d个词条到列表", i))
  3158. -- 从可用列表中移除已选词条,避免重复
  3159. tempTotalWeight = tempTotalWeight - selectedWeightedEntry.weight
  3160. table.remove(tempAvailableEntries, selectedIndex)
  3161. end
  3162. if #selectedProperties ~= 4 then
  3163. info(string.format("生成的词条数量不正确: 期望4个,实际%d个", #selectedProperties))
  3164. sendluamsg(actor, LuaMessageIdToClient.TIPS, "词条生成数量错误")
  3165. if itemId and count then
  3166. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3167. end
  3168. return
  3169. end
  3170. info("随机生成的4个词条:", selectedProperties)
  3171. -- 应用新的属性到装备
  3172. local result = resetequipentry(actor, equipId, selectedProperties)
  3173. info("resetequipentry结果:", result)
  3174. if not result then
  3175. sendluamsg(actor, LuaMessageIdToClient.TIPS, "属性重置失败")
  3176. if itemId and count then
  3177. Bag.addItemToBag(actor, itemId, count, 0, 9999, "战旗/纪念戒指属性重置符使用失败")
  3178. end
  3179. return
  3180. end
  3181. -- 删除使用的道具
  3182. if itemId and count then
  3183. local bagIdx = gainbagidxbyitemid(actor, itemId)
  3184. if bagIdx and bagIdx > 0 then
  3185. removeitembyidxlist(actor, {bagIdx}, 0, "属性重置")
  3186. end
  3187. end
  3188. -- 发送成功消息
  3189. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备属性重置成功!")
  3190. return true
  3191. end
  3192. -- 使用血色城堡通行证(ID 50010013)
  3193. function this.useBloodyCastleTicket(actor, itemId, count)
  3194. -- 检查道具数量
  3195. local hasCount = getbagitemcountbyid(actor, itemId)
  3196. if hasCount == nil or tonumber(hasCount) < count then
  3197. noticeTip.noticeinfo(actor, "道具数量不足")
  3198. return false
  3199. end
  3200. -- 获取血色城堡面板信息
  3201. local configId = 11001 -- 默认使用第一个血色城堡配置
  3202. -- 检查玩家等级是否符合要求
  3203. local playerLevel = getbaseinfo(actor, "level")
  3204. local castleConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId)
  3205. if castleConfig == nil or #castleConfig == 0 then
  3206. noticeTip.noticeinfo(actor, "无法获取血色城堡配置信息")
  3207. return false
  3208. end
  3209. local minLevel = castleConfig[1][1]
  3210. local maxLevel = castleConfig[1][2]
  3211. if playerLevel < minLevel or playerLevel > maxLevel then
  3212. noticeTip.noticeinfo(actor, "您的等级不符合该血色城堡的要求")
  3213. return false
  3214. end
  3215. -- 检查今日剩余次数
  3216. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  3217. local leftCount = getleftcountofactivity(actor, activityId)
  3218. if leftCount <= 0 then
  3219. noticeTip.noticeinfo(actor, "今日血色城堡挑战次数已用完")
  3220. return false
  3221. end
  3222. -- 扣除道具
  3223. removeitemfrombag(actor, itemId, count, 0, 9999, "血色城堡")
  3224. -- 请求进入血色城堡
  3225. BloodyCastle.ReqEnterBloodyCastle(actor, configId)
  3226. noticeTip.noticeinfo(actor, "正在进入血色城堡...")
  3227. return true
  3228. end
  3229. -- 使用赤色要塞通行证(ID 50010014)
  3230. function this.useRedFortressTicket(actor, itemId, count)
  3231. -- 检查道具数量
  3232. local hasCount = getbagitemcountbyid(actor, itemId)
  3233. if hasCount == nil or tonumber(hasCount) < count then
  3234. noticeTip.noticeinfo(actor, "道具数量不足")
  3235. return false
  3236. end
  3237. -- 获取赤色要塞配置信息
  3238. local configId = 17001 -- 默认使用第一个赤色要塞配置
  3239. -- 检查玩家等级是否符合要求
  3240. local playerLevel = getbaseinfo(actor, "level")
  3241. local fortressConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId)
  3242. if fortressConfig == nil or #fortressConfig == 0 then
  3243. noticeTip.noticeinfo(actor, "无法获取赤色要塞配置信息")
  3244. return false
  3245. end
  3246. local minLevel = fortressConfig[1][1]
  3247. local maxLevel = fortressConfig[1][2]
  3248. if playerLevel < minLevel or playerLevel > maxLevel then
  3249. noticeTip.noticeinfo(actor, "您的等级不符合该赤色要塞的要求")
  3250. return false
  3251. end
  3252. -- 检查今日剩余次数
  3253. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  3254. local leftCount = getleftcountofactivity(actor, activityId)
  3255. if leftCount <= 0 then
  3256. noticeTip.noticeinfo(actor, "今日赤色要塞挑战次数已用完")
  3257. return false
  3258. end
  3259. -- 扣除道具
  3260. removeitemfrombag(actor, itemId, count, 0, 9999, "赤色要塞")
  3261. -- 请求进入赤色要塞
  3262. RedFortress.ReqEnterRedFortress(actor, configId)
  3263. noticeTip.noticeinfo(actor, "正在进入赤色要塞...")
  3264. return true
  3265. end
  3266. -- 使用卡利玛神庙通行证(ID 50010015)
  3267. function this.useKalimaTempleTicket(actor, itemId, count)
  3268. -- 检查道具数量
  3269. local hasCount = getbagitemcountbyid(actor, itemId)
  3270. if hasCount == nil or tonumber(hasCount) < count then
  3271. noticeTip.noticeinfo(actor, "道具数量不足")
  3272. return false
  3273. end
  3274. -- 获取卡利玛神庙配置信息
  3275. local configId = 19001001 -- 默认使用第一个卡利玛神庙配置
  3276. -- 检查玩家等级是否符合要求
  3277. local playerLevel = getbaseinfo(actor, "level")
  3278. local templeConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId)
  3279. if templeConfig == nil or #templeConfig == 0 then
  3280. noticeTip.noticeinfo(actor, "无法获取卡利玛神庙配置信息")
  3281. return false
  3282. end
  3283. local minLevel = templeConfig[1][1]
  3284. local maxLevel = templeConfig[1][2]
  3285. if playerLevel < minLevel or playerLevel > maxLevel then
  3286. noticeTip.noticeinfo(actor, "您的等级不符合该卡利玛神庙的要求")
  3287. return false
  3288. end
  3289. -- 检查今日剩余次数
  3290. local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId)
  3291. local leftCount = getleftcountofactivity(actor, activityId)
  3292. if leftCount <= 0 then
  3293. noticeTip.noticeinfo(actor, "今日卡利玛神庙挑战次数已用完")
  3294. return false
  3295. end
  3296. -- 扣除道具
  3297. removeitemfrombag(actor, itemId, count, 0, 9999, "卡利玛神庙")
  3298. -- 请求进入卡利玛神庙
  3299. KalimaTemple.ReqEnterKalimaTemple(actor, configId)
  3300. noticeTip.noticeinfo(actor, "正在进入卡利玛神庙...")
  3301. return true
  3302. end
  3303. -- 使用大师天赋洗点果实
  3304. function this.useMasterTalentResetFruit(actor, itemId, count)
  3305. -- 检查道具数量
  3306. local hasCount = getbagitemcountbyid(actor, itemId)
  3307. if hasCount == nil or tonumber(hasCount) < count then
  3308. noticeTip.noticeinfo(actor, "道具数量不足")
  3309. return false
  3310. end
  3311. -- 检查玩家是否有大师天赋数据
  3312. local masterTalentData = getplaydef(actor, "T$大师天赋数据")
  3313. if masterTalentData == nil or next(masterTalentData) == nil then
  3314. noticeTip.noticeinfo(actor, "您还没有大师天赋数据")
  3315. return false
  3316. end
  3317. -- 扣除道具
  3318. removeitemfrombag(actor, itemId, count, 0, 9999, "大师天赋洗点果实")
  3319. -- 重置所有类型的大师天赋
  3320. for _, masterType in pairs(MasterTalentType) do
  3321. local msgData = {
  3322. type = masterType
  3323. }
  3324. Master.reqResetMaster(actor, msgData)
  3325. end
  3326. noticeTip.noticeinfo(actor, "大师天赋点数已重置")
  3327. return true
  3328. end
  3329. function EquipAndAppear.equipFix(actor, msgData)
  3330. local itemId = msgData.itemId
  3331. local equipInfo = getequipinfo(actor, itemId, 1)
  3332. if equipInfo == nil then
  3333. sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备不存在")
  3334. return
  3335. end
  3336. local cfg = ConfigDataManager.getById("cfg_equip_fix", equipInfo.cfgid)
  3337. if cfg == nil then
  3338. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备不可修复")
  3339. return
  3340. end
  3341. local isFixed = API.GetItemData(actor, itemId, "isfixed") or 0
  3342. if isFixed ~= nil and isFixed == 1 then
  3343. sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已修复,不可再次修复")
  3344. return
  3345. end
  3346. API.SetItemData(actor, itemId, "isfixed", 1)
  3347. -- local equips = getputonequipinfo(actor)
  3348. -- local equip = equips[1] --测试,取一件装备
  3349. -- local equipId = equip.id
  3350. -- setequipbasicattr(actor,equipId,1,{{attrid=200011,value=10},{attrid=200021,value=120}});
  3351. -- --或者这样也可以
  3352. -- --setequipbasicattr(actor,equipId,1,{[200011]=10,[200021]=40});
  3353. local fixTypes = string.split(cfg.fixs, "#")
  3354. for i, v in ipairs(fixTypes) do
  3355. if v == "1" then
  3356. EquipAndAppear.resetBasicattr(actor, equipInfo)
  3357. elseif v == "2" then
  3358. EquipAndAppear.resetEntries(actor, equipInfo)
  3359. end
  3360. end
  3361. APISendCenterMsg(actor, "装备修复成功", "#00ff00")
  3362. end
  3363. function EquipAndAppear.resetBasicattr(actor, equipInfo)
  3364. local cfgEquip = ConfigDataManager.getById("cfg_equip_entryLib", equipInfo.cfgid)
  3365. if cfgEquip == nil then
  3366. return false
  3367. end
  3368. local basicattr = {}
  3369. local attributes = string.split(cfgEquip.attribute, "|")
  3370. for i, v in ipairs(attributes) do
  3371. local abs = string.split(v, "#")
  3372. local aid = tonumber(abs[1])
  3373. local anum = tonumber(abs[2])
  3374. table.insert(basicattr, {attrid = aid, value = anum})
  3375. end
  3376. setequipbasicattr(actor, equipInfo.id, 1, basicattr)
  3377. APISendCenterMsg(actor, "装备基本属性重置成功!", "#00ff00")
  3378. return true
  3379. end
  3380. function EquipAndAppear.resetEntries(actor, equipInfo)
  3381. local cfgEquip = ConfigDataManager.getById("cfg_equip_entryLib", equipInfo.cfgid)
  3382. if cfgEquip == nil then
  3383. return false
  3384. end
  3385. local num = EquipRefined.random_weighted2(cfgEquip.attcountweight, 1)[1]
  3386. if EquipRefined.resetEquipEntryWithRandomAttrs(actor, equipInfo.id, num) == false then
  3387. return false
  3388. end
  3389. return true
  3390. end