using Thousandto.Cfg.Data; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using Thousandto.Plugins.Common; using UnityEngine.Gonbest.MagicCube; using Thousandto.Code.Center; namespace Thousandto.Code.Logic { /// /// 常用的工具类--这里集合一些通用的逻辑方法. /// public static class CommonUtils { public const int CN_DIANFENG_LEVEL = int.MaxValue; public static bool IsDFLevel(int level) { return level > CN_DIANFENG_LEVEL; } //获取巅峰等级 public static bool TryGetDFLevel(int level, out int outLevel) { if (level > CN_DIANFENG_LEVEL) { outLevel = level - CN_DIANFENG_LEVEL; return true; } outLevel = level; return false; } //获取等级描述 public static string GetLevelDesc(int level) { int outlevel; if (TryGetDFLevel(level, out outlevel)) { //return "巅峰" + outlevel.ToString(); return DeclareMessageString.Get(DeclareMessageString.C_TEXT_DIANFENG) + outlevel.ToString(); } else { return outlevel.ToString(); } } //获取玩家头像的图标名字 public static string GetPlayerHeaderSpriteName(int headId, int occ) { //var config = DeclareFashion.Get(headId); //if (config != null && config.Type == 2) //{ // return DeclareDataUtils.GetValueWithPrefix(occ, config.ResDecorate,"{0}#"); ; //} return string.Format("head_{0}", occ); } //获取玩家气泡的图标名字 public static string GetPlayerChatBgSpriteName(int chatBgid, int occ) { return "n_d_14"; } //获取等级的背景SpriteName public static string GetMainPlayerBgSpriteName(int level) { //if (IsDFLevel(level)) //{ // return "main_player_back_1"; //} //else { return "main_player_back"; } } //获取等级的背景SpriteName public static string GetLevelBgSpriteName(int level) { if (IsDFLevel(level)) { return "main_level_back_1"; } else { return "main_level_back"; } } public static string ConvertStr(string value) { string ret = value; if (value.Contains("[&]")) { int start = ret.IndexOf("[&]"); int end = 0; string str = value; string startStr = str.Substring(0, start); str = str.Substring(start); start = str.IndexOf("[&]"); str = str.Replace("[&]", ""); end = str.IndexOf("[/&]"); string replaceStr = str.Substring(0, end); string endStr = str.Substring(end + 4); replaceStr = Center.GameCenter.LanguageConvertSystem.ConvertLan(replaceStr); StringBuilder sb = new StringBuilder(); sb.Append(startStr); sb.Append(replaceStr); sb.Append(endStr); ret = sb.ToString(); if (ret.Contains("[&]")) { ret = ConvertStr(ret); } } return ret; } public static string ConvertParamStruct(int mark, string value) { string ret = null; //标记是 0 源值 1 是messageString中的ID值 2 数据表名字需要翻译 switch (mark) { case 0: ret = value; break; case 1: ret = DeclareMessageString.Get(int.Parse(value)); break; case 2: if (value.Contains("[&]")) { int start = value.IndexOf("[&]"); int end = 0; string str = value; string startStr = str.Substring(0, start); str = str.Substring(start); start = str.IndexOf("[&]"); str = str.Replace("[&]", ""); end = str.IndexOf("[/&]"); string replaceStr = str.Substring(0, end); string endStr = str.Substring(end + 4); replaceStr = Center.GameCenter.LanguageConvertSystem.ConvertLan(replaceStr); StringBuilder sb = new StringBuilder(); sb.Append(startStr); sb.Append(replaceStr); sb.Append(endStr); ret = sb.ToString(); } else { ret = Center.GameCenter.LanguageConvertSystem.ConvertLan(value); } break; case 3: //需要翻译跨服名字 var sid = int.Parse(value); if (GameCenter.LuaSystem.Adaptor.HasServer(sid)) { ret = string.Format("S{0}_{1}", GameCenter.LuaSystem.Adaptor.GetServerShowID(sid), GameCenter.LuaSystem.Adaptor.GetServerName(sid)); } break; } return ret; } public static Color ParseColor24(string text, int offset) { int r = (HexToDecimal(text[offset]) << 4) | HexToDecimal(text[offset + 1]); int g = (HexToDecimal(text[offset + 2]) << 4) | HexToDecimal(text[offset + 3]); int b = (HexToDecimal(text[offset + 4]) << 4) | HexToDecimal(text[offset + 5]); float f = 1f / 255f; return new Color(f * r, f * g, f * b); } public static int HexToDecimal(char ch) { switch (ch) { case '0': return 0x0; case '1': return 0x1; case '2': return 0x2; case '3': return 0x3; case '4': return 0x4; case '5': return 0x5; case '6': return 0x6; case '7': return 0x7; case '8': return 0x8; case '9': return 0x9; case 'a': case 'A': return 0xA; case 'b': case 'B': return 0xB; case 'c': case 'C': return 0xC; case 'd': case 'D': return 0xD; case 'e': case 'E': return 0xE; case 'f': case 'F': return 0xF; } return 0xF; } //数字转换大单位的文本 public static string CovertToBigUnit(double num, int validCount) { var singleNum = 1L; var danwei = string.Empty; switch (FLanguage.Default) { case "": case FLanguage.CH: if (num < 10000L) { singleNum = 1; } else if (num < 100000000) { danwei = "万"; singleNum = 10000; } else if (num < 1000000000000) { danwei = "亿"; singleNum = 100000000; } else { danwei = "万亿"; singleNum = 1000000000000; } break; default: if (num < 1000L) { singleNum = 1; } else if (num < 1000000L) { danwei = "K"; singleNum = 1000; } else if (num < 1000000000L) { danwei = "M"; singleNum = 1000000; } else { danwei = "B"; singleNum = 1000000000; } break; } if (validCount > 2) { num /= singleNum; if (string.IsNullOrEmpty(danwei)) { return num.ToString(); } else { if (num % 1 == 0) { //无小数 return string.Format("{0}{1}", num, danwei); } else { if (num >= Math.Pow(10, validCount - 1)) { //不留小数位 return string.Format("{0}{1}", (long)num, danwei); } else if (num >= Math.Pow(10, validCount - 2)) { //留一位小数 return string.Format("{0:F1}{1}", num, danwei); } else { //有小数 return string.Format("{0:F2}{1}", num, danwei); } } } } else { if (string.IsNullOrEmpty(danwei)) { return num.ToString(); } else { if (num % singleNum == 0) { //无小数 return string.Format("{0}{1}", num / singleNum, danwei); } else { //有小数 return string.Format("{0:F2}{1}", num / singleNum, danwei); } } } } } }