Пример #1
0
 public static void Clear(this RobotManagerComponent self)
 {
     foreach (Entity entity in self.Children.Values.ToArray())
     {
         entity.Dispose();
     }
 }
Пример #2
0
 public static void RemoveAll(this RobotManagerComponent self)
 {
     foreach (Entity robot in self.Children.Values.ToArray())
     {
         robot.Dispose();
     }
 }
Пример #3
0
        public async ETTask Run(ModeContex contex, string content)
        {
            switch (content)
            {
            case ConsoleMode.CreateRobot:
                Log.Console("CreateRobot args error!");
                break;

            default:
                CreateRobotArgs options = null;
                Parser.Default.ParseArguments <CreateRobotArgs>(content.Split(' '))
                .WithNotParsed(error => throw new Exception($"CreateRobotArgs error!"))
                .WithParsed(o => { options = o; });

                // 获取当前进程的RobotScene
                using (ListComponent <StartSceneConfig> thisProcessRobotScenes = ListComponent <StartSceneConfig> .Create())
                {
                    List <StartSceneConfig> robotSceneConfigs = StartSceneConfigCategory.Instance.Robots;
                    foreach (StartSceneConfig robotSceneConfig in robotSceneConfigs)
                    {
                        if (robotSceneConfig.Process != Game.Options.Process)
                        {
                            continue;
                        }
                        thisProcessRobotScenes.Add(robotSceneConfig);
                    }

                    // 创建机器人
                    for (int i = 0; i < options.Num; ++i)
                    {
                        int index = i % thisProcessRobotScenes.Count;
                        StartSceneConfig      robotSceneConfig      = thisProcessRobotScenes[index];
                        Scene                 robotScene            = Game.Scene.Get(robotSceneConfig.Id);
                        RobotManagerComponent robotManagerComponent = robotScene.GetComponent <RobotManagerComponent>();
                        Scene                 robot = await robotManagerComponent.NewRobot(Game.Options.Process * 10000 + i);

                        robot.AddComponent <AIComponent, int>(1);
                        Log.Console($"create robot {robot.Zone}");
                        await TimerComponent.Instance.WaitAsync(2000);
                    }
                }
                break;
            }
            contex.Parent.RemoveComponent <ModeContex>();
            await ETTask.CompletedTask;
        }
Пример #4
0
        public static async ETTask <Scene> NewRobot(this RobotManagerComponent self, int zone)
        {
            Scene zoneScene = null;

            try
            {
                zoneScene = SceneFactory.CreateZoneScene(zone, "Robot", self);
                await LoginHelper.Login(zoneScene, ConstValue.LoginAddress, zone.ToString(), zone.ToString());

                await EnterMapHelper.EnterMapAsync(zoneScene);

                Log.Debug($"create robot ok: {zone}");
                return(zoneScene);
            }
            catch (Exception e)
            {
                zoneScene?.Dispose();
                throw new Exception($"RobotSceneManagerComponent create robot fail, zone: {zone}", e);
            }
        }
Пример #5
0
 public static void Remove(this RobotManagerComponent self, long id)
 {
     self.GetChild <Scene>(id)?.Dispose();
 }