CommonUtil.lua 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088
  1. module("CommonUtil", package.seeall);
  2. function GetMetatableLua(obj)
  3. return getmetatable(obj)
  4. end
  5. function StringConcat(...)
  6. local list = {...}
  7. local result = ""
  8. for i = 1, #list do
  9. result = result .. tostring(list[i])
  10. end
  11. return result
  12. end
  13. function BindGridViewItem2LuaStatic(name, go)
  14. if go == nil or tolua.isnull(go) then
  15. return nil
  16. end
  17. local lua = require("GridViewItem/"..name.."_Generate"):new()
  18. if lua ~= nil then
  19. lua.gameObject = go
  20. lua:InitGenerate(go.transform)
  21. else
  22. lua = go
  23. end
  24. return lua
  25. end
  26. function BindGridViewItem2Lua(wndOwner, name, go)
  27. if wndOwner.gridItemList == nil then
  28. wndOwner.gridItemList = {}
  29. end
  30. if wndOwner.gridItemList[name] == nil then
  31. wndOwner.gridItemList[name] = {}
  32. end
  33. if go == nil or tolua.isnull(go) then
  34. return nil
  35. end
  36. local lua = wndOwner.gridItemList[name][go]
  37. if not lua then
  38. lua = require("GridViewItem/"..name.."_Generate"):new()
  39. wndOwner.gridItemList[name][go] = lua
  40. lua.gameObject = go
  41. lua:InitGenerate(go.transform)
  42. end
  43. return lua
  44. end
  45. function GetBindGridViewItem2Lua(wndOwner, name, go)
  46. if wndOwner.gridItemList == nil then
  47. return nil
  48. end
  49. if wndOwner.gridItemList[name] == nil then
  50. return nil
  51. end
  52. return wndOwner.gridItemList[name][go]
  53. end
  54. function ClearBindGridViewItem2Lua(wndOwner, name, go)
  55. if wndOwner.gridItemList == nil then
  56. return
  57. end
  58. if wndOwner.gridItemList[name] == nil then
  59. return
  60. end
  61. local itemLua = wndOwner.gridItemList[name][go]
  62. if not itemLua then return end
  63. if itemLua.uIEffectCfg then
  64. itemLua.uIEffectCfg:Clean()
  65. end
  66. itemLua:GenerateDestroy()
  67. itemLua.uiParticle = nil
  68. itemLua.gameObject = nil
  69. itemLua.transform = nil
  70. wndOwner.gridItemList[name][go] = nil
  71. end
  72. function ClearGridViewItem(wndOwner, name)
  73. if wndOwner.gridItemList == nil then
  74. return
  75. end
  76. if wndOwner.gridItemList[name] == nil then
  77. return
  78. end
  79. for k,v in pairs(wndOwner.gridItemList[name]) do
  80. if v.uIEffectCfg then
  81. v.uIEffectCfg:Clean()
  82. end
  83. v:GenerateDestroy()
  84. v.uiParticle = nil
  85. v.gameObject = nil
  86. v.transform = nil
  87. end
  88. wndOwner.gridItemList[name] = nil
  89. end
  90. function SetCanvasGroupStatus(go, status)
  91. --local canvasGroup = go:GetOrAddComponent(Enum.TypeInfo.CanvasGroup)
  92. --canvasGroup.alpha = status and 1 or 0
  93. --canvasGroup.interactable = status and true or false
  94. --canvasGroup.blocksRaycasts = status and true or false
  95. go:SetActive(status)
  96. end
  97. function LoopGridViewEleCreate(wndOwner, loopScrollRect, gridLayoutGroup, list, interTime, updateCB, needWhole, svRectTransform)
  98. LoopGridViewEleCreateNew(wndOwner, loopScrollRect, gridLayoutGroup, list, interTime, nil,updateCB, needWhole, svRectTransform)
  99. end
  100. function LoopGridViewEleCreateNew(wndOwner, loopScrollRect, gridLayoutGroup, list, interTime, luaTbl,updateCB, needWhole, svRectTransform,movePos)
  101. if loopScrollRect == nil then return end
  102. if needWhole then
  103. loopScrollRect.totalCount = math.ceil(#list / loopScrollRect.contentConstraintCount)
  104. local elm = loopScrollRect.Cell:GetComponent(Enum.TypeInfo.LayoutElement)
  105. local height = loopScrollRect.totalCount * elm.preferredHeight
  106. local oriSize = svRectTransform.sizeDelta
  107. oriSize.y = height
  108. svRectTransform.sizeDelta = oriSize
  109. end
  110. local function getRefreshCount()
  111. local count = loopScrollRect.totalCount * loopScrollRect.contentConstraintCount
  112. return count >= #list and #list or count
  113. end
  114. local gridViewItem = loopScrollRect.Cell:GetComponent(Enum.TypeInfo.UIGridViewMark)
  115. local name = gridViewItem and gridViewItem.GridItemName or loopScrollRect.Cell.name
  116. local needInter = interTime > 0
  117. local refreshCount = getRefreshCount()
  118. --处理gird生成
  119. local OnUpdate = function (owner, go, idx)
  120. go.name = idx
  121. --LogError("========================".. go.name.."=========================")
  122. local itemLua = CommonUtil.BindGridViewItem2Lua(wndOwner, name, go)
  123. itemLua.prefabName = name
  124. if needInter then
  125. CommonUtil.SetCanvasGroupStatus(itemLua.gameObject, false)
  126. ManagerContainer.LuaTimerMgr:AddTimer(interTime * idx, 1, false, function(sequence, param)
  127. CommonUtil.SetCanvasGroupStatus(itemLua.gameObject, true)
  128. end, nil)
  129. if idx == refreshCount - 1 then
  130. needInter = false
  131. end
  132. end
  133. if luaTbl~= nil then
  134. updateCB(luaTbl,itemLua, idx,list[idx+1])
  135. else
  136. updateCB(itemLua, idx,list[idx+1])
  137. end
  138. end
  139. loopScrollRect:SetUpdateCellCallback(wndOwner, OnUpdate);
  140. if loopScrollRect.content.childCount > 0 then
  141. --loopScrollRect:ClearCells();
  142. end
  143. loopScrollRect.totalCount = #list;
  144. if movePos == nil then
  145. loopScrollRect:MoveTo(0);
  146. loopScrollRect:RefreshCells()
  147. --LogError("----------MoveTo 0-----RefreshCells----")
  148. else
  149. -- loopScrollRect:MoveTo(movePos)
  150. loopScrollRect:SetItemStartIdx(movePos)
  151. end
  152. end
  153. function LoopGridViewEleCreateWithList(wndOwner, loopScrollRect, gridLayoutGroup, list, interTime, luaTbl,updateCB, needWhole, svRectTransform,movePos)
  154. if loopScrollRect == nil then return end
  155. if needWhole then
  156. loopScrollRect.totalCount = math.ceil(list.Count / loopScrollRect.contentConstraintCount)
  157. local elm = loopScrollRect.Cell:GetComponent(Enum.TypeInfo.LayoutElement)
  158. local height = loopScrollRect.totalCount * elm.preferredHeight
  159. local oriSize = svRectTransform.sizeDelta
  160. oriSize.y = height
  161. svRectTransform.sizeDelta = oriSize
  162. end
  163. local function getRefreshCount()
  164. local count = loopScrollRect.totalCount * loopScrollRect.contentConstraintCount
  165. return count >= list.Count and list.Count or count
  166. end
  167. local gridViewItem = loopScrollRect.Cell:GetComponent(Enum.TypeInfo.UIGridViewMark)
  168. local name = gridViewItem and gridViewItem.GridItemName or loopScrollRect.Cell.name
  169. local needInter = interTime > 0
  170. local refreshCount = getRefreshCount()
  171. --处理gird生成
  172. local OnUpdate = function (owner, go, idx)
  173. go.name = idx
  174. local itemLua = CommonUtil.BindGridViewItem2Lua(wndOwner, name, go)
  175. itemLua.prefabName = name
  176. if needInter then
  177. CommonUtil.SetCanvasGroupStatus(itemLua.gameObject, false)
  178. ManagerContainer.LuaTimerMgr:AddTimer(interTime * idx, 1, false, function(sequence, param)
  179. CommonUtil.SetCanvasGroupStatus(itemLua.gameObject, true)
  180. end, nil)
  181. if idx == refreshCount - 1 then
  182. needInter = false
  183. end
  184. end
  185. if luaTbl~= nil then
  186. updateCB(luaTbl,itemLua, idx)
  187. else
  188. updateCB(itemLua, idx)
  189. end
  190. end
  191. loopScrollRect:SetUpdateCellCallback(wndOwner, OnUpdate);
  192. if loopScrollRect.content.childCount > 0 then
  193. --loopScrollRect:ClearCells();
  194. end
  195. loopScrollRect.totalCount = list.Count;
  196. if movePos == nil then
  197. loopScrollRect:MoveTo(0);
  198. loopScrollRect:RefreshCells()
  199. else
  200. -- loopScrollRect:MoveTo(movePos)
  201. loopScrollRect:SetItemStartIdx(movePos)
  202. end
  203. end
  204. function LoopGridViewEleCreateNoItem(wndOwner, loopScrollRect, list, interTime, luaTbl, updateCB,movePos)
  205. if loopScrollRect == nil then return end
  206. local function getRefreshCount()
  207. local count = loopScrollRect.totalCount * loopScrollRect.contentConstraintCount
  208. return count >= #list and #list or count
  209. end
  210. local needInter = interTime > 0
  211. local refreshCount = getRefreshCount()
  212. --处理gird生成
  213. local OnUpdate = function (owner, go, idx)
  214. go.name = idx
  215. if needInter then
  216. CommonUtil.SetCanvasGroupStatus(go, false)
  217. ManagerContainer.LuaTimerMgr:AddTimer(interTime * idx, 1, false, function(sequence, param)
  218. CommonUtil.SetCanvasGroupStatus(go, true)
  219. end, nil)
  220. if idx == refreshCount - 1 then
  221. needInter = false
  222. end
  223. end
  224. if luaTbl~= nil then
  225. updateCB(luaTbl, go, idx,list[idx+1])
  226. else
  227. updateCB(go, idx,list[idx+1])
  228. end
  229. end
  230. loopScrollRect:SetUpdateCellCallback(wndOwner, OnUpdate);
  231. if loopScrollRect.content.childCount > 0 then
  232. --loopScrollRect:ClearCells();
  233. end
  234. loopScrollRect.totalCount = #list;
  235. if movePos == nil then
  236. loopScrollRect:MoveTo(0);
  237. loopScrollRect:RefreshCells()
  238. else
  239. -- loopScrollRect:MoveTo(movePos)
  240. loopScrollRect:SetItemStartIdx(movePos)
  241. end
  242. end
  243. function ArrayFilterEquipWeapon(datas, jobType)
  244. local newDatas = {}
  245. for i = 1, #datas do
  246. local equipData = ManagerContainer.CfgMgr:GetEquipById(datas[i].cfgId)
  247. if CommonUtil.EleInTable(jobType, equipData.JobType) then
  248. newDatas[#newDatas + 1] = datas[i]
  249. end
  250. end
  251. return newDatas
  252. end
  253. function ArrayFilterSelections(array, filterType, keys, values)
  254. local function FilterCheck(element)
  255. if filterType == Enum.FilterType.AND then
  256. local result = {}
  257. for i = 1,#keys do
  258. result[i] = false
  259. if element[keys[i]] == nil then
  260. result[i] = true
  261. else
  262. if type(values[i]) == "table" then
  263. if not next(values[i]) then
  264. result[i] = true
  265. end
  266. else
  267. if values[i] == nil then
  268. result[i] = true
  269. end
  270. end
  271. if not result[i] then
  272. if type(element[keys[i]]) == "table" then
  273. if type(values[i]) == "table" then
  274. local result1 = false
  275. for _,v in pairs(values[i]) do
  276. if CommonUtil.EleInTable(v, element[keys[i]]) then
  277. result1 = true
  278. end
  279. end
  280. result[i] = result1
  281. else
  282. if CommonUtil.EleInTable(values[i], element[keys[i]]) then
  283. result[i] = true
  284. end
  285. end
  286. else
  287. if type(values[i]) == "table" then
  288. local result1 = false
  289. for _,v in pairs(values[i]) do
  290. if element[keys[i]] == v then
  291. result1 = true
  292. end
  293. end
  294. result[i] = result1
  295. else
  296. if element[keys[i]] == values[i] then
  297. result[i] = true
  298. end
  299. end
  300. end
  301. end
  302. end
  303. end
  304. local endResult = true
  305. for _,v in pairs(result) do
  306. if not v then
  307. endResult = false
  308. break
  309. end
  310. end
  311. return endResult
  312. else
  313. local result = false
  314. for i = 1,#keys do
  315. if element[keys[i]] == nil then
  316. result = true
  317. break
  318. end
  319. if type(values[i]) == "table" then
  320. if not next(values[i]) then
  321. result = true
  322. break
  323. end
  324. else
  325. if values[i] == nil then
  326. result = true
  327. break
  328. end
  329. end
  330. if type(element[keys[i]]) == "table" then
  331. if type(values[i]) == "table" then
  332. local result1 = false
  333. for _,v in pairs(values[i]) do
  334. if CommonUtil.EleInTable(v, element[keys[i]]) then
  335. result1 = true
  336. break
  337. end
  338. end
  339. if result1 then
  340. result = true
  341. break
  342. end
  343. else
  344. if CommonUtil.EleInTable(values[i], element[keys[i]]) then
  345. result = true
  346. break
  347. end
  348. end
  349. else
  350. if type(values[i]) == "table" then
  351. local result1 = false
  352. for _,v in pairs(values[i]) do
  353. if element[keys[i]] == v then
  354. result1 = true
  355. break
  356. end
  357. end
  358. if result1 then
  359. result = true
  360. break
  361. end
  362. else
  363. if element[keys[i]] == values[i] then
  364. result = true
  365. break
  366. end
  367. end
  368. end
  369. end
  370. return result
  371. end
  372. end
  373. local list = {}
  374. if array == nil then
  375. return list
  376. end
  377. for _,v in pairs(array) do
  378. if FilterCheck(v) then
  379. list[#list + 1] = v
  380. end
  381. end
  382. return list
  383. end
  384. function ArraySortSelections(array, upOrDown, ...)
  385. if array == nil then
  386. return nil
  387. end
  388. local sorts = {...}
  389. local function boolean2Number(value)
  390. if type(value) == "boolean" then
  391. return value and 1 or 0
  392. end
  393. return value
  394. end
  395. local function UpSort(a, b)
  396. if #sorts == 1 then
  397. return a[sorts[1]] < b[sorts[1]]
  398. else
  399. local index = 1
  400. while index <= #sorts do
  401. if index > 1 then
  402. if a[sorts[index - 1]] == b[sorts[index - 1]] then
  403. if a[sorts[index]] ~= b[sorts[index]] then
  404. return boolean2Number(a[sorts[index]]) < boolean2Number(b[sorts[index]])
  405. end
  406. else
  407. return boolean2Number(a[sorts[index - 1]]) < boolean2Number(b[sorts[index - 1]])
  408. end
  409. end
  410. index = index + 1
  411. end
  412. end
  413. end
  414. local function DownSort(a, b)
  415. if #sorts == 1 then
  416. return a[sorts[1]] > b[sorts[1]]
  417. else
  418. local index = 1
  419. while index <= #sorts do
  420. if index > 1 then
  421. if a[sorts[index - 1]] == b[sorts[index - 1]] then
  422. if a[sorts[index]] ~= b[sorts[index]] then
  423. return boolean2Number(a[sorts[index]]) > boolean2Number(b[sorts[index]])
  424. end
  425. else
  426. return boolean2Number(a[sorts[index - 1]]) > boolean2Number(b[sorts[index - 1]])
  427. end
  428. end
  429. index = index + 1
  430. end
  431. end
  432. end
  433. table.sort( array, upOrDown and UpSort or DownSort)
  434. end
  435. function ArraySortListSelections(array, keys, vals)
  436. if array == nil then
  437. return nil
  438. end
  439. if keys == nil or type(keys) ~= "table" then
  440. return nil
  441. end
  442. if vals == nil or type(vals) ~= "table" then
  443. return nil
  444. end
  445. local function boolean2Number(value)
  446. if type(value) == "boolean" then
  447. return value and 1 or 0
  448. end
  449. return value
  450. end
  451. local function Sort(a, b)
  452. if #vals == 1 then
  453. local sortType = keys[1] or Enum.TableSortRule.Down
  454. return sortType == Enum.TableSortRule.Down and boolean2Number(a[vals[1]]) > boolean2Number(b[vals[1]]) or boolean2Number(a[vals[1]]) < boolean2Number(b[vals[1]])
  455. else
  456. local index = 1
  457. while index <= #vals do
  458. if index > 1 then
  459. if a[vals[index - 1]] == b[vals[index - 1]] then
  460. if a[vals[index]] ~= b[vals[index]] then
  461. local sortType = keys[index] or Enum.TableSortRule.Down
  462. local result = (sortType == Enum.TableSortRule.Down and {boolean2Number(a[vals[index]]) > boolean2Number(b[vals[index]])} or {boolean2Number(a[vals[index]]) < boolean2Number(b[vals[index]])})[1]
  463. return result
  464. end
  465. else
  466. local sortType = keys[index - 1] or Enum.TableSortRule.Down
  467. local result = (sortType == Enum.TableSortRule.Down and {boolean2Number(a[vals[index - 1]]) > boolean2Number(b[vals[index - 1]])} or {boolean2Number(a[vals[index - 1]]) < boolean2Number(b[vals[index - 1]])})[1]
  468. return result
  469. end
  470. end
  471. index = index + 1
  472. end
  473. end
  474. end
  475. table.sort( array, Sort)
  476. end
  477. --传入 wndlua, 页签按钮 parent , 页签点击事件
  478. function CreateToggleMouduleOnlyBtns(wndRoot, toggleData, togglesRoot, defaultIndex, onToggleClick, cbOwner, needGetHide, dontTrigger)
  479. if toggleData == nil then
  480. toggleData = {}
  481. end
  482. --toggleData.toggleDefaultIndex = defaultIndex
  483. local function ToggleClick(index)
  484. --toggleData.toggleDefaultIndex = index
  485. onToggleClick(cbOwner or wndRoot, index)
  486. end
  487. local function ToggleClick1(index)
  488. toggleData.toggleDefaultIndex = index
  489. for j = 1,#toggleData.toggleList do
  490. toggleData.toggleList[j].isOn = j == index
  491. local on = toggleData.toggleList[j].transform:Find("On")
  492. if on ~= nil then
  493. on.gameObject:SetActive(j == index)
  494. end
  495. local off = toggleData.toggleList[j].transform:Find("Off")
  496. if off ~= nil then
  497. off.gameObject:SetActive(j ~= index)
  498. end
  499. end
  500. end
  501. local toggleGroup = togglesRoot:GetComponent('ToggleGroup')
  502. if toggleData.toggleList == nil then
  503. if toggleGroup ~= nil then
  504. --存在 togglegroup 组件
  505. toggleData.toggleList = {}
  506. local trans = togglesRoot.transform
  507. local toggles = togglesRoot:GetComponentsInChildren(Enum.TypeInfo.Toggle, needGetHide or false)
  508. for i = 1, toggles.Length do
  509. local toggle = toggles[i - 1]
  510. if toggle ~= nil then
  511. toggleData.toggleList[#toggleData.toggleList + 1] = toggle
  512. wndRoot.uiBase:AddToggleUniqueEventListener(toggle, nil, function (owner, toggle, params,result)
  513. if not result then return end
  514. if toggleData.toggleDefaultIndex == i then return end
  515. ToggleClick1(i)
  516. ToggleClick(i)
  517. end)
  518. end
  519. end
  520. end
  521. end
  522. --if #toggleData.toggleList > 0 then
  523. -- toggleData.toggleList[toggleData.toggleDefaultIndex].isOn = true
  524. --
  525. -- local on = toggleData.toggleList[toggleData.toggleDefaultIndex].transform:Find("On")
  526. -- if on ~= nil then
  527. -- on.gameObject:SetActive(true)
  528. -- end
  529. --end
  530. if not dontTrigger then
  531. ToggleClick1(defaultIndex)
  532. ToggleClick(defaultIndex)
  533. end
  534. end
  535. function SetGOLayer(go, layerName)
  536. if tolua.isnull(go) then return end
  537. local layer = LayerMask.NameToLayer(layerName)
  538. local list = go:GetComponentsInChildren(Enum.TypeInfo.Transform)
  539. for i = 1, list.Length do
  540. list[i - 1].gameObject.layer = layer
  541. end
  542. end
  543. function CreateModels(wnd, num, ids, callback, param)
  544. local initIds = System.Array.CreateInstance(Enum.TypeInfo.Int32, num)
  545. for i = 1, #ids do
  546. initIds[i - 1] = ids[i]
  547. end
  548. ManagerContainer.LuaModelMgr:CreateModel(initIds, wnd, callback, param)
  549. end
  550. function DestroyGO(go)
  551. if tolua.isnull(go) then return end
  552. UnityEngine.GameObject.Destroy(go)
  553. end
  554. function DestroyGOImmediate(go)
  555. if tolua.isnull(go) then return end
  556. UnityEngine.GameObject.DestroyImmediate(go);
  557. end
  558. function Table2List(table, list)
  559. if list == nil then
  560. return nil
  561. end
  562. list:Clear()
  563. for _,v in pairs(table) do
  564. list:Add(v)
  565. end
  566. return list
  567. end
  568. function List2Table(list)
  569. local table = {}
  570. list:ForEach(function(v) table[#table + 1] = v end)
  571. return table
  572. end
  573. function LoadIcon(wnd, name, cb, itemLua, key)
  574. local seqId
  575. if itemLua and key then
  576. if itemLua.AsyncSeqIds == nil then
  577. itemLua.AsyncSeqIds = {}
  578. end
  579. seqId = itemLua.AsyncSeqIds[key]
  580. if seqId then
  581. ManagerContainer.ResMgr:UnloadAssetBySeqId(seqId)
  582. end
  583. end
  584. if name == "" or name == nil then
  585. return -1
  586. end
  587. local _name = ManagerContainer.LuaLocalizedTextureCfgMgr:GetLocalize(name)
  588. if _name ~= nil and _name ~= "" then
  589. name = _name
  590. end
  591. seqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.SingleSprite, Constants.IconDir, {name}, nil, cb)
  592. if not ManagerContainer.ResMgr:SeqIdEquals(seqId, 0) then
  593. if itemLua and key then
  594. itemLua.AsyncSeqIds[key] = seqId
  595. end
  596. if wnd then
  597. if wnd.AsyncSeqIds == nil then
  598. wnd.AsyncSeqIds = {}
  599. end
  600. wnd.AsyncSeqIds[#wnd.AsyncSeqIds + 1] = seqId
  601. end
  602. end
  603. return seqId
  604. end
  605. function CloseUIClearAsyncSeqIds(wnd)
  606. if wnd.AsyncSeqIds then
  607. for _,v in pairs(wnd.AsyncSeqIds) do
  608. ManagerContainer.ResMgr:UnloadAssetBySeqId(v)
  609. end
  610. wnd.AsyncSeqIds = nil
  611. end
  612. end
  613. function LoadTexture(wnd, name, cb)
  614. if name == "" or name == nil then
  615. return -1
  616. end
  617. local seqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.Texture2D, Constants.IconDir, {name}, nil, cb)
  618. if not ManagerContainer.ResMgr:SeqIdEquals(seqId, 0) then
  619. if wnd then
  620. if wnd.AsyncSeqIds == nil then
  621. wnd.AsyncSeqIds = {}
  622. end
  623. wnd.AsyncSeqIds[#wnd.AsyncSeqIds + 1] = seqId
  624. end
  625. end
  626. return seqId
  627. end
  628. function GetIconsTotalPath(name)
  629. return CommonUtil.StringConcat(Constants.IconDir, "/",name)
  630. end
  631. function TableClone(org)
  632. local function copy(org, res)
  633. for k,v in pairs(org) do
  634. if type(v) ~= "table" then
  635. res[k] = v;
  636. else
  637. res[k] = {};
  638. copy(v, res[k])
  639. end
  640. end
  641. end
  642. if not org then return end
  643. local res = {}
  644. copy(org, res)
  645. return res
  646. end
  647. function FormatNumber(number,isReturnW)
  648. if number == nil or (type(number) ~= "number" and type(number) ~= "userdata") then
  649. LogError("参数数值类型错误 ")
  650. else
  651. if type(number) == "userdata" and number.name() == "int64" then
  652. number = #number
  653. end
  654. number = math.floor(number)
  655. local num_length, num_str = string.len(number), tostring(number)
  656. local total_length = 4
  657. local function handler_dot(curNum, curUnit)
  658. local tmp_decimal_str = ""
  659. local integer_num, dot_num = math.modf(curNum/curUnit)
  660. local offset = total_length - string.len(integer_num)
  661. local decimal_num = curNum/curUnit
  662. if decimal_num ~= 0 and string.find(tostring(decimal_num), "%.") then
  663. tmp_decimal_str = tmp_decimal_str .. string.sub(tostring(decimal_num), string.find(tostring(decimal_num), "%."), string.find(tostring(decimal_num), "%.") + offset)
  664. local first_str = string.sub(tostring(tmp_decimal_str), 2, 2)
  665. local second_str= string.sub(tostring(tmp_decimal_str), 3, 3)
  666. if second_str ~= "0" and second_str ~= "" then
  667. --tmp_decimal_str = tmp_decimal_str .. string.sub(tostring(decimal_num), 2, string.find(tostring(decimal_num), ".") + 3)
  668. else
  669. if first_str ~= "" and first_str ~= "0" then
  670. tmp_decimal_str = "." .. first_str
  671. else
  672. tmp_decimal_str = integer_num == 0 and "0" or ".0"
  673. end
  674. end
  675. end
  676. return tostring(integer_num) .. tmp_decimal_str
  677. end
  678. if num_length < 5 then
  679. return num_str
  680. elseif num_length >= 5 and num_length < 9 or isReturnW then--万
  681. return handler_dot(number, 10^3) .. Get_Wan_string()--handler_dot(number, 10^4) .. Get_Wan_string()--"萬"
  682. elseif num_length >= 9 and not isReturnW then--亿
  683. return handler_dot(number, 10^9) .. Get_Yi_string()--"億"
  684. end
  685. end
  686. end
  687. function FormatPercentNumber(number)
  688. if number == nil or type(number) ~= "number" then
  689. LogError("参数数值类型错误")
  690. else
  691. local integer_num, dot_num = math.modf(number*100)
  692. local decimal_num = number*100
  693. local tmp_decimal_str = ""
  694. if decimal_num ~= 0 and string.find(tostring(decimal_num), "%.") then
  695. tmp_decimal_str = tmp_decimal_str .. string.sub(tostring(decimal_num), string.find(tostring(decimal_num), "%."), string.find(tostring(decimal_num), "%.") + 2)
  696. local first_str = string.sub(tostring(tmp_decimal_str), 2, 2)
  697. local second_str= string.sub(tostring(tmp_decimal_str), 3, 3)
  698. if second_str ~= "0" and second_str ~= "" then
  699. --tmp_decimal_str = tmp_decimal_str .. string.sub(tostring(decimal_num), 2, string.find(tostring(decimal_num), ".") + 3)
  700. else
  701. if first_str ~= "" and first_str ~= "0" then
  702. tmp_decimal_str = "." .. first_str
  703. else
  704. tmp_decimal_str = ""
  705. end
  706. end
  707. end
  708. return tostring(integer_num) .. tmp_decimal_str
  709. end
  710. end
  711. function IsConditionOutColor(text, out, value)
  712. if out then
  713. text.text = string.format(Constant.RedColorText, value)
  714. --text.color = Color.New(Constant.RedColor[1], Constant.RedColor[2], Constant.RedColor[3], 1)
  715. else
  716. text.text = value
  717. end
  718. end
  719. function SetTextColor(text, colorText)
  720. if colorText == nil then return end
  721. text.text = string.format(colorText, text.text)
  722. end
  723. function SetGraphicColor(graphic, colors)
  724. graphic.color = Color.New(colors[1], colors[2], colors[3], colors[4] ~= nil and colors[4] or 1)
  725. end
  726. function NeedUIGray(uiObj, status)
  727. if uiObj.material == nil then return end
  728. if status then
  729. uiObj.material = ManagerContainer.ResMgr:GetGrayMat()
  730. else
  731. uiObj.material = nil
  732. end
  733. end
  734. function SetTotalChildrenGray(uiObj, status)
  735. local children = uiObj:GetComponentsInChildren(Enum.TypeInfo.Graphic, true)
  736. for i = 0, children.Length - 1 do
  737. if not children[i].gameObject:GetComponent(Enum.TypeInfo.UIParticle) then
  738. if status then
  739. children[i].material = ManagerContainer.ResMgr:GetGrayMat()
  740. else
  741. children[i].material = nil
  742. end
  743. end
  744. end
  745. end
  746. function SetUITableNilInPackage(id)
  747. --LogError("nil ".. name)
  748. local uiData = ManagerContainer.CfgMgr:GetUIData(id)
  749. if uiData == nil then
  750. return
  751. end
  752. local luaPath = nil
  753. if uiData.lua_path and uiData.lua_path ~= '' then
  754. luaPath = string.gsub(uiData.lua_path, "/", ".")
  755. end
  756. local path = string.gsub(uiData.res_path, "/", ".")
  757. local viewGePath = CommonUtil.StringConcat(path, "View_Generate")
  758. local viewPath = nil
  759. if luaPath then
  760. viewPath = CommonUtil.StringConcat(luaPath, "View")
  761. --local ctrPath = CommonUtil.StringConcat(name, '.', name, "Ctr")
  762. else
  763. viewPath = CommonUtil.StringConcat(path, "View")
  764. end
  765. CommonUtil.Unrequire(viewPath)
  766. CommonUtil.Unrequire(viewGePath)
  767. --CommonUtil.Unrequire(ctrPath)
  768. end
  769. function SetUIGridItemTableNilInPackage(name)
  770. local itemPath = CommonUtil.StringConcat("GridViewItem.", name, "_Generate")
  771. CommonUtil.Unrequire(itemPath)
  772. end
  773. function Unrequire(name)
  774. --LogError(name)
  775. --LogError(package.loaded[name])
  776. package.loaded[name] = nil
  777. _G[name] = nil
  778. --LogError(package.loaded[name])
  779. end
  780. ---谨慎使用 该接口会把对象放入 lua对象池
  781. function BatchCreateItems(wndOwner, itemlua, parent, data, ...)
  782. if wndOwner.batchItemList == nil then
  783. wndOwner.batchItemList = {}
  784. end
  785. local prefabName = itemlua.prefabName
  786. if wndOwner.batchItemList[prefabName] == nil then
  787. wndOwner.batchItemList[prefabName] = {}
  788. end
  789. local batchItemList = wndOwner.batchItemList[prefabName]
  790. -- GameObject 的缓存池
  791. local stack = batchItemList.stack
  792. if stack == nil then
  793. stack = {}
  794. batchItemList.stack = stack
  795. end
  796. local go = itemlua.gameObject
  797. go.transform:SetParent(parent)
  798. go.transform.localPosition = Vector3.zero
  799. go.transform.localRotation = Quaternion.identity
  800. go.transform.localScale = Vector3.one
  801. go:SetActive(true)
  802. local luaCtr = require("Common/".. itemlua.prefabName .. "Ctr")
  803. if luaCtr then
  804. luaCtr:SetData(wndOwner, itemlua, data, ...)
  805. end
  806. stack[go] = itemlua
  807. end
  808. function BatchCreateItems1(wndOwner, itemlua, parent)
  809. if wndOwner.batchItemList == nil then
  810. wndOwner.batchItemList = {}
  811. end
  812. local prefabName = itemlua.prefabName
  813. if wndOwner.batchItemList[prefabName] == nil then
  814. wndOwner.batchItemList[prefabName] = {}
  815. end
  816. local batchItemList = wndOwner.batchItemList[prefabName]
  817. -- GameObject 的缓存池
  818. local stack = batchItemList.stack
  819. if stack == nil then
  820. stack = {}
  821. batchItemList.stack = stack
  822. end
  823. local go = itemlua.gameObject
  824. go.transform:SetParent(parent)
  825. go.transform.localPosition = Vector3.zero
  826. go.transform.localRotation = Quaternion.identity
  827. go.transform.localScale = Vector3.one
  828. go:SetActive(true)
  829. stack[go] = itemlua
  830. end
  831. function AddBatchItemsByItemlua(wndOwner, itemlua)
  832. if wndOwner.batchItemList == nil then
  833. wndOwner.batchItemList = {}
  834. end
  835. local prefabName = itemlua.prefabName
  836. if wndOwner.batchItemList[prefabName] == nil then
  837. wndOwner.batchItemList[prefabName] = {}
  838. end
  839. local batchItemList = wndOwner.batchItemList[prefabName]
  840. -- GameObject 的缓存池
  841. local stack = batchItemList.stack
  842. if stack == nil then
  843. stack = {}
  844. batchItemList.stack = stack
  845. end
  846. stack[itemlua.gameObject] = itemlua
  847. end
  848. function RecycleFromBatchItemsByPrefabName(wndOwner, prefabName)
  849. if wndOwner.batchItemList ~= nil and wndOwner.batchItemList[prefabName] ~= nil then
  850. local batchItemList = wndOwner.batchItemList[prefabName]
  851. local stack = batchItemList.stack
  852. if stack ~= nil then
  853. for k, v in pairs(stack) do
  854. DG.Tweening.DOTween.Kill(k.transform)
  855. ManagerContainer.GoPoolMgr:RecycleGo(v)
  856. stack[k] = nil
  857. end
  858. end
  859. end
  860. end
  861. function GetBatchItemByGo(wndOwner, prefabName, go)
  862. if wndOwner.batchItemList ~= nil and wndOwner.batchItemList[prefabName] ~= nil then
  863. local batchItemList = wndOwner.batchItemList[prefabName]
  864. local stack = batchItemList.stack
  865. if stack ~= nil then
  866. return stack[go]
  867. end
  868. end
  869. return nil
  870. end
  871. function RecycleFromBatchItems(wndOwner, itemlua)
  872. local prefabName = itemlua.oriName ~= "" and itemlua.oriName or itemlua.prefabName
  873. if wndOwner.batchItemList ~= nil and wndOwner.batchItemList[prefabName] ~= nil then
  874. local batchItemList = wndOwner.batchItemList[prefabName]
  875. local stack = batchItemList.stack
  876. if stack ~= nil then
  877. if stack[itemlua.gameObject] then
  878. stack[itemlua.gameObject] = nil
  879. end
  880. end
  881. end
  882. DG.Tweening.DOTween.Kill(itemlua.transform)
  883. ManagerContainer.GoPoolMgr:RecycleGo(itemlua)
  884. end
  885. function HideAllChildren(parent)
  886. if parent.childCount == 0 then return end
  887. for i = 0, parent.childCount - 1 do
  888. local child = parent:GetChild(i)
  889. child.gameObject:SetActive(false)
  890. end
  891. end
  892. ---谨慎使用 该接口会把对象放入 lua对象池
  893. function BatchCreateItemsLoopWithMould(wnd, mould, parent, data, idx, ...)
  894. if parent.childCount < idx then
  895. local params = {...}
  896. ManagerContainer.GoPoolMgr:SpawnGoNewLua(mould, function (itemlua)
  897. CommonUtil.BatchCreateItems(wnd, itemlua, parent, data, unpack(params))
  898. end)
  899. else
  900. local child = parent:GetChild(idx - 1)
  901. child.gameObject:SetActive(true)
  902. if wnd.batchItemList == nil then
  903. wnd.batchItemList = {}
  904. end
  905. if wnd.batchItemList[mould.prefabName] == nil then
  906. wnd.batchItemList[mould.prefabName] = {}
  907. end
  908. local batchItemList = wnd.batchItemList[mould.prefabName]
  909. -- GameObject 的缓存池
  910. local stack = batchItemList.stack
  911. if stack == nil then
  912. stack = {}
  913. batchItemList.stack = stack
  914. end
  915. local go = child.gameObject
  916. local itemlua1 = stack[go]
  917. local luaCtr = require("Common/".. itemlua1.prefabName .. "Ctr")
  918. if luaCtr then
  919. luaCtr:SetData(wnd, itemlua1, data, ...)
  920. end
  921. end
  922. end
  923. function BatchCreateItemsLoopSpawnItem(wnd, type, parent, data, idx, ...)
  924. if parent.childCount < idx then
  925. local params = {...}
  926. ManagerContainer.GoPoolMgr:SpawnItemGo(type, function (itemlua)
  927. CommonUtil.BatchCreateItems(wnd, itemlua, parent, data, unpack(params))
  928. end)
  929. else
  930. local prefabName = GetResTypePrefabName(type)
  931. local child = parent:GetChild(idx - 1)
  932. child.gameObject:SetActive(true)
  933. if wnd.batchItemList == nil then
  934. wnd.batchItemList = {}
  935. end
  936. if wnd.batchItemList[prefabName] == nil then
  937. wnd.batchItemList[prefabName] = {}
  938. end
  939. local batchItemList = wnd.batchItemList[prefabName]
  940. -- GameObject 的缓存池
  941. local stack = batchItemList.stack
  942. if stack == nil then
  943. stack = {}
  944. batchItemList.stack = stack
  945. end
  946. local go = child.gameObject
  947. local itemlua1 = stack[go]
  948. local luaCtr = require("Common/".. itemlua1.prefabName .. "Ctr")
  949. if luaCtr then
  950. luaCtr:SetData(wnd, itemlua1, data, ...)
  951. end
  952. end
  953. end
  954. function BatchCreateItemsLoopSpawnPrefabNew(wnd, list, prefabName, parent,...)
  955. local idx = 0
  956. for _,v in pairs(list) do
  957. idx = idx + 1
  958. CommonUtil.BatchCreateItemsLoopSpawnPrefab(wnd, prefabName, parent, v, idx, ...)
  959. end
  960. if parent.childCount > idx then
  961. for i = idx + 1, parent.childCount do
  962. local child = parent:GetChild(i - 1)
  963. child.gameObject:SetActive(false)
  964. end
  965. end
  966. end
  967. function BatchCreateItemsLoopSpawnPrefabNew1(wnd, list, prefabName, luaName, parent,...)
  968. local idx = 0
  969. for _,v in pairs(list) do
  970. idx = idx + 1
  971. if parent.childCount < idx then
  972. local params = {...}
  973. ManagerContainer.GoPoolMgr:SpawnPrefabGo(prefabName, function (itemlua)
  974. CommonUtil.BatchCreateItems(wnd, itemlua, parent, v, unpack(params))
  975. end)
  976. else
  977. luaName = luaName or prefabName
  978. local child = parent:GetChild(idx - 1)
  979. child.gameObject:SetActive(true)
  980. if wnd.batchItemList == nil then
  981. wnd.batchItemList = {}
  982. end
  983. if wnd.batchItemList[luaName] == nil then
  984. wnd.batchItemList[luaName] = {}
  985. end
  986. local batchItemList = wnd.batchItemList[luaName]
  987. -- GameObject 的缓存池
  988. local stack = batchItemList.stack
  989. if stack == nil then
  990. stack = {}
  991. batchItemList.stack = stack
  992. end
  993. local go = child.gameObject
  994. local itemlua1 = stack[go]
  995. local luaCtr = require("Common/".. luaName .. "Ctr")
  996. if luaCtr then
  997. luaCtr:SetData(wnd, itemlua1, v, ...)
  998. end
  999. end
  1000. end
  1001. if parent.childCount > idx then
  1002. for i = idx + 1, parent.childCount do
  1003. local child = parent:GetChild(i - 1)
  1004. child.gameObject:SetActive(false)
  1005. end
  1006. end
  1007. end
  1008. function BatchCreateItemsLoopSpawnPrefab(wnd, prefabName, parent, data, idx, ...)
  1009. if parent.childCount < idx then
  1010. local params = {...}
  1011. ManagerContainer.GoPoolMgr:SpawnPrefabGo(prefabName, function (itemlua)
  1012. CommonUtil.BatchCreateItems(wnd, itemlua, parent, data, unpack(params))
  1013. end)
  1014. else
  1015. local prefabName = prefabName
  1016. local child = parent:GetChild(idx - 1)
  1017. child.gameObject:SetActive(true)
  1018. if wnd.batchItemList == nil then
  1019. wnd.batchItemList = {}
  1020. end
  1021. if wnd.batchItemList[prefabName] == nil then
  1022. wnd.batchItemList[prefabName] = {}
  1023. end
  1024. local batchItemList = wnd.batchItemList[prefabName]
  1025. -- GameObject 的缓存池
  1026. local stack = batchItemList.stack
  1027. if stack == nil then
  1028. stack = {}
  1029. batchItemList.stack = stack
  1030. end
  1031. local go = child.gameObject
  1032. local itemlua1 = stack[go]
  1033. local luaCtr = require("Common/".. itemlua1.prefabName .. "Ctr")
  1034. if luaCtr then
  1035. luaCtr:SetData(wnd, itemlua1, data, ...)
  1036. end
  1037. end
  1038. end
  1039. function BatchDisposeItems(owner)
  1040. if owner.batchItemList ~= nil then
  1041. for k,v in pairs(owner.batchItemList) do
  1042. for k1,v1 in pairs(v.stack) do
  1043. ManagerContainer.GoPoolMgr:RecycleGo(v1)
  1044. v1 = nil
  1045. end
  1046. v = nil
  1047. end
  1048. end
  1049. owner.batchItemList = nil
  1050. end
  1051. function DisposeBatchGridChildsItem(owner, parent, name)
  1052. if owner.batchItemList ~= nil and parent ~= nil then
  1053. local list = owner.batchItemList[name]
  1054. if list == nil then return end
  1055. local gos = {}
  1056. for i = 1, parent.childCount do
  1057. local child = parent:GetChild(i - 1)
  1058. gos[i] = child.gameObject
  1059. end
  1060. for _,v in pairs(gos) do
  1061. local itemlua = list.stack[v]
  1062. if itemlua ~= nil then
  1063. ManagerContainer.GoPoolMgr:RecycleGo(itemlua)
  1064. itemlua = nil
  1065. end
  1066. end
  1067. end
  1068. end
  1069. function UpdateItemPrefab(wnd, itemlua, logicData, enterType, onClickOwner, onClickCB, params)
  1070. local name = itemlua:getClassName()
  1071. name = string.sub(name, 1, #name - 4)
  1072. local luaCtr = require("Common/" .. name .. "Ctr")
  1073. return luaCtr:SetData(wnd, itemlua, logicData, enterType, onClickOwner, onClickCB, params)
  1074. end
  1075. function EleInTable(ele, table)
  1076. if table == nil then return false end
  1077. for k,v in pairs(table) do
  1078. if v == ele then
  1079. return true, k
  1080. end
  1081. end
  1082. return false
  1083. end
  1084. --- 英雄属性数值转化到用于显示的字符串
  1085. function HeroAttrFormatValue(attrId, attrValue, need10000Percent)
  1086. local val = SDataUtil.InvConvert(attrValue)
  1087. if attrId > 21 then
  1088. val = CommonUtil.Floor3PointNum(attrId, val)
  1089. return (SDataUtil.IsGreater(val, 0) and '+' or (SDataUtil.IsLess(val, 0) and '-'or '')) .. Mathf.Abs((need10000Percent and val*10000 or val) / 100) .. "%"
  1090. else
  1091. val = Mathf.Floor(val)
  1092. return (SDataUtil.IsGreater(val, 0) and '+' or (SDataUtil.IsLess(val, 0) and '-'or '')) .. tostring(val)
  1093. end
  1094. end
  1095. function HeroAttrFormatValueNoSign(attrId, attrValue, need10000Percent)
  1096. local val = SDataUtil.InvConvert(attrValue)
  1097. if attrId > 21 then
  1098. val = CommonUtil.Floor3PointNum(attrId, val)
  1099. return Mathf.Abs((need10000Percent and val*10000 or val) / 100) .. "%"
  1100. else
  1101. val = Mathf.Floor(val)
  1102. return Mathf.Abs(val)
  1103. end
  1104. end
  1105. --- 英雄属性转化语言表Key
  1106. function HeroAttrFormatName(attrId, attrValue)
  1107. local name = "Attr_" .. attrId
  1108. if attrId == 54 or attrId == 55
  1109. or attrId == 59 or attrId == 60 then
  1110. name = name .. (SDataUtil.IsGreater(attrValue, 0) and '_0' or '_1')
  1111. end
  1112. return name
  1113. end
  1114. --- 英雄属性值转化为实际运算的值
  1115. function HeroAttrCalcValue(attrId, attrValue)
  1116. if attrId < Enum.HeroAttrType.STR_Percent then
  1117. return attrValue
  1118. else
  1119. -- return attrValue * 0.0001
  1120. return SDataUtil.Multiply(attrValue,0.0001)
  1121. end
  1122. end
  1123. --实例化对象
  1124. function Instantiate(_original, _parent, _localScaleRate)
  1125. local _go = UnityEngine.GameObject.Instantiate(_original);
  1126. if _parent then
  1127. local _scale = Vector3.one;
  1128. if _localScaleRate then
  1129. _scale = _scale * _localScaleRate;
  1130. end
  1131. _go.transform:SetParent(_parent);
  1132. _go.transform.localPosition = Vector3.zero;
  1133. _go.transform.localScale = _scale;
  1134. _go.transform.localRotation = Quaternion.identity;
  1135. end
  1136. return _go;
  1137. end
  1138. --Error弹窗
  1139. function PopErrorTips(Key)
  1140. if not ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIErrorTips) then
  1141. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIErrorTips, {errorId=Key}, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 11)
  1142. else
  1143. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ERROR_DESC_DISPLAY, {errorId=Key})
  1144. end
  1145. end
  1146. -- 获得装备的品质
  1147. function GetEquipItemQuality(itemCfgId)
  1148. local equipCfgData = ManagerContainer.CfgMgr:GetEquipById(itemCfgId)
  1149. local divide = Constant.Quality_Equip_Divide[equipCfgData.EquipLevel]
  1150. return divide[1], divide[2]
  1151. end
  1152. -- 获得道具的品质
  1153. function GetItemQuality(itemCfgId)
  1154. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  1155. if itemCfgData.ResType == Enum.ItemType.Equip then
  1156. return GetEquipItemQuality(itemCfgId)
  1157. else
  1158. return itemCfgData.Quality, 0
  1159. end
  1160. end
  1161. function GetDeltaAttrs(roleId, curAttrs, oneAttrList)
  1162. local dic = ManagerContainer.LuaActorDataMgr:GetIncreaseSecondAttrVal(
  1163. roleId,
  1164. oneAttrList[Enum.HeroAttrType.STR] + curAttrs[Enum.HeroAttrType.STR],
  1165. oneAttrList[Enum.HeroAttrType.AGI] + curAttrs[Enum.HeroAttrType.AGI],
  1166. oneAttrList[Enum.HeroAttrType.INT] + curAttrs[Enum.HeroAttrType.INT],
  1167. oneAttrList[Enum.HeroAttrType.VIT] + curAttrs[Enum.HeroAttrType.VIT],
  1168. oneAttrList[Enum.HeroAttrType.DEX] + curAttrs[Enum.HeroAttrType.DEX],
  1169. oneAttrList[Enum.HeroAttrType.LUK] + curAttrs[Enum.HeroAttrType.LUK]
  1170. )
  1171. local iter = dic:GetEnumerator()
  1172. local newAttrs = {}
  1173. while iter:MoveNext() do
  1174. newAttrs[iter.Current.Key] = math.floor(iter.Current.Value)
  1175. end
  1176. return newAttrs
  1177. end
  1178. --获取主角或伙伴当前的MVP卡牌祝福变化数据表
  1179. function GetCurCardLv(idx)
  1180. local lastLv = ManagerContainer.DataMgr.CardData:GetCardSuitLastLvById(idx)
  1181. local curlv = ManagerContainer.DataMgr.CardData:GetCardSuitLvById(idx)
  1182. local state = ManagerContainer.DataMgr.CardData:GetCardSuitStateById(idx)
  1183. if not state then
  1184. curlv = curlv - 1
  1185. end
  1186. if curlv > lastLv then
  1187. return {lastLv,curlv}
  1188. end
  1189. return nil
  1190. end
  1191. function AttrNoticeDisplay(slotIndex)
  1192. local oldAttr, newAttr
  1193. if slotIndex == 1 then
  1194. oldAttr = ManagerContainer.DataMgr.UserData:GetLastTotalAtttrs()
  1195. newAttr = ManagerContainer.DataMgr.UserData:GetHeroData().attrs
  1196. else
  1197. oldAttr = ManagerContainer.DataMgr.PartnerData:GetLastTotalAttrs(slotIndex)
  1198. local list = ManagerContainer.DataMgr.PartnerData:GetPartnerDataBySlotIndex(slotIndex)
  1199. newAttr = list == nil and nil or list.attrs
  1200. end
  1201. local specialAttr = nil
  1202. local temp = CommonUtil.GetCurCardLv(slotIndex)
  1203. if temp then
  1204. specialAttr = {{temp[1],temp[2]}}
  1205. end
  1206. if oldAttr == nil or newAttr == nil then return end
  1207. local increase = false
  1208. local deltaEquipAttr = {}
  1209. for _,v in pairs(Enum.HeroAttrType) do
  1210. if v >= Enum.HeroAttrType.Life then
  1211. deltaEquipAttr[v] = SDataUtil.Sub((newAttr[v] or 0),(oldAttr[v] or 0))
  1212. if SDataUtil.IsGreater(deltaEquipAttr[v], 0) then
  1213. increase = true
  1214. end
  1215. end
  1216. end
  1217. if increase then
  1218. ManagerContainer.LuaUIMgr:AttrNoticeDisplay1({oldAttr, newAttr,specialAttr})
  1219. end
  1220. end
  1221. function GetOwnResCountByItemId(id)
  1222. local count = 0
  1223. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(id)
  1224. if itemCfgData == nil then
  1225. LogError(tostring(id) .. " isnt exist in ItemCfg")
  1226. return 0
  1227. end
  1228. if itemCfgData.ResType <= Enum.ItemType.ParterExp or
  1229. itemCfgData.ResType == Enum.ItemType.SkillExp or
  1230. itemCfgData.ResType == Enum.ItemType.AdvanceSkillExp or
  1231. itemCfgData.ResType == Enum.ItemType.Parter then
  1232. count = ManagerContainer.DataMgr.UserData:GetCurrency(id)
  1233. elseif itemCfgData.ResType == Enum.ItemType.PetExp or
  1234. itemCfgData.ResType == Enum.ItemType.HeroSpirit or
  1235. itemCfgData.ResType == Enum.ItemType.PetStone or
  1236. itemCfgData.ResType == Enum.ItemType.GuildStone or
  1237. itemCfgData.ResType == Enum.ItemType.HundredDojoStone or
  1238. itemCfgData.ResType == Enum.ItemType.GuildWarStone or
  1239. itemCfgData.ResType == Enum.ItemType.PetCrystal or
  1240. itemCfgData.ResType == Enum.ItemType.BoliShopExp or
  1241. itemCfgData.ResType == Enum.ItemType.RecruitStone or
  1242. itemCfgData.ResType == Enum.ItemType.WalletNum or
  1243. itemCfgData.ResType == Enum.ItemType.ROCoin then
  1244. count = ManagerContainer.DataMgr.UserData:GetResById(id)
  1245. elseif itemCfgData.ResType == Enum.ItemType.Gift or
  1246. itemCfgData.ResType == Enum.ItemType.Income or
  1247. itemCfgData.ResType == Enum.ItemType.Item then
  1248. count = ManagerContainer.DataMgr.BagData:GetItemCountByCfgId(id)
  1249. elseif itemCfgData.ResType == Enum.ItemType.Equip then
  1250. count = ManagerContainer.DataMgr.EquipData:GetEquipCountById(id)
  1251. elseif itemCfgData.ResType == Enum.ItemType.ParterChip then
  1252. count = ManagerContainer.DataMgr.ChipData:GetChipCountById(id)
  1253. elseif itemCfgData.ResType == Enum.ItemType.Card then
  1254. count = ManagerContainer.DataMgr.CardData:GetCardCountById(id)
  1255. elseif itemCfgData.ResType == Enum.ItemType.Pet then
  1256. count = ManagerContainer.DataMgr.PetDataMgr:GetPetCountById(id)
  1257. elseif itemCfgData.ResType == Enum.ItemType.Cangpin then
  1258. count = ManagerContainer.DataMgr.KeepSakeBookData:GetMaterialById(id)
  1259. else
  1260. count = ManagerContainer.DataMgr.BagData:GetItemCountByCfgId(id)
  1261. end
  1262. return count
  1263. end
  1264. function DeserializeCfgItemList(data)
  1265. if data == nil then return nil end
  1266. local list = {}
  1267. for k,v in pairs(data) do
  1268. if type(v) == "table" then
  1269. list[#list + 1] = v
  1270. else
  1271. list = {data}
  1272. return list
  1273. end
  1274. end
  1275. return list
  1276. end
  1277. --- 职业ID转换角色ID
  1278. ---@param jobId integer
  1279. ---@param sex integer
  1280. ---@return integer
  1281. function JobIdToRoleId(jobId, sex)
  1282. if not jobId or not sex then
  1283. return 100001
  1284. end
  1285. return jobId * 10 + sex
  1286. end
  1287. --- 角色ID转换职业ID
  1288. ---@param roleId integer
  1289. ---@return integer integer
  1290. function RoleIdToJobId(roleId)
  1291. if not roleId then
  1292. return 10000, 1
  1293. end
  1294. return Mathf.Round(roleId * 0.1), roleId % 10
  1295. end
  1296. --- 已弃用
  1297. function GetAsyncIdx(wnd, itemLua, name)
  1298. local asyncIdx = itemLua[name]
  1299. -- if asyncIdx then
  1300. -- ManagerContainer.ResMgr:ClearUIAsyncLoadReqsByIdx(wnd.uiData.id, asyncIdx)
  1301. -- else
  1302. -- asyncIdx = wnd.controller:GetAsyncIdx()
  1303. -- itemLua[name] = asyncIdx
  1304. -- end
  1305. return asyncIdx
  1306. end
  1307. function LocalUIPos2ScreenPos(worldPos)
  1308. return CameraMgr.Instance.UICamera:WorldToScreenPoint(worldPos);
  1309. end
  1310. function ConvertUIPos2ScreenPos(worldPos)
  1311. local tempPos = CameraMgr.Instance.UICamera:WorldToViewportPoint(worldPos);
  1312. local finalPos = Vector3.New((tempPos.x - 0.5) * ManagerContainer.LuaUIMgr.SCREEN_WIDTH, (tempPos.y - 0.5) * ManagerContainer.LuaUIMgr.SCREEN_HEIGHT, 0);
  1313. return finalPos;
  1314. end
  1315. function IsScreenUIMoveLimit(screenPos, size)
  1316. if screenPos.x > UnityEngine.Screen.width - size.x/2
  1317. or screenPos.x < size.x/2
  1318. or screenPos.y > UnityEngine.Screen.height - size.y/2
  1319. or screenPos.y < size.y/2
  1320. then
  1321. return false
  1322. end
  1323. return true
  1324. end
  1325. function ConvertScreenPos2UIPos(screenPos)
  1326. local tempPos = CameraMgr.Instance.UICamera:ScreenToViewportPoint(screenPos)
  1327. return Vector3.New((tempPos.x - 0.5) * ManagerContainer.LuaUIMgr.SCREEN_WIDTH, (tempPos.y - 0.5) * ManagerContainer.LuaUIMgr.SCREEN_HEIGHT, 0);
  1328. end
  1329. function SetRepeatButtonEvent(owner, addBtn, addCB, reduceBtn, reduceCB)
  1330. if addBtn.repeatButton == nil or reduceBtn.repeatButton == nil then
  1331. LogError("请检查 按钮上的 repeatbutton 组件是否存在或是是否导出到lua")
  1332. return
  1333. end
  1334. addBtn.repeatButton:AddRepeatClickEventListener(owner, addCB)
  1335. reduceBtn.repeatButton:AddRepeatClickEventListener(owner, reduceCB)
  1336. end
  1337. function TableToVector3(table, defaultValue)
  1338. if not table then
  1339. return defaultValue or Vector3.zero
  1340. end
  1341. local x = table[1] or 0
  1342. local y = table[2] or 0
  1343. local z = table[3] or 0
  1344. return Vector3.New(x, y, z)
  1345. end
  1346. function TableToVector2(table, defaultValue)
  1347. if not table then
  1348. return defaultValue or Vector2.zero
  1349. end
  1350. local x = table[1] or 0
  1351. local y = table[2] or 0
  1352. return Vector2.New(x, y)
  1353. end
  1354. function TableToQuaternion(table, defaultValue)
  1355. if not table then
  1356. return defaultValue or Quaternion.identity
  1357. end
  1358. local x = table[1] or 0
  1359. local y = table[2] or 0
  1360. local z = table[3] or 0
  1361. return Quaternion.Euler(x, y, z)
  1362. end
  1363. function TableToGridPos(table)
  1364. if not table then return 0,0 end
  1365. local x = table[1] or 0
  1366. local y = table[2] or 0
  1367. return x, y
  1368. end
  1369. function TableIsEmpty(table)
  1370. return (_G.next(table) == nil)
  1371. end
  1372. function GetTableCount(table)
  1373. local count = 0
  1374. for k,v in pairs(table) do
  1375. count = count + 1
  1376. end
  1377. return count
  1378. end
  1379. function GetItemTypeName(itemType)
  1380. if itemType == Enum.ItemType.Coin then
  1381. return I18N.T("Coin")
  1382. end
  1383. if itemType == Enum.ItemType.Diamond then
  1384. return I18N.T("Diamond")
  1385. end
  1386. if itemType == Enum.ItemType.RoleBaseExp then
  1387. return I18N.T("Exp")
  1388. end
  1389. if itemType == Enum.ItemType.RoleJobExp then
  1390. return I18N.T("JobExp")
  1391. end
  1392. if itemType == Enum.ItemType.ParterExp then
  1393. return I18N.T("ParterExp")
  1394. end
  1395. return ""
  1396. end
  1397. function GetVaildNickName(nickName)
  1398. if not nickName or nickName == '' or nickName == 'NickName' then
  1399. return I18N.T('NewGamePlayer')
  1400. end
  1401. return nickName
  1402. end
  1403. function GetShortVaildNickName(nickName)
  1404. nickName = CommonUtil.GetVaildNickName(nickName)
  1405. local totalLength = GetActualStringLength(nickName)
  1406. if totalLength > 4 then
  1407. nickName = Utf8StrSub(nickName, 1, 4).."..."
  1408. end
  1409. return nickName
  1410. end
  1411. --根据当前的段位积分获取当前所属段位的信息
  1412. function GetCurDunData(_danScore)
  1413. local levelDatas = ManagerContainer.CfgMgr:GetArenaLevelDatas()
  1414. local nextKey = -1
  1415. local levelCfg = nil
  1416. for key=10001, 20000 do
  1417. levelCfg = levelDatas[key]
  1418. if levelCfg~= nil then
  1419. if _danScore <= levelCfg.ArenaLevelScore then
  1420. nextKey = key+1
  1421. break;
  1422. end
  1423. end
  1424. end
  1425. return levelCfg, nextKey
  1426. end
  1427. function SetRewardItemData(pageTbl,itemId,itemLua,cnt,onClickCB)
  1428. if pageTbl == nil or itemLua == nil or itemId == nil then
  1429. return
  1430. end
  1431. local IconItemCtr = require("Common/IconItemCtr")
  1432. local data = {cfgId = itemId, num = cnt}
  1433. IconItemCtr:SetData(pageTbl, itemLua, data, Enum.ItemIEnterType.Bag, pageTbl, onClickCB)
  1434. end
  1435. function SetRewardItemDataNew(pageTbl,itemId,itemLua,cnt,fromType, onClickCB)
  1436. if pageTbl == nil or itemLua == nil or itemId == nil then
  1437. return
  1438. end
  1439. local IconItemCtr = require("Common/IconItemCtr")
  1440. local data = {cfgId = itemId, num = cnt, cornerType = fromType}
  1441. IconItemCtr:SetData(pageTbl, itemLua, data, Enum.ItemIEnterType.Bag, pageTbl, onClickCB)
  1442. end
  1443. function TaskDescParse(cond)
  1444. local desc = ""
  1445. if cond[1] == Enum.TaskType.Level_Battle_Count then
  1446. local levelId = cond[2]
  1447. local levelData = ManagerContainer.CfgMgr:GetLeveNameById(levelId)
  1448. desc = ManagerContainer.CfgMgr:GetLanguageValueByKey("Condition_"..cond[1], levelData)
  1449. elseif cond[1] == Enum.TaskType.Hero_Id_Level then
  1450. desc = ManagerContainer.CfgMgr:GetLanguageValueByKey("Condition_"..cond[1], cond[#cond])
  1451. else
  1452. desc = ManagerContainer.CfgMgr:GetLanguageValueByKey("Condition_"..cond[1], cond[2], cond[3])
  1453. end
  1454. return desc
  1455. end
  1456. function GetResTypePrefabName(itemType)
  1457. local prefabName = ""
  1458. if itemType == Enum.ItemType.Equip then
  1459. prefabName = Enum.PrefabNames.EquipItem
  1460. elseif itemType == Enum.ItemType.Coin or
  1461. itemType == Enum.ItemType.Diamond or
  1462. itemType == Enum.ItemType.RoleBaseExp or
  1463. itemType == Enum.ItemType.RoleJobExp or
  1464. itemType == Enum.ItemType.ParterExp or
  1465. itemType == Enum.ItemType.FashionPaper or
  1466. itemType == Enum.ItemType.SkillExp or
  1467. itemType == Enum.ItemType.Gift or
  1468. itemType == Enum.ItemType.SkillBook or
  1469. itemType == Enum.ItemType.PetExp or
  1470. itemType == Enum.ItemType.PetStone or
  1471. itemType == Enum.ItemType.Income or
  1472. itemType == Enum.ItemType.SkillEquipSlotMat or
  1473. itemType == Enum.ItemType.SkillEquip or
  1474. itemType == Enum.ItemType.Item then
  1475. prefabName = Enum.PrefabNames.ItemItem
  1476. elseif itemType == Enum.ItemType.ParterChip then
  1477. prefabName = Enum.PrefabNames.ChipItem
  1478. elseif itemType == Enum.ItemType.Card then
  1479. prefabName = Enum.PrefabNames.CardIconItem
  1480. elseif itemType == Enum.ItemType.Parter then
  1481. prefabName = Enum.PrefabNames.ParterItem
  1482. elseif itemType == Enum.PrefabNames.IconSmallItem then
  1483. prefabName = Enum.PrefabNames.IconSmallItem
  1484. else
  1485. LogError("通用Item不支持该类型,仔细看看 " .. itemType)
  1486. return nil
  1487. end
  1488. return prefabName
  1489. end
  1490. function GetMinRefineLevel(slots)
  1491. if slots == nil then return 0 end
  1492. local minLv = 100
  1493. for i = 1, #slots do
  1494. if slots[i].level < minLv then
  1495. minLv = slots[i].level
  1496. end
  1497. end
  1498. if minLv == 100 then
  1499. return 0
  1500. end
  1501. if minLv >= 5 then
  1502. return minLv
  1503. end
  1504. return 0
  1505. end
  1506. function GetSuitNum(slots, slotType)
  1507. if slots == nil then return 0 end
  1508. if slots[slotType].equip_id == 0 then return 0 end
  1509. local equipData = ManagerContainer.CfgMgr:GetEquipById(slots[slotType].equip_id)
  1510. local suitNum = 0
  1511. if equipData.Suit == 0 then
  1512. return suitNum
  1513. end
  1514. local suitId = ManagerContainer.CfgMgr:GetEquipSuitById(equipData.Suit)
  1515. for i = 1, #slots do
  1516. if slots[i].equip_id > 0 then
  1517. local equipData1 = ManagerContainer.CfgMgr:GetEquipById(slots[i].equip_id)
  1518. local suitId1 = ManagerContainer.CfgMgr:GetEquipSuitById(equipData1.Suit)
  1519. if suitId == suitId1 or equipData1.EquipLevel > equipData.EquipLevel then
  1520. suitNum = suitNum + 1
  1521. end
  1522. end
  1523. end
  1524. return suitNum
  1525. end
  1526. function GetAllHeroLogicDatas()
  1527. local heroList = {}
  1528. local userData = ManagerContainer.DataMgr.UserData:GetHeroData()
  1529. heroList[#heroList + 1] = userData
  1530. local partnerDatas = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  1531. for _,v in pairs(partnerDatas) do
  1532. heroList[#heroList + 1] = v
  1533. end
  1534. return heroList
  1535. end
  1536. function GetHeroLogicDataByUid(uid)
  1537. if uid == 1 then
  1538. return ManagerContainer.DataMgr.UserData:GetHeroData()
  1539. else
  1540. return ManagerContainer.DataMgr.PartnerData:GetPartnerDataByUniqueId(uid)
  1541. end
  1542. end
  1543. function GetHeroActorDataByUid(uid)
  1544. if uid == 1 then
  1545. local userRoleId = ManagerContainer.DataMgr.UserData:GetUserRoleId()
  1546. return ManagerContainer.LuaActorDataMgr:GetHeroActorData(userRoleId)
  1547. else
  1548. local partnerData = CommonUtil.GetHeroLogicDataByUid(uid)
  1549. return ManagerContainer.LuaActorDataMgr:GetFellowActorData(uid,partnerData.configId)
  1550. end
  1551. end
  1552. function GetHeroCfgDataByUid(uid)
  1553. if uid == 1 then
  1554. local roleId = ManagerContainer.DataMgr.UserData:GetUserRoleId()
  1555. return ManagerContainer.CfgMgr:GetRoleDataById(roleId)
  1556. else
  1557. local heroData = ManagerContainer.DataMgr.PartnerData:GetPartnerDataByUniqueId(uid)
  1558. return ManagerContainer.CfgMgr:GetPartnerDataById(heroData.configId)
  1559. end
  1560. end
  1561. function GetHeroJobCfgDataByUid(uid)
  1562. if uid == 1 then
  1563. local jobId = ManagerContainer.DataMgr.UserData:GetJobCfgId()
  1564. return ManagerContainer.CfgMgr:GetJobDataById(jobId)
  1565. else
  1566. local heroData = ManagerContainer.DataMgr.PartnerData:GetPartnerDataByUniqueId(uid)
  1567. return ManagerContainer.CfgMgr:GetPartnerDataById(heroData.configId)
  1568. end
  1569. end
  1570. function GetHeroLogicDataByPostId(PostId)
  1571. if PostId == 1 then
  1572. return ManagerContainer.DataMgr.UserData:GetHeroData()
  1573. else
  1574. local partnerDatas = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  1575. for _,v in pairs(partnerDatas) do
  1576. local cfgData = ManagerContainer.CfgMgr:GetPartnerDataById(v.configId)
  1577. if cfgData.PostId == PostId - 1 then
  1578. return v
  1579. end
  1580. end
  1581. return nil
  1582. end
  1583. end
  1584. function GetHeroJobAndNameByUid(uid, configId)
  1585. local name = ""
  1586. if uid == 1 then
  1587. local cfgData = ManagerContainer.CfgMgr:GetJobDataById(configId)
  1588. if cfgData == nil then
  1589. return ""
  1590. end
  1591. local nickName = ManagerContainer.DataMgr.UserData:GetUserNickname()
  1592. name = I18N.T(cfgData.JobName) .. nickName
  1593. else
  1594. local cfgData = ManagerContainer.CfgMgr:GetPartnerDataById(configId)
  1595. if cfgData == nil then
  1596. return ""
  1597. end
  1598. name = I18N.T(cfgData.JobName) .. I18N.T(cfgData.Name)
  1599. end
  1600. return name
  1601. end
  1602. function GetHeroSplitJobAndNameByUid(uid, configId)
  1603. local jobName = ""
  1604. local roleName = ""
  1605. if uid == 1 then
  1606. local cfgData = ManagerContainer.CfgMgr:GetJobDataById(configId)
  1607. if cfgData == nil then
  1608. return ""
  1609. end
  1610. roleName = ManagerContainer.DataMgr.UserData:GetUserNickname()
  1611. jobName = I18N.T(cfgData.JobName)
  1612. else
  1613. local cfgData = ManagerContainer.CfgMgr:GetPartnerDataById(configId)
  1614. if cfgData == nil then
  1615. return ""
  1616. end
  1617. jobName = I18N.T(cfgData.JobName)
  1618. roleName = I18N.T(cfgData.Name)
  1619. end
  1620. return jobName, roleName
  1621. end
  1622. --- 获得技能的CfgId
  1623. ---@param skillId integer 技能Id
  1624. ---@param skillSlotLv integer 技能槽位等级
  1625. ---@return integer 技能的CfgId
  1626. function GetSkillCfgIdByIdAndLv(skillId, skillLv)
  1627. return skillId * 1000 + skillLv
  1628. end
  1629. --- 获得技能槽位的CfgId
  1630. ---@param skillId integer 技能槽位的顺序ID
  1631. ---@param skillSlotLv integer 技能槽位等级
  1632. ---@return integer 技能槽位的CfgId
  1633. function GetSkillSlotCfgIdByIdxAndLv(skillSlotIdx, skillSlotLv)
  1634. return skillSlotIdx * 1000 + skillSlotLv
  1635. end
  1636. --- 获得技能升级效果的CfgId
  1637. ---@param skillId integer 技能Id
  1638. ---@param skillLv integer 技能等级
  1639. ---@return integer 技能升级效果的CfgId
  1640. function GetSkillUpEffectCfgIdByIdAndLv(skillId, skillLv)
  1641. return skillId * 1000 + skillLv
  1642. end
  1643. --- 找到下一个解锁的技能 (最终解释权归 李慧勇)
  1644. ---@param heroId integer 英雄Id
  1645. function FindNextUnlockSkill(heroId)
  1646. local heroLv = ManagerContainer.DataMgr.UserData:GetHeroLv(heroId)
  1647. local jobCfgId = ManagerContainer.DataMgr.UserData:GetHeroJobCfgId(heroId)
  1648. local skillTreeLs = nil
  1649. if ManagerContainer.DataMgr.UserData:IsLeaderHero(heroId) then
  1650. local job = ManagerContainer.CfgMgr:GetJobDataById(jobCfgId)
  1651. skillTreeLs = ManagerContainer.CfgMgr:GetSkillTreeByFeature(job.JobType, job.JobBranch, job.JobStage)
  1652. else
  1653. local job = ManagerContainer.CfgMgr:GetPartnerDataById(jobCfgId)
  1654. skillTreeLs = ManagerContainer.CfgMgr:GetParterSkillTreeByFeature(job.JobType, job.ParterId)
  1655. end
  1656. local nextLv = nil
  1657. local skillType = nil
  1658. local skillId = nil
  1659. local skillTreeCfgData = nil
  1660. if skillTreeLs then
  1661. for i = 1, #skillTreeLs do
  1662. skillTreeCfgData = skillTreeLs[i]
  1663. local needLevel = skillTreeCfgData.OpenLevel
  1664. if needLevel > heroLv then
  1665. if not nextLv or nextLv > needLevel then
  1666. nextLv = needLevel
  1667. skillType = skillTreeCfgData.SkillType
  1668. skillId = skillTreeCfgData.SkillId
  1669. end
  1670. end
  1671. end
  1672. end
  1673. return nextLv, skillType, skillId
  1674. end
  1675. function GetResetSkillLvCost()
  1676. local costCfgId = 2
  1677. local costNum = 0
  1678. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  1679. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  1680. local boliShooLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  1681. local boliShopCfg = ManagerContainer.CfgMgr:GetBoLiVipCfgById(boliShooLv)
  1682. if vipCfg and vipCfg.SkillReset >= 1 or boliShopCfg and boliShopCfg.SkillReset >= 1 then
  1683. return costCfgId, costNum
  1684. end
  1685. local cfg = GlobalConfig.Instance:GetConfigStrValue(182)
  1686. if cfg and cfg ~= '' then
  1687. local itemCfgs = string.split(cfg, ';')
  1688. if itemCfgs then
  1689. local resetCount = ManagerContainer.DataMgr.UserData:GetSkillResetCount()
  1690. if resetCount < 0 then
  1691. resetCount = 1
  1692. else
  1693. resetCount = resetCount + 1
  1694. end
  1695. local index = 0
  1696. for _,v in pairs(itemCfgs) do
  1697. if v and v ~= '' then
  1698. local itemCfg = string.split(v, ':')
  1699. if itemCfg and #itemCfg >= 2 then
  1700. if index < resetCount then
  1701. costCfgId = itemCfg[1] and tonumber(itemCfg[1]) or 1
  1702. costNum = itemCfg[2] and tonumber(itemCfg[2]) or 0
  1703. end
  1704. index = index + 1
  1705. end
  1706. end
  1707. end
  1708. end
  1709. end
  1710. return costCfgId, costNum
  1711. end
  1712. function GetHeroIdBySlotSkillLowerLv(isBattle)
  1713. local heroData = ManagerContainer.DataMgr.UserData:GetHeroData()
  1714. local lowerLv = nil
  1715. local lowerId = nil
  1716. local lv
  1717. local validSlotNum = 0
  1718. if heroData and heroData.skillData then
  1719. validSlotNum = heroData.skillData:GetUnlockSlotNum()
  1720. for i = 1, validSlotNum do
  1721. local skillId = heroData.skillData:GetSlotSkillId(i)
  1722. if CommonUtil.CheckSkillCanLvUp(heroData, skillId) == 0 then
  1723. lv = heroData.skillData:GetSkillLv(skillId)
  1724. if not lowerLv or lowerLv > lv then
  1725. lowerLv = lv
  1726. lowerId = heroData.id
  1727. end
  1728. end
  1729. end
  1730. end
  1731. local partnerDatas = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  1732. if partnerDatas then
  1733. for _,v in pairs(partnerDatas) do
  1734. if v and v.skillData then
  1735. if not isBattle or v.isBattle then
  1736. validSlotNum = v.skillData:GetUnlockSlotNum()
  1737. for i = 1, validSlotNum do
  1738. local skillId = v.skillData:GetSlotSkillId(i)
  1739. if CommonUtil.CheckSkillCanLvUp(v, skillId) == 0 then
  1740. lv = v.skillData:GetSkillLv(skillId)
  1741. if not lowerLv or lowerLv > lv then
  1742. lowerLv = lv
  1743. lowerId = v.id
  1744. elseif lowerLv == lv then
  1745. if lowerId and lowerId > v.id then
  1746. lowerId = v.id
  1747. end
  1748. end
  1749. end
  1750. end
  1751. end
  1752. end
  1753. end
  1754. end
  1755. if not lowerId then
  1756. return 0
  1757. end
  1758. return lowerId
  1759. end
  1760. function GetAllSlotSkillCanUpNum(isBattle)
  1761. local num = 0
  1762. local validSlotNum = 0
  1763. local heroData = ManagerContainer.DataMgr.UserData:GetHeroData()
  1764. if heroData and heroData.skillData then
  1765. validSlotNum = heroData.skillData:GetUnlockSlotNum()
  1766. for i = 1, validSlotNum do
  1767. if CommonUtil.CheckSkillCanLvUp(heroData, heroData.skillData:GetSlotSkillId(i)) == 0 then
  1768. num = num + 1
  1769. end
  1770. end
  1771. end
  1772. local partnerDatas = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  1773. if partnerDatas then
  1774. for _,v in pairs(partnerDatas) do
  1775. if v and v.skillData then
  1776. if not isBattle or v.isBattle then
  1777. validSlotNum = v.skillData:GetUnlockSlotNum()
  1778. for i = 1, validSlotNum do
  1779. if CommonUtil.CheckSkillCanLvUp(v, v.skillData:GetSlotSkillId(i)) == 0 then
  1780. num = num + 1
  1781. end
  1782. end
  1783. end
  1784. end
  1785. end
  1786. end
  1787. return num
  1788. end
  1789. function HasSkillCanUp(heroId, isBattle)
  1790. local heroData = ManagerContainer.DataMgr.UserData:GetHeroData(heroId)
  1791. if heroData and heroData.skillData then
  1792. if not isBattle or heroData.isBattle then
  1793. local unlockSkillMap = heroData.skillData:GetUnlockSkillMap()
  1794. if unlockSkillMap then
  1795. for skillId, _ in pairs(unlockSkillMap) do
  1796. if CommonUtil.CheckSkillCanLvUp(heroData, skillId) == 0 then
  1797. return true
  1798. end
  1799. end
  1800. end
  1801. end
  1802. end
  1803. return false
  1804. end
  1805. --- 检查技能是否能升级
  1806. ---@param heroId integer 英雄Id
  1807. ---@param skillId integer 技能Id
  1808. ---@return integer 0:能升级;其它查看Error_Code文件
  1809. function CheckSkillCanLvUp(heroData, skillId)
  1810. if not heroData then
  1811. return 133
  1812. end
  1813. local skillTreeCfgData = nil
  1814. if ManagerContainer.DataMgr.UserData:IsLeaderHero(heroData.id) then
  1815. skillTreeCfgData = ManagerContainer.CfgMgr:GetSkillTreeCfgById(skillId)
  1816. else
  1817. skillTreeCfgData = ManagerContainer.CfgMgr:GetParterSkillTreeCfgById(skillId)
  1818. end
  1819. if not skillTreeCfgData then
  1820. return 133
  1821. end
  1822. local skillData = heroData.skillData
  1823. if not skillData then
  1824. return 133
  1825. end
  1826. if not skillData:GetIsUnlock(skillId) then
  1827. return 134
  1828. end
  1829. local curLv = skillData:GetSkillLv(skillId)
  1830. if curLv >= skillTreeCfgData.MaxLv then
  1831. return 137
  1832. end
  1833. local upgradeLevel = ManagerContainer.CfgMgr:GetSkillDemandCfgUpGradeLevelById(skillTreeCfgData.OpenLevel) --skillTreeCfgData.UpGradeLevel
  1834. if not upgradeLevel or not upgradeLevel[curLv] then
  1835. return 141
  1836. end
  1837. if (heroData.baseLevel < upgradeLevel[curLv]) then return 141 end
  1838. local upgradeCost = ManagerContainer.CfgMgr:GetSkillDemandCfgUpGradeCostById(skillTreeCfgData.OpenLevel) --skillTreeCfgData.UpGradeCost
  1839. if not upgradeCost or not upgradeCost[curLv] or #(upgradeCost[curLv]) < 2 then
  1840. return 139
  1841. end
  1842. local itemCfgId = upgradeCost[curLv][1]
  1843. local itemNum = upgradeCost[curLv][2]
  1844. if CommonUtil.GetOwnResCountByItemId(itemCfgId) < itemNum then
  1845. return 139, itemCfgId
  1846. end
  1847. return 0
  1848. end
  1849. function GetDanCfg(danScore)
  1850. if danScore == nil then
  1851. return nil
  1852. end
  1853. local levelDatas = ManagerContainer.CfgMgr:GetArenaLevelDatas()
  1854. for key=10001, 20000 do
  1855. local levelCfg = levelDatas[key]
  1856. if levelCfg~= nil then
  1857. if danScore <= levelCfg.ArenaLevelScore then
  1858. return levelCfg
  1859. end
  1860. end
  1861. end
  1862. return nil
  1863. end
  1864. function GetPreciseDecimal(nNum, n)
  1865. if type(nNum) ~= "number" then
  1866. return nNum;
  1867. end
  1868. n = n or 0;
  1869. n = math.floor(n)
  1870. local fmt = '%.' .. n .. 'f'
  1871. local nRet = tonumber(string.format(fmt, nNum))
  1872. return nRet;
  1873. end
  1874. function GetPreciseDecimalFloor(nNum, n)
  1875. if type(nNum) ~= "number" then
  1876. return nNum;
  1877. end
  1878. n = n or 0;
  1879. n = math.floor(n)
  1880. if n < 0 then
  1881. n = 0;
  1882. end
  1883. local nDecimal = 10 ^ n
  1884. local nTemp = math.floor(nNum * nDecimal);
  1885. local nRet = nTemp / nDecimal;
  1886. return nRet;
  1887. end
  1888. --- 由服务器传输的浮点的价格容易出现后缀很多的问题,
  1889. --- 比如0.1传到lua变成0.100000001490116
  1890. function GetValidPayPrice(price)
  1891. return CommonUtil.GetPreciseDecimalFloor(price + 0.0005, 3)
  1892. end
  1893. function ParseKeyValue2Map(item_list)
  1894. local data = {}
  1895. for _,v in pairs(item_list) do
  1896. data[v.key] = v.value
  1897. end
  1898. return data
  1899. end
  1900. function ParseUITargetPath(wnd, resPath)
  1901. if resPath == "" then
  1902. return
  1903. end
  1904. resPath = resPath:gsub(" ", "")
  1905. local path = resPath:split('.')
  1906. local target = wnd
  1907. local index = 1
  1908. while index <= #path do
  1909. local ok, err = pcall(function() return target[path[index]] end)
  1910. if not ok then
  1911. LogError(wnd.uiData.id.." 找不到资源对象 "..resPath)
  1912. return
  1913. else
  1914. target = target[path[index]]
  1915. if target == nil then
  1916. LogError(wnd.uiData.id.." 找不到资源对象 "..resPath)
  1917. return
  1918. end
  1919. index = index + 1
  1920. end
  1921. end
  1922. return target
  1923. end
  1924. function GetEquipForgeTypeByCfgId(cfgId)
  1925. local equipCfgData = ManagerContainer.CfgMgr:GetEquipById(cfgId)
  1926. if equipCfgData.Type == Enum.SlotEquipType.Head then
  1927. return Enum.ForgeType.Head
  1928. elseif equipCfgData.Type == Enum.SlotEquipType.Body then
  1929. return Enum.ForgeType.Body
  1930. elseif equipCfgData.Type == Enum.SlotEquipType.Wrap then
  1931. return Enum.ForgeType.Wrap
  1932. elseif equipCfgData.Type == Enum.SlotEquipType.Shoes then
  1933. return Enum.ForgeType.Shoes
  1934. elseif equipCfgData.Type == Enum.SlotEquipType.Jew then
  1935. return Enum.ForgeType.Jew
  1936. elseif equipCfgData.Type == Enum.SlotEquipType.Weapon then
  1937. if CommonUtil.EleInTable(Enum.JobWeaponMap.Sword, equipCfgData.JobType) then
  1938. return Enum.ForgeType.Sword
  1939. elseif CommonUtil.EleInTable(Enum.JobWeaponMap.Katar, equipCfgData.JobType) then
  1940. return Enum.ForgeType.Katar
  1941. elseif CommonUtil.EleInTable(Enum.JobWeaponMap.Bow, equipCfgData.JobType) then
  1942. return Enum.ForgeType.Bow
  1943. elseif CommonUtil.EleInTable(Enum.JobWeaponMap.Staff, equipCfgData.JobType) then
  1944. return Enum.ForgeType.Staff
  1945. elseif CommonUtil.EleInTable(Enum.JobWeaponMap.Priest, equipCfgData.JobType) then
  1946. return Enum.ForgeType.Priest
  1947. end
  1948. end
  1949. return nil
  1950. end
  1951. function GetFashionAttrMap(fashionMap)
  1952. -- 时装有效属性
  1953. local vaildMap = {}
  1954. local vaildAttrStr = GlobalConfig.Instance:GetConfigStrValue(125)
  1955. if vaildAttrStr then
  1956. local vaildAttrArr = string.split(vaildAttrStr, ';')
  1957. for i = 1, #vaildAttrArr do
  1958. local attrId = tonumber(vaildAttrArr[i])
  1959. if attrId then
  1960. vaildMap[attrId] = 0
  1961. end
  1962. end
  1963. end
  1964. if fashionMap then
  1965. for _,v in pairs(fashionMap) do
  1966. if v and v.cfgId then
  1967. local fashionData = ManagerContainer.CfgMgr:GetFashionById(v.cfgId)
  1968. local fashionAttr = fashionData.FashionAttr
  1969. -- 一条属性的时候
  1970. if type(fashionAttr[1]) == 'number' then
  1971. local attrId = fashionAttr[1]
  1972. if vaildMap[attrId] ~= nil then
  1973. vaildMap[attrId] = vaildMap[attrId] + fashionAttr[2]
  1974. end
  1975. else
  1976. for _,v1 in pairs(fashionAttr) do
  1977. local attrId = v1[1]
  1978. if vaildMap[attrId] ~= nil then
  1979. vaildMap[attrId] = vaildMap[attrId]+ v1[2]
  1980. end
  1981. end
  1982. end
  1983. end
  1984. end
  1985. end
  1986. return vaildMap
  1987. end
  1988. function checkNums( nums )
  1989. local n = nums
  1990. if n >= 0 then
  1991. return n
  1992. else
  1993. n = 0 - n
  1994. n = 0xffffffff - n + 1
  1995. end
  1996. return n
  1997. end
  1998. function And(num1,num2)
  1999. local tmp1 = checkNums(num1)
  2000. local tmp2 = checkNums(num2)
  2001. local ret = 0
  2002. local count = 0
  2003. repeat
  2004. local s1 = tmp1 % 2
  2005. local s2 = tmp2 % 2
  2006. if s1 == s2 and s1 == 1 then
  2007. ret = ret + 2^count
  2008. end
  2009. tmp1 = math.modf(tmp1/2)
  2010. tmp2 = math.modf(tmp2/2)
  2011. count = count + 1
  2012. until(tmp1 == 0 and tmp2 == 0)
  2013. return ret
  2014. end
  2015. function Or(num1,num2)
  2016. local tmp1 = checkNums(num1)
  2017. local tmp2 = checkNums(num2)
  2018. local ret = 0
  2019. local count = 0
  2020. repeat
  2021. local s1 = tmp1 % 2
  2022. local s2 = tmp2 % 2
  2023. if s1 == s2 and s1 == 0 then
  2024. else
  2025. ret = ret + 2^count
  2026. end
  2027. tmp1 = math.modf(tmp1/2)
  2028. tmp2 = math.modf(tmp2/2)
  2029. count = count + 1
  2030. until(tmp1 == 0 and tmp2 == 0)
  2031. return ret
  2032. end
  2033. function Xor(num1,num2)
  2034. local tmp1 = checkNums(num1)
  2035. local tmp2 = checkNums(num2)
  2036. local ret = 0
  2037. local count = 0
  2038. repeat
  2039. local s1 = tmp1 % 2
  2040. local s2 = tmp2 % 2
  2041. if s1 ~= s2 then
  2042. ret = ret + 2^count
  2043. end
  2044. tmp1 = math.modf(tmp1/2)
  2045. tmp2 = math.modf(tmp2/2)
  2046. count = count + 1
  2047. until(tmp1 == 0 and tmp2 == 0)
  2048. return ret
  2049. end
  2050. function Clamp(min, max, val)
  2051. val = math.min(max, val)
  2052. val = math.max(min, val)
  2053. return val
  2054. end
  2055. function Get2Powers(...)
  2056. local state = 0
  2057. for _,v in pairs({...}) do
  2058. state = state + 2^v
  2059. end
  2060. return state
  2061. end
  2062. function ResetAnimator(animator, name)
  2063. animator:Play(name or "Idle");
  2064. animator:Update(0);
  2065. end
  2066. function DeserializeGlobalStrToTable(val)
  2067. local table = string.split(val, ';')
  2068. local table1 = {}
  2069. for _, value in pairs(table) do
  2070. if value then
  2071. if string.find(value, ':') then
  2072. local info = string.split(value, ':')
  2073. table1[#table1 + 1] = info
  2074. else
  2075. table1[#table1 + 1] = value
  2076. end
  2077. end
  2078. end
  2079. return table1
  2080. end
  2081. function DeserializeGlobalStrToNumberTable(val)
  2082. local table = string.split(val, ';')
  2083. local table1 = {}
  2084. for _, value in pairs(table) do
  2085. if value then
  2086. if string.find(value, ':') then
  2087. local info = string.split(value, ':')
  2088. for i = 1, #info do
  2089. info[i] = tonumber(info[i])
  2090. end
  2091. table1[#table1 + 1] = info
  2092. else
  2093. table1[#table1 + 1] = tonumber(value)
  2094. end
  2095. end
  2096. end
  2097. return table1
  2098. end
  2099. --获取今天某个时间点的时间戳,比如你想获取今天五点的时间戳,可以传入数据:GetTodayTimeStamp(5)
  2100. function GetTodayTimeStamp(_h, _m, _s)
  2101. local _curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime() / 1000;
  2102. local _oneDaySeconds = ManagerContainer.LuaTimerMgr.OneDaySeconds
  2103. _zeroOClockSeconds = #_curTime - math.fmod((#_curTime + 8 * 3600), _oneDaySeconds);
  2104. _h = _h or 0;
  2105. _m = _m or 0;
  2106. _s = _s or 0;
  2107. local _second = CommonUtil.GetSomeDayTimeStamp(_curTime, _h, _m, _s);
  2108. return _second;
  2109. end
  2110. --获取某个时间戳所在天的某个时间点的时间戳,传参就是获得_stamp所在的天的_h时_m分_s秒的时间戳,注意:_stamp传入的是秒,不是毫秒
  2111. function GetSomeDayTimeStamp(_stamp, _h, _m, _s)
  2112. _stamp = tonumber(tostring(_stamp));
  2113. local _zeroOClockSeconds = 0;
  2114. _zeroOClockSeconds = _stamp - math.fmod((_stamp + 8 * 3600), Constant.OneDaySeconds);
  2115. _h = _h or 0;
  2116. _m = _m or 0;
  2117. _s = _s or 0;
  2118. local _second = _zeroOClockSeconds + (_h or 0) * 3600 + (_m or 0) * 60 + _s or 0;
  2119. return _second;
  2120. end
  2121. function GetHeadFrameDataById(_id)
  2122. if _id and _id > 0 then
  2123. local _data = ManagerContainer.CfgMgr:GetHeadFrameById(_id);
  2124. if _data then
  2125. return _data;
  2126. else
  2127. LogError("Can not find head frame data by id : " .. tostring(_id))
  2128. end
  2129. end
  2130. return nil;
  2131. end
  2132. --返回的bool值表示是否找到了对应的数据,如果时false则表明返回的是默认头像框
  2133. function GetHeadFrameName(_id)
  2134. if _id and _id > 0 then
  2135. local _data = ManagerContainer.CfgMgr:GetHeadFrameById(_id)
  2136. if _data then
  2137. return _data.HeadFrameIcon, true
  2138. else
  2139. LogError("Can not find head frame data by id : " .. tostring(_id))
  2140. end
  2141. end
  2142. return "", false
  2143. end
  2144. function SetPlayerHeadAndFrame(pageTbl,headNode,actorData,smallFrame, headFrame, onClickOwner, onClickCB, logicData, replaceParams)
  2145. if headNode == nil or actorData == nil then
  2146. return
  2147. end
  2148. headNode.levelText:SetActive(actorData.Level ~= nil)
  2149. if actorData.Level then
  2150. headNode.levelText.text.text = tostring(actorData.Level)
  2151. end
  2152. if actorData.ProfessionIcon ~= nil and actorData.ProfessionIcon ~= "" then
  2153. CommonUtil.LoadIcon(pageTbl, actorData.ProfessionIcon, function (sprite)
  2154. headNode.jobIcon.image.sprite = sprite
  2155. end,headNode, "PlayerJobIdx")
  2156. headNode.jobIcon:SetActive(true)
  2157. else
  2158. headNode.jobIcon:SetActive(false)
  2159. end
  2160. CommonUtil.LoadIcon(pageTbl, actorData.HeadIcon, function (sprite)
  2161. headNode.head.image.sprite = sprite
  2162. end,headNode, "PlayerHeadIdx")
  2163. if actorData.IsHero then
  2164. headNode.frame:SetActive(true)
  2165. headNode.headFrame:SetActive(false)
  2166. local headFramePath = CommonUtil.GetHeadFrameName(headFrame);
  2167. CommonUtil.LoadIcon(pageTbl, headFramePath, function (sprite)
  2168. headNode.frame.image.sprite = sprite
  2169. end,headNode, "PlayerHeadFrameIdx")
  2170. else
  2171. local frameIcon = Constant.Quality_White_Head_Frame_Icon
  2172. if actorData.StrengthLevel ~= nil then
  2173. if actorData.StrengthLevel == 100 then
  2174. frameIcon = Constant.Quality_HeadFrame_Lead_Icon
  2175. elseif actorData.StrengthLevel > 0 then
  2176. frameIcon = Constant.Quality_HeadFrame_Icons[math.min(actorData.StrengthLevel, #Constant.Quality_HeadFrame_Icons)]
  2177. end
  2178. end
  2179. if replaceParams ~= nil and replaceParams.StrengthLevel ~= nil then
  2180. frameIcon = Constant.Quality_White_Head_Frame_Icon
  2181. if replaceParams.StrengthLevel == 100 then
  2182. frameIcon = Constant.Quality_HeadFrame_Lead_Icon
  2183. elseif replaceParams.StrengthLevel > 0 then
  2184. frameIcon = Constant.Quality_HeadFrame_Icons[math.min(replaceParams.StrengthLevel, #Constant.Quality_HeadFrame_Icons)]
  2185. end
  2186. end
  2187. --取消s资源
  2188. --if smallFrame then
  2189. -- frameIcon = frameIcon .."_s"
  2190. --end
  2191. headNode.frame:SetActive(false)
  2192. headNode.headFrame:SetActive(true)
  2193. CommonUtil.LoadIcon(pageTbl, frameIcon, function (sprite)
  2194. headNode.headFrame.image.sprite = sprite
  2195. end,headNode, "PlayerHeadFrameIdx")
  2196. end
  2197. if onClickOwner and onClickCB then
  2198. headNode.head.button.interactable = true
  2199. onClickOwner.uiBase:AddButtonUniqueEventListener(headNode.head.button, onClickOwner, onClickCB, logicData)
  2200. else
  2201. headNode.head.button.interactable = false
  2202. end
  2203. end
  2204. function SetActorItemData(pageTbl,actorLua,actorData,bEnemy,UpdateSkillCDTimer)
  2205. if actorLua == nil or actorData == nil then
  2206. return
  2207. end
  2208. if actorLua.bgFriend ~= nil then
  2209. actorLua.bgFriend:SetActive(not bEnemy)
  2210. end
  2211. if actorLua.bgEnemy ~= nil then
  2212. actorLua.bgEnemy:SetActive(bEnemy)
  2213. end
  2214. if actorLua.actorName~= nil then
  2215. actorLua.actorName.text.text = actorData.Name
  2216. end
  2217. if actorLua.hp~= nil then
  2218. actorLua.hp.image.fillAmount = 1
  2219. end
  2220. if actorLua.sp~= nil then
  2221. actorLua.sp.image.fillAmount = 1
  2222. end
  2223. if actorLua.headItem~= nil then
  2224. if actorLua.headItem.level~= nil then
  2225. actorLua.headItem.level.text.text = "Lv."..tostring(actorData.Level)
  2226. end
  2227. if actorLua.headItem.jobIcon~= nil then
  2228. if actorData.ProfessionIcon ~= nil and actorData.ProfessionIcon ~= "" then
  2229. CommonUtil.LoadIcon(pageTbl, actorData.ProfessionIcon, function (sprite)
  2230. actorLua.headItem.jobIcon.image.sprite = sprite
  2231. end)
  2232. actorLua.headItem.jobIcon:SetActive(true)
  2233. else
  2234. actorLua.headItem.jobIcon:SetActive(false)
  2235. end
  2236. end
  2237. if actorLua.headItem.head ~= nil then
  2238. CommonUtil.LoadIcon(pageTbl, actorData.HeadIcon, function (sprite)
  2239. actorLua.headItem.head.image.sprite = sprite
  2240. end)
  2241. end
  2242. if actorLua.headItem.headFrame~= nil then
  2243. -- 突破等级
  2244. local frameIcon = Constant.Quality_White_Head_Frame_Icon
  2245. if actorData.StrengthLevel == 100 then
  2246. frameIcon = Constant.Quality_HeadFrame_Lead_Icon
  2247. else
  2248. frameIcon = Constant.Quality_HeadFrame_Icons[math.min(actorData.StrengthLevel, #Constant.Quality_HeadFrame_Icons)]
  2249. end
  2250. CommonUtil.LoadIcon(pageTbl, frameIcon, function (sprite)
  2251. actorLua.headItem.headFrame.image.sprite = sprite
  2252. end)
  2253. if actorData.StrengthLevel == 100 then
  2254. actorLua.headItem.headFrame.image.rectTransform.offsetMax = Vector2(0,22)
  2255. else
  2256. actorLua.headItem.headFrame.image.rectTransform.offsetMax = Vector2(0,0)
  2257. end
  2258. end
  2259. end
  2260. SetCurSkillInfo(actorLua.skillNode,actorData.CastSkillParam,pageTbl,UpdateSkillCDTimer)
  2261. if actorLua.deadNode ~= nil then
  2262. actorLua.deadNode:SetActive(false)
  2263. end
  2264. end
  2265. function SetCurSkillInfo(skillNode,skillInfo,pageTbl,UpdateSkillCDTimer)
  2266. if skillNode == nil or skillInfo == nil then
  2267. return nil
  2268. end
  2269. CommonUtil.LoadIcon(pageTbl, skillInfo.skillIcon, function (sprite)
  2270. skillNode.skillIcon.image.sprite = sprite
  2271. end)
  2272. skillNode.forbidNode:SetActive(skillInfo.IsForbidden)
  2273. skillNode.extraNode:SetActive(skillInfo.IsEnhance)
  2274. if skillInfo.IsCasting then
  2275. skillNode.releaseNode:SetActive(true)
  2276. skillNode.keepNode:SetActive(true)
  2277. skillNode.skillProgress:SetActive(false)
  2278. skillNode.waitNode:SetActive(false)
  2279. skillNode.skillCD:SetActive(false)
  2280. if skillInfo.teamSide == 0 then
  2281. local timerHander = pageTbl.skillCDTimers[skillInfo.actorId]
  2282. if timerHander ~= nil and timerHander ~= -1 then
  2283. ManagerContainer.LuaTimerMgr:RemoveTimer(timerHander)
  2284. pageTbl.skillCDTimers[skillInfo.actorId] = -1
  2285. end
  2286. else
  2287. local timerHander = pageTbl.enemySkillCDTimers[skillInfo.actorId]
  2288. if timerHander ~= nil and timerHander ~= -1 then
  2289. ManagerContainer.LuaTimerMgr:RemoveTimer(timerHander)
  2290. pageTbl.enemySkillCDTimers[skillInfo.actorId] = -1
  2291. end
  2292. end
  2293. else
  2294. if skillInfo.cdTime > 0 then
  2295. UpdateSkillCD(skillNode,skillInfo.cdTime,skillInfo.cdTime)
  2296. local cnt = skillInfo.cdTime*1000 / 100
  2297. if skillInfo.teamSide == 0 then
  2298. local timerHander = pageTbl.skillCDTimers[skillInfo.actorId]
  2299. if timerHander ~= nil and timerHander ~= -1 then
  2300. ManagerContainer.LuaTimerMgr:RemoveTimer(timerHander)
  2301. pageTbl.skillCDTimers[skillInfo.actorId] = -1
  2302. end
  2303. if UpdateSkillCDTimer ~= nil then
  2304. timerHander = ManagerContainer.LuaTimerMgr:AddTimer(100, cnt, pageTbl, UpdateSkillCDTimer, {skillParam = skillInfo,totalTime = skillInfo.cdTime})
  2305. pageTbl.skillCDTimers[skillInfo.actorId] = timerHander
  2306. end
  2307. else
  2308. local timerHander = pageTbl.enemySkillCDTimers[skillInfo.actorId]
  2309. if timerHander ~= nil and timerHander ~= -1 then
  2310. ManagerContainer.LuaTimerMgr:RemoveTimer(timerHander)
  2311. pageTbl.enemySkillCDTimers[skillInfo.actorId] = -1
  2312. end
  2313. if UpdateSkillCDTimer ~= nil then
  2314. timerHander = ManagerContainer.LuaTimerMgr:AddTimer(100, cnt, pageTbl, UpdateSkillCDTimer, {skillParam = skillInfo,totalTime = skillInfo.cdTime})
  2315. pageTbl.enemySkillCDTimers[skillInfo.actorId] = timerHander
  2316. end
  2317. end
  2318. else
  2319. skillNode.skillProgress.image.fillAmount = 0
  2320. skillNode.skillCD.text.text = ""
  2321. skillNode.waitNode:SetActive(true)
  2322. end
  2323. skillNode.releaseNode:SetActive(false)
  2324. skillNode.keepNode:SetActive(false)
  2325. skillNode.skillProgress:SetActive(true)
  2326. skillNode.skillCD:SetActive(true)
  2327. end
  2328. end
  2329. function UpdateSkillCD(skillNode,leftTime,totalTime)
  2330. if skillNode == nil then
  2331. return
  2332. end
  2333. local time = CommonUtil.GetPreciseDecimal(leftTime,1)
  2334. if time > 0 then
  2335. skillNode.skillProgress.image.fillAmount = time / totalTime
  2336. skillNode.skillCD.text.text = tostring(time)
  2337. else
  2338. skillNode.skillProgress.image.fillAmount = 0
  2339. skillNode.skillCD.text.text = ""
  2340. end
  2341. skillNode.waitNode:SetActive(time == 0)
  2342. end
  2343. function SetFighterLife(actorLua,life,maxLife)
  2344. if actorLua == nil then
  2345. return
  2346. end
  2347. if maxLife == nil or maxLife == 0 then
  2348. return
  2349. end
  2350. if actorLua ~= nil then
  2351. actorLua.hp.image.fillAmount = SDataUtil.InvConvert(life) / SDataUtil.InvConvert(maxLife)
  2352. actorLua.deadNode:SetActive(SDataUtil.InvConvert(life) == 0)
  2353. end
  2354. end
  2355. function SetFighterSp(actorLua,sp,maxSp)
  2356. if actorLua == nil then
  2357. return
  2358. end
  2359. if maxSp == nil or maxSp == 0 then
  2360. return
  2361. end
  2362. if actorLua ~= nil then
  2363. actorLua.sp.image.fillAmount = SDataUtil.InvConvert(sp)/ SDataUtil.InvConvert(maxSp)
  2364. end
  2365. end
  2366. function SetFighterSkill(actorLua,skillParam,pageTbl,UpdateSkillCDTimer)
  2367. if actorLua ~= nil then
  2368. SetCurSkillInfo(actorLua.skillNode,skillParam,pageTbl,UpdateSkillCDTimer)
  2369. if skillParam.IsCasting then
  2370. actorLua.animator:Play("SkillRelease");
  2371. elseif skillParam.IsForbidden then
  2372. actorLua.animator:Play("SkillForbidden");
  2373. else
  2374. actorLua.animator:Play("SkillWait");
  2375. end
  2376. end
  2377. end
  2378. function SetCommonSkillItem(owner, skillItem, skillIdOrCfgData, skillLv, onClickCb, ...)
  2379. if not skillItem then
  2380. return
  2381. end
  2382. local skillCfgData
  2383. if type(skillIdOrCfgData) == "table" then
  2384. skillCfgData = skillIdOrCfgData
  2385. else
  2386. skillCfgData = skillIdOrCfgData and ManagerContainer.CfgMgr:GetSkillCfgById(skillIdOrCfgData) or nil
  2387. end
  2388. if skillCfgData then
  2389. skillItem.icon.image.sprite = nil
  2390. CommonUtil.LoadIcon(owner, skillCfgData.Icon, function (sprite)
  2391. skillItem.icon.image.sprite = sprite
  2392. end, skillItem, 'SkillIcon')
  2393. if onClickCb then
  2394. skillItem.icon.button.enabled = true
  2395. owner.uiBase:AddButtonUniqueEventListener(skillItem.icon.button, owner, onClickCb, ...)
  2396. else
  2397. skillItem.icon.button.enabled = false
  2398. end
  2399. skillItem.num.text.text = (I18N.SetLanguageValue('Lv') .. tostring(skillLv))
  2400. if skillCfgData.SpcSkillDec then
  2401. skillItem.extTagTxt.text.text = string.formatbykey('LabelSkillGai')
  2402. skillItem.extTag:SetActive(true)
  2403. else
  2404. skillItem.extTag:SetActive(false)
  2405. end
  2406. else
  2407. skillItem.extTag:SetActive(false)
  2408. end
  2409. end
  2410. function GetPlayerHeadIcon(briefInfo)
  2411. if briefInfo == nil then
  2412. return nil
  2413. end
  2414. local jobId = briefInfo.config_id
  2415. local sex = briefInfo.gender or 1
  2416. local roleCfg = ManagerContainer.CfgMgr:GetRoleDataById(CommonUtil.JobIdToRoleId(jobId,sex))
  2417. return (roleCfg and roleCfg.HeadId or '')
  2418. end
  2419. --根据年月日判断今天是星期几,基姆拉尔森计算公式
  2420. function CalculateWeekDay(_y, _m, _d)
  2421. local _mModf = 3 * math.modf((_m + 1) / 5);
  2422. local _yModf = math.modf(_y / 4) + math.modf(_y / 100) + math.modf(_y / 400);
  2423. local _YMD = _yModf + _mModf + 2 * _m + _d;
  2424. local _weekDay = math.fmod(_YMD, 7);
  2425. if _weekDay == 0 then
  2426. return Enum.WeekDay.Sun;
  2427. elseif _weekDay == 1 then
  2428. return Enum.WeekDay.Mon;
  2429. elseif _weekDay == 2 then
  2430. return Enum.WeekDay.Tue;
  2431. elseif _weekDay == 3 then
  2432. return Enum.WeekDay.Wed;
  2433. elseif _weekDay == 4 then
  2434. return Enum.WeekDay.Thu;
  2435. elseif _weekDay == 5 then
  2436. return Enum.WeekDay.Fri;
  2437. elseif _weekDay == 6 then
  2438. return Enum.WeekDay.Sat;
  2439. end
  2440. return _weekDay;
  2441. end
  2442. --将时间转换成时分秒,规则是大于一天显示几天几小时,小于一天显示小时:分钟:秒
  2443. function FormatTimeDMS(_time)
  2444. local _outPut, _outTime;
  2445. if _time > 0 then
  2446. _outTime = false;
  2447. local _hours = _time / 60 / 60;
  2448. if _hours > 24 then
  2449. local _dayCount = math.floor(_hours / 24);
  2450. local _hourCount = math.floor(_hours - _dayCount * 24);
  2451. _outPut = tostring(_dayCount) .. I18N.T("D") .. tostring(_hourCount) .. I18N.T("H"); --XX天XX小時
  2452. else
  2453. local _itemStr = tostring(_time);
  2454. _outPut = ManagerContainer.LuaTimerMgr:ParseSeconds2Time(tonumber(_itemStr));
  2455. end
  2456. else
  2457. _outTime = true;
  2458. _outPut = "00:00:00";
  2459. end
  2460. return _outPut, _outTime;
  2461. end
  2462. --number 保留3位小数 四舍五入
  2463. function Floor3PointNum(attrId, num)
  2464. if attrId > 21 then
  2465. return math.floor(SDataUtil.InvConvert(num) * 1000 + 0.5)* 0.001
  2466. else
  2467. return math.floor(SDataUtil.InvConvert(num))
  2468. end
  2469. end
  2470. function ACKShowRewardList(reward_list)
  2471. if reward_list == nil then return end
  2472. local data = {}
  2473. for _,v in pairs(reward_list) do
  2474. data[v.key] = v.value
  2475. end
  2476. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_EQUIP_AND_ITEM_ADD, data)
  2477. end
  2478. function ACKSpecialShowRewardList(reward_list)
  2479. if reward_list == nil then return end
  2480. local data = {}
  2481. for _,v in pairs(reward_list) do
  2482. data[#data + 1] = {v.key, v.value, v.vip}
  2483. end
  2484. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_EQUIP_AND_ITEM_ADD_LIST, data)
  2485. end
  2486. function GetCurSeasonTitle(paramList)
  2487. if nil == paramList then
  2488. LogError("Nil ParamList");
  2489. return;
  2490. end
  2491. local title = I18N.T("None")
  2492. local titleIcon = nil;
  2493. local competitionTitleIcon
  2494. local selectionCompetitionDatas = ManagerContainer.CfgMgr:GetAllSelectionCompetitionDatas()
  2495. local recruit = paramList[1]
  2496. if recruit == 0 then
  2497. recruit = 10
  2498. end
  2499. local curRecruitCfgData = ManagerContainer.CfgMgr:GetCompetitionDataById(recruit)
  2500. if curRecruitCfgData then
  2501. title = I18N.T(curRecruitCfgData.CompetitionTitle[1])
  2502. competitionTitleIcon = curRecruitCfgData.CompetitionTitleIcon[1]
  2503. end
  2504. local rank = paramList[2]
  2505. if rank == nil then
  2506. return title, nil, competitionTitleIcon
  2507. else
  2508. if rank == 0 then
  2509. rank = 100000
  2510. end
  2511. local curSelectionCfgData, idx = ManagerContainer.CfgMgr:GetCompetitionDatasByRank(selectionCompetitionDatas, recruit, rank)
  2512. if curSelectionCfgData then
  2513. title = title ..I18N.T(curSelectionCfgData.CompetitionTitle[idx])
  2514. --competitionTitleIcon = curSelectionCfgData.CompetitionTitleIcon[idx]
  2515. end
  2516. return title, nil, competitionTitleIcon
  2517. end
  2518. end
  2519. --local bit = require "bit"
  2520. --local bit_rshift = bit.rshift
  2521. --local bit_lshift = bit.lshift
  2522. --local bit_bor = bit.bor
  2523. function GetOnlineStatus(onlineStatus, offlineTime)
  2524. if onlineStatus or (offlineTime == 0) then
  2525. return string.formatbykey("FriendsOnline")
  2526. else
  2527. return CommonUtil.GetOfflineTimeStr(offlineTime)
  2528. end
  2529. end
  2530. function GetOfflineTimeStr(offlineTime)
  2531. local time = (ManagerContainer.LuaTimerMgr:CurLuaServerTime() - offlineTime) / 1000
  2532. if time < 3600 then
  2533. return string.formatbykey("FriendsOffline")
  2534. elseif time < 86400 then
  2535. local hours = math.floor(#time/3600)
  2536. return string.formatbykey("FriendsOfflineHour",hours)
  2537. elseif time < 259200 then
  2538. return string.formatbykey("FriendsOfflineDay",1)
  2539. else
  2540. return string.formatbykey("FriendsOfflineDay",3)
  2541. end
  2542. end
  2543. function GetGuildPostStr(post)
  2544. if post == Enum.GuildPostType.President then
  2545. return string.formatbykey('GuildInfo_009')
  2546. elseif post == Enum.GuildPostType.VicePresident then
  2547. return string.formatbykey('GuildInfo_010')
  2548. else
  2549. return ''
  2550. end
  2551. end
  2552. function ResLackErrorNotice(resId, resCost, dontNotice)
  2553. local ownedCount = CommonUtil.GetOwnResCountByItemId(resId)
  2554. if ownedCount < resCost then
  2555. if not dontNotice then
  2556. CommonUtil.ItemNotEnoughHandle(resId)
  2557. end
  2558. return true
  2559. end
  2560. return false
  2561. end
  2562. function ItemNotEnoughHandle(cfgId, id)
  2563. if Constant.OpenPay then
  2564. if cfgId then
  2565. local cfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  2566. if cfgData then
  2567. if cfgData.ResType == Enum.ItemType.Diamond then
  2568. local data = {"NoDiamondTip", nil, id, nil, CommonUtil.ItemNotEnoughSkipRuneShop}
  2569. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  2570. return
  2571. end
  2572. end
  2573. end
  2574. end
  2575. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(CommonUtil.GetItemNotEnoughInfo(cfgId))
  2576. end
  2577. function ItemNotEnoughSkipRuneShop(id)
  2578. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, id)
  2579. end
  2580. function GetItemNotEnoughInfo(cfgId)
  2581. if cfgId then
  2582. local cfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  2583. if cfgData then
  2584. local itemName = I18N.T(tostring(cfgData.Name))
  2585. if cfgData.SourceFun and #cfgData.SourceFun > 0 then
  2586. local sourceFunStr = nil
  2587. for i = 1, #cfgData.SourceFun do
  2588. if sourceFunStr then
  2589. sourceFunStr = sourceFunStr .. ' , ' .. string.formatbykey('SourceFunColor', string.formatbykey('SourceFun' .. tostring(cfgData.SourceFun[i])))
  2590. else
  2591. sourceFunStr = string.formatbykey('SourceFunColor', string.formatbykey('SourceFun' .. tostring(cfgData.SourceFun[i])))
  2592. end
  2593. end
  2594. if sourceFunStr then
  2595. return 'ItemNotEnoughSource', itemName, sourceFunStr
  2596. end
  2597. end
  2598. return 'ItemNotEnough', itemName
  2599. end
  2600. end
  2601. return 'ItemNotEnoughDefault'
  2602. end
  2603. function TableToColor(table)
  2604. if not table then return Color.white end
  2605. return Color(table[1] or 0, table[2] or 0, table[3] or 0, table[4] or 1)
  2606. end
  2607. function GetSkillTreeCfgData(heroId,skillId)
  2608. local skillTreeCfgData
  2609. if ManagerContainer.DataMgr.UserData:IsLeaderHero(heroId) then
  2610. skillTreeCfgData = ManagerContainer.CfgMgr:GetSkillTreeCfgById(skillId)
  2611. else
  2612. skillTreeCfgData = ManagerContainer.CfgMgr:GetParterSkillTreeCfgById(skillId)
  2613. end
  2614. return skillTreeCfgData
  2615. end
  2616. function CheckSkillCanAvance(heroId, skillId)
  2617. local skillTreeCfgData = CommonUtil.GetSkillTreeCfgData(heroId,skillId)
  2618. if not skillTreeCfgData then
  2619. return 133
  2620. end
  2621. local herodata = ManagerContainer.DataMgr.UserData:GetHeroData(heroId)
  2622. local jobdata = ManagerContainer.CfgMgr:GetJobDataById(herodata.configId)
  2623. if jobdata and jobdata.JobStage < skillTreeCfgData.SkillBranch then
  2624. return 200 --该角色尚未满足转职需求
  2625. end
  2626. local jobBranch = jobdata and jobdata.JobBranch or 0
  2627. local nextSkilldata
  2628. if skillTreeCfgData.SuperSkill then
  2629. if #skillTreeCfgData.SuperSkill > 1 and jobBranch ~= 0 then
  2630. nextSkilldata = CommonUtil.GetSkillTreeCfgData(heroId,skillTreeCfgData.SuperSkill[jobBranch][2])
  2631. else
  2632. nextSkilldata = CommonUtil.GetSkillTreeCfgData(heroId,skillTreeCfgData.SuperSkill[1][2])
  2633. end
  2634. end
  2635. local openLevel = nextSkilldata and nextSkilldata.OpenLevel or 0
  2636. local openNeedCost = nextSkilldata.OpenNeedCost
  2637. if openLevel > 0 then
  2638. if (ManagerContainer.DataMgr.UserData:GetHeroLv(heroId) < openLevel) then return 141 end --角色等级不足
  2639. end
  2640. if openNeedCost then
  2641. local openNeedCosts = nil
  2642. if type(openNeedCost[1]) == 'number' then
  2643. if #openNeedCost > 1 then
  2644. openNeedCosts = {openNeedCost}
  2645. end
  2646. else
  2647. openNeedCosts = openNeedCost
  2648. end
  2649. if openNeedCosts then
  2650. for i = 1, #openNeedCosts do
  2651. local itemCfgId = openNeedCosts[i][1]
  2652. local itemNum = openNeedCosts[i][2]
  2653. if CommonUtil.GetOwnResCountByItemId(itemCfgId) < itemNum then
  2654. return 139, itemCfgId
  2655. end
  2656. end
  2657. end
  2658. end
  2659. return 0
  2660. end
  2661. function GetPetSkillStarIconAndColor(petSkillList,skillLv)
  2662. local count = 0
  2663. if petSkillList then
  2664. for _,v in pairs(petSkillList) do
  2665. count = count + v.level
  2666. end
  2667. elseif skillLv then
  2668. count = skillLv
  2669. else
  2670. return
  2671. end
  2672. local idx = math.floor((math.max(count - 1, 0)) / 10) + 1
  2673. local num = count % 10
  2674. local num1 = num == 0 and 10 or num
  2675. return Constant.Pet_Star_Icons[idx], string.format(Constant.Pet_Star_Text_Color[idx], num1), count
  2676. end
  2677. function ReplaceBattleSkillBySkillEquip(heroData, battleSkills)
  2678. --神器技能替换
  2679. local skillEquipSlot = heroData.skillEquipSlot
  2680. if skillEquipSlot then
  2681. local skillEquipSLotList = skillEquipSlot.slotList
  2682. if skillEquipSLotList then
  2683. for i = 1, #skillEquipSLotList do
  2684. local skillEquipData = skillEquipSLotList[i]
  2685. if skillEquipData.starLv > 0 then
  2686. local cfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(skillEquipData.cfgId)
  2687. if cfgData then
  2688. for j = skillEquipData.starLv, 1, -1 do
  2689. local skills = cfgData.ArtifacFuncId[j]
  2690. if type(battleSkills) == "table" then
  2691. for _,v in pairs(battleSkills) do
  2692. if v.skillId == skills[2] or v.skillId == skills[3] then
  2693. v.skillId = skills[4]
  2694. end
  2695. end
  2696. else
  2697. for i = 1, battleSkills.Length do
  2698. local params = battleSkills[i - 1]
  2699. if params.skillId == skills[2] or params.skillId == skills[3] then
  2700. params.skillId = skills[4]
  2701. battleSkills[i - 1] = params
  2702. end
  2703. end
  2704. end
  2705. end
  2706. end
  2707. end
  2708. end
  2709. end
  2710. end
  2711. return battleSkills
  2712. end
  2713. function UpdateHeroExtGoShowData(heroData)
  2714. if not heroData then return end
  2715. if not heroData.extGoesShowData then
  2716. heroData.extGoesShowData = {}
  2717. end
  2718. if heroData.skillEquipSlot and heroData.skillEquipSlot.slotList then
  2719. local curSkillEquipData = heroData.skillEquipSlot.slotList[1]
  2720. if curSkillEquipData then
  2721. heroData.extGoesShowData[Enum.HeroExtGoesShowType.God_Art] = curSkillEquipData.cfgId
  2722. end
  2723. end
  2724. if heroData.strengthLevel then
  2725. heroData.extGoesShowData[Enum.HeroExtGoesShowType.Strength_Halo] = heroData.strengthLevel
  2726. end
  2727. end
  2728. function UpdatePetExtGoShowData(petData, heroData)
  2729. if not petData or not heroData then return end
  2730. if not petData.extGoesShowData then
  2731. petData.extGoesShowData = {}
  2732. end
  2733. if heroData.battlePetId > 0 and heroData.petQiyueData and heroData.petQiyueData.slotList then
  2734. local slotList = heroData.petQiyueData.slotList
  2735. if #slotList > 0 then
  2736. local data1 = petData.extGoesShowData[Enum.HeroExtGoesShowType.Pet_Qiyue]
  2737. if not data1 then
  2738. data1 = {}
  2739. end
  2740. data1.sumNum = 0
  2741. data1.battlePetId = petData.cfgId
  2742. data1.count = 0
  2743. data1.cfgIds = {}
  2744. for i = 1, #slotList do
  2745. local data = slotList[i]
  2746. if data.petId > 0 then
  2747. data1.cfgIds[#data1.cfgIds + 1] = data.petCfgId
  2748. data1.sumNum = data1.sumNum + data.petCfgId
  2749. data1.count = data1.count + 1
  2750. end
  2751. end
  2752. petData.extGoesShowData[Enum.HeroExtGoesShowType.Pet_Qiyue] = data1
  2753. end
  2754. end
  2755. end
  2756. function Get_Wan_string()
  2757. return 'K'--"W"
  2758. end
  2759. function Get_Yi_string()
  2760. return 'B'--"E"
  2761. end