FormTestClient.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.ZoneEditor;
  3. using CommonAIClient.Client;
  4. using CommonLang;
  5. using CommonLang.Protocol;
  6. using GameEditorPlugin.Win32.BattleClient;
  7. using GameEditorPlugin.Win32.Runtime;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using XmdsServerNode.Node;
  16. using XmdsServerNode.Node.Interface;
  17. using XmdsServerTest.Server;
  18. using CommonAI.ZoneServer;
  19. using CommonAIServer.Connector;
  20. using CommonLang.Concurrent;
  21. using XmdsCommonServer.Message;
  22. namespace XmdsServerTest
  23. {
  24. public class FormTestClient : GameEditorPluginServer.Client.FormTestClient
  25. {
  26. private static AtomicInteger uuid_gen = new AtomicInteger(1);
  27. public static FormLauncher StartWinForm(int unit_template_id, byte force, string roomID, int scendID, bool autoLaunch = false)
  28. {
  29. ClientLoader loader = new ClientLoader();
  30. FormLauncher.Templates = ZoneNodeManager.Templates;
  31. var client = new FormLauncher(
  32. ZoneNodeManager.NodeConfig.GAME_DATA_ROOT_PATH,
  33. "test_" + uuid_gen.IncrementAndGet(), // player_uuid
  34. roomID.ToString(), // room_id
  35. typeof(CommonNetwork.Sockets.NetSession).FullName,
  36. NodeTestServer.Instance.ClientConnectString,
  37. ZoneNodeManager.NodeConfig.GAME_UPDATE_INTERVAL_MS, // update interval
  38. ZoneNodeManager.NodeConfig.CLIENT_SYNC_OBJECT_IN_RANGE, // sync range
  39. unit_template_id,
  40. force,
  41. scendID,
  42. loader, false, autoLaunch);
  43. client.OnLaunchOver += Client_OnLaunchOver;
  44. client.Show();
  45. return client;
  46. }
  47. private static bool Client_OnLaunchOver(FormLauncher launcher)
  48. {
  49. var enter = launcher.Loader.GenUnitInfoR2B(launcher.UnitTemplateID);
  50. enter.Force = launcher.Force;
  51. var ret = new FormTestClient();
  52. ret.Init(
  53. launcher.PlayerUUID,
  54. launcher.RoomID,
  55. launcher.ConnectString,
  56. launcher.NetDirver,
  57. enter);
  58. ret.Shown += (sender, e) => { launcher.Visible = false; };
  59. ret.FormClosed += (sender, e) => { launcher.Visible = true; };
  60. launcher.Disposed += (sender, e) => { };
  61. ret.Show();
  62. return true;
  63. }
  64. private class ClientLoader : TestClientLoader
  65. {
  66. public override CommonAI.ZoneServer.CreateUnitInfoR2B GenUnitInfoR2B(int unitID)
  67. {
  68. CommonAI.ZoneServer.CreateUnitInfoR2B ret = new CommonAI.ZoneServer.CreateUnitInfoR2B();
  69. ret.UnitTemplateID = unitID;
  70. return ret;
  71. }
  72. public override Type ZoneFactoryType
  73. {
  74. get { return typeof(XmdsCommon.Plugin.XmdsZoneFactory); }
  75. }
  76. }
  77. public void Init(string playerUUID, string roomID, string connectString, string netDriver, CreateUnitInfoR2B enter)
  78. {
  79. base.Init(ZoneNodeManager.NodeConfig, playerUUID, roomID, connectString, netDriver, enter);
  80. base.BattlePanel.OnPanelLoaded += BattlePanel_OnPanelLoaded;
  81. }
  82. private void BattlePanel_OnPanelLoaded()
  83. {
  84. base.BattlePanel.BattleClient.Layer.ActorAdded += Layer_ActorAdded;
  85. }
  86. private void Layer_ActorAdded(CommonAI.ZoneClient.ZoneLayer layer, CommonAI.ZoneClient.ZoneActor actor)
  87. {
  88. //actor.SendAction(new MarkForTestBotAction());
  89. }
  90. }
  91. }