Auxiliary.cs 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. using LitJson;
  2. using MiniJSON;
  3. using ScottGarland;
  4. using DragonBones;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using UnityEngine.Events;
  8. using UnityEngine.Advertisements;
  9. using System;
  10. using System.IO;
  11. using System.Xml;
  12. using System.Linq;
  13. using System.Net.Mail;
  14. using System.Net;
  15. using System.Text;
  16. using System.Collections;
  17. using System.Diagnostics;
  18. using System.Collections.Generic;
  19. using System.Security.Cryptography;
  20. using System.Runtime.Serialization.Formatters.Binary;
  21. using System.Security;
  22. using System.Text.RegularExpressions;
  23. using System.Security.Cryptography.Xml;
  24. using Debug = UnityEngine.Debug;
  25. using Random = UnityEngine.Random;
  26. using Transform = UnityEngine.Transform;
  27. public enum Unit
  28. {
  29. Second
  30. }
  31. public class Amount
  32. {
  33. public static double 百 = 100;
  34. public static double 千 = 1000;
  35. public static double 万 = 10000;
  36. public static double 十万 = 100000;
  37. public static double 百万 = 1000000;
  38. public static double 千万 = 10000000;
  39. public static double 亿 = 100000000;
  40. public static double 十亿 = 1000000000;
  41. public static double 千亿 = 100000000000;
  42. public static double 兆 = 1000000000000;
  43. public static double 千兆 = 1000000000000000;
  44. public static double 京 = 10000000000000000;
  45. public static double 千京 = 10000000000000000000;
  46. public static BigInteger 垓 = new BigInteger("100000000000000000000");
  47. public static BigInteger 千垓 = new BigInteger("100000000000000000000000");
  48. }
  49. public class Auxiliary : Regist
  50. {
  51. #region 变量
  52. public string String1;
  53. public string String2;
  54. public TextAsset TextAsset;
  55. public Texture2D Texture;
  56. public Font Font;
  57. public GameObject Go;
  58. public List<GameObject> GoList;
  59. public List<SpriteRenderer> SrList;
  60. public static bool AnyKeyUp;
  61. public static bool AnyKeyDown;
  62. public static Auxiliary Instance;
  63. public static MD5 MD5
  64. {
  65. get
  66. {
  67. if (_MD5 == null)
  68. {
  69. _MD5 = new MD5CryptoServiceProvider();
  70. }
  71. return _MD5;
  72. }
  73. set { _MD5 = value; }
  74. }
  75. public static DESCryptoServiceProvider Des
  76. {
  77. get
  78. {
  79. if (_Des == null)
  80. {
  81. _Des = new DESCryptoServiceProvider();
  82. _Des.IV = Encoding.UTF8.GetBytes("19283740");
  83. _Des.Key = Encoding.UTF8.GetBytes("93287123");
  84. }
  85. return _Des;
  86. }
  87. set { _Des = value; }
  88. }
  89. private static MD5 _MD5;
  90. private static DESCryptoServiceProvider _Des;
  91. #endregion
  92. public override bool RegistImmed()
  93. {
  94. if (base.RegistImmed())
  95. {
  96. return true;
  97. }
  98. enabled = true;
  99. return false;
  100. }
  101. private void Awake()
  102. {
  103. Instance = this;
  104. }
  105. private void Update()
  106. {
  107. #region 调试
  108. if (Input.GetKeyDown(KeyCode.Escape))
  109. {
  110. ManaServer.GetProductID
  111. (
  112. "com.dashgame.garden.packone",
  113. data =>
  114. {
  115. Debug.Log(data);
  116. //AliplayManager.Instance.Pay(data, str);
  117. }
  118. );
  119. }
  120. if (Input.GetKeyDown(KeyCode.M))
  121. {
  122. ManaTutorial.EnterD1();
  123. }
  124. if (Input.GetKeyDown(KeyCode.N))
  125. {
  126. //ManaCenter.Coin = 0;
  127. //ManaCenter.Diamond = 0;
  128. //foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  129. //{
  130. // VARIABLE.Value.Unlock = true;
  131. //}
  132. //foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  133. //{
  134. // VARIABLE.Value.Unlock = false;
  135. //}
  136. //ManaGarden.FlowerInfoDic.First().Value.Unlock = true;
  137. }
  138. if (Input.GetKeyDown(KeyCode.B))
  139. {
  140. foreach (var VARIABLE in ManaPlayer.CloseUnitDic)
  141. {
  142. VARIABLE.Value.Unlock();
  143. }
  144. }
  145. if (Input.GetKeyDown(KeyCode.Z))
  146. {
  147. ManaCenter.MiniTimer = 0;
  148. }
  149. if (Input.GetKeyDown(KeyCode.X))
  150. {
  151. ManaMiniGame.GameTimer = 45;
  152. //Lottery.TempTypeList = new List<int>();
  153. //Lottery.TempValueList = new List<int>();
  154. //Lottery.TempLotteryList = new List<Lottery>();
  155. //Lottery.EnterAnimation();
  156. //ManaReso.Get("Bc_LotteryItem1").TweenForEuler();
  157. //ManaReso.Get("Bc_LotteryItem2").TweenForEuler();
  158. //ManaReso.Get("Bc_LotteryItem3").TweenForEuler();
  159. }
  160. if (Input.GetKeyDown(KeyCode.C))
  161. {
  162. ManaMiniGame.Score = 1000;
  163. ManaSign.SignTime = new DateTime(2007, 1, 1);
  164. }
  165. if (Input.GetKeyDown(KeyCode.V))
  166. {
  167. ManaServer.MailReward mailReward = new ManaServer.MailReward("1", "pack", "4");
  168. ManaServer.MailReward mailReward1 = new ManaServer.MailReward("1", "close", "2");
  169. ManaServer.GetMainReward(mailReward);
  170. ManaServer.GetMainReward(mailReward1);
  171. ManaGarden.ElfTimer = 0;
  172. //ManaServer.Time = new DateTime(2007,1,1);
  173. }
  174. //if (Input.GetKeyDown(KeyCode.P))
  175. //{
  176. // ManaData.Level += 20;
  177. //}
  178. if (Input.GetKeyDown(KeyCode.O))
  179. {
  180. for (int i = 0; i < ManaCenter.CoolList.Count; i++)
  181. {
  182. ManaCenter.CoolList[i].CoolTimer = 0;
  183. }
  184. }
  185. //if (Input.GetKeyDown(KeyCode.I))
  186. //{
  187. // ManaCenter.Coin += 1000;
  188. // ManaCenter.Diamond += 1000;
  189. //}
  190. //if (Input.GetKeyDown(KeyCode.U))
  191. //{
  192. // Data.SavePlayerConfig();
  193. // Data.SaveXml();
  194. //}
  195. //if (Input.GetKeyDown(KeyCode.Y))
  196. //{
  197. // Data.ResetPlayerConfig();
  198. // Data.SaveXml();
  199. //}
  200. //if (Input.GetKeyDown(KeyCode.T))
  201. //{
  202. // ManaData.Pause = !ManaData.Pause;
  203. //}
  204. #endregion
  205. #region 输入检测
  206. if (Input.GetKeyDown(KeyCode.Escape))
  207. {
  208. ManaMiniGame.Pause = true;
  209. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, () => { ManaMiniGame.Pause = false; });
  210. }
  211. if (AnyKeyUp)
  212. {
  213. if (Input.anyKey == false)
  214. {
  215. AnyKeyUp = false;
  216. }
  217. }
  218. if (Input.anyKeyDown)
  219. {
  220. AnyKeyDown = true;
  221. }
  222. if (AnyKeyDown)
  223. {
  224. if (Input.anyKey == false)
  225. {
  226. AnyKeyUp = true;
  227. AnyKeyDown = false;
  228. }
  229. }
  230. #endregion
  231. }
  232. private static void ResetAllCd()
  233. {
  234. for (int i = 0; i < ManaCenter.CoolList.Count; i++)
  235. {
  236. ManaCenter.CoolList[i].CoolTimer = 0;
  237. }
  238. }
  239. public static byte[] GetMD5(object obj)
  240. {
  241. MemoryStream memoryStream = new MemoryStream();
  242. BinaryFormatter binaryFormatter = new BinaryFormatter();
  243. binaryFormatter.Serialize(memoryStream, obj);
  244. byte[] bytes = memoryStream.GetBuffer();
  245. memoryStream.Dispose();
  246. return MD5.ComputeHash(bytes);
  247. }
  248. public static void EncryptXml(XmlDocument doc)
  249. {
  250. EncryptedXml encryptedXml = new EncryptedXml();
  251. XmlElement xmlElement = doc.DocumentElement;
  252. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  253. EncryptedData encryptedData = new EncryptedData();
  254. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  255. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  256. encryptedData.CipherData.CipherValue = bytes;
  257. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  258. }
  259. public static void DecryptXml(XmlDocument doc)
  260. {
  261. EncryptedXml encryptedXml = new EncryptedXml();
  262. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  263. EncryptedData encryptedData = new EncryptedData();
  264. encryptedData.LoadXml(encryptXmlElement);
  265. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  266. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  267. }
  268. public static byte[] Encrypt(string str)
  269. {
  270. byte[] bytes = Encoding.UTF8.GetBytes(str);
  271. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  272. return encryptBytes;
  273. }
  274. public static byte[] ToBytes(string str)
  275. {
  276. string[] strings = str.Split(' ');
  277. byte[] bytes = new byte[strings.Length];
  278. for (int i = 0; i < bytes.Length; i++)
  279. {
  280. bytes[i] = byte.Parse(strings[i]);
  281. }
  282. return bytes;
  283. }
  284. public static string Decrypt(string str)
  285. {
  286. byte[] encryptBytes = ToBytes(str);
  287. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  288. return Encoding.UTF8.GetString(decryptBytes);
  289. }
  290. public static string ToString(byte[] bytes)
  291. {
  292. StringBuilder strB = new StringBuilder();
  293. for (int i = 0; i < bytes.Length; i++)
  294. {
  295. if (i == bytes.Length - 1)
  296. {
  297. strB.Append(bytes[i]);
  298. }
  299. else
  300. {
  301. strB.Append(bytes[i] + " ");
  302. }
  303. }
  304. return strB.ToString();
  305. }
  306. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic, bool enableIgnore = true)
  307. {
  308. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  309. for (int i = 0; i < transforms.Length; i++)
  310. {
  311. if (enableIgnore)
  312. {
  313. if (transforms[i].GetComponent<IgnoreIndexing>())
  314. {
  315. continue;
  316. }
  317. }
  318. if (dic.ContainsKey(transforms[i].name))
  319. {
  320. throw new Exception(transforms[i].name);
  321. }
  322. else
  323. {
  324. dic.Add(transforms[i].name, transforms[i]);
  325. }
  326. }
  327. }
  328. public static string GetUnit(int value, Unit unit)
  329. {
  330. if (unit == Unit.Second)
  331. {
  332. if (ManaLan.CurrentLan == Lan.English)
  333. {
  334. if (value == 0 || value == 1)
  335. {
  336. return " Second";
  337. }
  338. else
  339. {
  340. return " Seconds";
  341. }
  342. }
  343. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  344. {
  345. return "秒";
  346. }
  347. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  348. {
  349. return "秒";
  350. }
  351. else
  352. {
  353. throw new Exception();
  354. }
  355. }
  356. else
  357. {
  358. throw new Exception();
  359. }
  360. }
  361. public static string GetStreamPath()
  362. {
  363. if (Application.isEditor)
  364. {
  365. return "file://" + Application.streamingAssetsPath;
  366. }
  367. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  368. {
  369. return "file://" + Application.streamingAssetsPath;
  370. }
  371. else if (Application.isMobilePlatform)
  372. {
  373. return Application.streamingAssetsPath;
  374. }
  375. else
  376. {
  377. throw new Exception();
  378. }
  379. }
  380. public Coroutine DelayCall(UnityAction function, int frame)
  381. {
  382. return StartCoroutine(IDelayCall(function, frame));
  383. }
  384. public Coroutine DelayCall(UnityAction function, float time)
  385. {
  386. return StartCoroutine(IDelayCall(function, time));
  387. }
  388. public static IEnumerator IDelayCall(UnityAction function, int frame)
  389. {
  390. int count = 0;
  391. while (count < frame)
  392. {
  393. count++;
  394. yield return null;
  395. }
  396. function.Invoke();
  397. }
  398. public static IEnumerator IDelayCall(UnityAction function, float time)
  399. {
  400. yield return new WaitForSeconds(time);
  401. function.Invoke();
  402. }
  403. public static string FmlParse1(string str)
  404. {
  405. int index = 0;
  406. int openIndex = 0;
  407. bool flag = false;
  408. bool group = false;
  409. for (int i = 0; i < str.Length; i++)
  410. {
  411. if (group)
  412. {
  413. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  414. {
  415. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  416. i = 0;
  417. group = false;
  418. }
  419. else if (i == str.Length - 1)
  420. {
  421. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  422. break;
  423. }
  424. }
  425. else
  426. {
  427. if (str[i] == '+' || str[i] == '-')
  428. {
  429. flag = true;
  430. openIndex = i + 1;
  431. }
  432. else if (str[i] == '*' || str[i] == '/')
  433. {
  434. index = i;
  435. group = true;
  436. if (!flag)
  437. {
  438. openIndex = 0;
  439. }
  440. }
  441. }
  442. }
  443. group = false;
  444. for (int i = 0; i < str.Length; i++)
  445. {
  446. if (group)
  447. {
  448. if (str[i] == '+' || str[i] == '-')
  449. {
  450. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  451. i = -1;
  452. group = false;
  453. }
  454. else if (i == str.Length - 1)
  455. {
  456. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  457. }
  458. }
  459. else
  460. {
  461. if (str[i] == '+' || str[i] == '-')
  462. {
  463. index = i;
  464. group = true;
  465. }
  466. }
  467. }
  468. return str;
  469. }
  470. public static string FmlParse2(char op, string str1, string str2)
  471. {
  472. double var1 = double.Parse(str1);
  473. double var2 = double.Parse(str2);
  474. if (op == '+')
  475. {
  476. return (var1 + var2).ToString();
  477. }
  478. else if (op == '-')
  479. {
  480. return (var1 - var2).ToString();
  481. }
  482. else if (op == '*')
  483. {
  484. return (var1 * var2).ToString();
  485. }
  486. else if (op == '/')
  487. {
  488. return (var1 / var2).ToString();
  489. }
  490. else
  491. {
  492. throw new Exception(op.ToString());
  493. }
  494. }
  495. public static double FmlParse(string str, params string[] strings)
  496. {
  497. for (int i = 0; i < strings.Length; i += 2)
  498. {
  499. if (str.Contains(strings[i]))
  500. {
  501. str = str.Replace(strings[i], strings[i + 1]);
  502. }
  503. else
  504. {
  505. //Debug.Log("No such var " + strings[i + 1]);
  506. }
  507. }
  508. int openIndex = 0;
  509. for (int i = 0; i < str.Length; i++)
  510. {
  511. if (str[i] == '(')
  512. {
  513. openIndex = i;
  514. }
  515. else if (str[i] == ')')
  516. {
  517. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  518. i = -1;
  519. }
  520. }
  521. return double.Parse(FmlParse1(str));
  522. }
  523. public static string OmitNumberStr(int accuray, string str)
  524. {
  525. int index = str.IndexOf('.');
  526. if (index == -1)
  527. {
  528. return str;
  529. }
  530. if (accuray == 0)
  531. {
  532. return str.Substring(0, index);
  533. }
  534. else
  535. {
  536. for (int i = index + 1; i < index + accuray + 1; i++)
  537. {
  538. if (str[i] != '0')
  539. {
  540. return str.Substring(0, index + accuray + 1);
  541. }
  542. }
  543. return str.Substring(0, index);
  544. }
  545. }
  546. public static double ShrinkNumber(double value, int accuracy = 1)
  547. {
  548. if (ManaLan.CurrentLan == Lan.English)
  549. {
  550. if (value < Amount.千)
  551. {
  552. return value;
  553. }
  554. else if (value < Amount.百万)
  555. {
  556. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  557. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千;
  558. }
  559. else if (value < Amount.十亿)
  560. {
  561. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  562. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.百万;
  563. }
  564. else if (value < Amount.兆)
  565. {
  566. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  567. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.十亿;
  568. }
  569. else if (value < Amount.千兆)
  570. {
  571. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  572. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  573. }
  574. else
  575. {
  576. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  577. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  578. }
  579. }
  580. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  581. {
  582. if (value < Amount.万)
  583. {
  584. return value;
  585. }
  586. else if (value < Amount.千万)
  587. {
  588. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  589. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.万;
  590. }
  591. else if (value < Amount.亿)
  592. {
  593. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  594. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千万;
  595. }
  596. else if (value < Amount.千亿)
  597. {
  598. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  599. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.亿;
  600. }
  601. else if (value < Amount.兆)
  602. {
  603. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  604. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千亿;
  605. }
  606. else if (value < Amount.千兆)
  607. {
  608. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  609. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  610. }
  611. else if (value < Amount.京)
  612. {
  613. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  614. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  615. }
  616. else if (value < Amount.千京)
  617. {
  618. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  619. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.京;
  620. }
  621. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  622. {
  623. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  624. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千京;
  625. }
  626. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  627. {
  628. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  629. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10;
  630. }
  631. else
  632. {
  633. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  634. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10000;
  635. }
  636. }
  637. else
  638. {
  639. throw new Exception();
  640. }
  641. }
  642. public static string ShrinkNumberStr(double value, int accuracy = 1)
  643. {
  644. if (ManaLan.CurrentLan == Lan.English)
  645. {
  646. if (value < Amount.千)
  647. {
  648. return value.ToString("0");
  649. }
  650. else if (value < Amount.百万)
  651. {
  652. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  653. return OmitNumberStr(accuracy, str) + "K";
  654. }
  655. else if (value < Amount.十亿)
  656. {
  657. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  658. return OmitNumberStr(accuracy, str) + "M";
  659. }
  660. else if (value < Amount.兆)
  661. {
  662. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  663. return OmitNumberStr(accuracy, str) + "B";
  664. }
  665. else if (value < Amount.千兆)
  666. {
  667. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  668. return OmitNumberStr(accuracy, str) + "T";
  669. }
  670. else
  671. {
  672. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  673. return OmitNumberStr(accuracy, str) + "T";
  674. }
  675. }
  676. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  677. {
  678. if (value < Amount.万)
  679. {
  680. return value.ToString("0");
  681. }
  682. else if (value < Amount.千万)
  683. {
  684. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  685. return OmitNumberStr(accuracy, str) + "万";
  686. }
  687. else if (value < Amount.亿)
  688. {
  689. string str = (value/Amount.千万).ToString("F" + (accuracy + 1));
  690. return OmitNumberStr(accuracy, str) + "千万";
  691. }
  692. else if (value < Amount.千亿)
  693. {
  694. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  695. return OmitNumberStr(accuracy, str) + "亿";
  696. }
  697. else if (value < Amount.兆)
  698. {
  699. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  700. return OmitNumberStr(accuracy, str) + "千亿";
  701. }
  702. else if (value < Amount.千兆)
  703. {
  704. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  705. return OmitNumberStr(accuracy, str) + "兆";
  706. }
  707. else if (value < Amount.京)
  708. {
  709. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  710. return OmitNumberStr(accuracy, str) + "千兆";
  711. }
  712. else if (value < Amount.千京)
  713. {
  714. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  715. return OmitNumberStr(accuracy, str) + "京";
  716. }
  717. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  718. {
  719. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  720. return OmitNumberStr(accuracy, str) + "千京";
  721. }
  722. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  723. {
  724. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  725. return OmitNumberStr(0, str) + "垓";
  726. }
  727. else
  728. {
  729. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  730. return OmitNumberStr(0, str) + "千垓";
  731. }
  732. }
  733. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  734. {
  735. if (value < Amount.万)
  736. {
  737. return value.ToString("0");
  738. }
  739. else if (value < Amount.千万)
  740. {
  741. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  742. return OmitNumberStr(accuracy, str) + "萬";
  743. }
  744. else if (value < Amount.亿)
  745. {
  746. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  747. return OmitNumberStr(accuracy, str) + "千萬";
  748. }
  749. else if (value < Amount.千亿)
  750. {
  751. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  752. return OmitNumberStr(accuracy, str) + "億";
  753. }
  754. else if (value < Amount.兆)
  755. {
  756. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  757. return OmitNumberStr(accuracy, str) + "千億";
  758. }
  759. else if (value < Amount.千兆)
  760. {
  761. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  762. return OmitNumberStr(accuracy, str) + "兆";
  763. }
  764. else if (value < Amount.京)
  765. {
  766. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  767. return OmitNumberStr(accuracy, str) + "千兆";
  768. }
  769. else if (value < Amount.千京)
  770. {
  771. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  772. return OmitNumberStr(accuracy, str) + "京";
  773. }
  774. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  775. {
  776. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  777. return OmitNumberStr(accuracy, str) + "千京";
  778. }
  779. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  780. {
  781. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  782. return OmitNumberStr(0, str) + "垓";
  783. }
  784. else
  785. {
  786. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  787. return OmitNumberStr(0, str) + "千垓";
  788. }
  789. }
  790. else
  791. {
  792. throw new Exception();
  793. }
  794. }
  795. public static string ImageParse(Current current)
  796. {
  797. if (current == Current.Coin)
  798. {
  799. return "<(金币)>";
  800. }
  801. else if (current == Current.Diamond)
  802. {
  803. return "<(钻石)>";
  804. }
  805. else if (current == Current.Cash)
  806. {
  807. return Language.GetStr("Common", "Cash");
  808. }
  809. else
  810. {
  811. throw new Exception(current.ToString());
  812. }
  813. }
  814. public static Current CurrentParse(string str)
  815. {
  816. if (string.IsNullOrEmpty(str))
  817. {
  818. return Current.Free;
  819. }
  820. else
  821. {
  822. int number = int.Parse(str);
  823. if (number == 1)
  824. {
  825. return Current.Coin;
  826. }
  827. else if (number == 2)
  828. {
  829. return Current.Diamond;
  830. }
  831. else if (number == 3)
  832. {
  833. return Current.Cash;
  834. }
  835. else if (number == 4)
  836. {
  837. return Current.Other;
  838. }
  839. else if (number == 5)
  840. {
  841. return Current.AD;
  842. }
  843. else
  844. {
  845. throw new Exception(number.ToString());
  846. }
  847. }
  848. }
  849. public static int IntParse(string str, int defaultValue)
  850. {
  851. if (string.IsNullOrEmpty(str))
  852. {
  853. return defaultValue;
  854. }
  855. else
  856. {
  857. return int.Parse(str);
  858. }
  859. }
  860. public static long LongParse(string str, long defaultValue)
  861. {
  862. if (string.IsNullOrEmpty(str))
  863. {
  864. return defaultValue;
  865. }
  866. else
  867. {
  868. return long.Parse(str);
  869. }
  870. }
  871. public static bool BoolParse(string str, bool defaultValue)
  872. {
  873. if (string.IsNullOrEmpty(str))
  874. {
  875. return defaultValue;
  876. }
  877. else
  878. {
  879. return Convert.ToBoolean(int.Parse(str));
  880. }
  881. }
  882. public static float FloatParse(string str, float defaultValue)
  883. {
  884. if (string.IsNullOrEmpty(str))
  885. {
  886. return defaultValue;
  887. }
  888. else
  889. {
  890. return float.Parse(str);
  891. }
  892. }
  893. public static double DoubleParse(string str, double defaultValue)
  894. {
  895. if (string.IsNullOrEmpty(str))
  896. {
  897. return defaultValue;
  898. }
  899. else
  900. {
  901. return float.Parse(str);
  902. }
  903. }
  904. public static Vector3 VectorParse(char cah, string str, Vector3 defaultValue)
  905. {
  906. if (string.IsNullOrEmpty(str))
  907. {
  908. return defaultValue;
  909. }
  910. else
  911. {
  912. string[] strings = str.Split(',');
  913. if (strings.Length == 2)
  914. {
  915. Vector2 result = new Vector2();
  916. result.x = float.Parse(strings[0]);
  917. result.y = float.Parse(strings[1]);
  918. return result;
  919. }
  920. else if (strings.Length == 3)
  921. {
  922. Vector3 result = new Vector3();
  923. result.x = float.Parse(strings[0]);
  924. result.y = float.Parse(strings[1]);
  925. result.z = float.Parse(strings[2]);
  926. return result;
  927. }
  928. else
  929. {
  930. throw new Exception();
  931. }
  932. }
  933. }
  934. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  935. {
  936. if (string.IsNullOrEmpty(str))
  937. {
  938. return defaultValue;
  939. }
  940. else
  941. {
  942. string[] strings = str.Split(cah);
  943. List<int> list = new List<int>();
  944. for (int i = 0; i < strings.Length; i++)
  945. {
  946. list.Add(int.Parse(strings[i]));
  947. }
  948. return list;
  949. }
  950. }
  951. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  952. {
  953. if (string.IsNullOrEmpty(str))
  954. {
  955. return defaultValue;
  956. }
  957. else
  958. {
  959. string[] strings = str.Split(cah);
  960. List<string> list = new List<string>();
  961. for (int i = 0; i < strings.Length; i++)
  962. {
  963. list.Add(strings[i]);
  964. }
  965. return list;
  966. }
  967. }
  968. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  969. {
  970. if (string.IsNullOrEmpty(str))
  971. {
  972. return defaultValue;
  973. }
  974. else
  975. {
  976. string[] strings = str.Split(cah);
  977. List<double> list = new List<double>();
  978. for (int i = 0; i < strings.Length; i++)
  979. {
  980. list.Add(double.Parse(strings[i]));
  981. }
  982. return list;
  983. }
  984. }
  985. }