StartSceneConfig.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Net;
  4. namespace ET
  5. {
  6. public partial class StartSceneConfigCategory
  7. {
  8. public MultiMap<int, StartSceneConfig> Gates = new MultiMap<int, StartSceneConfig>();
  9. public MultiMap<int, StartSceneConfig> ProcessScenes = new MultiMap<int, StartSceneConfig>();
  10. public Dictionary<long, Dictionary<string, StartSceneConfig>> ZoneScenesByName = new Dictionary<long, Dictionary<string, StartSceneConfig>>();
  11. public StartSceneConfig LocationConfig;
  12. public List<StartSceneConfig> Robots = new List<StartSceneConfig>();
  13. public List<StartSceneConfig> GetByProcess(int process)
  14. {
  15. return this.ProcessScenes[process];
  16. }
  17. public StartSceneConfig GetBySceneName(int zone, string name)
  18. {
  19. return this.ZoneScenesByName[zone][name];
  20. }
  21. public override void EndInit()
  22. {
  23. foreach (StartSceneConfig startSceneConfig in this.GetAll().Values)
  24. {
  25. this.ProcessScenes.Add(startSceneConfig.Process, startSceneConfig);
  26. if (!this.ZoneScenesByName.ContainsKey(startSceneConfig.Zone))
  27. {
  28. this.ZoneScenesByName.Add(startSceneConfig.Zone, new Dictionary<string, StartSceneConfig>());
  29. }
  30. this.ZoneScenesByName[startSceneConfig.Zone].Add(startSceneConfig.Name, startSceneConfig);
  31. switch (startSceneConfig.Type)
  32. {
  33. case SceneType.Gate:
  34. this.Gates.Add(startSceneConfig.Zone, startSceneConfig);
  35. break;
  36. case SceneType.Location:
  37. this.LocationConfig = startSceneConfig;
  38. break;
  39. case SceneType.Robot:
  40. this.Robots.Add(startSceneConfig);
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. public partial class StartSceneConfig: ISupportInitialize
  47. {
  48. public long InstanceId;
  49. public SceneType Type;
  50. public StartProcessConfig StartProcessConfig
  51. {
  52. get
  53. {
  54. return StartProcessConfigCategory.Instance.Get(this.Process);
  55. }
  56. }
  57. public StartZoneConfig StartZoneConfig
  58. {
  59. get
  60. {
  61. return StartZoneConfigCategory.Instance.Get(this.Zone);
  62. }
  63. }
  64. // 内网地址外网端口,通过防火墙映射端口过来
  65. private IPEndPoint innerIPOutPort;
  66. public IPEndPoint InnerIPOutPort
  67. {
  68. get
  69. {
  70. if (innerIPOutPort == null)
  71. {
  72. this.innerIPOutPort = NetworkHelper.ToIPEndPoint($"{this.StartProcessConfig.InnerIP}:{this.OuterPort}");
  73. }
  74. return this.innerIPOutPort;
  75. }
  76. }
  77. private IPEndPoint outerIPPort;
  78. // 外网地址外网端口
  79. public IPEndPoint OuterIPPort
  80. {
  81. get
  82. {
  83. if (this.outerIPPort == null)
  84. {
  85. this.outerIPPort = NetworkHelper.ToIPEndPoint($"{this.StartProcessConfig.OuterIP}:{this.OuterPort}");
  86. }
  87. return this.outerIPPort;
  88. }
  89. }
  90. public override void BeginInit()
  91. {
  92. }
  93. public override void EndInit()
  94. {
  95. this.Type = EnumHelper.FromString<SceneType>(this.SceneType);
  96. InstanceIdStruct instanceIdStruct = new InstanceIdStruct(this.Process, (uint) this.Id);
  97. this.InstanceId = instanceIdStruct.ToLong();
  98. }
  99. }
  100. }