Ejemplo n.º 1
0
        public async ETTask Run(ModeContex contex, string content)
        {
            switch (content)
            {
            case ConsoleMode.ReloadConfig:
                contex.Parent.RemoveComponent <ModeContex>();
                Log.Console("C must have config name, like: C UnitConfig");
                break;

            default:
                string[] ss         = content.Split(" ");
                string   configName = ss[1];
                string   category   = $"{configName}Category";
                Type     type       = Game.EventSystem.GetType($"ET.{category}");
                if (type == null)
                {
                    Log.Console($"reload config but not find {category}");
                    return;
                }
                ConfigComponent.Instance.LoadOneConfig(type);
                Log.Console($"reload config {configName} finish!");
                break;
            }

            await ETTask.CompletedTask;
        }
Ejemplo n.º 2
0
        public async ETTask Run(ModeContex contex, string content)
        {
            string[] ss = content.Split(" ");
            switch (ss[0])
            {
            case ConsoleMode.Robot:
                break;

            case "Run":
            {
                int caseType = int.Parse(ss[1]);

                try
                {
                    RobotLog.Debug($"run case start: {caseType}");
                    await RobotCaseDispatcherComponent.Instance.Run(caseType, content);

                    RobotLog.Debug($"run case finish: {caseType}");
                }
                catch (Exception e)
                {
                    RobotLog.Debug($"run case error: {caseType}\n{e}");
                }
                break;
            }

            case "RunAll":
            {
                FieldInfo[] fieldInfos = typeof(RobotCaseType).GetFields();
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    int caseType = (int)fieldInfo.GetValue(null);
                    if (caseType > RobotCaseType.MaxCaseType)
                    {
                        RobotLog.Debug($"case > {RobotCaseType.MaxCaseType}: {caseType}");
                        break;
                    }
                    try
                    {
                        RobotLog.Debug($"run case start: {caseType}");
                        await RobotCaseDispatcherComponent.Instance.Run(caseType, content);

                        RobotLog.Debug($"---------run case finish: {caseType}");
                    }
                    catch (Exception e)
                    {
                        RobotLog.Debug($"run case error: {caseType}\n{e}");
                        break;
                    }
                }
                break;
            }
            }
            await ETTask.CompletedTask;
        }
Ejemplo n.º 3
0
        public static async ETTask Start(this ConsoleComponent self)
        {
            self.CancellationTokenSource = new CancellationTokenSource();

            while (true)
            {
                try
                {
                    ModeContex modeContex = self.GetComponent <ModeContex>();
                    string     line       = await Task.Factory.StartNew(() =>
                    {
                        Console.Write($"{modeContex?.Mode ?? ""}> ");
                        return(Console.In.ReadLine());
                    }, self.CancellationTokenSource.Token);

                    line = line.Trim();

                    switch (line)
                    {
                    case "":
                        break;

                    case "exit":
                        self.RemoveComponent <ModeContex>();
                        break;

                    default:
                    {
                        string[] lines = line.Split(" ");
                        string   mode  = modeContex == null? lines[0] : modeContex.Mode;

                        if (!self.Handlers.TryGetValue(mode, out IConsoleHandler iConsoleHandler))
                        {
                            Log.Console($"not found command: {line}");
                            break;
                        }

                        if (modeContex == null)
                        {
                            modeContex      = self.AddComponent <ModeContex>();
                            modeContex.Mode = mode;
                        }
                        await iConsoleHandler.Run(modeContex, line);

                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    Log.Console(e.ToString());
                }
            }
        }
Ejemplo n.º 4
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;
        }