源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4022 lines
113 KiB

преди 4 седмици
  1. local LuaEventListener = LuaEventListener
  2. local LuaClickListener = LuaClickListener
  3. local LuaDragListener = LuaDragListener
  4. local LuaDragExtendListener = LuaDragExtendListener
  5. local Application = Application
  6. local GameObject = GameObject
  7. local Util = Util
  8. local table_insert = table.insert
  9. local unpack = unpack
  10. local is_50_version = EnglineVersion and AppConst_EnglineVer >= 50
  11. local is_52_version = EnglineVersion and AppConst_EnglineVer >= 52
  12. local is_61_version = EnglineVersion and AppConst_EnglineVer >= 61
  13. --判断游戏对象是否已经被销毁为 null
  14. function IsNull(obj)
  15. if obj == nil or obj == false then return true end
  16. return Util.Equals(obj, nil)
  17. end
  18. function GetChildTransforms(transform, names)
  19. if transform then
  20. local childs = {}
  21. if is_52_version then
  22. local objs = Util.GetChildTransforms(transform, names)
  23. for i = 0,objs.Length - 1 do
  24. table_insert(childs, objs[i])
  25. end
  26. else
  27. for i = 1, #names do
  28. table_insert(childs, transform:FindChild(names[i]))
  29. end
  30. end
  31. return unpack(childs)
  32. end
  33. end
  34. function GetChildGameObjects(transform, names)
  35. if transform then
  36. local childs = {}
  37. if is_52_version then
  38. local objs = Util.GetChildGameObjects(transform, names)
  39. for i = 0,objs.Length - 1 do
  40. table_insert(childs, objs[i])
  41. end
  42. else
  43. for i = 1, #names do
  44. table_insert(childs, transform:FindChild(names[i]).gameObject)
  45. end
  46. end
  47. return unpack(childs)
  48. end
  49. end
  50. function GetChildImages(transform, names)
  51. if transform then
  52. local childs = {}
  53. if is_52_version then
  54. local objs = Util.GetChildImages(transform, names)
  55. for i = 0,objs.Length - 1 do
  56. table_insert(childs, objs[i])
  57. end
  58. else
  59. for i = 1, #names do
  60. table_insert(childs, transform:FindChild(names[i]):GetComponent("Image"))
  61. end
  62. end
  63. return unpack(childs)
  64. end
  65. end
  66. function GetChildTexts(transform, names)
  67. if transform then
  68. local childs = {}
  69. if is_52_version then
  70. local objs = Util.GetChildTexts(transform, names)
  71. for i = 0,objs.Length - 1 do
  72. table_insert(childs, objs[i])
  73. end
  74. else
  75. for i = 1, #names do
  76. table_insert(childs, transform:FindChild(names[i]):GetComponent("Text"))
  77. end
  78. end
  79. return unpack(childs)
  80. end
  81. end
  82. --打印方法的调用位置
  83. function PrintFunctionCallPos(function_name, stack_layer)
  84. if RuntimePlatform and (SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone()) then
  85. return
  86. end
  87. local create_info = debug.getinfo(stack_layer or 3, "Sl")
  88. local print_msg = ""
  89. if create_info then
  90. function_name = function_name or ""
  91. print_msg = string.format("%s calledPos = %s[%d]",function_name, create_info.source,create_info.currentline)
  92. print(print_msg)
  93. end
  94. return print_msg
  95. end
  96. function NewTable()
  97. PrintFunctionCallPos("NewTable")
  98. return {}
  99. end
  100. --输出报错栈
  101. function TraceBack(str)
  102. if RuntimePlatform and (SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone()) then
  103. return
  104. end
  105. if str then
  106. LogError("error_reason is: ".. str .. debug.traceback("", 2))
  107. else
  108. LogError(debug.traceback("", 2))
  109. end
  110. end
  111. function tracebackex()
  112. local ret = ""
  113. local level = 3
  114. ret = ret .. "stack traceback:\n"
  115. -- while true do
  116. --get stack info
  117. local info = debug.getinfo(level, "Sln")
  118. if not info then return end
  119. if info.what == "C" then -- C function
  120. ret = ret .. tostring(level) .. "\tC function\n"
  121. else -- Lua function
  122. ret = ret .. string.format("\t[%s]:%d in function `%s`\n", info.short_src, info.currentline, info.name or "")
  123. end
  124. --get local vars
  125. local i = 1
  126. while true do
  127. local name, value = debug.getlocal(level, i)
  128. if not name then break end
  129. ret = ret .. "\t\t" .. name .. " =\t" .. tostringex(value, 3) .. "\n"
  130. i = i + 1
  131. end
  132. level = level + 1
  133. -- end
  134. return ret
  135. end
  136. function tostringex(v, len)
  137. if len == nil then len = 0 end
  138. local pre = string.rep('\t', len)
  139. local ret = ""
  140. if type(v) == "table" then
  141. if len > 5 then return "\t{ ... }" end
  142. local t = ""
  143. for k, v1 in pairs(v) do
  144. t = t .. "\n\t" .. pre .. tostring(k) .. ":"
  145. t = t .. tostringex(v1, len + 1)
  146. end
  147. if t == "" then
  148. ret = ret .. pre .. "{ }\t(" .. tostring(v) .. ")"
  149. else
  150. if len > 0 then
  151. ret = ret .. "\t(" .. tostring(v) .. ")\n"
  152. end
  153. ret = ret .. pre .. "{" .. t .. "\n" .. pre .. "}"
  154. end
  155. else
  156. ret = ret .. pre .. tostring(v) .. "\t(" .. type(v) .. ")"
  157. end
  158. return ret
  159. end
  160. --捕获报错 is_safe = false 表示有异常 可以在else里用替换方法
  161. function TryCatch(func, ...)
  162. local args = { ... }
  163. local paramCount = select('#', ...)
  164. args = {xpcall(func, TraceBack, unpack(args, 1, paramCount))}
  165. local is_safe = table.remove(args, 1)
  166. return is_safe, args
  167. end
  168. function ShowBlackGround(alpha, show_type, sky_res, parent)
  169. if not lua_viewM.main_cancas_last_visible or lua_viewM.is_lock_screen then
  170. return
  171. end
  172. if show_type and show_type == 2 then
  173. MainCamera:getInstance():ShowBlackSky(sky_res)
  174. else
  175. if global_black_ground_go == nil then
  176. global_black_ground_go = UiFactory.createChild(parent or MainCamera.Instance.camera_gameObject.transform, UIType.SpriteRenderer, "global_black_ground_go")
  177. lua_resM:loadSprite(UiFactory, "uiComponent_asset", "com_black", function(objs)
  178. if objs[0] then
  179. global_black_ground_go:GetComponent("SpriteRenderer").sprite = objs[0]
  180. global_black_ground_go.transform.localPosition = Vector3(0, 0, 1)
  181. global_black_ground_go.transform.localScale = Vector3.one * 10
  182. SetLocalRotation(global_black_ground_go.transform, 0)
  183. global_black_ground_go:GetComponent("SpriteRenderer").color = Color(1 ,1 ,1 ,alpha or 0.8)
  184. end
  185. end)
  186. else
  187. if parent then
  188. global_black_ground_go.transform:SetParent(parent)
  189. end
  190. end
  191. global_black_ground_go:SetActive(true)
  192. local main_role = Scene.Instance:GetMainRole()
  193. if main_role then
  194. main_role:AddSceneObject()
  195. end
  196. end
  197. end
  198. function HideBlackGround(show_type, sky_res)
  199. if show_type and show_type == 2 then
  200. MainCamera:getInstance():HideBlackSky(sky_res)
  201. else
  202. if global_black_ground_go then
  203. global_black_ground_go:SetActive(false)
  204. local main_role = Scene.Instance:GetMainRole()
  205. if main_role then
  206. main_role:RemoveScreenObj()
  207. end
  208. end
  209. end
  210. end
  211. function SetAlphaBlackGround()
  212. if global_black_ground_go then
  213. local compoent = global_black_ground_go:GetComponent("Image")
  214. if compoent then
  215. compoent.alpha = 0
  216. end
  217. local main_role = Scene.Instance:GetMainRole()
  218. if main_role then
  219. main_role:RemoveScreenObj()
  220. end
  221. end
  222. end
  223. function FindBone(transform, bone_name)
  224. if transform then
  225. --先从一级子节点找起
  226. local obj = transform.Find(transform, bone_name)
  227. if obj then
  228. return obj
  229. end
  230. --[[
  231. -- gameObject.name对比有GCAlloc
  232. local objs = transform:GetComponentsInChildren(typeof(UnityEngine.Transform))
  233. for i=1,objs.Length do
  234. if objs[i-1].name == bone_name then
  235. return objs[i-1]
  236. end
  237. end
  238. ]]
  239. local count = transform.childCount
  240. for i=1,count do
  241. local child_trans = transform:GetChild(i-1)
  242. local child_obj = FindBone(child_trans, bone_name)
  243. if child_obj then
  244. return child_obj
  245. end
  246. end
  247. end
  248. return nil
  249. end
  250. function SetChildRenderQueue(game_object,ignore_bone,render_queue, ignore_mat)
  251. if game_object then
  252. local objs = game_object:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  253. for i=1,objs.Length do
  254. if objs[i-1].name ~= ignore_bone then
  255. local mats = objs[i-1].sharedMaterials
  256. for i=0, mats.Length - 1 do
  257. if ignore_mat and mats[i].name ~= ignore_mat then
  258. mats[i].renderQueue = render_queue
  259. end
  260. end
  261. end
  262. end
  263. end
  264. end
  265. --输出日志--
  266. function log( ... )
  267. lua_logM:Log( ... )
  268. end
  269. --错误日志--
  270. function LogError( ... )
  271. lua_logM:LogError( ... )
  272. end
  273. --警告日志--
  274. function logWarn( ... )
  275. lua_logM:LogWarn( ... )
  276. end
  277. --查找对象--
  278. function find(str)
  279. return GameObject.Find(str);
  280. end
  281. function destroy(obj,immediate)
  282. if not obj then
  283. return
  284. end
  285. if immediate then
  286. GameObject.DestroyImmediate(obj)
  287. else
  288. GameObject.Destroy(obj);
  289. end
  290. end
  291. function newObject(prefab)
  292. --print("-----newObject------",prefab)
  293. return Util.newObject(prefab)
  294. end
  295. function Trim(str)
  296. --去除字符串str两端空格
  297. -- @param str 需要去除空格的字符串
  298. --[[
  299. local p1, p2, s = string.find(str, "^%s*(.-)%s*$")
  300. if p1 then
  301. return s
  302. else
  303. return str
  304. end]]
  305. if str == nil or type(str) == "table" then return "" end
  306. str = string.gsub(str, "^[ \t\n\r]+", "")
  307. return string.gsub(str, "[ \t\n\r]+$", "")
  308. -- return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
  309. end
  310. function Join(join_table, joiner)
  311. -- 以某个连接符为标准,返回一个table所有字段连接结果
  312. -- @param join_table 连接table
  313. -- @param joiner 连接符
  314. -- @param return 用连接符连接后的字符串
  315. if #join_table == 0 then
  316. return ""
  317. end
  318. local fmt = "%s"
  319. for i = 2, #join_table do
  320. fmt = fmt .. joiner .. "%s"
  321. end
  322. return string.format(fmt, unpack(join_table))
  323. end
  324. function Printf(fmt, ...)
  325. -- 格式化输出字符串,类似c函数printf风格
  326. print(string.format(fmt, ...))
  327. end
  328. function DeepCopy(object)
  329. -- @param object 需要深拷贝的对象
  330. -- @return 深拷贝完成的对象
  331. local lookup_table = {}
  332. local function _copy(object)
  333. if type(object) ~= "table" then
  334. return object
  335. elseif lookup_table[object] then
  336. return lookup_table[object]
  337. end
  338. local new_table = {}
  339. lookup_table[object] = new_table
  340. for index, value in pairs(object) do
  341. new_table[_copy(index)] = _copy(value)
  342. end
  343. return setmetatable(new_table, getmetatable(object))
  344. end
  345. return _copy(object)
  346. end
  347. function RemoveRepeat(list, equal_func)
  348. local new_list = {}
  349. local have = false
  350. for k,v in pairs(list or {}) do
  351. have = false
  352. for kk,vv in pairs(new_list) do
  353. if equal_func(v, vv) then
  354. have = true
  355. break
  356. end
  357. end
  358. if not have then
  359. table.insert( new_list, v )
  360. end
  361. end
  362. return new_list
  363. end
  364. function ToBoolean(s)
  365. -- 将字符串转换为boolean值
  366. local transform_map = {
  367. ["true"] = true,
  368. ["false"] = false,
  369. }
  370. return transform_map[s]
  371. end
  372. --[[
  373. ]]
  374. function GetSexByCareer(career_id)
  375. for index,data in pairs(Config.Career) do
  376. if data.career_id == career_id then
  377. return data.sex
  378. end
  379. end
  380. return 1
  381. end
  382. --将 szFullString 对象拆分为一个子字符串表
  383. function Split(szFullString, szSeparator, start_pos)
  384. if not szFullString or not szSeparator then
  385. return {}
  386. end
  387. local nFindStartIndex = start_pos or 1
  388. local nSplitIndex = 1
  389. local nSplitArray = {}
  390. while true do
  391. local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
  392. if not nFindLastIndex then
  393. nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
  394. break
  395. end
  396. table.insert(nSplitArray, string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1))
  397. nFindStartIndex = nFindLastIndex + string.len(szSeparator)
  398. nSplitIndex = nSplitIndex + 1
  399. end
  400. return nSplitArray
  401. end
  402. -- 通过一个指定的字符串切割另一个字符串
  403. function SplitByStr(str, delimeter)
  404. local res = {}
  405. if not str or not delimeter then return res end
  406. local find, sub, insert = string.find, string.sub, table.insert
  407. local start, start_pos, end_pos = 1, 1, 1
  408. while true do
  409. start_pos, end_pos = find(str, delimeter, start, true)
  410. if not start_pos then
  411. break
  412. end
  413. insert(res, sub(str, start, start_pos - 1))
  414. start = end_pos + 1
  415. end
  416. insert(res, sub(str, start))
  417. return res
  418. end
  419. -- 根据国家获得不同的html文本
  420. function GetHtmlColorStringByCountry(realm,label)
  421. return "<font color = '"..ColorUtil:getRealmColorNew(realm).."'>"..label.."</font>"
  422. -- return "<font color = '"..ColorUtil:dencodeRealmType(realm).."'>"..label.."</font>" --旧的
  423. end
  424. --访问common目录的资源
  425. function toURL(url)
  426. return "common/"..url
  427. -- return url
  428. end
  429. --[[
  430. *
  431. * @param id
  432. * @return
  433. *
  434. --]]
  435. function getJinjiePreFix(id, type)
  436. local arr={"", "[1阶]", "[2阶]", "[3阶]", "[4阶]", "[5阶]", "[6阶]", "[7阶]", "[8阶]", "[9阶]", "[10阶]", "[11阶]", "[12阶]", "[13阶]", "[14阶]", "[15阶]", "[16阶]", "[17阶]", "[18阶]"}
  437. local str = arr[id + 1]
  438. if str == nil then
  439. return ""
  440. end
  441. if type ~= nil then
  442. str = string.gsub(str, "%[", "")
  443. str = string.gsub(str, "%]", "")
  444. end
  445. return str
  446. end
  447. --连接两个tab
  448. function TableConcat(tab1,tab2)
  449. local tab = {}
  450. for i=1,#tab1 do
  451. table.insert(tab,tab1[i])
  452. end
  453. for j=1,#tab2 do
  454. table.insert(tab,tab2[j])
  455. end
  456. return tab
  457. end
  458. function TableContains(tb,item)
  459. if table == nil or item == nil then
  460. return false
  461. end
  462. for key, value in pairs(tb) do
  463. if item == value then
  464. return true
  465. end
  466. end
  467. return false
  468. end
  469. function TableRemove(tb,item)
  470. if tb == nil or item == nil then
  471. return
  472. end
  473. for key, value in pairs(tb) do
  474. if item == value then
  475. table.remove(tb,key)
  476. return
  477. end
  478. end
  479. end
  480. function GetMaxLenString(str,max)
  481. local data = {}
  482. local charlen = 0
  483. local len = 0
  484. local string = ""
  485. --[[
  486. UTF8的编码规则
  487. 1. 0x000x7F(0-127), 0xC20xF4(194-244); UTF8 ascii 0~127 ascii
  488. 2. 0xC0, 0xC1,0xF50xFF(192, 193 245-255)UTF8编码中
  489. 3. 0x800xBF(128-191)()
  490. ]]
  491. for v in string.gmatch(str,"[%z\1-\127\194-\244][\128-\191]*") do
  492. table.insert(data,v)
  493. end
  494. for i,v in ipairs(data) do
  495. if string.len(v) > 1 then
  496. charlen = 1 -- 汉字的长度重置为1
  497. else
  498. charlen = 1
  499. end
  500. len = len + charlen
  501. string = string .. v
  502. if len >= max then
  503. break
  504. end
  505. end
  506. return string,len
  507. end
  508. --[[
  509. @
  510. --]]
  511. function round(number)
  512. return math.floor(number + 0.5)
  513. end
  514. --[[
  515. @
  516. @func
  517. @time ()
  518. @arg
  519. --]]
  520. function setTimeout(func,time,...)
  521. local arg = {...}
  522. if func == nil or type(func) == "number" then return end
  523. local timeOutId = nil
  524. local timeFunc = function()
  525. func(unpack(arg))
  526. GlobalTimerQuest:CancelQuest(timeOutId)
  527. func = nil
  528. end
  529. timeOutId = GlobalTimerQuest:AddDelayQuest(timeFunc,time)
  530. return timeOutId
  531. end
  532. function ChineseNumber(num)
  533. if num == nil then return end
  534. local chinese_num = {"","", "", "", "", "", "", "", "", ""}
  535. local tem_name_list = {"","","","","",""}
  536. local num_str = tostring(num)
  537. local num_len = string.len(num_str)
  538. local final_content = {}
  539. local cell_content = ""
  540. for i = 1, num_len do
  541. if string.sub(num_str,i,i) == "0" then
  542. if num_len > 1 and (i == num_len or tonumber(string.sub(num_str,i+1,num_len)) == 0) then --尾数的零不显示
  543. cell_content = ""
  544. else
  545. cell_content = chinese_num[1]
  546. end
  547. else
  548. if (string.sub(num_str,i,i) + 1) == 2 and (num_len - i + 1) == num_len and num_len > 1 then --防止两位数以上第一个数字出现 一 比如 一十
  549. cell_content = tem_name_list[num_len - i + 1]
  550. else
  551. cell_content = chinese_num[string.sub(num_str,i,i) + 1] .. tem_name_list[num_len - i + 1]
  552. end
  553. end
  554. if i == 1 or cell_content ~= chinese_num[1] or final_content[i-1] ~= chinese_num[1] then --避免中间出现重复的零
  555. table.insert(final_content,cell_content)
  556. end
  557. end
  558. return table.concat(final_content)
  559. end
  560. --罗马数字转换Ⅰ、Ⅱ、Ⅲ、Ⅳ、Ⅴ、Ⅵ、Ⅶ、Ⅷ、Ⅸ
  561. function RomeNumber(num)
  562. if num == nil then return end
  563. local chinese_num = {"N","", "", "", "", "", "", "", "", ""}
  564. local tem_name_list = {"","X","C","M"}
  565. local num_str = tostring(num)
  566. local num_len = string.len(num_str)
  567. local final_content = {}
  568. local cell_content = ""
  569. for i = 1, num_len do
  570. if string.sub(num_str,i,i) == "0" then
  571. if num_len > 1 and (i == num_len or tonumber(string.sub(num_str,i+1,num_len)) == 0) then --尾数的零不显示
  572. cell_content = ""
  573. else
  574. cell_content = chinese_num[1]
  575. end
  576. else
  577. if (string.sub(num_str,i,i) + 1) == 2 and (num_len - i + 1) == num_len and num_len > 1 then --防止两位数以上第一个数字出现 一 比如 一十
  578. cell_content = tem_name_list[num_len - i + 1]
  579. else
  580. cell_content = chinese_num[string.sub(num_str,i,i) + 1] .. tem_name_list[num_len - i + 1]
  581. end
  582. end
  583. if i == 1 or cell_content ~= chinese_num[1] or final_content[i-1] ~= chinese_num[1] then --避免中间出现重复的零
  584. table.insert(final_content,cell_content)
  585. end
  586. end
  587. return table.concat(final_content)
  588. end
  589. -- function GetMoneyTypeRes( money_type )--1绑钱,2绑金,3金币
  590. -- local res = ""
  591. -- if money_type == 1 then
  592. -- res = "comp:xx_btongIcon"
  593. -- elseif money_type == 2 then
  594. -- res = "comp:xx_bgoldIcon"
  595. -- elseif money_type == 3 then
  596. -- res = "comp:xx_goldIcon"
  597. -- end
  598. -- print("xxxxxxxxxxxxxxxxxxxxxx",money_type,res)
  599. -- return res
  600. -- end
  601. --0:物品, 1:彩钻, 2:红钻, 3:金币, 5:经验
  602. --解析类似 [[ [{0,100100,100},{3,0,1000}] ]]},
  603. function GetServerConfigReward( config_str)
  604. local good_list={}
  605. local lua=ErlangParser:GetInstance():Parse(config_str)
  606. for i,v in ipairs(lua) do
  607. local vo={}
  608. if v[1] == "0" then
  609. vo.typeId=tonumber(v[2])
  610. elseif v[1] == "1" then
  611. vo.typeId=36010001
  612. elseif v[1] == "2" then
  613. vo.typeId=36020001
  614. elseif v[1] == "3" then
  615. vo.typeId=36030001
  616. elseif v[1] == "4" then
  617. vo.typeId=36050001
  618. elseif v[1] == "5" then
  619. vo.typeId=36060001
  620. end
  621. vo.itemType = tonumber(v[1])
  622. vo.count = tonumber(v[3])
  623. table.insert(good_list,vo)
  624. end
  625. return good_list
  626. end
  627. --0:物品, 1:彩钻, 2:红钻, 3:金币, 5:经验 8社团资金 17社团成长值
  628. --解析服务端发来的奖励列表
  629. function GetServerRewardList( list, key1, key2, key3)
  630. local good_list={}
  631. for i,v in ipairs(list) do
  632. local vo={}
  633. if v[key1] == 0 then
  634. vo.typeId=v[key2]
  635. elseif v[key1] == 1 then
  636. vo.typeId=36010001
  637. elseif v[key1] == 2 then
  638. vo.typeId=36020001
  639. elseif v[key1] == 3 then
  640. vo.typeId=36030001
  641. elseif v[key1] == 4 then
  642. vo.typeId=36050001
  643. elseif v[key1] == 5 then
  644. vo.typeId=36060001
  645. elseif v[key1] == 8 then
  646. vo.typeId=36050002
  647. elseif v[key1] == 17 then
  648. vo.typeId=36050003
  649. else
  650. vo.typeId=v[key2]
  651. end
  652. vo.itemType = v[key1]
  653. vo.count = v[key3]
  654. table.insert(good_list,vo)
  655. end
  656. return good_list
  657. end
  658. --解析类似 {aircraft_stage, Stage}
  659. function ConvertServerConfigTable(tbl)
  660. local ret = {}
  661. for k,v in ipairs(tbl) do
  662. if v[1] then
  663. ret[v[1]] = {}
  664. for i,vv in ipairs(v) do
  665. if tonumber(i) > 1 then
  666. table.insert(ret[v[1]],tonumber(vv))
  667. end
  668. end
  669. end
  670. end
  671. return ret
  672. end
  673. --[[
  674. @describtion:ipad的分辨率对比
  675. @return:bool, ture ipad的分辨率 false代表小于ipad的分辨率
  676. ]]
  677. function NowScreenCompareIpadScreen()
  678. local view_size = Game.UI:GetScreenView()
  679. local is_ipad_screen = false
  680. local view_ratio = view_size.y / view_size.x
  681. local ipad_ratio = 768 / 1024
  682. if view_ratio < ipad_ratio then
  683. is_ipad_screen = false
  684. elseif view_ratio >= ipad_ratio then
  685. is_ipad_screen = true
  686. end
  687. return is_ipad_screen
  688. end
  689. -- 检查table是否为空
  690. function IsTableEmpty(tbl)
  691. return not tbl or _G.next( tbl ) == nil
  692. end
  693. -- 获取table长度,当数据不连续时不能用#
  694. function TableSize(tbl)
  695. if IsTableEmpty(tbl) then
  696. return 0
  697. end
  698. local len = 0
  699. for _ in pairs(tbl) do
  700. len = len + 1
  701. end
  702. return len
  703. end
  704. --无符号的32位转换成有符号的32位
  705. function UnsignToSigned(number)
  706. if number >= 4000000000 then --无符号的数大于这个数默认为负数了
  707. return -1 * bit.bnot(number - 1)
  708. else
  709. return number
  710. end
  711. end
  712. function insertElement(arr, obj)
  713. local flag = true;
  714. for i=1,#arr do
  715. if arr[i] == obj then
  716. flag = false;
  717. break ;
  718. end
  719. end
  720. if flag then
  721. table.insert(arr, obj);
  722. end
  723. end
  724. function deleteElement(arr, obj)
  725. for i=#arr,1,-1 do
  726. if arr[i] and arr[i] == obj then
  727. table.remove(arr, i);
  728. end
  729. end
  730. end
  731. function utf8_to_unicode(str)
  732. if not str or str == "" then
  733. return nil
  734. end
  735. local res, seq, val = {}, 0, nil
  736. for i = 1, #str do
  737. local c = string.byte(str, i)
  738. if seq == 0 then
  739. if val then
  740. res[#res + 1] = string.format("%04x", val)
  741. end
  742. seq = c < 0x80 and 1 or c < 0xE0 and 2 or c < 0xF0 and 3 or
  743. c < 0xF8 and 4 or --c < 0xFC and 5 or c < 0xFE and 6 or
  744. 0
  745. if seq == 0 then
  746. return str
  747. end
  748. val = bit.band(c, 2 ^ (8 - seq) - 1)
  749. else
  750. val = bit.bor(bit.lshift(val, 6), bit.band(c, 0x3F))
  751. end
  752. seq = seq - 1
  753. end
  754. if val then
  755. res[#res + 1] = string.format("%04x", val)
  756. end
  757. if #res == 0 then
  758. return str
  759. end
  760. return "\\u" .. table.concat(res, " \\u")
  761. end
  762. function HasLimitChar(str)
  763. --[[local function hex2bin( hexstr )
  764. local s = string.gsub(hexstr, "(.)(.)%s", function ( h, l )
  765. return string.char(h2b[h]*16+h2b[l])
  766. end)
  767. return s
  768. end]]
  769. local unicode_str = utf8_to_unicode(str)
  770. if not unicode_str or type(unicode_str) ~= "string" or unicode_str == "" then
  771. return false
  772. end
  773. local str = string.gsub(unicode_str,"\\u","0x")
  774. str = Split(str," ")
  775. for k,v in pairs(str) do
  776. local value = tonumber(v)
  777. --放过一批创角名字的特殊字符
  778. --のミ★、灬о+メ丶◎ζξ
  779. if value == 0x306E or value == 0x30DF or value == 0x2605 or value == 0x3001 or value == 0x706C or value == 0x043E
  780. or value == 0xFF0B or value == 0x30E1 or value == 0x4E36 or value == 0x25CE or value == 0x03B6 or value == 0x03BE then
  781. return false
  782. end
  783. --中文
  784. if not ((value >= 0x4E00 and value <= 0x9FA5) or (value >= 0x0021 and value <= 0x007F)) and
  785. --韩文
  786. not ((value >= 0xAC00 and value <= 0xD7AF) or (value >= 0x0021 and value <= 0x007F)) and
  787. --日文
  788. not ((value >= 0x3040 and value <= 0x31FF) or (value >= 0x0021 and value <= 0x007F)) then
  789. return true
  790. end
  791. end
  792. return false
  793. end
  794. --[[@
  795. : ID
  796. :
  797. plat_name string
  798. server_id ID int16
  799. role_id ID int32
  800. :
  801. ID int32
  802. :
  803. : deadline
  804. ]]
  805. function GenerateRoleId( plat_name, server_id, role_id)
  806. plat_name = plat_name or ""
  807. server_id = server_id or 0
  808. role_id = role_id or 0
  809. local tmp_val = server_id
  810. if string.len(plat_name) <= 0 then
  811. plat_name = "0"
  812. end
  813. tmp_val = tmp_val + tonumber(string.byte(plat_name , 1))
  814. tmp_val = math.modf(tmp_val, 19)
  815. tmp_val = tmp_val + 1
  816. tmp_val = bit.lshift(tmp_val, 24)
  817. --tmp_val = bit.toint(bit.bor(tmp_val, role_id))
  818. tmp_val = bit.bor(tmp_val, role_id)
  819. tmp_val = bit.band(tmp_val, 0x0fffffff)
  820. return tmp_val
  821. end
  822. function GenerateSuperMemberData()
  823. local config = Config.SuperMemberQQSpecial[ClientConfig.plat_name]
  824. local use_remote = false
  825. if ClientConfig.super_member_qq_special then
  826. config = Game.System:ReadJsonStr( ClientConfig.super_member_qq_special )
  827. if config and config.first == 1 then
  828. use_remote = true
  829. end
  830. end
  831. if not use_remote and MallModel.Instance.kaifuTime > Config.CloseBetaActivity.SuperMemberForNewServerTime then
  832. local server_info = LoginController.Instance:GetPlatUserInfo()
  833. -- 混服和应用宝专服
  834. if ClientConfig.plat_belong ~= "1" or ( tonumber(server_info.belongid) == 7 and string.find(ClientConfig.plat_name, "yyb")) then
  835. config = Config.CloseBetaActivity.SuperMemberForNewServerConfig
  836. end
  837. end
  838. return config
  839. end
  840. function PrintTable( tbl , level)
  841. if RuntimePlatform and (SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone()) then
  842. return
  843. end
  844. if tbl == nil or type(tbl) ~= "table" then
  845. return
  846. end
  847. level = level or 1
  848. local indent_str = ""
  849. for i = 1, level do
  850. indent_str = indent_str.." "
  851. end
  852. print(indent_str .. "{")
  853. for k,v in pairs(tbl) do
  854. local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
  855. print(item_str)
  856. if type(v) == "table" then
  857. PrintTable(v, level + 1)
  858. end
  859. end
  860. print(indent_str .. "}")
  861. end
  862. --把整个table的内容拼接成一个字符串
  863. function GetTableContentStr( tbl, level, return_counter )
  864. if tbl == nil or type(tbl) ~= "table" then
  865. return ""
  866. end
  867. return_counter = return_counter or 3 --剩下多少层就返回,防止无限打印
  868. if return_counter <= 0 then
  869. return ""
  870. end
  871. return_counter = return_counter - 1
  872. level = level or 1
  873. local indent_str = ""
  874. for i = 1, level do
  875. indent_str = indent_str.." "
  876. end
  877. indent_str = indent_str .. "{\n"
  878. -- print(indent_str .. "{")
  879. for k,v in pairs(tbl) do
  880. local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
  881. indent_str = item_str.."\n"
  882. -- print(item_str)
  883. if type(v) == "table" then
  884. indent_str = indent_str .. GetTableContentStr(v, level + 1, return_counter)
  885. end
  886. end
  887. -- print(indent_str .. "}")
  888. indent_str = indent_str .. "}\n"
  889. return indent_str
  890. end
  891. function GetCallStackStr()
  892. local level = 1
  893. local str = ""
  894. while true do
  895. local info = debug.getinfo(level, "Sl")
  896. if not info then break end
  897. if info.what == "C" then
  898. str = str..level.."\tC function\n"
  899. else
  900. str = str..string.format("[%s]:%d\n",info.short_src, info.currentline)
  901. end
  902. level = level + 1
  903. end
  904. return str
  905. end
  906. function PrintCallStack( )
  907. if RuntimePlatform and (SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone()) then
  908. return
  909. end
  910. local level = 1
  911. while true do
  912. local info = debug.getinfo(level, "Sl")
  913. if not info then break end
  914. if info.what == "C" then
  915. print(level, "C function")
  916. else
  917. print(string.format("[%s]:%d",
  918. info.short_src, info.currentline))
  919. end
  920. level = level + 1
  921. end
  922. end
  923. --屏幕坐标转视口坐标
  924. function ScreenToViewportPoint(x,y)
  925. return x / ScreenConvertRatio, y / ScreenConvertRatio
  926. end
  927. --视口坐标转换屏幕坐标
  928. function ViewportToScreenPoint(x,y)
  929. return x * ScreenConvertRatio, y * ScreenConvertRatio
  930. end
  931. --统一错误码提示,Config.Errorcode
  932. function ErrorCodeShow(code, strParam)
  933. local tmp = Config.Errorcode[code] or GlobalErrorCode[code]
  934. local str = "未知返回码" .. code
  935. if tmp then
  936. str = tmp.about or tmp
  937. if strParam then
  938. local args = Split(strParam, ",")
  939. for i, v in ipairs(args) do
  940. str = string.gsub(str, "{"..i.."}", v)
  941. end
  942. end
  943. end
  944. print("HWR:utilManager [983]error_code: ",code)
  945. Message.show(str,"fault")
  946. end
  947. --删除<color></color>标签
  948. function DeleteColorTag(text)
  949. if text == nil or Trim(text) =="" then return text end
  950. --text = Trim(text)
  951. local function replaceLeft(str)
  952. return ""
  953. end
  954. local text = string.gsub(text, "%<color[^%>^/]+%>", replaceLeft)
  955. local function replaceRight(str)
  956. return ""
  957. end
  958. local text = string.gsub(text, "%</color%>", replaceRight)
  959. return text
  960. end
  961. --获取跨服长名称
  962. function GetCSLongName( role_name, server_name, no_dot, server_color )
  963. if not server_name then return role_name end
  964. local tb = {}
  965. if string.find(server_name, "-") then
  966. tb = Split(server_name, "-")
  967. elseif string.find(server_name, "_") then
  968. tb = Split(server_name, "_")
  969. else
  970. tb[1] = server_name
  971. end
  972. local server_id = tonumber(tb[1])
  973. if server_id == 0 then
  974. server_id = 1
  975. end
  976. server_id = server_id%1000
  977. if server_id == 0 then
  978. server_id = 1000
  979. end
  980. local ser_str = ""
  981. if no_dot then
  982. ser_str = "S" .. server_id
  983. else
  984. ser_str = "S" .. server_id .. ". "
  985. end
  986. if server_color then
  987. ser_str = "<color=" .. server_color .. ">" .. ser_str .. "</color>"
  988. end
  989. return ser_str .. role_name
  990. end
  991. --解析链接点击标签,适用于这种格式<a@类型@参数1@参数2>XXX</a>, 例如<a@goods@110101>强化石</a>
  992. function FormatHyperLinkParam(txt, cache_text)
  993. local final_list = {}
  994. --如果文本为空 或者没有需要解释的下划线或者点击事件 则过滤掉
  995. if txt == nil or Trim(txt) == "" or (not string.find(txt, "</a>") and not string.find(txt, "</u>")) then return final_list end
  996. --txt = Trim(txt)
  997. local a_list = {} --保存a标签的所有数据
  998. local p1, p2, param_str = string.find(txt, "%<a([^%>^/.]-)%>")
  999. local count = 1
  1000. while p1 do
  1001. a_list[count] = {}
  1002. a_list[count].param = param_str
  1003. a_list[count].has_link = true
  1004. a_list[count].start_pos = p1
  1005. local _, _, text = string.find(txt,"(.-)%<%/a%>", p2 + 1)
  1006. text = text or ""
  1007. text = string.gsub(text, "<u>", "")
  1008. a_list[count].text = string.gsub(text, "</u>", "")
  1009. p1, p2, param_str = string.find(txt, "%<a([^%>^/.]-)%>", p1 + 1)
  1010. count = count + 1
  1011. end
  1012. local u_list = {}--保存u标签的所有数据
  1013. p1, p2, param_str = string.find(txt, "%<u%>(.-)%<%/u%>")
  1014. count = 1
  1015. while p1 do
  1016. u_list[count] = {}
  1017. u_list[count].start_pos = p1
  1018. param_str = string.gsub(param_str, "<a[^%>^/.]->", "")
  1019. u_list[count].text = string.gsub(param_str, "</a>", "")
  1020. u_list[count].has_under_line = true
  1021. p1, p2, param_str = string.find(txt, "%<u%>(.-)%<%/u%>", p1 + 1)
  1022. count = count + 1
  1023. end
  1024. local n_list = {}--保存</a>后面没有标签的所有数据
  1025. p1, p2, param_str = string.find(txt, "%</a%>([^<u>]+)%<")
  1026. count = 1
  1027. while p1 do
  1028. n_list[count] = {}
  1029. n_list[count].text = param_str
  1030. n_list[count].start_pos = p1
  1031. p1, p2, param_str = string.find(txt, "%</a%>([^<u>]+)%<%a", p1 + 1)
  1032. count = count + 1
  1033. end
  1034. local n2_list = {}--保存</u>后面没有标签的所有数据
  1035. p1, p2, param_str = string.find(txt, "%</u%>([^</a>]+)%<")
  1036. count = 1
  1037. while p1 do
  1038. n2_list[count] = {}
  1039. n2_list[count].text = param_str
  1040. n2_list[count].start_pos = p1
  1041. p1, p2, param_str = string.find(txt, "%</u%>([^</a>]+)%<", p1 + 1)
  1042. count = count + 1
  1043. end
  1044. local c_list = {}--保存color标签的所有数据
  1045. if cache_text then
  1046. p1, p2, color_str, content_str = string.find(cache_text, "%<color%=([^%>^/.]-)%>([^%>^/.]-)%<%/color")
  1047. count = 1
  1048. while p1 do
  1049. c_list[count] = {}
  1050. c_list[count].color = color_str
  1051. c_list[count].text = content_str
  1052. c_list[count].start_pos = p1
  1053. p1, p2, color_str, content_str = string.find(cache_text, "%<color%=([^%>^/.]-)%>([^%>^/.]-)%<%/color", p1 + 1)
  1054. count = count + 1
  1055. end
  1056. end
  1057. p1, p2, param_str = string.find(txt, "([^<u>]+)")
  1058. local p3, p4, param_str2 = string.find(txt, "%<u%>")
  1059. if p1 and param_str and not p3 and not param_str2 then
  1060. param_str = param_str
  1061. elseif not p1 and not param_str and p3 and param_str2 then
  1062. param_str = param_str2
  1063. elseif p1 and param_str and p3 and param_str2 then
  1064. param_str = p1 < p3 and param_str or param_str2
  1065. end
  1066. if param_str and string.len(param_str) > 0 then
  1067. table.insert(final_list, 1, {text = param_str, start_pos = 0})--开头没有标签的内容插入队列里作为第一个元素
  1068. end
  1069. --------------------------把以上所有列表存入总表------------------------
  1070. for i, vo in ipairs(a_list) do
  1071. table.insert(final_list, vo)
  1072. end
  1073. local function getFinalVoByText(text)
  1074. for i, vo in ipairs(final_list) do
  1075. if text == vo.text then
  1076. return vo
  1077. end
  1078. end
  1079. end
  1080. local have = false
  1081. for i, vo in ipairs(u_list) do
  1082. have = getFinalVoByText(vo.text)
  1083. if not have then
  1084. table.insert(final_list, vo)
  1085. end
  1086. end
  1087. local final_vo = nil
  1088. for i, vo in ipairs(u_list) do
  1089. final_vo = getFinalVoByText(vo.text)
  1090. if final_vo then
  1091. final_vo.has_under_line = true
  1092. else
  1093. table.insert(final_list, vo)
  1094. end
  1095. if final_vo then
  1096. for j, c_vo in ipairs(c_list) do
  1097. if c_vo.text == vo.text then
  1098. vo.color = c_vo.color
  1099. final_vo.color = c_vo.color
  1100. break
  1101. end
  1102. end
  1103. end
  1104. end
  1105. for i, vo in ipairs(n_list) do
  1106. table.insert(final_list, vo)
  1107. end
  1108. for i, vo in ipairs(n2_list) do
  1109. table.insert(final_list, vo)
  1110. end
  1111. ---------------------------------对总表做排序---------------------
  1112. local function sort_func(v1, v2)
  1113. return v1.start_pos < v2.start_pos
  1114. end
  1115. table.sort(final_list, sort_func)
  1116. return final_list
  1117. end
  1118. --判断一段文本是否添加了超链接
  1119. function HasLink(txt)
  1120. if txt and string.find(txt, "</a>") then
  1121. return true
  1122. end
  1123. return false
  1124. end
  1125. --封装一些比较特殊的标签数据
  1126. function PackageSpecialTab(txt)
  1127. txt = IsContainsUrlTab(txt)
  1128. if txt == nil or Trim(txt) == "" or not string.find(txt, "</a>") then return txt end
  1129. --txt = Trim(txt)
  1130. local function replaceFunc(str)
  1131. local txt = string.sub(str, 2, -2)
  1132. local arr = Split(txt,"@")
  1133. PrintTable(arr)
  1134. local name = ""
  1135. if tostring(arr[2]) == "goods" or tostring(arr[2]) == "goods2" or tostring(arr[2]) == "goods5" or tostring(arr[2]) == "goods7" or tostring(arr[2]) == "goods9" then --物品
  1136. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(tonumber(arr[3])) or GoodsModel:getInstance():GetGoodsBasicByTypeId(tonumber(arr[5]))
  1137. local empower_lv = tonumber(arr[6]) or 0
  1138. if basic then
  1139. local color = WordManager.GetGoodsColor(basic.color + empower_lv)
  1140. if tonumber(basic.color) == 0 then -- 对主界面的提示框的绿色物品特殊处理
  1141. color = ColorUtil.SHALLOW_GREEN
  1142. end
  1143. if empower_lv == 3 then
  1144. name = SetSevenColorStr("[" .. Trim(basic.goods_name) .. "]")
  1145. else
  1146. name = "<color=" .. color .. ">" .. "[" .. Trim(basic.goods_name) .. "]" .. "</color>"
  1147. end
  1148. if basic.type == 11 and (basic.subtype == 10 or basic.subtype == 11)then --装备鉴定物, 碎片,显示鉴定物对应的装备图标
  1149. local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(basic.type_id, RoleManager.Instance.mainRoleInfo.career, basic.color)
  1150. goods_icon = icon
  1151. name = _name
  1152. end
  1153. end
  1154. elseif tostring(arr[2]) == "goods6" or tostring(arr[2]) == "goods3" or tostring(arr[2]) == "goods4" or tostring(arr[2]) == "goods6" then --物品 加括号
  1155. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(tonumber(arr[3]))
  1156. if basic then
  1157. local color = WordManager.GetGoodsColor(basic.color)
  1158. if tonumber(basic.color) == 0 then -- 对主界面的提示框的绿色物品特殊处理
  1159. color = ColorUtil.SHALLOW_GREEN
  1160. end
  1161. name = "<color=" .. color .. ">" .. "[" .. Trim(basic.goods_name) .. "]" .. "</color>"
  1162. if basic.type == 11 and (basic.subtype == 10 or basic.subtype == 11) then --装备鉴定物, 碎片,显示鉴定物对应的装备图标
  1163. local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(basic.type_id, RoleManager.Instance.mainRoleInfo.career, basic.color)
  1164. goods_icon = icon
  1165. name = "<" .. Trim(_name) .. ">"
  1166. end
  1167. end
  1168. elseif tostring(arr[2]) == "goods8" then --消耗物品
  1169. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(tonumber(arr[3]))
  1170. if basic then
  1171. local have_num = GoodsModel:getInstance():GetCountWithType(0, tonumber(arr[3]))
  1172. if tonumber(arr[4]) > have_num then
  1173. name = "<color=" ..ColorUtil.RED.. ">"..Trim(basic.goods_name)..""..have_num.."/"..tonumber(arr[4])..")</color>"
  1174. else
  1175. name = "<color=" ..ColorUtil.GREEN.. ">"..Trim(basic.goods_name)..""..have_num.."/"..tonumber(arr[4])..")</color>"
  1176. end
  1177. --[[if basic.type == 11 and (basic.subtype == 10 or basic.subtype == 11)then --装备鉴定物, 碎片,显示鉴定物对应的装备图标
  1178. local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(basic.type_id, RoleManager.Instance.mainRoleInfo.career, basic.color)
  1179. goods_icon = icon
  1180. name = "<" .. Trim(_name) .. ">"
  1181. end--]]
  1182. end
  1183. elseif tostring(arr[2]) == "scene" then --场景
  1184. local scene_info = SceneManager.Instance:GetSceneInfo(tonumber(arr[3]))
  1185. if scene_info then
  1186. name = Trim(scene_info.name)
  1187. end
  1188. elseif tostring(arr[2]) == "scene2" or tostring(arr[2]) == "treasure3" or tostring(arr[2]) == "valhallapk" then
  1189. local scene_info = SceneManager.Instance:GetSceneInfo(tonumber(arr[3]))
  1190. if scene_info then
  1191. name = "<color=" .. ColorUtil.GREEN .. "><" .. Trim(scene_info.name) .. "(".. arr[4] ..",".. arr[5] ..")".. "></color>"
  1192. end
  1193. -- elseif tostring(arr[2]) == "partner" or arr[2] == "partner2" then --伙伴
  1194. -- local color, name_str = PartnerModel:getInstance():GetPartnerQualityAndName(tonumber(arr[3]))
  1195. -- if color and name_str then
  1196. -- logWarn(color,name_str)
  1197. -- name = "<color='" .. WordManager.GetPartnerColor(color) .. "'>" .. name_str .. "</color>"
  1198. -- end
  1199. -- elseif tostring(arr[2]) == "partner3" then --伙伴 加括号
  1200. -- local color, name_str = PartnerModel:getInstance():GetPartnerQualityAndName(tonumber(arr[3]))
  1201. -- if color and name_str then
  1202. -- logWarn(color,name_str)
  1203. -- name = "<color='" .. WordManager.GetPartnerColor(color) .. "'>" .. "<" .. name_str .. ">" .. "</color>"
  1204. -- end
  1205. -- elseif tostring(arr[2]) == "treasure" then --藏宝图地点
  1206. -- local event_type = tonumber(arr[3])
  1207. -- if event_type == 1 then -- 打开宝图介绍界面
  1208. -- name = string.format("<color=%s>[查看详情]</color>", WordManager.GetChuanwenColor(0))
  1209. -- elseif event_type == 2 then -- 跳转到藏宝图boss位置
  1210. -- name = string.format("<color=%s>[立即前往]</color>", WordManager.GetChuanwenColor(0))
  1211. -- end
  1212. elseif tostring(arr[2]) == "scene3" then --点击前往
  1213. -- name = string.format("<color='%s'>点击前往</color>", ColorUtil.GREEN)
  1214. name = string.format("<color=%s>点击前往</color>", WordManager.GetChuanwenColor(0))
  1215. elseif tostring(arr[2]) == "player" then
  1216. name = arr[3]
  1217. elseif tostring(arr[2]) == "player2" then
  1218. name = arr[3]
  1219. elseif tostring(arr[2]) == "angel" then
  1220. -- name = string.format("<color='%s'>点击前往</color>", ColorUtil.GREEN)
  1221. name = string.format("<color=%s>点击前往</color>", WordManager.GetChuanwenColor(0))
  1222. elseif tostring(arr[2]) == "skill" then
  1223. local cfg = ConfigItemMgr.Instance:GetSkillItem(tonumber(arr[3]))
  1224. if cfg then
  1225. name = string.format("<color=#ff3232>%s</color>",Trim(cfg.name))..","..Trim(cfg.lvs[1].desc)
  1226. end
  1227. elseif tostring(arr[2]) == "mate_show" then
  1228. name = MateConst.ShowMateText
  1229. elseif tostring(arr[2]) == "beachcallgift" then
  1230. name = "<color=#04bd27>[给我投票]</color>"
  1231. elseif tostring(arr[2]) == "dunManyTeam" then
  1232. name = string.format("<color=%s>[前往组队]</color>", WordManager.GetChuanwenColor(1))
  1233. elseif tostring(arr[2]) == "dunManyGuardianTeam" then
  1234. name = string.format("<color=%s>[我要进组]</color>", WordManager.GetChuanwenColor(1))
  1235. elseif tostring(arr[2]) == "firstrecharge" then
  1236. name = string.format("<color=%s>[我也要首充]</color>", WordManager.GetChuanwenColor(1))
  1237. elseif tostring(arr[2]) == "fortuneCat" then -- 招财猫
  1238. name = string.format("<color=%s>[我也要翻倍]</color>", WordManager.GetChuanwenColor(1))
  1239. elseif tostring(arr[2]) == "racerank" then -- 竞榜活动
  1240. name = string.format("<color=%s>[我也要冲榜]</color>", WordManager.GetChuanwenColor(1))
  1241. elseif tostring(arr[2]) == "kfGroupBuying"then -- 开服团购活动
  1242. name = string.format("<color=%s>[前往砍价拼团]</color>", WordManager.GetChuanwenColor(1))
  1243. elseif tostring(arr[2]) == "mobilizationGroupBuying" then
  1244. name = string.format("<color=%s>[前往砍价拼团]</color>", WordManager.GetChuanwenColor(1))
  1245. elseif tostring(arr[2]) == "attr_id_val" then -- 属性id和数值
  1246. local _, name1, _, val1 = WordManager:GetPropertyInfo(tonumber(arr[3]), tonumber(arr[4]))
  1247. name = name1 .. "" .. val1
  1248. elseif tostring(arr[2]) == "mon" then -- 怪物id,表现为读取配置显示怪物名称
  1249. local monster_cfg = ConfigItemMgr.Instance:GetMonsterDataItem(tonumber(arr[3]))
  1250. name = monster_cfg and Trim(monster_cfg.name) or ""
  1251. elseif tostring(arr[2]) == "marble" then -- 弹珠机
  1252. name = string.format("<color=%s>[我也要弹]</color>", WordManager.GetChuanwenColor(1))
  1253. elseif tostring(arr[2]) == "mono" then -- 大富翁
  1254. name = string.format("<color=%s>[前往超级富豪]</color>", WordManager.GetChuanwenColor(1))
  1255. elseif tostring(arr[2]) == "contract" then -- 万物宝典
  1256. name = string.format("<color=%s>[我也要解锁]</color>", WordManager.GetChuanwenColor(1))
  1257. elseif tostring(arr[2]) == "contractLv" then -- 万物宝典
  1258. name = string.format("<color=%s>[我也要升级]</color>", WordManager.GetChuanwenColor(1))
  1259. elseif tostring(arr[2]) == "escortHelp" then -- 护送协助
  1260. name = string.format("<color=%s>[立即前往]</color>", WordManager.GetChuanwenColor(1))
  1261. elseif tostring(arr[2]) == "guild_csgr_enter" then -- 本国团战
  1262. name = string.format("<color=%s>[立即前往]</color>", WordManager.GetChuanwenColor(1))
  1263. elseif tostring(arr[2]) == "bosspass" then -- 幻魔宝典
  1264. name = string.format("<color=%s>[我也要解锁]</color>", WordManager.GetChuanwenColor(1))
  1265. elseif tostring(arr[2]) == "bosspassLv" then -- 幻魔宝典
  1266. name = string.format("<color=%s>[立即前往]</color>", WordManager.GetChuanwenColor(1))
  1267. elseif tostring(arr[2]) == "hopegift" then--明日之礼
  1268. name = string.format("<color=%s>[我也要抽]</color>", WordManager.GetChuanwenColor(1))
  1269. elseif tostring(arr[2]) == "playername" then -- 聊天@别人
  1270. name = HtmlColorTxt( "@" .. arr[3], ColorUtil.BLUE_DARK)
  1271. elseif tostring(arr[2]) == "mobilize" then -- 全民动员
  1272. name = string.format("<color=%s>[我也要达成]</color>", WordManager.GetChuanwenColor(1))
  1273. end
  1274. return "<" .. txt..">" .. name
  1275. end
  1276. txt = string.gsub(txt, "%<a[^%>^/]+%>", replaceFunc)
  1277. return txt
  1278. end
  1279. --是否包含Url标签
  1280. function IsContainsUrlTab( content )
  1281. if string.find(content, "[[]/url[]]") then
  1282. local function replaceFunc( str )
  1283. local arr
  1284. local new_str
  1285. arr = Split(str,"]")
  1286. new_str = string.format("<a@url@%s><color='%s'> %s</color></a>",arr[1],WordManager.GetChuanwenColor(4),arr[2])
  1287. return new_str
  1288. end
  1289. content = string.gsub(content, "%[url%s(.-)%[%/url%]",replaceFunc)
  1290. end
  1291. return content
  1292. end
  1293. --封装带url的特殊标签
  1294. function PackageSpecialUrlTab( content,url )
  1295. if string.find(url, "[[]/url[]]") then
  1296. local function replaceFunc( str )
  1297. local arr
  1298. local new_str
  1299. arr = Split(str,"]")
  1300. PrintTable(arr)
  1301. if tostring(arr[2]) and tostring(arr[2]) ~= "" then
  1302. new_str = string.format("<a@url@%s><color='%s'> %s</color></a>",arr[1],WordManager.GetChuanwenColor(4),arr[2])
  1303. elseif tostring(arr[2]) == "" then
  1304. new_str = string.format("<a@url@%s><color='%s'> 点击前往</color></a>",arr[1],WordManager.GetChuanwenColor(4))
  1305. end
  1306. return new_str
  1307. end
  1308. url = string.gsub(url, "%[url%s(.-)%[%/url%]",replaceFunc)
  1309. end
  1310. return PackageSpecialTab(content) .. url
  1311. end
  1312. --设置inlinetext的文本(no_chat_general在聊天栏部分颜色需要进行一次转换)
  1313. function SetInlineText(inline_text, content, url, no_chat_general)
  1314. if inline_text == nil then return end
  1315. content = content or ""
  1316. if url then
  1317. content = PackageSpecialUrlTab(content, url)
  1318. else
  1319. content = PackageSpecialTab(content)
  1320. end
  1321. if no_chat_general then
  1322. content = string.gsub(content, ColorUtil.GREEN_DARK, ColorUtil.GREEN_DARK_CH)
  1323. end
  1324. inlineSpriteMgr:PackageInlineText(inline_text, content)
  1325. end
  1326. --给inlinetext添加点击事件 可支持多行换行以及各种图文混排
  1327. function AddInlineLickEvent(inline_text, call_back)
  1328. if inline_text then
  1329. local function lua_callback(param, x, y)
  1330. local param_list = Split(param, "@", 2)
  1331. GlobalEventSystem:Fire(EventName.UNDER_LINE_CLICK_EVENT, param_list, x, y)
  1332. if call_back then
  1333. call_back(param_list,x,y)
  1334. end
  1335. end
  1336. inline_text:AddLinkEvent(lua_callback)
  1337. end
  1338. end
  1339. --[[
  1340. 西线
  1341. --下划线,标识<u></u>
  1342. --超链接,标识<a@类型@参数1@参数2>XXX</a>, 例如<a@goods@110101>强化石</a> 参数用@开始分隔
  1343. @param :
  1344. ref_tar必须是继承baseclass的对象
  1345. parent_transform:
  1346. call_back
  1347. hide_click:
  1348. hide_line:线
  1349. ]]
  1350. function AddUnderLineAndClick(ref_tar, parent_transform, call_back, hide_click, hide_line)
  1351. if parent_transform == nil then return end
  1352. local txt = parent_transform:GetComponent("Text").text
  1353. local cache_label_list = ref_tar[parent_transform]
  1354. if cache_label_list == nil then
  1355. cache_label_list = {}
  1356. ref_tar[parent_transform] = cache_label_list
  1357. else
  1358. for i, item in ipairs(cache_label_list) do
  1359. item:SetActive(false)
  1360. end
  1361. end
  1362. txt = PackageSpecialTab(txt)
  1363. local txt_cache = txt --保存一份文本
  1364. txt_cache = string.gsub(txt_cache, "%<a[^%>^/]+%>", "")
  1365. txt_cache = string.gsub(txt_cache, "</a>", "")
  1366. txt_cache = string.gsub(txt_cache, "<u>", "")
  1367. txt_cache = string.gsub(txt_cache, "%<%/u>", "")
  1368. --先去掉颜色标签,不然颜色标签会影响下划线的位置运算
  1369. txt = DeleteColorTag(txt)
  1370. --解析超链接
  1371. local final_list= FormatHyperLinkParam(txt, txt_cache)
  1372. parent_text = parent_transform:GetComponent("Text")
  1373. parent_text.text = txt_cache
  1374. local inlie
  1375. if not hide_click then
  1376. inlie = parent_transform:GetComponent("InlieText")
  1377. if inlie then --inlieText监听超链接点击
  1378. AddInlineLickEvent(parent_text, call_back)
  1379. end
  1380. end
  1381. local label_cache_list = {}
  1382. local current_width = 0
  1383. local label_count = 0
  1384. if not IsTableEmpty(final_list) then
  1385. for i, vo in ipairs(final_list) do
  1386. if vo.has_under_line or vo.has_link then
  1387. label_count = label_count + 1
  1388. --创建下划线的label
  1389. local child_label = cache_label_list[label_count]
  1390. if child_label == nil then
  1391. child_label = UiFactory.createChild(parent_transform, UIType.Label2,"child_label")
  1392. child_label.transform.pivot = Vector2(0, 1)
  1393. cache_label_list[label_count] = child_label
  1394. child_label.transform.anchorMin = Vector2(0, 1)
  1395. child_label.transform.anchorMax = Vector2(0, 1)
  1396. child_label.transform:GetComponent("Text").fontSize = parent_text.fontSize
  1397. child_label.transform:GetComponent("Text").raycastTarget = true
  1398. child_label.transform:GetComponent("Text").alignment = UnityEngine.TextAnchor.LowerCenter
  1399. else
  1400. child_label:SetActive(true)
  1401. end
  1402. parent_text.text = vo.text .. " "--这里先临时加两个空格,否则会出现最后一个下划线符号不显示
  1403. local curr_text_width = parent_text.preferredWidth
  1404. parent_text.text = vo.text
  1405. local curr_text_height = parent_text.preferredHeight + 5 --暂时加增大文本高度 为了避免下划线渲染不出来,+1不够 改成5
  1406. child_label.transform.sizeDelta = Vector2(curr_text_width, curr_text_height)
  1407. child_label.transform.localPosition = Vector3(current_width - parent_transform.pivot.x * parent_transform.sizeDelta.x, 0, 0)
  1408. --设置"___"下划线文本
  1409. local str = ""
  1410. for i = 1, string.len(vo.text) do
  1411. if vo.has_under_line == false or hide_line then
  1412. str = str .. " "
  1413. else
  1414. str = str .. "_"
  1415. end
  1416. end
  1417. local color_str = vo.color or "#31ee4a"
  1418. child_label:GetComponent("Text").text = "<color="..color_str..">"..str.."</color>"
  1419. if not hide_click and not inlie then --每一个下划线都有点击事件 如果是inlieText就不要监听,inlieText有超链接的监听
  1420. local function onBtnClickHandler(target, x, y)
  1421. local param_list = {}
  1422. if vo.param then
  1423. param_list = Split(vo.param, "@", 2)
  1424. GlobalEventSystem:Fire(EventName.UNDER_LINE_CLICK_EVENT, param_list, x, y)
  1425. end
  1426. if call_back then
  1427. call_back(param_list, x, y)
  1428. end
  1429. end
  1430. AddClickEvent(child_label, onBtnClickHandler)
  1431. end
  1432. end
  1433. parent_text.text = vo.text
  1434. current_width = current_width + parent_text.preferredWidth
  1435. end
  1436. end
  1437. parent_text.text = txt_cache
  1438. end
  1439. -- left 靠左或者居中 调用此方法前必须先赋值text!!!
  1440. -- 目标,头衔,头衔Img,名字,是否靠左,vip,vipImg
  1441. function SetTitlePos(target,title,t_img,text,left,vip,v_img)
  1442. -- print(target,title,t_img,text,left,vip,v_img)
  1443. local delta_x = 6
  1444. local width = text.preferredWidth
  1445. t_img.gameObject:SetActive(title ~= 0)
  1446. if title ~= 0 then
  1447. RoleTitleModel:getInstance():SetTitleImageByTouxian(target, t_img, title)
  1448. -- lua_resM:setImageSprite(target,t_img,"common_asset","title_icon_"..title)
  1449. t_img.rectTransform.anchoredPosition = Vector2.zero
  1450. text.rectTransform.anchoredPosition = Vector2(t_img.transform.sizeDelta.x + delta_x,0)
  1451. width = width + t_img.transform.sizeDelta.x + delta_x
  1452. t_img.gameObject:SetActive(true)
  1453. else
  1454. t_img.gameObject:SetActive(false)
  1455. t_img.rectTransform.anchoredPosition = Vector2(-t_img.transform.sizeDelta.x,0)
  1456. end
  1457. if vip then
  1458. VipModel:GetInstance():GetVipIcon(target,v_img,vip)
  1459. width = vip ~= 0 and width + v_img.transform.sizeDelta.x + delta_x or width
  1460. end
  1461. if not left then
  1462. --217是整个父物体的宽度
  1463. t_img.rectTransform.anchoredPosition = Vector2(217/2 - width/2, 0)
  1464. end
  1465. --无论居中还是靠左,text和vip都是在它左边组件的右边
  1466. text.rectTransform.anchoredPosition = Vector2(t_img.rectTransform.anchoredPosition.x + t_img.transform.sizeDelta.x + delta_x, 0)
  1467. v_img.rectTransform.anchoredPosition = Vector2(text.rectTransform.anchoredPosition.x + text.preferredWidth + delta_x, 0)
  1468. end
  1469. function utf8_to_unicode(str)
  1470. if not str or str == "" then
  1471. return nil
  1472. end
  1473. local res, seq, val = {}, 0, nil
  1474. for i = 1, #str do
  1475. local c = string.byte(str, i)
  1476. if seq == 0 then
  1477. if val then
  1478. res[#res + 1] = string.format("%04x", val)
  1479. end
  1480. seq = c < 0x80 and 1 or c < 0xE0 and 2 or c < 0xF0 and 3 or
  1481. c < 0xF8 and 4 or --c < 0xFC and 5 or c < 0xFE and 6 or
  1482. 0
  1483. if seq == 0 then
  1484. return str
  1485. end
  1486. val = bit.band(c, 2 ^ (8 - seq) - 1)
  1487. else
  1488. val = bit.bor(bit.lshift(val, 6), bit.band(c, 0x3F))
  1489. end
  1490. seq = seq - 1
  1491. end
  1492. if val then
  1493. res[#res + 1] = string.format("%04x", val)
  1494. end
  1495. if #res == 0 then
  1496. return str
  1497. end
  1498. return "\\u" .. table.concat(res, " \\u")
  1499. end
  1500. -- function HasLimitChar(str)
  1501. -- -- if not ClientConfig.is_chinese_verison then
  1502. -- -- return str
  1503. -- -- end
  1504. -- local unicode_str = utf8_to_unicode(str)
  1505. -- if not unicode_str or type(unicode_str) ~= "string" or unicode_str == "" then
  1506. -- return false
  1507. -- end
  1508. -- local str = string.gsub(unicode_str,"\\u","0x")
  1509. -- str = Split(str," ")
  1510. -- for k,v in pairs(str) do
  1511. -- local value = tonumber(v)
  1512. -- --中文
  1513. -- if not ((value >= 0x4E00 and value <= 0x9FA5) or (value >= 0x0021 and value <= 0x007F)) and
  1514. -- --韩文
  1515. -- not ((value >= 0xAC00 and value <= 0xD7AF) or (value >= 0x0021 and value <= 0x007F)) and
  1516. -- --日文
  1517. -- not ((value >= 0x3040 and value <= 0x31FF) or (value >= 0x0021 and value <= 0x007F)) then
  1518. -- return true
  1519. -- end
  1520. -- end
  1521. -- return false
  1522. -- end
  1523. --计算单位,保证数字最多只有4个(军衔进阶界面战力显示用)
  1524. function CalUnitNumWithMaxNum(num,max_num)
  1525. local max_num = max_num and max_num or 4
  1526. local str = ""
  1527. if num < 10000 then --小于1万
  1528. str = num
  1529. elseif num < 100000000 then --小于1亿
  1530. -- local a,b = math.modf(num/10000)
  1531. -- local left_num = 1--整数部分位数
  1532. -- for i=1,max_num + 1 do
  1533. -- if a~=0 then
  1534. -- a = math.floor(a/10)
  1535. -- else
  1536. -- left_num = i - 1
  1537. -- break
  1538. -- end
  1539. -- end
  1540. -- if b == 0 then
  1541. -- str = string.format("%d万", num/10000)
  1542. -- else
  1543. -- local cal_str = "%0."..(max_num-left_num).."f"
  1544. -- str = string.format(cal_str.."万", num/10000)
  1545. -- end
  1546. --万单位的不显示小数点
  1547. str = string.format("%d万", math.floor(num/10000))
  1548. elseif num < 1000000000000 then --小于1万亿
  1549. local a,b = math.modf(num/100000000)
  1550. local left_num = 1--整数部分位数
  1551. for i=1,max_num + 1 do
  1552. if a~=0 then
  1553. a = math.floor(a/10)
  1554. else
  1555. left_num = i - 1
  1556. break
  1557. end
  1558. end
  1559. if b == 0 then
  1560. str = string.format("%d亿", num/100000000)
  1561. else
  1562. local cal_str = "%0."..(max_num-left_num).."f"
  1563. str = string.format(cal_str.."亿", num/100000000)
  1564. end
  1565. else --超过1万亿
  1566. str = string.format("%0.2f万亿", num/1000000000000)
  1567. end
  1568. return str
  1569. end
  1570. --计算单位
  1571. function CalUnitNum( num )
  1572. local str = ""
  1573. if num < 10000 then --小于1万
  1574. str = num
  1575. elseif num < 100000000 then --小于1亿
  1576. str = string.format("%0.2f万", num/10000)
  1577. elseif num < 1000000000000 then --小于1万亿
  1578. str = string.format("%0.2f亿", num/100000000)
  1579. else --超过1万亿
  1580. str = string.format("%0.2f万亿", num/1000000000000)
  1581. end
  1582. return str
  1583. end
  1584. --计算单位,不留小数和万字
  1585. function CalUnitNum1(num)
  1586. local str = ""
  1587. if num < 10000 then --小于1万
  1588. str = num
  1589. elseif num < 100000000 then --小于1亿
  1590. str = string.format("%d", num/10000)
  1591. elseif num < 1000000000000 then --小于1万亿
  1592. str = string.format("%d", num/100000000)
  1593. else --超过1万亿
  1594. str = string.format("%d", num/100000000)
  1595. end
  1596. return str
  1597. end
  1598. --计算单位,不留小数版本
  1599. function CalUnitNum2( num )
  1600. local str = ""
  1601. if num < 10000 then --小于1万
  1602. str = num
  1603. elseif num < 100000000 then --小于1亿
  1604. str = string.format("%d万", num/10000)
  1605. elseif num < 1000000000000 then --小于1万亿
  1606. str = string.format("%d亿", num/100000000)
  1607. else --超过1万亿
  1608. str = string.format("%d亿", num/100000000)
  1609. end
  1610. return str
  1611. end
  1612. --计算单位
  1613. function CalUnitNum3( num )
  1614. local str = ""
  1615. if num < 100000000 then --小于1亿
  1616. str = num
  1617. elseif num < 1000000000000 then --小于1万亿
  1618. str = string.format("%0.2f亿", num/100000000)
  1619. else --超过1万亿
  1620. str = string.format("%0.2f亿", num/100000000)
  1621. end
  1622. return str
  1623. end
  1624. --计算单位 保留一位小数
  1625. function CalUnitNum4( num )
  1626. local str = ""
  1627. if num < 10000 then --小于1万
  1628. str = num
  1629. elseif num < 100000000 then --小于1亿
  1630. str = string.format("%0.1f万", num/10000)
  1631. elseif num < 1000000000000 then --小于1万亿
  1632. str = string.format("%0.1f亿", num/100000000)
  1633. else --超过1万亿
  1634. str = string.format("%0.1f亿", num/100000000)
  1635. end
  1636. return str
  1637. end
  1638. --万以上的数转为万单位
  1639. function ChangeNumByTenThousand(num)
  1640. local str = num
  1641. if str and tonumber(str) >= 10000 then --万
  1642. str = string.format("%.1f万", str / 10000)
  1643. str = string.gsub(str,"%.0","")
  1644. end
  1645. return str
  1646. end
  1647. local function chsize(char)
  1648. if not char then
  1649. print("not char")
  1650. return 0
  1651. elseif char > 240 then
  1652. return 4
  1653. elseif char > 225 then
  1654. return 3
  1655. elseif char > 192 then
  1656. return 2
  1657. else
  1658. return 1
  1659. end
  1660. end
  1661. -- 计算utf8字符串字符数, 各种字符都按一个字符计算
  1662. -- 例如utf8len("1你好") => 3
  1663. function utf8len(str)
  1664. local len = 0
  1665. local currentIndex = 1
  1666. while currentIndex <= #str do
  1667. local char = string.byte(str, currentIndex)
  1668. currentIndex = currentIndex + chsize(char)
  1669. len = len +1
  1670. end
  1671. return len
  1672. end
  1673. --计算战力,适用于配置表的属性格式
  1674. function CalAttrPowerByBaseAttr( pro_list )
  1675. local coe_arr = {
  1676. [1] = 0.25, --生命
  1677. [3] = 2.5, --攻击
  1678. [4] = 2.5, --防御
  1679. [5] = 7.5, --命中
  1680. [6] = 7.5, --闪避
  1681. [7] = 7.5, --暴击
  1682. [8] = 7.5, --坚韧
  1683. [29] = 100, --暴击伤害
  1684. [30] = 100, --暴伤减免
  1685. [35] = 160, --伤害加成
  1686. [36] = 160, --伤害减免
  1687. }
  1688. local power = 0
  1689. local coe_arr_val = 0
  1690. for k, v in ipairs(pro_list) do
  1691. coe_arr_val = coe_arr[tonumber(v[1])] and coe_arr[tonumber(v[1])] or 0
  1692. power = power + coe_arr_val*tonumber(v[2])
  1693. end
  1694. return round(power)
  1695. end
  1696. function HtmlColorTxt(content, color, sizeScale)
  1697. local ncolor = color or "#ffffff"
  1698. if sizeScale then
  1699. return "<size=".. sizeScale .. "em><color=" .. ncolor .. ">" .. content .. "</color></size>"
  1700. else
  1701. return "<color=" .. ncolor .. ">" .. content .. "</color>"
  1702. end
  1703. end
  1704. function PairsByKeysInvert(t)
  1705. local temp = {}
  1706. for k in pairs(t) do
  1707. temp[#temp+1] = k
  1708. end
  1709. table.sort(temp)
  1710. local i = #temp+1
  1711. return function()
  1712. i = i-1
  1713. return temp[i], t[temp[i]]
  1714. end
  1715. end
  1716. --根据pairs修改而来,保证遍历的顺序是从小到大
  1717. function pairsByKeys(t)
  1718. local temp = {}
  1719. for k in pairs(t) do
  1720. temp[#temp+1] = k
  1721. end
  1722. table.sort(temp)
  1723. local i = 0
  1724. return function()
  1725. i = i+1
  1726. return temp[i], t[temp[i]]
  1727. end
  1728. end
  1729. function UtilGetRolePicPath(role_id,out_server,head_ver)
  1730. head_ver = head_ver or 0
  1731. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  1732. local server_id = out_server or playerInfo.server_id
  1733. local file_path = Util.DataPath .. "/rolehead/"
  1734. local file_name = role_id .. "_" .. head_ver .. ".jpg"
  1735. return file_path,file_name
  1736. end
  1737. local rechange_tab = {
  1738. ['['] = "{",
  1739. [']'] = "}",
  1740. ['<'] = "",
  1741. ['>'] = "",
  1742. key = "[%[%]<>]"
  1743. }
  1744. function stringtotable(str,is_check_chinese)
  1745. if str == "" then
  1746. return nil
  1747. end
  1748. local tab = {}
  1749. if str == nil or str == "nil" then
  1750. return nil
  1751. elseif type(str) ~= "string" then
  1752. tab = {}
  1753. return tab
  1754. elseif #str == 0 then
  1755. tab = {}
  1756. return tab
  1757. end
  1758. local _s = ""
  1759. local number = 0
  1760. str = string.gsub(str , rechange_tab.key,function(s,...)
  1761. return rechange_tab[s] or s
  1762. end)
  1763. local index,_ = string.find(str , "%b{}")
  1764. if not index then
  1765. str = string.format("{%s}",str)
  1766. end
  1767. string.gsub(str , "%b{}",function(s)
  1768. -- print(s)
  1769. number = number + 1
  1770. if number >= 2 then
  1771. _s = _s .. ","
  1772. end
  1773. _s = _s .. s
  1774. end)
  1775. if number > 1 then
  1776. _s = "{" .. _s .. "}"
  1777. end
  1778. if is_check_chinese then
  1779. _s = string.gsub(_s , "([%z\1-\31\33-\43\45-\122\124\126\127\194-\244].-)([,}].-)",function(s,f)
  1780. if tonumber(s) == nil then
  1781. s = "'"..s.."'"
  1782. end
  1783. return s..f
  1784. end)
  1785. else
  1786. _s = string.gsub(_s , "([%w%d].-)([,}].-)",function(s,f)
  1787. if tonumber(s) == nil then
  1788. s = "'"..s.."'"
  1789. end
  1790. return s..f
  1791. end)
  1792. end
  1793. local code, ret = pcall(loadstring(string.format("do local _=%s return _ end", _s)))
  1794. if code then
  1795. return ret
  1796. else
  1797. tab = {}
  1798. return tab
  1799. end
  1800. end
  1801. function GetSkillPowerAttrList(skill_power_info)
  1802. local result = {}
  1803. local data = stringtotable(skill_power_info.attr)
  1804. local coe_arr = {
  1805. [1] = true, --生命
  1806. [3] = true, --攻击
  1807. [4] = true, --防御
  1808. [5] = true, --命中
  1809. [6] = true, --闪避
  1810. [7] = true, --暴击
  1811. [8] = true, --坚韧
  1812. [29] = true, --暴击伤害
  1813. [30] = true, --暴伤减免
  1814. [35] = true, --伤害加成
  1815. [36] = true, --伤害减免
  1816. }
  1817. local function get_coe(key)
  1818. for k,v in pairs(coe_arr) do
  1819. if tonumber(key) == k then
  1820. local arr = coe_arr[k]
  1821. coe_arr[k] = nil
  1822. return arr
  1823. end
  1824. end
  1825. end
  1826. --目前暂不判断
  1827. --被动技能 对象(自己):v[4] == 1
  1828. --被动技能 概率:v[3] == 1000
  1829. for i,v in pairs(data) do
  1830. if get_coe(v[1]) and v[5] > 0 then
  1831. local item = {v[1], v[5]}
  1832. table.insert(result, item)
  1833. end
  1834. end
  1835. return result
  1836. end
  1837. function GetSkillPower( skill_power_info )
  1838. return CalAttrPowerByBaseAttr(GetSkillPowerAttrList(skill_power_info))
  1839. end
  1840. function GetSkillAttrBySkill( skill_id, skill_lv, need_power ,is_have)
  1841. local new_atr_tb = {}
  1842. -------------------------
  1843. skill_lv = skill_lv or 1
  1844. local power_conf = 0
  1845. local skill_conf = SkillManager:getInstance():getSkillFromConfig(skill_id)
  1846. if skill_conf and skill_conf.lvs and skill_conf.lvs[skill_lv] then
  1847. local temp_tb = stringtotable(skill_conf.lvs[skill_lv].base_attr)
  1848. power_conf = tonumber(skill_conf.lvs[skill_lv].power) or 0
  1849. for k,v in pairs(temp_tb) do
  1850. table.insert( new_atr_tb, {v[2],v[3]} )
  1851. end
  1852. end
  1853. if need_power then
  1854. return new_atr_tb,GetFighting(new_atr_tb, is_have) + power_conf
  1855. else
  1856. return new_atr_tb
  1857. end
  1858. end
  1859. function GetSkillConfPowerBySkill( skill_id, skill_lv)
  1860. local new_atr_tb = {}
  1861. -------------------------
  1862. skill_lv = skill_lv or 1
  1863. local power_conf = 0
  1864. local skill_conf = SkillManager:getInstance():getSkillFromConfig(skill_id)
  1865. if skill_conf and skill_conf.lvs and skill_conf.lvs[skill_lv] then
  1866. local temp_tb = stringtotable(skill_conf.lvs[skill_lv].base_attr)
  1867. power_conf = tonumber(skill_conf.lvs[skill_lv].power) or 0
  1868. end
  1869. return power_conf
  1870. end
  1871. function SetGameFrameRate( value )
  1872. if not FINAL_FRAMERATE then
  1873. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1874. FINAL_FRAMERATE = GameSettingManager.PerformanceList[1].val_list[1]
  1875. elseif SystemMemoryLevel.Cur == SystemMemoryLevel.Middle then
  1876. FINAL_FRAMERATE = GameSettingManager.PerformanceList[1].val_list[2]
  1877. else
  1878. FINAL_FRAMERATE = GameSettingManager.PerformanceList[1].val_list[3]
  1879. end
  1880. end
  1881. local value = value or FINAL_FRAMERATE
  1882. Application.targetFrameRate = value
  1883. end
  1884. --千万以上的数转为亿单位
  1885. function ChangeNum(num)
  1886. local str = num
  1887. if str and tonumber(str) >= 100000000 then --千万
  1888. str = string.format("%.2f亿", str / 1000000000)
  1889. end
  1890. return str
  1891. end
  1892. --模拟器设置
  1893. function InitSimulatorSetting( )
  1894. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1895. SystemMemoryLevel.Cur = SystemMemoryLevel.Middle
  1896. lua_settingM:SetPostEffectLevel(2)
  1897. end
  1898. --Optimizer.SetShaderLodValue(300)
  1899. lua_settingM.sysSet.quality = 3
  1900. lua_settingM.sysSet.fps = 50
  1901. lua_settingM:ApplySetting()
  1902. end
  1903. function InitResLoadSpeed( scale_speed )
  1904. if SystemRuntimePlatform.IsWindows() then
  1905. return
  1906. end
  1907. local scale = scale_speed or 1
  1908. local load_count = 6
  1909. local download = 3
  1910. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1911. load_count = 4
  1912. download = 2
  1913. elseif SystemMemoryLevel.Cur == SystemMemoryLevel.Middle then
  1914. load_count = 5
  1915. download = 2
  1916. end
  1917. resMgr:SetLoadAssetsMaxCount( load_count * scale )
  1918. resMgr:SetDownloadMaxCount( download * scale )
  1919. end
  1920. function SetAsyncUpLoadLevel( level )
  1921. if SystemRuntimePlatform.IsWindows() then
  1922. return
  1923. end
  1924. local time_slice = 4
  1925. local buff_size = 16
  1926. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  1927. time_slice = 4
  1928. buff_size = 8
  1929. end
  1930. time_slice = time_slice * level
  1931. buff_size = buff_size * level
  1932. QualitySettings.asyncUploadTimeSlice = time_slice
  1933. QualitySettings.asyncUploadBufferSize = buff_size
  1934. end
  1935. function InitEngineData()
  1936. if tonumber(AppConst.EnglineVer) >= 77 then
  1937. resMgr:SetCacheDownloadMode(false)
  1938. resMgr:SetNewDownloadMode(true)
  1939. resMgr.m_download_timeout = 20
  1940. end
  1941. -- if SystemRuntimePlatform.IsAndroid() then
  1942. -- if tonumber(AppConst.EnglineVer) >= 91 then
  1943. -- networkMgr.socket.mUseThread = true --是否开启多线程收发协议模式
  1944. -- if SystemMemoryLevel.Cur == SystemMemoryLevel.Hight and SystemRuntimePlatform.IsAndroid() then
  1945. -- networkMgr.socket.mUseThread = false
  1946. -- networkMgr.socket.writeFunc = 1
  1947. -- networkMgr.socket.use_read_cache_state = false
  1948. -- networkMgr.socket.use_sent_cache_state = false
  1949. -- end
  1950. -- end
  1951. -- else
  1952. networkMgr.socket.mUseThread = true
  1953. -- end
  1954. end
  1955. function GameDontDestroyOnLoad()
  1956. local obj = GameObject.Find("root").transform
  1957. while obj.parent ~= nil do
  1958. obj = obj.parent
  1959. end
  1960. UnityEngine.Object.DontDestroyOnLoad(obj.gameObject)
  1961. end
  1962. function CheckIphoneXState()
  1963. local iphonex_offset = 55 --像素
  1964. local mode_func = function()
  1965. ClientConfig.iphone_x_offset_left = iphonex_offset
  1966. local orientation = SDKUtil.CallIntFunc( "IosSystem", "GetIosOrientation", "")
  1967. if tonumber(orientation) ~= 0 then
  1968. ClientConfig.orientation_did_change = tonumber(orientation)
  1969. end
  1970. if ClientConfig.orientation_did_change == 3 then --默认
  1971. ClientConfig.iphone_x_offset_left = iphonex_offset
  1972. ClientConfig.iphone_x_offset_right = 0
  1973. elseif ClientConfig.orientation_did_change == 4 then --反转
  1974. ClientConfig.iphone_x_offset_right = iphonex_offset
  1975. ClientConfig.iphone_x_offset_left = 0
  1976. end
  1977. end
  1978. if ClientConfig.iphone_x_model then
  1979. mode_func()
  1980. end
  1981. local device_list = {}
  1982. if SystemRuntimePlatform.IsIphone() then
  1983. device_list = {
  1984. ["iPhone10,3"] = true,
  1985. ["iPhone10,6"] = true,
  1986. ["iPhone11,2"] = true,
  1987. ["iPhone11,4"] = true,
  1988. ["iPhone11,6"] = true,
  1989. ["iPhone11,8"] = true,
  1990. }
  1991. elseif SystemRuntimePlatform.IsAndroid() and OriginalResolutionWidth == 2280 then
  1992. device_list =
  1993. {
  1994. ["OPPOPACM00"] = true,
  1995. ["OPPOPACT00"] = true,
  1996. ["OPPOPAAT00"] = true,
  1997. ["OPPOPAAM00"] = true,
  1998. ["OPPOPADT00"] = true,
  1999. ["OPPOPADM00"] = true,
  2000. ["VIVOVIVOY85"] = true,
  2001. ["VIVOVIVOY85A"] = true,
  2002. ["VIVOVIVOX21"] = true,
  2003. ["VIVOVIVOX21A"] = true,
  2004. }
  2005. elseif SystemRuntimePlatform.IsAndroid() and OriginalResolutionWidth == 1520 then
  2006. device_list = {
  2007. ["VIVOV1732A"] = true,
  2008. ["VIVOV1732T"] = true,
  2009. ["OPPOPBAM00"] = true,
  2010. }
  2011. elseif SystemRuntimePlatform.IsAndroid() and OriginalResolutionWidth == 2340 then
  2012. device_list = {
  2013. ["SAMSUNGSM-G8870"] = true,
  2014. ["VIVOV1824A"] = true,
  2015. }
  2016. else
  2017. return
  2018. end
  2019. local device = string.gsub(SystemInfo.deviceModel," ","")
  2020. if SystemRuntimePlatform.IsAndroid() then
  2021. device = string.upper(device)
  2022. end
  2023. if device_list[device] then
  2024. ClientConfig.iphone_x_model = true
  2025. if SystemRuntimePlatform.IsAndroid() then
  2026. CheckAndroidHairAndOrientation(iphonex_offset)
  2027. else
  2028. mode_func()
  2029. end
  2030. else
  2031. if SystemRuntimePlatform.IsIphone() then
  2032. local hair_size = SDKUtil.CallIntFunc( "IosSystem", "GetIosHairSystemSize", "")
  2033. if tonumber(hair_size) > 0 then
  2034. ClientConfig.iphone_x_model = true
  2035. iphonex_offset = tonumber(hair_size)
  2036. mode_func()
  2037. end
  2038. end
  2039. end
  2040. end
  2041. function CheckAndroidHairAndOrientation(size)
  2042. if tonumber(AppConst.EnglineVer) >= 85 then
  2043. --local orientation = SDKUtil.CallIntFunc( "SystemData", "OrientationChanged", "")
  2044. if orientation and tonumber(orientation) > 0 then
  2045. ClientConfig.orientation_did_change = tonumber(orientation)
  2046. end
  2047. if ClientConfig.orientation_did_change == 3 then
  2048. ClientConfig.iphone_x_offset_left = size
  2049. ClientConfig.iphone_x_offset_right = size
  2050. else
  2051. ClientConfig.iphone_x_offset_left = size
  2052. ClientConfig.iphone_x_offset_right = size
  2053. end
  2054. else
  2055. ClientConfig.iphone_x_offset_left = size
  2056. ClientConfig.iphone_x_offset_right = size
  2057. end
  2058. end
  2059. function CheckAndroid9SystemHair()
  2060. if SystemRuntimePlatform.IsAndroid() and not ClientConfig.iphone_x_model then
  2061. local size = SDKUtil.CallIntFunc( "SystemData", "GetSafeTop", "")
  2062. local size_num = tonumber(size)
  2063. -- local temp_str = "GetSafeTop = " .. tostring(size_num)
  2064. -- GameError.Instance:SendErrorMsg(temp_str)
  2065. if size_num then
  2066. local temp_size = size_num > 55 and 55 or size_num
  2067. temp_size = temp_size <= 0 and 10 or temp_size
  2068. ClientConfig.iphone_x_model = true
  2069. CheckAndroidHairAndOrientation(temp_size)
  2070. end
  2071. end
  2072. end
  2073. --设置材质贴图
  2074. function SetMaterialTexture(material, texture)
  2075. if material:HasProperty("_MainTex") then
  2076. material:SetTexture("_MainTex", texture)
  2077. elseif material:HasProperty("_AmitTex") then
  2078. material:SetTexture("_AmitTex", texture)
  2079. end
  2080. end
  2081. --获取材质贴图
  2082. function GetMaterialTexture(material)
  2083. local texture
  2084. if material:HasProperty("_MainTex") then
  2085. texture = material:GetTexture("_MainTex")
  2086. elseif material:HasProperty("_AmitTex") then
  2087. texture = material:GetTexture("_AmitTex")
  2088. elseif material:HasProperty("_Amitex") then
  2089. texture = material:GetTexture("_Amitex")
  2090. end
  2091. return texture
  2092. end
  2093. --取等级模型id列表的衣服id
  2094. function GetRoleClotheId(level_model_list)
  2095. local model_res_list = level_model_list
  2096. if model_res_list then
  2097. for k,v in ipairs(model_res_list) do
  2098. if v.part_pos == FashionPartPos.Clothe then
  2099. return v.level_model_id
  2100. end
  2101. end
  2102. end
  2103. end
  2104. --取时装衣服贴图id
  2105. --is_only_have_fashion_id:fashion_model_id如果是表示时装id而不是资源id,则要去FashionModel转化一下
  2106. function GetRoleClotheTextureId(vo, is_only_have_fashion_id)
  2107. local model_res_list = vo.fashion_model_list
  2108. if model_res_list then
  2109. for k,v in ipairs(model_res_list) do
  2110. if v.part_pos == FashionModel.FashionType.CLOTHES then
  2111. --需要折算id返回
  2112. local id = v.fashion_model_id
  2113. if is_only_have_fashion_id and v.fashion_model_id ~= 0 then
  2114. id = FashionModel:GetInstance():GetFashionModelId(v.fashion_model_id, vo.career, v.fashion_color)
  2115. end
  2116. if id < 1000 then
  2117. id = id + vo.career * 1000
  2118. end
  2119. if v.fashion_chartlet_id > 1 then--配色大于1要多连接一个配色
  2120. id = id .. v.fashion_chartlet_id
  2121. end
  2122. return tonumber(id), 0
  2123. end
  2124. end
  2125. end
  2126. end
  2127. --取坐骑id
  2128. function GetHorseTextureId(foster_list)
  2129. local model_res_list = foster_list
  2130. if model_res_list then
  2131. for k,v in ipairs(model_res_list) do
  2132. if v.type_id == FosterConst.ModuleId.FHorse then
  2133. local cfg = FosterModel.Instance:GetBaseConfOne(v.type_id, v.stage_id, 0)
  2134. if cfg then
  2135. return cfg.resource
  2136. end
  2137. end
  2138. end
  2139. end
  2140. return 1000
  2141. end
  2142. --上面取坐骑id的先不删,新建一个方法,先取珍宝再取进阶
  2143. function GetHorseClotheId( vo )
  2144. if vo then
  2145. local function get_foster_skin( type_id )
  2146. for k,v in pairs(vo.foster_skin_list) do
  2147. if not v.skin_id then
  2148. --数据结构改了,写法要修正,补全一个skin_id
  2149. if v.type_id == FosterConst.ModuleId.FHorse then
  2150. --武器的珍宝需要手动折算2次成资源名
  2151. v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2152. --你的数据要有职业哦,不然我没法完全正确地补全skin_id
  2153. -- v.skin_id = GameResPath:GetFWeaponResName( vo.career or 1,v.skin_id)--写错了,等祖荣哥回来改
  2154. -- else
  2155. -- v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2156. end
  2157. end
  2158. if v.type_id == type_id and v.skin_id > 0 then
  2159. return v.skin_id
  2160. end
  2161. end
  2162. end
  2163. for k,v in pairs(vo.foster_skin_list) do
  2164. if v.type_id == FosterConst.ModuleId.FHorse then
  2165. return get_foster_skin(v.type_id)
  2166. end
  2167. end
  2168. for k,v in pairs(vo.foster_list) do
  2169. if v.type_id == FosterConst.ModuleId.FHorse then
  2170. return FosterModel:GetInstance():GetModuleResIdByStage(v.type_id,v.stage_id)
  2171. end
  2172. end
  2173. end
  2174. return 1000
  2175. end
  2176. --取时装头发id
  2177. --is_only_have_fashion_id:fashion_model_id如果是表示时装id而不是资源id,则要去FashionModel转化一下
  2178. function GetRoleHeadId(vo, is_only_have_fashion_id)
  2179. local model_res_list = vo.fashion_model_list
  2180. if model_res_list then
  2181. for k,v in ipairs(model_res_list) do
  2182. if v.part_pos == FashionModel.FashionType.HEAD then
  2183. --需要折算id返回
  2184. local id = v.fashion_model_id
  2185. if is_only_have_fashion_id and v.fashion_model_id ~= 0 then
  2186. id = FashionModel:GetInstance():GetFashionModelId(v.fashion_model_id, vo.career, v.fashion_color)
  2187. end
  2188. if id < 1000 then
  2189. id = id + vo.career * 1000
  2190. end
  2191. if v.fashion_chartlet_id > 1 then
  2192. id = id .. v.fashion_chartlet_id
  2193. end
  2194. return tonumber(id)
  2195. end
  2196. end
  2197. end
  2198. model_res_list = vo.level_model_list
  2199. if model_res_list then
  2200. for k,v in ipairs(model_res_list) do
  2201. if v.part_pos == FashionPartPos.Head then
  2202. return v.level_model_id
  2203. end
  2204. end
  2205. end
  2206. end
  2207. --取时装发饰id
  2208. function GetRoleHatId(vo)
  2209. local model_res_list = vo.fashion_model_list
  2210. if model_res_list then
  2211. for k,v in ipairs(model_res_list) do
  2212. if v.part_pos == FashionModel.FashionType.HAT then
  2213. return v.fashion_model_id
  2214. end
  2215. end
  2216. end
  2217. end
  2218. --明日之星直接取发饰的资源id
  2219. function GetRoleHatTextureId(vo)
  2220. local model_res_list = vo.fashion_model_list
  2221. if model_res_list then
  2222. for k,v in ipairs(model_res_list) do
  2223. if v.part_pos == FashionModel.FashionType.HAT then
  2224. return FashionModel:GetInstance():GetFashionModelId(v.fashion_model_id, 0, v.fashion_color)
  2225. end
  2226. end
  2227. end
  2228. end
  2229. --is_only_have_fashion_id:fashion_model_id如果是表示时装id而不是资源id,则要去FashionModel转化一下
  2230. function GetWingClotheId( vo ,is_only_have_fashion_id)
  2231. if vo then
  2232. --珍宝
  2233. local function get_foster_skin( type_id )
  2234. for k,v in pairs(vo.foster_skin_list) do
  2235. if not v.skin_id then
  2236. --数据结构改了,写法要修正,补全一个skin_id
  2237. if v.type_id == FosterConst.ModuleId.FWing then
  2238. --武器的珍宝需要手动折算2次成资源名
  2239. v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2240. --你的数据要有职业哦,不然我没法完全正确地补全skin_id
  2241. -- v.skin_id = GameResPath:GetFWeaponResName( vo.career or 1,v.skin_id)--写错了,等祖荣哥回来改
  2242. -- else
  2243. -- v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2244. end
  2245. end
  2246. if v.type_id == type_id and v.skin_id > 0 then
  2247. return v.skin_id
  2248. end
  2249. end
  2250. end
  2251. for k,v in pairs(vo.foster_skin_list) do
  2252. if v.type_id == FosterConst.ModuleId.FWing then
  2253. local foster_skin_id = get_foster_skin(v.type_id)
  2254. if foster_skin_id and foster_skin_id > 0 then
  2255. return get_foster_skin(v.type_id)
  2256. end
  2257. end
  2258. end
  2259. for k,v in pairs(vo.foster_list) do
  2260. if v.type_id == FosterConst.ModuleId.FWing then
  2261. return FosterModel:GetInstance():GetModuleResIdByStage(v.type_id,v.stage_id)
  2262. end
  2263. end
  2264. --时装
  2265. local model_res_list = vo.fashion_model_list
  2266. if model_res_list then
  2267. for k,v in ipairs(model_res_list) do
  2268. if v.part_pos == FashionModel.FashionType.WING then
  2269. if v.fashion_model_id ~= 0 then--明日之星可能会出现modelid为0的情况,这里要跳过
  2270. if is_only_have_fashion_id then
  2271. return FashionModel:GetInstance():GetFashionModelId(v.fashion_model_id, vo.career, v.fashion_color),v.fashion_chartlet_id
  2272. else
  2273. return v.fashion_model_id
  2274. end
  2275. end
  2276. end
  2277. end
  2278. end
  2279. --进阶
  2280. model_res_list = vo.level_model_list
  2281. if model_res_list then
  2282. for k,v in ipairs(model_res_list) do
  2283. if v.part_pos == FashionPartPos.wing then
  2284. return v.level_model_id
  2285. end
  2286. end
  2287. end
  2288. end
  2289. end
  2290. --取宝具id
  2291. function GetTalismanClotheId( vo )
  2292. if vo then
  2293. local function get_foster_skin( type_id )
  2294. for k,v in pairs(vo.foster_skin_list) do
  2295. if not v.skin_id then
  2296. --数据结构改了,写法要修正,补全一个skin_id
  2297. if v.type_id == FosterConst.ModuleId.FPearl then
  2298. --武器的珍宝需要手动折算2次成资源名
  2299. v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2300. --你的数据要有职业哦,不然我没法完全正确地补全skin_id
  2301. -- v.skin_id = GameResPath:GetFWeaponResName( vo.career or 1,v.skin_id)--写错了,等祖荣哥回来改
  2302. -- else
  2303. -- v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2304. end
  2305. end
  2306. if v.type_id == type_id and v.skin_id > 0 then
  2307. return v.skin_id
  2308. end
  2309. end
  2310. end
  2311. for k,v in pairs(vo.foster_skin_list) do
  2312. if v.type_id == FosterConst.ModuleId.FPearl then
  2313. local foster_id = get_foster_skin(v.type_id)
  2314. if foster_id and foster_id > 0 then
  2315. return foster_id
  2316. end
  2317. end
  2318. end
  2319. for k,v in pairs(vo.foster_list) do
  2320. if v.type_id == FosterConst.ModuleId.FPearl then
  2321. return FosterModel:GetInstance():GetModuleResIdByStage(v.type_id,v.stage_id)
  2322. end
  2323. end
  2324. end
  2325. end
  2326. --先去时装模型列表的 再取等级模型id列表的武器id
  2327. --is_only_have_fashion_model_id:fashion_model_id如果是表示资源id(居然和翅膀不一样,再特殊处理一下吧)
  2328. function GetWeaponClotheId(vo,is_only_have_fashion_model_id)
  2329. if vo then
  2330. --珍宝
  2331. if vo.foster_skin_list then
  2332. for k,v in pairs(vo.foster_skin_list) do
  2333. if not v.skin_id then
  2334. --数据结构改了,写法要修正,补全一个skin_id
  2335. if v.type_id == FosterConst.ModuleId.FWeapon then
  2336. --武器的珍宝需要手动折算2次成资源名
  2337. v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2338. --你的数据要有职业哦,不然我没法完全正确地补全skin_id
  2339. if v.skin_id and v.skin_id > 0 then
  2340. v.skin_id = GameResPath:GetFWeaponResName( vo.career or 1,v.skin_id)
  2341. end
  2342. -- else
  2343. -- v.skin_id = ShapeModel:GetInstance():GetModelRes( v.type_id, v.sub_id, v.star )
  2344. end
  2345. end
  2346. if v.type_id == FosterConst.ModuleId.FWeapon and v.skin_id > 0 then
  2347. return v.skin_id
  2348. end
  2349. end
  2350. end
  2351. for k,v in pairs(vo.foster_list) do
  2352. if v.type_id == FosterConst.ModuleId.FWeapon then
  2353. --防止stage_id等于0
  2354. local stage_id = v.stage_id == 0 and 1 or v.stage_id
  2355. local res_id = FosterModel:GetInstance():GetModuleResIdByStage(v.type_id, stage_id)
  2356. return GameResPath:GetFWeaponResName(vo.career,res_id)
  2357. end
  2358. end
  2359. --时装
  2360. local model_res_list = vo.fashion_model_list
  2361. if model_res_list then
  2362. for k,v in ipairs(model_res_list) do
  2363. if v.part_pos == FashionModel.FashionType.WEAPON then
  2364. local figure_id = v.fashion_model_id
  2365. if is_only_have_fashion_model_id then
  2366. local figure_id = FashionModel:GetInstance():GetFashionModelId(v.fashion_model_id, vo.career, v.fashion_color)
  2367. --需要折算id返回
  2368. if figure_id < 1000 then
  2369. figure_id = figure_id + vo.career * 1000
  2370. end
  2371. return figure_id
  2372. else
  2373. --需要折算id返回
  2374. if figure_id < 1000 then
  2375. figure_id = figure_id + vo.career * 1000
  2376. end
  2377. return figure_id
  2378. end
  2379. end
  2380. end
  2381. end
  2382. --进阶
  2383. model_res_list = vo.level_model_list
  2384. if model_res_list then
  2385. for k,v in ipairs(model_res_list) do
  2386. if v.part_pos == FashionPartPos.Weapon then
  2387. return v.level_model_id
  2388. end
  2389. end
  2390. end
  2391. end
  2392. end
  2393. function GetRoleHeadPath(career,sex,turn)
  2394. career = career or 1
  2395. sex = sex or 1
  2396. turn = turn or 1
  2397. local cfg = Config.Transfercareer[career.."@"..turn]
  2398. if cfg then
  2399. return "head_circle_" .. cfg.icon
  2400. end
  2401. return ""
  2402. end
  2403. --[[
  2404. local test = {1, 2, 3, 4}
  2405. _G.next(test) = nil
  2406. for i, v in pairs(test) do
  2407. print(v)
  2408. end]]
  2409. --中文字符串的截取
  2410. function SubStringUTF8(str, startIndex, endIndex)
  2411. if startIndex < 0 then
  2412. startIndex = SubStringGetTotalIndex(str) + startIndex + 1;
  2413. end
  2414. if endIndex ~= nil and endIndex < 0 then
  2415. endIndex = SubStringGetTotalIndex(str) + endIndex + 1;
  2416. end
  2417. if endIndex == nil then
  2418. return string.sub(str, SubStringGetTrueIndex(str, startIndex));
  2419. else
  2420. return string.sub(str, SubStringGetTrueIndex(str, startIndex), SubStringGetTrueIndex(str, endIndex + 1) - 1);
  2421. end
  2422. end
  2423. --获取中英混合UTF8字符串的真实字符数量
  2424. function SubStringGetTotalIndex(str)
  2425. local curIndex = 0;
  2426. local i = 1;
  2427. local lastCount = 1;
  2428. repeat
  2429. lastCount = SubStringGetByteCount(str, i)
  2430. i = i + lastCount;
  2431. curIndex = curIndex + 1;
  2432. until(lastCount == 0);
  2433. return curIndex - 1;
  2434. end
  2435. --[[
  2436. unity里面实际占位大小()
  2437. 1616
  2438. ]]--
  2439. function CalStringTrueLength( str )
  2440. if not str then
  2441. return 0
  2442. end
  2443. str = DeleteColorTag(str)
  2444. local length = 0;
  2445. local i = 1;
  2446. local lastCount = 1;
  2447. repeat
  2448. lastCount = SubStringGetByteCount(str, i)
  2449. i = i + lastCount;
  2450. if lastCount >= 2 then
  2451. length = length + 1;
  2452. else
  2453. length = length + 0.5;
  2454. end
  2455. until(lastCount == 0);
  2456. return length - 1;
  2457. end
  2458. function SubStringGetTrueIndex(str, index)
  2459. local curIndex = 0;
  2460. local i = 1;
  2461. local lastCount = 1;
  2462. repeat
  2463. lastCount = SubStringGetByteCount(str, i)
  2464. i = i + lastCount;
  2465. curIndex = curIndex + 1;
  2466. until(curIndex >= index);
  2467. return i - lastCount;
  2468. end
  2469. --返回当前字符实际占用的字符数
  2470. function SubStringGetByteCount(str, index)
  2471. local curByte = string.byte(str, index)
  2472. local byteCount = 1;
  2473. if curByte == nil then
  2474. byteCount = 0
  2475. elseif curByte > 0 and curByte <= 127 then
  2476. byteCount = 1
  2477. elseif curByte>=192 and curByte<=223 then
  2478. byteCount = 2
  2479. elseif curByte>=224 and curByte<=239 then
  2480. byteCount = 3
  2481. elseif curByte>=240 and curByte<=247 then
  2482. byteCount = 4
  2483. end
  2484. return byteCount;
  2485. end
  2486. --[[
  2487. @param
  2488. list:
  2489. deleteKey:key
  2490. deleteValue:value
  2491. ]]
  2492. function DeleteTable( list, deleteKey, deleteValue )
  2493. local delete_index={}
  2494. for i,v in ipairs(list) do
  2495. if v[deleteKey]==deleteValue then
  2496. table.insert(delete_index,i)
  2497. end
  2498. end
  2499. local del_num=0
  2500. for i,v in ipairs(delete_index) do
  2501. local index = v - del_num
  2502. table.remove(list, index)
  2503. del_num = del_num + 1
  2504. end
  2505. end
  2506. --删除表中数据 判断不相等版本
  2507. function DeleteTableUnEqual( list, deleteKey, deleteValue )
  2508. local delete_index={}
  2509. for i,v in ipairs(list) do
  2510. if v[deleteKey]~=deleteValue then
  2511. table.insert(delete_index,i)
  2512. end
  2513. end
  2514. local del_num=0
  2515. for i,v in ipairs(delete_index) do
  2516. local index = v - del_num
  2517. table.remove(list, index)
  2518. del_num = del_num + 1
  2519. end
  2520. end
  2521. function ToStringEx(value)
  2522. if type(value)=='table' then
  2523. return TableToStr(value)
  2524. elseif type(value)=='string' then
  2525. return "\'"..value.."\'"
  2526. else
  2527. return tostring(value)
  2528. end
  2529. end
  2530. function TableToStr(t)
  2531. if t == nil then return "" end
  2532. local retstr= "{"
  2533. local i = 1
  2534. for key,value in pairs(t) do
  2535. local signal = ","
  2536. if i==1 then
  2537. signal = ""
  2538. end
  2539. if key == i then
  2540. retstr = retstr..signal..ToStringEx(value)
  2541. else
  2542. if type(key)=='number' or type(key) == 'string' then
  2543. retstr = retstr..signal..'['..ToStringEx(key).."]="..ToStringEx(value)
  2544. else
  2545. if type(key)=='userdata' then
  2546. retstr = retstr..signal.."*s"..TableToStr(getmetatable(key)).."*e".."="..ToStringEx(value)
  2547. else
  2548. retstr = retstr..signal..key.."="..ToStringEx(value)
  2549. end
  2550. end
  2551. end
  2552. i = i+1
  2553. end
  2554. retstr = retstr.."}"
  2555. return retstr
  2556. end
  2557. function FindInTable( tbl, key, value )
  2558. for k,v in pairs(tbl) do
  2559. if (key and v[key] or v) == value then
  2560. return v
  2561. end
  2562. end
  2563. return nil
  2564. end
  2565. function StrToTable(str)
  2566. if str == nil or type(str) ~= "string" or str=="[]" then
  2567. return
  2568. end
  2569. return loadstring("return " .. str)()
  2570. end
  2571. --获取进度的最大值(返回空表示不显示进度)
  2572. function GetMaxProgress(list)
  2573. if list[1] and list[1][1] then
  2574. if list[1][1] == "attr" then
  2575. return list[1][#list[1]]
  2576. elseif list[1][1] == "boss" then
  2577. return #list[1][2]
  2578. elseif list[1][1] == "suit_type" then
  2579. return list[#list][2]
  2580. elseif list[1][1] == "vip" then
  2581. return 1
  2582. elseif list[1][1] == "equip_ids" then
  2583. return 1
  2584. elseif list[1][1] == "equip" then
  2585. return 1
  2586. elseif list[1][1] == "equip_suit" then
  2587. return 1
  2588. elseif list[1][1] == "equipment" then
  2589. if list[1][2] == "0" then
  2590. return 10
  2591. else
  2592. return list[1][3]
  2593. end
  2594. elseif list[1][1] == "equipment_sumstren_lv" then
  2595. return list[1][2]
  2596. else
  2597. return list[1][2] or 1
  2598. end
  2599. end
  2600. end
  2601. --删除字符串中的所有空格
  2602. function NoBlankStr(str)
  2603. local str = Trim(str)
  2604. str = string.gsub(str, "%s", "")
  2605. return str
  2606. end
  2607. --出现严重问题时触发后台报警流程
  2608. function UtilSentServerError( error_msg )
  2609. local server_name = "未知"
  2610. if LoginController and LoginController.Instance then
  2611. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  2612. if playerInfo then
  2613. server_name = playerInfo.server_name or ""
  2614. end
  2615. end
  2616. local plat_name = ClientConfig.plat_name
  2617. local ticket = "e04201e54b49a941434c48d971b59af5"
  2618. local now_method = "send_voice"
  2619. local cur_time = tostring(os.time())
  2620. local post_param = {
  2621. time = cur_time,
  2622. method = now_method,
  2623. sign = string.lower(Util.md5( ticket .. cur_time .. now_method )),
  2624. server = server_name,
  2625. platform = plat_name,
  2626. game = "qhbgd",
  2627. issue = error_msg or "出问题了",
  2628. }
  2629. local call_func = function(ret,error_msg,data)
  2630. print("-- SentServerError result --",ret,error_msg,data)
  2631. end
  2632. local url = string.gsub(ClientConfig.php_website_error,"api.php","api_admin.php")
  2633. HttpUtil.HttpPostRequest(url, post_param, call_func)
  2634. end
  2635. --把数组的顺序打乱[只支持连续的自然数key值]
  2636. function DisruptListSequence(list)
  2637. if not list or type(list) ~= "table" or not next(list) then
  2638. return
  2639. end
  2640. local len = TableSize(list)
  2641. local end_list = {}
  2642. for i = 1, len do
  2643. local index = len - i + 1
  2644. if index > 0 then
  2645. local random_key = math.random(1, index)
  2646. table.insert(end_list, list[random_key])
  2647. table.remove(list, random_key)
  2648. end
  2649. end
  2650. for i,v in ipairs(end_list) do
  2651. table.insert(list, v)
  2652. end
  2653. end
  2654. function PrintResList()
  2655. local func = function(load_count,load_list,request_count,request_list,loading_count,loading_list,hight_count,hight_list,mid_count,mid_list,low_count,low_list)
  2656. local msg = string.format("res count:%d@%d@%d@%d@%d@%d",load_count,request_count,loading_count or 0,hight_count or 0,mid_count or 0,low_count or 0)
  2657. if request_count > 0 then
  2658. for i=1,request_count do
  2659. msg = msg .. "\n" .. "request:" .. request_list[i-1]
  2660. end
  2661. end
  2662. if load_count > 0 then
  2663. for i=1,load_count do
  2664. msg = msg .. "\n" .. "load:" .. load_list[i-1]
  2665. end
  2666. end
  2667. if loading_count and loading_count > 0 then
  2668. for i=1,loading_count do
  2669. msg = msg .. "\n" .. "loading_list:" .. loading_list[i-1]
  2670. end
  2671. end
  2672. if hight_count and hight_count > 0 then
  2673. for i=1,hight_count do
  2674. msg = msg .. "\n" .. "hight_list:" .. hight_list[i-1]
  2675. end
  2676. end
  2677. if mid_count and mid_count > 0 then
  2678. for i=1,mid_count do
  2679. msg = msg .. "\n" .. "mid_list:" .. mid_list[i-1]
  2680. end
  2681. end
  2682. if low_count and low_count > 0 then
  2683. for i=1,low_count do
  2684. msg = msg .. "\n" .. "low_list:" .. low_list[i-1]
  2685. end
  2686. end
  2687. GameError.Instance:SendErrorToPHP(msg,LogType.Warning)
  2688. print(msg)
  2689. end
  2690. resMgr:PrintResourceLog(func)
  2691. end
  2692. --- nNum 源数字
  2693. --- n 小数位数
  2694. function GetPreciseDecimal(nNum, n)
  2695. if type(nNum) ~= "number" then
  2696. return nNum
  2697. end
  2698. n = n or 0;
  2699. n = math.floor(n)
  2700. if n < 0 then
  2701. n = 0
  2702. end
  2703. local nDecimal = 10 ^ n
  2704. local nTemp = math.floor(nNum * nDecimal);
  2705. local nRet = nTemp / nDecimal;
  2706. return nRet
  2707. end
  2708. function AttachGameRoot( transform )
  2709. if not G_GAMEROOT_TRANSFORM then
  2710. G_GAMEROOT_TRANSFORM = GameObject.Find("root").transform
  2711. end
  2712. transform:SetParent(G_GAMEROOT_TRANSFORM)
  2713. end
  2714. --传入{ vector3,vector3,...}
  2715. function ToVector3Array( table )
  2716. if AppConst.EnglineVer >= 74 then
  2717. return Util.ToVector3Array( table )
  2718. else
  2719. return nil
  2720. end
  2721. end
  2722. --传入{ vector2,vector2,...}
  2723. function ToVector2Array( table )
  2724. if AppConst.EnglineVer >= 74 then
  2725. return Util.ToVector2Array( table )
  2726. else
  2727. return nil
  2728. end
  2729. end
  2730. function GetPathFiles(path,pre, match_str)
  2731. if EnglineVersion and AppConst_EnglineVer >= 70 then
  2732. return FileTools.GetPathFiles(path,pre, match_str)
  2733. end
  2734. return {}
  2735. end
  2736. function OutPutValue(file_name, str)
  2737. if EnglineVersion and AppConst_EnglineVer >= 70 then
  2738. return FileTools.OutPutValue(file_name, str)
  2739. end
  2740. end
  2741. function CheckPathExists(path)
  2742. if EnglineVersion and AppConst.EnglineVer >= 70 then
  2743. return FileTools.CheckPathExists(path)
  2744. end
  2745. return false
  2746. end
  2747. function MatchCfg(path, pre, match_str, config)
  2748. if EnglineVersion and AppConst.EnglineVer >= 70 then
  2749. return FileTools.MatchCfg(path, pre, match_str, config)
  2750. end
  2751. return false
  2752. end
  2753. function ClearTrailRenderer(game_object)
  2754. if TrailRenderer and game_object and not IsNull(game_object) then
  2755. local com = game_object:GetComponentsInChildren(typeof(TrailRenderer),true)
  2756. if com.Length > 0 then
  2757. for i=1,com.Length do
  2758. com[i-1]:Clear()
  2759. end
  2760. end
  2761. end
  2762. end
  2763. function GetAssetBundleDependList(ab_name, callback)
  2764. if tonumber(AppConst.EnglineVer) < 81 then
  2765. Message.show("低版本引擎不支持该功能")
  2766. return
  2767. end
  2768. local func = function(state,objs)
  2769. if state and objs then
  2770. callback(objs)
  2771. else
  2772. callback(nil)
  2773. end
  2774. end
  2775. resMgr:GetDependResList(ab_name,func)
  2776. end
  2777. function ExportTerrainPreloadConfig()
  2778. local preload_res = {}
  2779. local function search_Dependencies(res,scene_id)
  2780. local function callback(objs)
  2781. if objs then
  2782. local len = objs.Length
  2783. for i = 1, len do
  2784. local str = objs[i-1]
  2785. local a,b = string.find(str, "/.*%.")
  2786. local name = string.sub(str,a+1,b-1)
  2787. if not preload_res[name] and not string.find(name,"shader") then
  2788. preload_res[name] = scene_id
  2789. end
  2790. end
  2791. end
  2792. end
  2793. GetAssetBundleDependList(res, callback)
  2794. end
  2795. local scene_list = Split(StepPackModule.PRELOAD_MAP_RES,",")
  2796. for _,scene_id in ipairs(scene_list) do
  2797. local name = "model"..scene_id
  2798. local config = Config[name]
  2799. if config then
  2800. for _, item in ipairs(config) do
  2801. local res = "terrain_prefab_"..item[1]
  2802. if not preload_res[res] then
  2803. preload_res[res] = scene_id
  2804. search_Dependencies(res,scene_id)
  2805. end
  2806. end
  2807. local data = ConfigItemMgr.Instance:GetSceneItem(scene_id)
  2808. if data then
  2809. local obj_cfg = nil
  2810. local res = nil
  2811. if data.Npcs then
  2812. for id, _ in pairs(data.Npcs) do
  2813. obj_cfg = ConfigItemMgr.Instance:GetNpcItem(id)
  2814. if obj_cfg and obj_cfg.icon > 0 then
  2815. res = "model_clothe_"..obj_cfg.icon
  2816. if not preload_res[res] then
  2817. preload_res[res] = scene_id
  2818. end
  2819. end
  2820. end
  2821. end
  2822. if data.mon then
  2823. for _, id in ipairs(data.mon) do
  2824. obj_cfg = ConfigItemMgr.Instance:GetMonsterDataItem(id)
  2825. if obj_cfg and obj_cfg.icon > 0 then
  2826. res = "model_clothe_"..obj_cfg.icon
  2827. if not preload_res[res] then
  2828. preload_res[res] = scene_id
  2829. end
  2830. end
  2831. end
  2832. end
  2833. else
  2834. LogError("场景DB文件缺失数据,id = " .. scene_id)
  2835. end
  2836. end
  2837. end
  2838. local preload_res_map = {}
  2839. local list_temp
  2840. for res, scene_id in pairs(preload_res) do
  2841. preload_res_map[scene_id] = preload_res_map[scene_id] or {}
  2842. list_temp = preload_res_map[scene_id]
  2843. list_temp[#list_temp+1] = res
  2844. end
  2845. local function sort_func(a,b)
  2846. return a < b
  2847. end
  2848. for scene_id, list in pairs(preload_res_map) do
  2849. table.sort(list, sort_func)
  2850. end
  2851. for _,scene_id in ipairs(scene_list) do
  2852. list_temp = preload_res_map[scene_id]
  2853. if list_temp then
  2854. table.insert(list_temp, 1, "terrain_scene_"..scene_id)
  2855. else
  2856. preload_res_map[scene_id] = {[1] = "terrain_scene_"..scene_id}
  2857. list_temp = preload_res_map[scene_id]
  2858. end
  2859. if Config.ConfigSceneEffect.EffectInfo[tonumber(scene_id)] then
  2860. local particle_name = scene_id .. "effect"
  2861. local file_path = AppConst.AppDataPath.."/StreamingAssets/rdata/" .. particle_name .. ".syrd"
  2862. local file = io.open(file_path, "rb")
  2863. if file then
  2864. table.insert(list_temp,particle_name)
  2865. else
  2866. print(file_path .. " is not exist")
  2867. end
  2868. end
  2869. end
  2870. local str = [[
  2871. --预加载的场景由策划配置,为新手200级使用的地图资源的顺序
  2872. --每个场景预加载配置承接上个场景,即上个场景出现的资源配置不需要在之后的场景配置中(上个场景配置了,就已经预加载了,不需要重复配置)
  2873. ]]
  2874. str = str.."Config.ConfigTerrainPreload = \n{\n"
  2875. for _, scene_id in ipairs(scene_list) do
  2876. local list = preload_res_map[scene_id]
  2877. if list then
  2878. str = str.." ["..scene_id.."] =\n {\n"
  2879. for i, res in ipairs(list) do
  2880. res = Util.GetBase64String(string.lower(res))
  2881. str = str.." ["..i.."] = "..[["]]..res..[["]]..",\n"
  2882. end
  2883. str = str.." },\n"
  2884. end
  2885. end
  2886. str = str.."}\n"
  2887. local fileName = AppConst.AppDataPath.."/Lua/config/client/ConfigTerrainPreload.lua"
  2888. local f = assert(io.open(fileName,'w'))
  2889. f:write(str)
  2890. f:close()
  2891. end
  2892. function SortTerrainShaderResUse()
  2893. local map_list = {1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,2001,2081,2102,2400,2500,3001,3100,3200,4001,4063,4064,4100,4200,4300,6100,7001,7100,7200}
  2894. local str
  2895. local shader_list = {}
  2896. local cache = {}
  2897. for index,map in pairs(map_list) do
  2898. local name = "model"..map
  2899. local config = Config[name]
  2900. if config then
  2901. for _, item in ipairs(config) do
  2902. local obj = item[1] .." " .. map
  2903. local shader = item[19]
  2904. if shader then
  2905. if not shader_list[shader] then
  2906. shader_list[shader] = {}
  2907. end
  2908. if not cache[obj] then
  2909. cache[obj] = true
  2910. table.insert(shader_list[shader],obj)
  2911. end
  2912. else
  2913. print("----------------shader is empty--------------",map,obj)
  2914. end
  2915. end
  2916. end
  2917. end
  2918. local str = "Config.ConfigTerrainShaderUse = \n{\n"
  2919. for shader, data in pairs(shader_list) do
  2920. str = str.." ["..[["]] .. shader .. [["]] .."] =\n {\n"
  2921. for i, res in ipairs(data) do
  2922. str = str.." ["..i.."] = "..[["]]..res..[["]]..",\n"
  2923. end
  2924. str = str.." },\n"
  2925. end
  2926. str = str.."}\n"
  2927. local fileName = AppConst.AppDataPath .."/Lua/config/client/ConfigTerrainShaderUse.lua"
  2928. local f = assert(io.open(fileName,'w'))
  2929. f:write(str)
  2930. f:close()
  2931. end
  2932. function SetSystemClipboard(value)
  2933. SDKUtil.CallSDKFunc("SystemData","Clipboard",{ data = tostring(value) })
  2934. end
  2935. function GetNoNewPlayerSmallMonster()
  2936. local mon = {}
  2937. for i=1000,9999 do
  2938. local data = ConfigItemMgr.Instance:GetSceneItem(i)
  2939. if data then
  2940. for _, id in ipairs(data.mon) do
  2941. local mon_cfg = ConfigItemMgr.Instance:GetMonsterDataItem(id)
  2942. if mon_cfg then
  2943. mon[mon_cfg.icon] = true
  2944. end
  2945. end
  2946. end
  2947. end
  2948. local data = ConfigItemMgr.Instance:GetSceneItem(1000)
  2949. if data then
  2950. for _, id in ipairs(data.mon) do
  2951. local mon_cfg = ConfigItemMgr.Instance:GetMonsterDataItem(id)
  2952. if mon_cfg then
  2953. mon[mon_cfg.icon] = nil
  2954. end
  2955. end
  2956. end
  2957. local sort_mon = {}
  2958. for i in pairs(mon) do
  2959. if i ~= nil then
  2960. table.insert(sort_mon, i)
  2961. end
  2962. end
  2963. table.sort(sort_mon, function(a,b) return (a < b) end)
  2964. for k,v in ipairs(sort_mon) do
  2965. print("------monster---------",v)
  2966. end
  2967. end
  2968. --输出定时器
  2969. function PrintTimerQuest()
  2970. local timer = GlobalTimerQuest
  2971. local str = ""
  2972. str = str.."timer_list:\n"
  2973. for i,vo in pairs(timer.timer_list) do
  2974. if vo.loop ~= 0 then
  2975. str = str.."TimerQuest:"..tostring(vo.source).."\n"
  2976. end
  2977. end
  2978. str = str.."\n\n"
  2979. str = str.."timer_list2:\n"
  2980. for i,vo in pairs(timer.timer_list2) do
  2981. if vo.loop ~= 0 then
  2982. str = str.."TimerQuest:"..tostring(vo.source).."\n"
  2983. end
  2984. end
  2985. str = str.."\n\n"
  2986. str = str.."timer_list3:\n"
  2987. for i,vo in pairs(timer.timer_list3) do
  2988. if vo.loop ~= 0 then
  2989. str = str.."TimerQuest:"..tostring(vo.source).."\n"
  2990. end
  2991. end
  2992. print(str)
  2993. local fileName = AppConst.AppDataPath.."/StreamingAssets/log/timer_quest.txt"
  2994. local f = assert(io.open(fileName,'w'))
  2995. f:write(str)
  2996. f:close()
  2997. end
  2998. --注册分帧执行器
  2999. function RegisterFraming(ref_tar,func_list,need_framing_load,interval,end_callback)
  3000. local func_len = #func_list
  3001. if not ref_tar or ref_tar._use_delete_method or func_len < 1 then
  3002. return
  3003. end
  3004. if ref_tar.framing_timer_id then
  3005. GlobalTimerQuest:CancelQuest(ref_tar.framing_timer_id)
  3006. ref_tar.framing_timer_id = nil
  3007. end
  3008. if need_framing_load == nil then
  3009. need_framing_load = true
  3010. end
  3011. if need_framing_load then
  3012. interval = interval or 0.01
  3013. local frame = 0
  3014. local function frame_func()
  3015. frame = frame + 1
  3016. local args = func_list[frame]
  3017. if type(args) == "function" then
  3018. args(ref_tar)
  3019. elseif type(args) == "table" then
  3020. if type(args[1]) == "function" then
  3021. args[1](ref_tar, unpack(args,2))
  3022. end
  3023. end
  3024. if func_len == frame then
  3025. if end_callback then
  3026. end_callback()
  3027. end
  3028. if ref_tar.framing_timer_id then
  3029. GlobalTimerQuest:CancelQuest(ref_tar.framing_timer_id)
  3030. ref_tar.framing_timer_id = nil
  3031. end
  3032. end
  3033. end
  3034. ref_tar.framing_timer_id = GlobalTimerQuest:AddPeriodQuest(frame_func, interval)
  3035. else
  3036. for _, args in ipairs(func_list) do
  3037. if type(args) == "function" then
  3038. args(ref_tar)
  3039. elseif type(args) == "table" then
  3040. if type(args[1]) == "function" then
  3041. args[1](ref_tar, unpack(args,2))
  3042. end
  3043. end
  3044. end
  3045. end
  3046. end
  3047. --界面销毁时取消分帧执行器
  3048. function UnregisterFraming(ref_tar)
  3049. if ref_tar.framing_timer_id then
  3050. GlobalTimerQuest:CancelQuest(ref_tar.framing_timer_id)
  3051. ref_tar.framing_timer_id = nil
  3052. end
  3053. end
  3054. function SetGoodsIcon(ref_tar, icon_img, type_id, setNativeSize, width, height, x, y)
  3055. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  3056. lua_resM:setOutsideImageSprite(ref_tar,icon_img,GameResPath.GetGoodsIcon(basic.goods_icon),setNativeSize)
  3057. if width and height then
  3058. SetSizeDelta(icon_img.transform, width, height)
  3059. end
  3060. if x and y then
  3061. SetAnchoredPosition(icon_img.transform, x, y)
  3062. end
  3063. end
  3064. function FindInScene(str)
  3065. local args = Split(str, "/")
  3066. if #args < 2 then
  3067. return GameObject.Find(str)
  3068. else
  3069. local root = GameObject.Find(args[1])
  3070. if root then
  3071. local len = string.len(args[1])+2
  3072. str = string.sub(str,len)
  3073. local child = root.transform:Find(str)
  3074. if child then
  3075. return child.gameObject
  3076. end
  3077. end
  3078. end
  3079. end
  3080. function SetFogStartDistance( value )
  3081. local render = UnityEngine.RenderSettings
  3082. if render then
  3083. render.fogStartDistance = value
  3084. end
  3085. end
  3086. function SetFogEndDistance( value )
  3087. local render = UnityEngine.RenderSettings
  3088. if render then
  3089. render.fogEndDistance = value
  3090. end
  3091. end
  3092. function SetGreenScreen(target)
  3093. local GreenImage = UiFactory.createChild(target,UIType.Image,"GreenImage")
  3094. local Image = GreenImage:GetComponent("Image")
  3095. Image.raycastTarget = false
  3096. Image.color = Color(0,1,0.13,1)
  3097. Image.sprite = nil
  3098. GreenImage:GetComponent("RectTransform").sizeDelta = Vector2(2000,1500)
  3099. end
  3100. -------------------------
  3101. --获取是否为百分比属性
  3102. function GetPropIsPercent( id )
  3103. id = id or 0
  3104. return (Config.ConfigItemAttr.Normal[id] and Config.ConfigItemAttr.Normal[id].is_percent) and id or false
  3105. end
  3106. function GetPropIsBasePercent( id )
  3107. id = id or 0
  3108. local tab = {
  3109. base_att = 1,
  3110. base_maxHp = 2,
  3111. base_def = 4,
  3112. base_hit = 5,
  3113. base_dodge = 6,
  3114. base_crit = 7,
  3115. base_ten = 8,
  3116. base_abs_att = 15,
  3117. base_abs_def = 16,
  3118. }
  3119. if (Config.ConfigItemAttr.Normal[id] and Config.ConfigItemAttr.Normal[id].base_per_add) then
  3120. return Config.ConfigItemAttr.Normal[id].base_per_add,tab[Config.ConfigItemAttr.Normal[id].base_per_add]
  3121. else
  3122. return false
  3123. end
  3124. end
  3125. --获取角色属性列表
  3126. function GetRolePropList( )
  3127. local mainVo = RoleManager.Instance.mainRoleInfo
  3128. return {
  3129. [1] = mainVo.att or 0,
  3130. [2] = mainVo.maxHp or 0,
  3131. [4] = mainVo.def or 0,
  3132. [5] = mainVo.hit or 0,
  3133. [6] = mainVo.dodge or 0,
  3134. [7] = mainVo.crit or 0,
  3135. [8] = mainVo.ten or 0,
  3136. [9] = mainVo.hurt_add_ratio or 0,
  3137. [10] = mainVo.hurt_del_ratio or 0,
  3138. [11] = mainVo.hit_ratio or 0,
  3139. [12] = mainVo.dodge_ratio or 0,
  3140. [13] = mainVo.crit_ratio or 0,
  3141. [14] = mainVo.uncrit_ratio or 0,
  3142. [15] = mainVo.abs_att or 0,
  3143. [16] = mainVo.abs_def or 0,
  3144. [19] = mainVo.att_add_ratio or 0,
  3145. [20] = mainVo.hp_add_ratio or 0,
  3146. [22] = mainVo.def_add_ratio or 0,
  3147. [23] = mainVo.hit_add_ratio or 0,
  3148. [24] = mainVo.dodge_add_ratio or 0,
  3149. [25] = mainVo.crit_add_ratio or 0,
  3150. [26] = mainVo.ten_add_ratio or 0,
  3151. [27] = mainVo.skill_hurt_add_ratio or 0,
  3152. [28] = mainVo.skill_hurt_del_ratio or 0,
  3153. [29] = mainVo.final_hurt_add_ratio or 0,
  3154. [30] = mainVo.final_hurt_del_ratio or 0,
  3155. [48] = mainVo.parry_ratio or 0,
  3156. [49] = mainVo.stab_ratio or 0,
  3157. [50] = mainVo.pvp_hurt_del_ratio or 0,
  3158. [51] = mainVo.pvp_hurt_add_ratio or 0,
  3159. [52] = mainVo.crit_hurt_add_ratio or 0,
  3160. [53] = mainVo.crit_hurt_del_ratio or 0,
  3161. [54] = mainVo.heart_ratio or 0,
  3162. [55] = mainVo.heart_add_hurt or 0,
  3163. [56] = mainVo.heart_resist_ratio or 0,
  3164. [57] = mainVo.heart_del_hurt or 0,
  3165. [95] = mainVo.suck_blood or 0,
  3166. [96] = mainVo.suck_blood_add or 0,
  3167. [97] = mainVo.suck_blood_minus or 0,
  3168. [98] = mainVo.boss_hurt_add_ratio or 0,
  3169. [99] = mainVo.boss_hurt_del_ratio or 0,
  3170. [100] = mainVo.mon_hurt_add_ratio or 0,
  3171. [101] = mainVo.mon_hurt_del_ratio or 0,
  3172. }
  3173. end
  3174. --获取百分比属性的实际使用加成
  3175. function GetPropPercentAdd( attr_id,attr_num )
  3176. attr_id = attr_id or 0
  3177. attr_num = attr_num or 0
  3178. if not GetPropIsPercent(attr_id) then
  3179. return 0
  3180. end
  3181. attr_num = attr_num or 0
  3182. return (1 + (5 * attr_num - 10000) / (2 * attr_num + 10000) ) * GetPropOneAddNum(attr_id) * 0.0002
  3183. end
  3184. --获得属性的加成系数
  3185. function GetPropOneAddNum( attr_id )
  3186. attr_id = attr_id or 0
  3187. local num = 0
  3188. if Config.ConfigItemAttr.Normal[attr_id] and Config.ConfigItemAttr.Normal[attr_id].add_num then
  3189. num = Config.ConfigItemAttr.Normal[attr_id].add_num
  3190. end
  3191. return num
  3192. end
  3193. --[[
  3194. is_have计算已有的属性战力,
  3195. Author:LZR
  3196. Description:,
  3197. parameters
  3198. list = {
  3199. [id] = { [1] = attr_id, [2] = attr_num },
  3200. }
  3201. list = {
  3202. [id] = { [1] = FuncId ,[2] = attr_id, [3] = attr_num }, id
  3203. }
  3204. ]]
  3205. function GetFighting( list,is_have )
  3206. list = list or {}
  3207. list = ComposeAttr(list)--合并属性
  3208. local cur_power = 0
  3209. local final_power = 0
  3210. -------------------------
  3211. --更改数据格式便于计算
  3212. local base_list = {}
  3213. for k,v in pairs(list) do
  3214. if #v == 3 then
  3215. base_list[tonumber(v[2])] = tonumber(v[3])
  3216. else
  3217. base_list[v[1]] = v[2]
  3218. end
  3219. end
  3220. -------------------------
  3221. local main_role = RoleManager.Instance.mainRoleInfo
  3222. if main_role then
  3223. -------------------------
  3224. --如果当前检查未获得的属性,包含了基础属性,那还要把那几个百分比基础加成加上去的参数补上
  3225. if not is_have then
  3226. local base_per_list = {[19] = true,[20] = true,[22] = true,[23] = true,[24] = true,[25] = true,26,[29] = true,[30] = true}
  3227. local base_add_id,match_id = 0, 0
  3228. local add_temp_num = 0
  3229. for k,v in pairs(base_per_list) do
  3230. base_add_id,match_id = GetPropIsBasePercent(k)
  3231. if base_add_id and base_list[match_id] then
  3232. --加成的这波属性,要算进基础属性百分比里面
  3233. add_temp_num = main_role[Config.ConfigItemAttr.Normal[k].tag] + (base_list[k] or 0)
  3234. base_list[match_id] = base_list[match_id] + math.floor( base_list[match_id] * add_temp_num/10000 )
  3235. end
  3236. end
  3237. end
  3238. -------------------------
  3239. --生成新旧属性表
  3240. local cur_prop_list = GetRolePropList()
  3241. local new_prop_list = DeepCopy(cur_prop_list)
  3242. for k,v in pairs(base_list) do
  3243. if new_prop_list[k] then
  3244. if is_have then
  3245. new_prop_list[k] = new_prop_list[k] - v
  3246. else
  3247. new_prop_list[k] = new_prop_list[k] + v
  3248. end
  3249. end
  3250. end
  3251. -------------------------
  3252. --百分比基础加成
  3253. for k,v in pairs(base_list) do
  3254. local base_add_id,match_id = GetPropIsBasePercent(k)
  3255. if base_add_id then
  3256. main_role[base_add_id] = main_role[base_add_id] or 1000
  3257. if is_have then
  3258. new_prop_list[match_id] = new_prop_list[match_id] - main_role[base_add_id]*(v / 10000)
  3259. else
  3260. new_prop_list[match_id] = new_prop_list[match_id] + main_role[base_add_id]*(v / 10000)
  3261. end
  3262. end
  3263. end
  3264. -------------------------
  3265. --罗列需要计算的属性id
  3266. local id_list = {
  3267. 1,2,4,5,6,7,8,15,16,9,10,11,12,13,14,27,28,48,49,50,51,52,53,54,55,56,57,
  3268. 95,96,97,98,99,100,101
  3269. }
  3270. -------------------------
  3271. --计算新旧战力
  3272. local PowerFactor_cur = 0
  3273. local PowerFactor_final = 0
  3274. for k,v in pairs(id_list) do
  3275. if GetPropIsPercent(v) then
  3276. PowerFactor_cur = PowerFactor_cur + GetPropPercentAdd(v,cur_prop_list[v])
  3277. PowerFactor_final = PowerFactor_final + GetPropPercentAdd(v,new_prop_list[v])
  3278. else
  3279. cur_power = cur_power + cur_prop_list[v] * GetPropOneAddNum( v )
  3280. final_power = final_power + new_prop_list[v] * GetPropOneAddNum( v )
  3281. end
  3282. end
  3283. cur_power = cur_power * (1 + PowerFactor_cur)
  3284. final_power = final_power * (1 + PowerFactor_final)
  3285. -------------------------
  3286. end
  3287. if is_have then
  3288. return math.floor(cur_power - final_power)
  3289. else
  3290. return math.floor(final_power - cur_power)
  3291. end
  3292. end
  3293. --判断模块是否开启
  3294. function GetModuleIsOpen( main_id,child_id,is_fade_show )
  3295. local _,conf = GetModuleOpenLevel(main_id,child_id)
  3296. if not conf or not RoleManager.Instance.mainRoleInfo then return end
  3297. -------------------------
  3298. local op_day,op_lv,op_task = 0,0,0
  3299. if is_fade_show and conf.icon_lv > 0 then
  3300. op_day = conf.icon_day
  3301. op_lv = conf.icon_lv
  3302. op_task = conf.icon_task or 0
  3303. else
  3304. op_day = conf.open_day
  3305. op_lv = conf.open_lv
  3306. op_task = conf.task_id or 0
  3307. end
  3308. -------------------------
  3309. local is_open = op_day == 0 or op_day <= ServerTimeModel:getInstance():GetOpenServerDay()--开服天数
  3310. is_open = is_open and MainUIModel:getInstance():GetFunOpenState(op_lv, op_task)--任务和等级
  3311. return is_open , conf
  3312. end
  3313. --获取开放等级, is_fade_show代表使用客户端的展示等级
  3314. function GetModuleOpenLevel( main_id,child_id,is_fade_show)
  3315. if not main_id then return end
  3316. child_id = child_id or 0
  3317. local base_conf = child_id == 0 and Config.Moduleid[main_id] or Config.Modulesub[main_id .. "@" .. child_id]
  3318. local open_lv = base_conf and base_conf.open_lv or 0
  3319. if is_fade_show and base_conf and base_conf.icon_lv > 0 then
  3320. return base_conf.icon_lv, base_conf
  3321. else
  3322. return open_lv, base_conf
  3323. end
  3324. end
  3325. --传入两属性,获得格式一样的属性
  3326. function GetAttrMatch( list_1,list_2,need_sort )
  3327. local data_1,data_2 = {},{}
  3328. list_1 = list_1 or {}
  3329. list_2 = list_2 or {}
  3330. for k,v in pairs(list_1) do
  3331. data_1[v[1]] = v[2]
  3332. end
  3333. for k,v in pairs(list_2) do
  3334. data_2[v[1]] = v[2]
  3335. end
  3336. -------------------------
  3337. for k,v in pairs(data_1) do
  3338. if not data_2[k] then
  3339. data_2[k] = 0
  3340. end
  3341. end
  3342. for k,v in pairs(data_2) do
  3343. if not data_1[k] then
  3344. data_1[k] = 0
  3345. end
  3346. end
  3347. -------------------------
  3348. local result_1,result_2 = {},{}
  3349. local index = 1
  3350. for k,v in pairs(data_1) do
  3351. result_1[index] = {k,v}
  3352. result_2[index] = {k,data_2[k]}
  3353. index = index + 1
  3354. end
  3355. -------------------------
  3356. if need_sort then
  3357. result_1 = SortAttrList(result_1)
  3358. result_2 = SortAttrList(result_2)
  3359. end
  3360. return result_1,result_2
  3361. end
  3362. --给属性列表排序,高级属性在前
  3363. function SortAttrList( list )
  3364. if not list then return {} end
  3365. local list_1 = {}
  3366. local list_2 = {}
  3367. for k,v in pairs(list) do
  3368. if WordManager:GetAttrIsSpecial(v[1]) then
  3369. table.insert( list_1, v )
  3370. else
  3371. table.insert( list_2, v )
  3372. end
  3373. end
  3374. local function sort_call( a,b )
  3375. return tonumber(a[1]) < tonumber(b[1])
  3376. end
  3377. if list_1[2] then
  3378. table.sort( list_1, sort_call )
  3379. end
  3380. if list_2[2] then
  3381. table.sort( list_2, sort_call )
  3382. end
  3383. for i,v in ipairs(list_2) do
  3384. table.insert( list_1, v )
  3385. end
  3386. return list_1
  3387. end
  3388. --通过condition获得关键值
  3389. function GetKeyValue( condition,key )
  3390. local value = nil
  3391. if condition then
  3392. for i,v in ipairs(condition) do
  3393. if v[1] and v[1] == key then
  3394. return v[2]
  3395. end
  3396. end
  3397. end
  3398. return value
  3399. end
  3400. --顺序表排序翻转
  3401. function StartToEnd(list)
  3402. if type(list) == "table" then
  3403. local len = #list
  3404. local new_list = {}
  3405. for i=1,len do
  3406. new_list[i] = list[len-i+1]
  3407. end
  3408. return new_list
  3409. end
  3410. end
  3411. -- 计算utf8字符串字符数, 各种中文算俩字符其他按一个字符计算
  3412. -- 为什么这么算呢 因为字号20的文本 在u3d里面
  3413. -- 例如utf8len("1你好") => 5 width = 5 *(20/2)
  3414. function utf8lenU3D(str)
  3415. local len = 0
  3416. local currentIndex = 1
  3417. while currentIndex <= #str do
  3418. local char = string.byte(str, currentIndex)
  3419. currentIndex = currentIndex + chsize(char)
  3420. if chsize(char) == 3 then
  3421. len = len + 2
  3422. else
  3423. len = len + 1
  3424. end
  3425. end
  3426. return len
  3427. end
  3428. --10进制数值转2进制 以table形式返回
  3429. --从左往右读
  3430. function TenbyteToTwobyte(num)
  3431. local num_table = {};
  3432. while num ~= 0 do
  3433. table.insert(num_table, math.fmod(num, 2));
  3434. num = math.floor(num/2)
  3435. end
  3436. return num_table
  3437. end
  3438. -- 属性图标根据颜色类型
  3439. function SetAttrIconByColorType(ref_tar, img_component, attr_id, force, color_type)
  3440. if not ref_tar or not img_component then return end
  3441. local color_list = {
  3442. [1] = "7d91ac",--暗淡的蓝色
  3443. [2] = "fdfdc9",--黄色
  3444. [3] = "ffffff",--白色
  3445. [4] = "a9c1e1",--浅蓝
  3446. }
  3447. img_component.color = ColorUtil:ConvertHexToRGBColor(color_list[color_type])
  3448. local a_name,b_name = GameResPath.GetAttrIcon(attr_id, force, 1)
  3449. lua_resM:setImageSprite(ref_tar, img_component, a_name, b_name, true)
  3450. end
  3451. function UrlEncode(s)
  3452. s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
  3453. return string.gsub(s, " ", "+")
  3454. end
  3455. function UrlDecode(s)
  3456. s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
  3457. return s
  3458. end
  3459. --货币单位
  3460. function GetPriceCompany( )
  3461. return ""
  3462. end
  3463. --合并两属性列表,结果会写入list_a
  3464. function CombineAttrList( list_a, list_b )
  3465. if not list_a or not list_b then return {} end
  3466. for kk,vv in pairs(list_b) do
  3467. local has_attr = false
  3468. for k,v in pairs(list_a) do
  3469. if v[1] == vv[1] then
  3470. v[2] = v[2]+vv[2]
  3471. has_attr = true
  3472. break
  3473. end
  3474. end
  3475. if not has_attr then
  3476. table.insert(list_a, vv)
  3477. end
  3478. end
  3479. return list_a
  3480. end
  3481. --获取属性差值,以attr_list2减去attr_list1的每个属性值,write_to_witch_list为1或2或nil,指定要把差值写入attr_list1还是attr_list2
  3482. function GetAttributeOffset( attr_list1, attr_list2, write_to_witch_list )
  3483. local result = {}
  3484. for k,v in pairs(attr_list2) do
  3485. local has_attr = false
  3486. for kk,vv in pairs(attr_list1) do
  3487. if v.index and v.index == vv.index then
  3488. result[v.index] = v.attr_value-vv.attr_value
  3489. has_attr = true
  3490. if write_to_witch_list then
  3491. if write_to_witch_list == 1 then
  3492. vv.add_attr = result[vv.index]
  3493. vv.add_attr_for_show = WordManager:GetPropertyValue(vv.index, vv.add_attr)
  3494. else
  3495. v.add_attr = result[v.index]
  3496. v.add_attr_for_show = WordManager:GetPropertyValue(v.index, v.add_attr)
  3497. end
  3498. end
  3499. break
  3500. elseif v[1] and v[1] == vv[1] then
  3501. --有些是用数组的,这里兼容下
  3502. result[v[1]] = v[2]-vv[2]
  3503. has_attr = true
  3504. if write_to_witch_list then
  3505. if write_to_witch_list == 1 then
  3506. vv.add_attr = result[vv[1]]
  3507. vv.add_attr_for_show = WordManager:GetPropertyValue(vv[1], vv.add_attr)
  3508. elseif write_to_witch_list == 2 then
  3509. v.add_attr = result[v[1]]
  3510. v.add_attr_for_show = WordManager:GetPropertyValue(v[1], v.add_attr)
  3511. end
  3512. end
  3513. break
  3514. end
  3515. end
  3516. if not has_attr then
  3517. --如果在列表1里没找到
  3518. if v.attr_value then
  3519. result[v.index] = v.attr_value
  3520. if write_to_witch_list then
  3521. if write_to_witch_list == 1 then
  3522. vv.add_attr = vv.attr_value
  3523. vv.add_attr_for_show = WordManager:GetPropertyValue(vv.index, vv.add_attr)
  3524. else
  3525. v.add_attr = v.attr_value
  3526. v.add_attr_for_show = WordManager:GetPropertyValue(v.index, v.add_attr)
  3527. end
  3528. end
  3529. elseif v[2] then
  3530. result[v[1]] = v[2]
  3531. if write_to_witch_list then
  3532. if write_to_witch_list == 1 then
  3533. vv.add_attr = vv[2]
  3534. vv.add_attr_for_show = WordManager:GetPropertyValue(vv[1], vv.add_attr)
  3535. else
  3536. v.add_attr = v[2]
  3537. v.add_attr_for_show = WordManager:GetPropertyValue(v[1], v.add_attr)
  3538. end
  3539. end
  3540. end
  3541. end
  3542. end
  3543. local new_attr_list = {}
  3544. for k,v in pairs(result) do
  3545. table.insert(new_attr_list, {k,v})
  3546. end
  3547. return new_attr_list
  3548. end
  3549. --上面那个放大有毒算不对 太菜了 计算两属性的差值attr_list2 - attr_list1
  3550. function GetAttributeOffset2( attr_list1, attr_list2 )
  3551. attr_list1 = ComposeAttr(attr_list1)
  3552. attr_list2 = ComposeAttr(attr_list2)
  3553. local new_list = {}
  3554. local is_find = false
  3555. for i,v in ipairs(attr_list2) do
  3556. is_find = false
  3557. for ii,vv in ipairs(attr_list1) do
  3558. if v[1] == vv[1] then
  3559. is_find = true
  3560. new_list[#new_list + 1] = {v[1],v[2]-vv[2] > 0 and v[2]-vv[2] or 0}
  3561. break
  3562. end
  3563. end
  3564. if not is_find then
  3565. new_list[#new_list + 1] = {v[1],v[2]}
  3566. end
  3567. end
  3568. return new_list
  3569. end
  3570. --合并相同属性值
  3571. function ComposeAttr( attr_list )
  3572. local com_list = {}--合并同样属性的战力值
  3573. for i,v in ipairs(attr_list) do
  3574. if not com_list[v[1]] then
  3575. com_list[v[1]] = {v[1],v[2]}
  3576. else
  3577. com_list[v[1]] = {v[1],v[2]+com_list[v[1]][2]}
  3578. end
  3579. end
  3580. local fight_attr_list = {}
  3581. for i,v in pairs(com_list) do
  3582. fight_attr_list[#fight_attr_list + 1] = v
  3583. end
  3584. return fight_attr_list
  3585. end
  3586. -- 根据字符长度限制文本展示内容,超过字符限制的内容就用...或addition_str代替
  3587. -- 例如: LimitTextByCharNum(玩家名称): 玩家名称
  3588. -- LimitTextByCharNum(玩家名称称): 玩家名称...
  3589. function LimitTextByCharNum(txt_str, len, sub_len, addition_str)
  3590. if not txt_str then return "" end
  3591. len = len or 4 -- 默认四个字符
  3592. sub_len = sub_len or len -- 截断位置,默认跟长度字符数相等
  3593. addition_str = addition_str or "..."
  3594. if utf8len(txt_str) > len then --
  3595. txt_str = SubStringUTF8(txt_str, 1, sub_len) .. addition_str
  3596. end
  3597. return txt_str
  3598. end
  3599. -- 转化角度
  3600. -- 类型1 将角度转化为 -180~180之间
  3601. function ClampAngleType1(angle)
  3602. if angle > 180 then
  3603. angle = angle - 360
  3604. elseif angle < -180 then
  3605. angle = angle + 360
  3606. end
  3607. return angle
  3608. end
  3609. -- 类型2 将角度转化为 0~360之间
  3610. function ClampAngleType2(angle)
  3611. if angle > 360 then
  3612. angle = angle - math.floor(angle / 360) * 360
  3613. elseif angle < 0 then
  3614. angle = angle + math.ceil(math.abs(angle) / 360) * 360
  3615. end
  3616. return angle
  3617. end
  3618. --设置七彩颜色字符串
  3619. function SetSevenColorStr( str )
  3620. str = str or ""
  3621. local new_str = ""
  3622. local len = #(string.gsub(str, "[\128-\191]", "")) -- 计算字符数(不是字节数)
  3623. if len > 0 then
  3624. local s = {}
  3625. local i = 1
  3626. for c in string.gmatch(str, ".[\128-\191]*" ) do -- 21.2 Pattern-Matching Functions
  3627. s[i]=c -- 21.7 Unicode
  3628. i=i+1
  3629. end
  3630. local color_index = 1
  3631. local max_color_list_len = #EquipModel.ColorList
  3632. for i,v in ipairs(s) do
  3633. new_str = new_str..HtmlColorTxt(v, EquipModel.ColorList[color_index])
  3634. color_index = color_index + 1
  3635. if color_index > max_color_list_len then
  3636. color_index = 1
  3637. end
  3638. end
  3639. end
  3640. return new_str
  3641. end
  3642. -- 随机打乱一个序列表的元素顺序
  3643. function RandomizeSequenceTableData(tb)
  3644. if not tb then return nil end
  3645. local ram_tb = {}
  3646. local len = #tb
  3647. for k = 1, len do
  3648. ram_tb[#ram_tb+1] = table.remove(tb, math.random(1, len - k + 1))
  3649. end
  3650. return ram_tb
  3651. end
  3652. -- 当有输入框然后又有字数限制的时候,要获取限制内的字符串就用这个方法,例:
  3653. -- new_str1 = abc啊啊啊 => abc啊啊啊
  3654. -- new_str2 = efgd啊啊啊 => efgd啊啊
  3655. -- new_str3 = ed啊啊aa啊啊 => ed啊啊aa(都是默认限制6位)
  3656. function GetInputLimitResultStr(str, limit)
  3657. limit = limit or 6
  3658. local len = #(string.gsub(str, "[\128-\191]", "")) -- 计算字符数(不是字节数)
  3659. local new_str = ""
  3660. local i = 0
  3661. if len > 0 then
  3662. for c in string.gmatch(str, ".[\128-\191]*" ) do -- 21.2 Pattern-Matching Functions
  3663. i = i + 1
  3664. new_str = new_str .. c
  3665. if i >= limit then
  3666. break
  3667. end
  3668. end
  3669. return new_str
  3670. end
  3671. return ""
  3672. end
  3673. function UrlEncode(s)
  3674. s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
  3675. return string.gsub(s, " ", "+")
  3676. end
  3677. function UrlDecode(s)
  3678. s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
  3679. return s
  3680. end
  3681. function ScreenShot( )
  3682. local name = "screenshot"..TimeUtil:getServerTime( )
  3683. local png_path = "phone/"..name..".png"
  3684. local save_path = Util.DataPath..png_path
  3685. if SystemRuntimePlatform.IsAndroid() then
  3686. local game_path = "luaFramework/"
  3687. save_path = game_path..png_path
  3688. end
  3689. if UnityEngine and UnityEngine.ScreenCapture then
  3690. UnityEngine.ScreenCapture.CaptureScreenshot(save_path)
  3691. end
  3692. local function on_delay( )
  3693. Message.show("截图成功:"..save_path)
  3694. end
  3695. setTimeout(on_delay, 1)
  3696. end