ItemNotices.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using Client.MirScenes;
  2. using Mir3Library;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace Client
  11. {
  12. public class ItemNotices
  13. {
  14. public static List<ItemNotice> Notices;
  15. static string fileName;
  16. public static List<ItemNotice> EnableNotices;
  17. public static void Init()
  18. {
  19. fileName = @".\Data\ItemNotices_" +GameScene.User.Name+".json";
  20. if (!File.Exists(fileName))
  21. {
  22. fileName = @".\Data\ItemNotices.json";
  23. }
  24. string json = File.ReadAllText(fileName);
  25. Notices = JsonConvert.DeserializeObject<List<ItemNotice>>(json);
  26. if (fileName!= @".\Data\ItemNotices.json")
  27. {
  28. json= File.ReadAllText(@".\Data\ItemNotices.json");
  29. var n= JsonConvert.DeserializeObject<List<ItemNotice>>(json);
  30. foreach (var item in n)
  31. {
  32. if (!Notices.Any(t=>t.Index==item.Index))
  33. {
  34. Notices.Add(item);
  35. }
  36. }
  37. }
  38. EnableNotices= Notices.Where(t=>t.Enable).ToList();
  39. }
  40. public static void Save()
  41. {
  42. File.WriteAllText(@".\Data\ItemNotices_" + GameScene.User.Name + ".json", JsonConvert.SerializeObject(Notices));
  43. }
  44. public static void AddNotice(ItemNotice notice)
  45. {
  46. Notices.Add(notice);
  47. }
  48. public static void ConfigInit()
  49. {
  50. Notices = new List<ItemNotice>();
  51. string ItemStrList = File.ReadAllText(@".\物品汇总.csv");
  52. foreach (var itemStr in ItemStrList.Split('\n'))
  53. {
  54. itemStr.Replace("\r", "");
  55. var strs = itemStr.Split(',');
  56. int id;
  57. try
  58. {
  59. id = int.Parse(strs[0]);
  60. }
  61. catch (Exception)
  62. {
  63. continue;
  64. }
  65. string name = strs[1];
  66. var notice = new ItemNotice()
  67. {
  68. Index = id,
  69. Name = name,
  70. Type = int.Parse(strs[2]),
  71. Grade = int.Parse(strs[3]),
  72. };
  73. if (mir3lib.FindItemName(name))
  74. {
  75. notice.Enable = true;
  76. notice.Grade4 = true;
  77. notice.IsNotice = true;
  78. }
  79. else
  80. {
  81. if (notice.Grade == 4)
  82. {
  83. notice.Grade4 = true;
  84. }
  85. else if (notice.Grade == 3)
  86. {
  87. notice.Grade3 = true;
  88. }
  89. }
  90. Notices.Add(notice);
  91. }
  92. File.WriteAllText(@".\Data\ItemNotices.json", JsonConvert.SerializeObject(Notices));
  93. }
  94. }
  95. public class ItemNotice
  96. {
  97. public bool Enable { get; set; }
  98. public int Index { get; set; }
  99. public string Name { get; set; }
  100. //是否极品
  101. public bool Grade4 { get; set; }
  102. //是否高级
  103. public bool Grade3 { get; set; }
  104. //是否提醒
  105. public bool IsNotice { get; set; }
  106. //是否自动捡取
  107. public bool IsAutoPickUp { get; set; } = true;
  108. //是否显示名字
  109. public bool IsShowName { get; set; } = true;
  110. public int Type { get; set; }
  111. public int Grade { get; set; }
  112. }
  113. }