private void Start()
        {
            LocalPlayerIndex = m_viewport.LocalPlayerIndex;

            int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex);

            m_cameraController = Dependencies.GameView.GetCameraController(LocalPlayerIndex);

            m_locationPicker = Dependencies.GameView.GetLocationPicker(LocalPlayerIndex);

            m_playersBot = MatchFactoryCli.CreateBotController(m_gameState.GetPlayer(playerIndex), m_engine.GetClientTaskEngine(playerIndex), new PlayerStrategy());
            m_playersBot.Init();

            SerializedTask[] taskTemplates = m_gameState.GetTaskTemplates(playerIndex);
            SerializedNamedTaskLaunchInfo[] taskTemplatesData = m_gameState.GetTaskTemplateData(playerIndex);
            for (int i = 0; i < taskTemplates.Length; ++i)
            {
                TaskTemplateType coreTaskType = taskTemplatesData[i].Type;
                m_playersBot.RegisterTask(coreTaskType, taskTemplates[i]);
            }
        }
Ejemplo n.º 2
0
        private void ProcessRequest(ClientRequest request, Action <ClientRequest> callback)
        {
            Cmd cmd = request.Cmd;

            if (cmd != null)
            {
                if (cmd.Code == CmdCode.GrantBotCtrl)
                {
                    m_bots = new IBotController[m_game.PlayersCount];
                    for (int i = 0; i < m_bots.Length; ++i)
                    {
                        Player player = m_game.GetPlayer(i);
                        if (player.IsActiveBot)
                        {
                            IBotController bot = MatchFactoryCli.CreateBotController(player, m_taskEngines[i], new DefaultStrategy());
                            bot.Init();
                            m_bots[i] = bot;
                        }
                    }
                    callback(request);
                }
                else if (cmd.Code == CmdCode.DenyBotCtrl)
                {
                    m_bots = new IBotController[m_game.PlayersCount];
                    for (int i = 0; i < m_bots.Length; ++i)
                    {
                        IBotController bot = m_bots[i];
                        if (bot != null)
                        {
                            bot.Reset();
                        }
                    }
                    m_bots = null;
                    callback(request);
                }
                else
                {
                    IVoxelDataController dc = m_game.GetVoxelDataController(request.PlayerIndex, cmd.UnitIndex);
                    if (cmd.Code != CmdCode.Move || dc == null)
                    {
                        if (dc == null)
                        {
                            request.Cmd.ErrorCode = CmdResultCode.Fail_NoUnit;
                        }
                        else
                        {
                            request.Cmd.ErrorCode = CmdResultCode.Fail_NotSupported;
                        }

                        SubmitResponse(request);
                    }
                    else
                    {
                        CoordinateCmd coordinateCmd = (CoordinateCmd)cmd;
                        Debug.Assert(coordinateCmd.Coordinates.Length > 1);
                        IPathFinder pathFinder = m_pathFinders[request.PlayerIndex];
#warning PathFinder should igore dataController.ControlledVoxelData
                        pathFinder.Find(cmd.UnitIndex, -1, dc.Clone(), coordinateCmd.Coordinates, (unitIndex, path) =>
                        {
                            coordinateCmd.Coordinates = path;
                            request.Cmd = coordinateCmd;
                            callback(request);
                        }, null);
                    }
                }
            }
        }