BattleUtils.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.ZoneEditor;
  3. using CommonAIServer.Node;
  4. using CommonLang;
  5. using CommonLang.Log;
  6. using CommonLang.Reflection;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace CommonRPG.Server.Battle
  13. {
  14. public static class BattleUtils
  15. {
  16. public static ZoneNodeFactory ZoneServerFactory { get; private set; }
  17. public static InstanceZoneFactory ZoneFactory { get; private set; }
  18. public static ZoneNodeConfig NodeConfig { get; private set; }
  19. public static EditorTemplates DataRoot { get; private set; }
  20. public static void Init(Logger log, Properties config)
  21. {
  22. if (ZoneFactory == null)
  23. {
  24. log.Info("********************************************************");
  25. log.Info("# 初始化战斗编辑器扩展 ");
  26. log.Info("********************************************************");
  27. ZoneFactory = ReflectionUtil.CreateInterface<InstanceZoneFactory>(config["ZoneFactory"]);
  28. TemplateManager.SetFactory(ZoneFactory);
  29. ZoneServerFactory = ReflectionUtil.CreateInterface<ZoneNodeFactory>(config["ZoneServerFactory"]);
  30. log.Info(" 战斗编辑器插件 : " + ZoneFactory);
  31. log.Info(" 战斗服务器插件 : " + ZoneServerFactory);
  32. }
  33. if (NodeConfig == null)
  34. {
  35. log.Info("********************************************************");
  36. log.Info("# 加载配置文件");
  37. log.Info("********************************************************");
  38. NodeConfig = ZoneServerFactory.GetConfig();
  39. var node_cfg = config.SubProperties("ZoneNodeConfig.");
  40. if (node_cfg != null)
  41. {
  42. node_cfg.LoadFields(NodeConfig);
  43. }
  44. }
  45. if (DataRoot == null)
  46. {
  47. log.Info("********************************************************");
  48. log.Info("# 加载模板数据");
  49. log.Info("********************************************************");
  50. try
  51. {
  52. DataRoot = TemplateManager.Factory.CreateEditorTemplates(config["DataRootPath"]);
  53. DataRoot.LoadAllTemplates();
  54. DataRoot.CacheAllScenes();
  55. }
  56. catch (Exception err)
  57. {
  58. throw new Exception("EditorTemplates init error : " + err.Message + "\n" + err.StackTrace, err);
  59. }
  60. log.Info("********************************************************");
  61. }
  62. }
  63. }
  64. }