RPGClientTemplateManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using DeepCore;
  6. using DeepCore.Log;
  7. using DeepMMO.Data;
  8. namespace DeepMMO.Client
  9. {
  10. public abstract class RPGClientTemplateManager
  11. {
  12. #region Singleton
  13. private static RPGClientTemplateManager s_instance;
  14. public static RPGClientTemplateManager Instance { get { return s_instance; } }
  15. protected RPGClientTemplateManager()
  16. {
  17. s_instance = this;
  18. log = LoggerFactory.GetLogger(GetType().Name);
  19. }
  20. #endregion
  21. protected readonly Logger log;
  22. //--------------------------------------------------------------------------------------
  23. #region Roles
  24. public abstract RoleTemplateData[] AllRoleTemplates { get; }
  25. public abstract RoleTemplateData GetRoleTemplate(int id, byte gender);
  26. #endregion
  27. //--------------------------------------------------------------------------------------
  28. #region ServerList
  29. private HashMap<string, ServerInfo> serverList = new HashMap<string, ServerInfo>();
  30. private HashMap<string, List<ServerInfo>> groupList = new HashMap<string, List<ServerInfo>>();
  31. private List<ServerInfo> recommendServers = new List<ServerInfo>();
  32. public virtual void LoadServerList(string serverListPath)
  33. {
  34. serverList.Clear();
  35. groupList.Clear();
  36. recommendServers.Clear();
  37. try
  38. {
  39. log.Info("Load Server From : " + serverListPath);
  40. ServerInfo.LoadServerList(serverListPath, serverList, groupList, recommendServers);
  41. }
  42. catch (Exception err)
  43. {
  44. throw new Exception("Load Server List Error From : " + serverListPath, err);
  45. }
  46. }
  47. public virtual ServerInfo GetServer(string serverID)
  48. {
  49. if (serverList.TryGetValue(serverID, out var info))
  50. {
  51. return info;
  52. }
  53. return null;
  54. }
  55. public virtual string GetServerGroupID(string serverID)
  56. {
  57. if (serverList.TryGetValue(serverID, out var info))
  58. {
  59. return info.group;
  60. }
  61. return serverID;
  62. }
  63. /// <summary>
  64. ///组对应的服务器ID.
  65. /// </summary>
  66. /// <param name="serverGroupID"></param>
  67. /// <returns></returns>
  68. public virtual List<ServerInfo> GetServers(string serverGroupID)
  69. {
  70. if (groupList.TryGetValue(serverGroupID, out var list))
  71. {
  72. return new List<ServerInfo>(list);
  73. }
  74. return null;
  75. }
  76. public virtual List<ServerInfo> GetRecommendServers()
  77. {
  78. return new List<ServerInfo>(recommendServers);
  79. }
  80. ///
  81. /// </summary>
  82. /// <param name="serverID"></param>
  83. /// <returns></returns>
  84. public virtual bool ServerIsOpen(string serverID)
  85. {
  86. if (serverList.TryGetValue(serverID, out var info))
  87. {
  88. return info.is_open;
  89. }
  90. return false;
  91. }
  92. /// <summary>
  93. /// 获取所有服务器配置
  94. /// </summary>
  95. /// <returns></returns>
  96. public virtual List<ServerInfo> GetAllServers()
  97. {
  98. return new List<ServerInfo>(serverList.Values);
  99. }
  100. #endregion
  101. //--------------------------------------------------------------------------------------
  102. }
  103. }