AIConfig.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using MongoDB.Bson.Serialization.Options;
  5. using System.ComponentModel;
  6. namespace ET
  7. {
  8. [Config]
  9. public partial class AIConfigCategory : Singleton<AIConfigCategory>, IMerge
  10. {
  11. [BsonElement]
  12. [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
  13. private Dictionary<int, AIConfig> dict = new();
  14. public void Merge(object o)
  15. {
  16. AIConfigCategory s = o as AIConfigCategory;
  17. foreach (var kv in s.dict)
  18. {
  19. this.dict.Add(kv.Key, kv.Value);
  20. }
  21. }
  22. public AIConfig Get(int id)
  23. {
  24. this.dict.TryGetValue(id, out AIConfig item);
  25. if (item == null)
  26. {
  27. throw new Exception($"配置找不到,配置表名: {nameof (AIConfig)},配置id: {id}");
  28. }
  29. return item;
  30. }
  31. public bool Contain(int id)
  32. {
  33. return this.dict.ContainsKey(id);
  34. }
  35. public Dictionary<int, AIConfig> GetAll()
  36. {
  37. return this.dict;
  38. }
  39. public AIConfig GetOne()
  40. {
  41. if (this.dict == null || this.dict.Count <= 0)
  42. {
  43. return null;
  44. }
  45. var enumerator = this.dict.Values.GetEnumerator();
  46. enumerator.MoveNext();
  47. return enumerator.Current;
  48. }
  49. }
  50. public partial class AIConfig: ProtoObject, IConfig
  51. {
  52. /// <summary>Id</summary>
  53. public int Id { get; set; }
  54. /// <summary>所属ai</summary>
  55. public int AIConfigId { get; set; }
  56. /// <summary>此ai中的顺序</summary>
  57. public int Order { get; set; }
  58. /// <summary>节点名字</summary>
  59. public string Name { get; set; }
  60. /// <summary>节点参数</summary>
  61. public int[] NodeParams { get; set; }
  62. }
  63. }