CharacterConfig.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 CharacterConfigCategory : ConfigSingleton<CharacterConfigCategory>, IMerge
  10. {
  11. [ProtoIgnore]
  12. [BsonIgnore]
  13. private Dictionary<int, CharacterConfig> dict = new Dictionary<int, CharacterConfig>();
  14. [BsonElement]
  15. [ProtoMember(1)]
  16. private List<CharacterConfig> list = new List<CharacterConfig>();
  17. public void Merge(object o)
  18. {
  19. CharacterConfigCategory s = o as CharacterConfigCategory;
  20. this.list.AddRange(s.list);
  21. }
  22. [ProtoAfterDeserialization]
  23. public void ProtoEndInit()
  24. {
  25. foreach (CharacterConfig 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 CharacterConfig Get(int id)
  34. {
  35. this.dict.TryGetValue(id, out CharacterConfig item);
  36. if (item == null)
  37. {
  38. throw new Exception($"配置找不到,配置表名: {nameof (CharacterConfig)},配置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, CharacterConfig> GetAll()
  47. {
  48. return this.dict;
  49. }
  50. public CharacterConfig 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 CharacterConfig: 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 ProName { get; set; }
  68. /// <summary>职业ID</summary>
  69. [ProtoMember(3)]
  70. public int Pro { get; set; }
  71. /// <summary>单位模板id</summary>
  72. [ProtoMember(4)]
  73. public int TemplateId { get; set; }
  74. /// <summary>等级上限</summary>
  75. [ProtoMember(5)]
  76. public int FinalLevel { get; set; }
  77. /// <summary>初始等级</summary>
  78. [ProtoMember(6)]
  79. public int InitLevel { get; set; }
  80. /// <summary>初始生命</summary>
  81. [ProtoMember(7)]
  82. public int InitMaxHP { get; set; }
  83. /// <summary>初始攻击</summary>
  84. [ProtoMember(8)]
  85. public int InitAttack { get; set; }
  86. /// <summary>基础攻速</summary>
  87. [ProtoMember(9)]
  88. public int BaseAtkSpeed { get; set; }
  89. /// <summary>基础移动速度</summary>
  90. [ProtoMember(10)]
  91. public int BaseMoveSpeed { get; set; }
  92. /// <summary>基础移速值</summary>
  93. [ProtoMember(11)]
  94. public string InitSpeed { get; set; }
  95. /// <summary>初始技能列表</summary>
  96. [ProtoMember(12)]
  97. public string InitSkill { get; set; }
  98. }
  99. }