CommonUtil.lua 100 KB

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