ItemIdConfig.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using ProtoBuf;
  5. namespace ET
  6. {
  7. [ProtoContract]
  8. [Config]
  9. public partial class ItemIdConfigCategory : ConfigSingleton<ItemIdConfigCategory>, IMerge
  10. {
  11. [ProtoIgnore]
  12. [BsonIgnore]
  13. private Dictionary<int, ItemIdConfig> dict = new Dictionary<int, ItemIdConfig>();
  14. [BsonElement]
  15. [ProtoMember(1)]
  16. private List<ItemIdConfig> list = new List<ItemIdConfig>();
  17. public void Merge(object o)
  18. {
  19. ItemIdConfigCategory s = o as ItemIdConfigCategory;
  20. this.list.AddRange(s.list);
  21. }
  22. [ProtoAfterDeserialization]
  23. public void ProtoEndInit()
  24. {
  25. foreach (ItemIdConfig config in list)
  26. {
  27. config.AfterEndInit();
  28. this.dict.Add(config.Id, config);
  29. }
  30. this.list.Clear();
  31. this.AfterEndInit();
  32. }
  33. public ItemIdConfig Get(int id)
  34. {
  35. this.dict.TryGetValue(id, out ItemIdConfig item);
  36. if (item == null)
  37. {
  38. throw new Exception($"配置找不到,配置表名: {nameof (ItemIdConfig)},配置id: {id}");
  39. }
  40. return item;
  41. }
  42. public bool Contain(int id)
  43. {
  44. return this.dict.ContainsKey(id);
  45. }
  46. public Dictionary<int, ItemIdConfig> GetAll()
  47. {
  48. return this.dict;
  49. }
  50. public ItemIdConfig GetOne()
  51. {
  52. if (this.dict == null || this.dict.Count <= 0)
  53. {
  54. return null;
  55. }
  56. return this.dict.Values.GetEnumerator().Current;
  57. }
  58. }
  59. [ProtoContract]
  60. public partial class ItemIdConfig: ProtoObject, IConfig
  61. {
  62. /// <summary>Id</summary>
  63. [ProtoMember(1)]
  64. public int Id { get; set; }
  65. /// <summary>物品类型名称</summary>
  66. [ProtoMember(2)]
  67. public string TypeName { get; set; }
  68. /// <summary>tips显示绑定</summary>
  69. [ProtoMember(3)]
  70. public int ShowBind { get; set; }
  71. /// <summary>排序</summary>
  72. [ProtoMember(4)]
  73. public int Order { get; set; }
  74. /// <summary>次级排序规则</summary>
  75. [ProtoMember(5)]
  76. public string OrderRule { get; set; }
  77. }
  78. }