|
|
@@ -1,112 +0,0 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-
|
|
|
-namespace ET.Server
|
|
|
-{
|
|
|
- public static partial class RobotCaseSystem
|
|
|
- {
|
|
|
- [EntitySystem]
|
|
|
- private static void Destroy(this RobotCase self)
|
|
|
- {
|
|
|
- Fiber root = self.Fiber();
|
|
|
- if (root.Id == 0)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 创建机器人,生命周期是RobotCase
|
|
|
- public static async ETTask NewRobot(this RobotCase self, int count, List<Scene> scenes)
|
|
|
- {
|
|
|
- ETTask[] tasks = new ETTask[count];
|
|
|
- for (int i = 0; i < count; ++i)
|
|
|
- {
|
|
|
- tasks[i] = self.NewRobot(scenes);
|
|
|
- }
|
|
|
-
|
|
|
- await ETTaskHelper.WaitAll(tasks);
|
|
|
- }
|
|
|
-
|
|
|
- private static async ETTask NewRobot(this RobotCase self, List<Scene> scenes)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- scenes.Add(await self.NewRobot());
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Log.Error(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 创建机器人,生命周期是RobotCase
|
|
|
- public static async ETTask NewZoneRobot(this RobotCase self, int zone, int count, List<Scene> scenes)
|
|
|
- {
|
|
|
- ETTask[] tasks = new ETTask[count];
|
|
|
- for (int i = 0; i < count; ++i)
|
|
|
- {
|
|
|
- tasks[i] = self.NewZoneRobot(zone + i, scenes);
|
|
|
- }
|
|
|
-
|
|
|
- await ETTaskHelper.WaitAll(tasks);
|
|
|
- }
|
|
|
-
|
|
|
- // 这个方法创建的是进程所属的机器人,建议使用RobotCase.NewRobot来创建
|
|
|
- private static async ETTask NewZoneRobot(this RobotCase self, int zone, List<Scene> scenes)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- scenes.Add(await self.NewRobot(zone));
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Log.Error(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static async ETTask<Scene> NewRobot(this RobotCase self, int zone)
|
|
|
- {
|
|
|
- return await self.NewRobot(zone, $"Robot_{zone}");
|
|
|
- }
|
|
|
-
|
|
|
- public static async ETTask<Scene> NewRobot(this RobotCase self, int zone, string name)
|
|
|
- {
|
|
|
- Scene clientScene = null;
|
|
|
- try
|
|
|
- {
|
|
|
- clientScene = await Client.SceneFactory.CreateClientFiber(self.Fiber(), zone, SceneType.Robot, name);
|
|
|
- await Client.LoginHelper.Login(self.Fiber(), zone.ToString(), zone.ToString());
|
|
|
- await Client.EnterMapHelper.EnterMapAsync(self.Fiber());
|
|
|
- Log.Debug($"create robot ok: {zone}");
|
|
|
- self.Scenes.Add(clientScene.Id);
|
|
|
- return clientScene;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- clientScene?.Dispose();
|
|
|
- throw new Exception($"RobotCase create robot fail, zone: {zone}", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static async ETTask<Scene> NewRobot(this RobotCase self)
|
|
|
- {
|
|
|
- int zone = self.GetParent<RobotCaseComponent>().GetN();
|
|
|
- Scene clientScene = null;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- clientScene = await Client.SceneFactory.CreateClientFiber(self.Fiber(), zone, SceneType.Robot, $"Robot_{zone}");
|
|
|
- await Client.LoginHelper.Login(self.Fiber(), zone.ToString(), zone.ToString());
|
|
|
- await Client.EnterMapHelper.EnterMapAsync(self.Fiber());
|
|
|
- Log.Debug($"create robot ok: {zone}");
|
|
|
- self.Scenes.Add(clientScene.Id);
|
|
|
- return clientScene;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- clientScene?.Dispose();
|
|
|
- throw new Exception($"RobotCase create robot fail, zone: {zone}", e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|