public void Execute(Cmd[] commands, long tick, long lagTicks)
        {
            HashSet <long> deadUnitsHs      = null;
            List <long>    spawnedUnitsList = null;

            for (int c = 0; c < commands.Length; ++c)
            {
                Cmd cmd = commands[c];
                if (cmd == null)
                {
                    continue;
                }

                if (cmd.Code == CmdCode.LeaveRoom)
                {
                    m_isInRoom = false;
                }
                else
                {
                    IMatchUnitControllerCli unitController = m_idToUnit[cmd.UnitIndex];

                    long duration = cmd.Duration;
                    duration -= lagTicks;
                    duration  = Math.Max(0, duration);

                    cmd.Duration = (int)duration;

                    IVoxelDataController dc        = unitController.DataController;
                    Coordinate           prevCoord = dc.Coordinate;

                    int radius = unitController.DataController.Abilities.VisionRadius;

                    unitController.ExecuteCommand(cmd, tick);
                    if (prevCoord != dc.Coordinate)
                    {
                        HandleCoordinateChange(dc, prevCoord, radius);
                    }

                    IList <VoxelDataCellPair> createdVoxels = unitController.CreatedVoxels;
                    if (createdVoxels.Count != 0)
                    {
                        CreateAssets(createdVoxels);
                        for (int i = 0; i < m_otherPlayerControllers.Length; ++i)
                        {
                            m_otherPlayerControllers[i].CreateAssets(createdVoxels);
                        }
                    }

                    IList <VoxelData> eatenOrDestroyed = unitController.EatenOrDestroyedVoxels;
                    if (eatenOrDestroyed.Count != 0)
                    {
                        RemoveAssets(eatenOrDestroyed);
                        for (int i = 0; i < m_otherPlayerControllers.Length; ++i)
                        {
                            m_otherPlayerControllers[i].RemoveAssets(eatenOrDestroyed);
                        }
                    }

                    if (cmd.Code == CmdCode.Composite)
                    {
                        CompositeCmd compositeCmd = (CompositeCmd)cmd;
                        for (int i = 0; i < compositeCmd.Commands.Length; ++i)
                        {
                            spawnedUnitsList = PostprocessCommand(spawnedUnitsList, compositeCmd.Commands[i], unitController);
                        }
                    }
                    else
                    {
                        spawnedUnitsList = PostprocessCommand(spawnedUnitsList, cmd, unitController);
                    }

                    //if (unitController.DataController.ControlledData.Unit.State == VoxelDataState.Dead)
                    if (!unitController.DataController.IsAlive)
                    {
                        //Voxel voxel = unitController.DataController.ControlledData.VoxelRef;
                        //Debug.Assert(voxel == null);//

                        if (deadUnitsHs == null)
                        {
                            deadUnitsHs = new HashSet <long>();
                        }

                        if (deadUnitsHs.Contains(cmd.UnitIndex))
                        {
                            Debug.LogError("Dead unit could not execute commands");
                        }
                        else
                        {
                            deadUnitsHs.Add(cmd.UnitIndex);
                        }
                    }
                }
            }


            if (deadUnitsHs != null)
            {
                long[] deadUnits = deadUnitsHs.ToArray();
                for (int i = 0; i < m_gameState.PlayersCount; ++i)
                {
                    m_selection.Unselect(i, m_playerIndex, deadUnits);
                    m_targetSelection.Unselect(i, m_playerIndex, deadUnits);
                }
                for (int i = 0; i < deadUnits.Length; ++i)
                {
                    long unitId = deadUnits[i];

                    RemoveUnitController(unitId);
                }
            }

            if (m_isLocalPlayer)
            {
                if (spawnedUnitsList != null)
                {
                    long[] spawnedUnits = spawnedUnitsList.ToArray();
                    spawnedUnits = spawnedUnits.Where(
                        u => m_gameState.GetVoxelDataController(m_playerIndex, u) != null &&
                        VoxelData.IsControllableUnit(m_gameState.GetVoxelDataController(m_playerIndex, u).ControlledData.Type)).ToArray();

                    m_selection.AddToSelection(m_playerIndex, m_playerIndex, spawnedUnits);
                }
            }
        }
Beispiel #2
0
        private void Update()
        {
            if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsMenuOpened(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging)
            {
                return;
            }

            if (m_gameState.IsReplay)
            {
                return;
            }

            int playerIndex = PlayerIndex;

            m_selectInterval   -= Time.deltaTime;
            m_unselectInterval -= Time.deltaTime;

            bool multiselect = m_inputManager.GetButton(InputAction.RB, LocalPlayerIndex);

            if (m_inputManager.GetButtonDown(InputAction.LMB, LocalPlayerIndex))
            {
                RaycastHit hitInfo;
                if (Physics.Raycast(m_cameraController.Ray, out hitInfo))
                {
                    Voxel voxel = hitInfo.transform.GetComponentInParent <Voxel>();
                    if (voxel != null)
                    {
                        VoxelData data = voxel.VoxelData;
                        if (VoxelData.IsControllableUnit(data.Type) && data.Owner == playerIndex)
                        {
                            m_unitSelection.ClearSelection(playerIndex);
                            m_unitSelection.Select(playerIndex, playerIndex, new[] { data.UnitOrAssetIndex });
                        }
                        else
                        {
                            m_unitSelection.ClearSelection(playerIndex);
                        }
                    }
                    else
                    {
                        m_unitSelection.ClearSelection(playerIndex);
                    }
                }
                else
                {
                    m_unitSelection.ClearSelection(playerIndex);
                }

                if (m_boxSelector != null)
                {
                    m_boxSelector.Activate();
                }
            }

            if (m_inputManager.GetButtonDown(InputAction.LB, LocalPlayerIndex))
            {
                bool select = true;

                if (multiselect)
                {
                    long[] units     = m_gameState.GetUnits(playerIndex).ToArray();
                    long   unitIndex = GetAt(units, m_cameraController.MapCursor);

                    if (m_unitSelection.IsSelected(playerIndex, playerIndex, unitIndex))
                    {
                        m_unitSelection.Unselect(playerIndex, playerIndex, new[] { unitIndex });
                        m_wasSelected.Remove(unitIndex);
                        select = false;
                    }
                }

                if (select)
                {
                    Select(playerIndex, multiselect);
                    m_selectInterval   = 0.3f;
                    m_unselectInterval = float.PositiveInfinity;
                    m_multiselectMode  = true;
                }
                else
                {
                    m_selectInterval   = float.PositiveInfinity;
                    m_unselectInterval = 0.3f;
                }
            }
            else if (m_inputManager.GetButton(InputAction.LB, LocalPlayerIndex))
            {
                if (m_selectInterval <= 0)
                {
                    Select(playerIndex, multiselect);
                    m_selectInterval = 0.2f;
                }

                if (m_unselectInterval <= 0)
                {
                    Unselect(playerIndex);
                    m_unselectInterval = 0.2f;
                }

                m_cameraController.IsInputEnabled = false;
            }
            else if (m_inputManager.GetButtonUp(InputAction.LB, LocalPlayerIndex, false, false))
            {
                m_cameraController.IsInputEnabled = true;
            }

            if (m_inputManager.GetButtonDown(InputAction.RB, LocalPlayerIndex))
            {
                m_multiselectMode = false;
            }
            else if (m_inputManager.GetButtonUp(InputAction.RB, LocalPlayerIndex))
            {
                if (!m_multiselectMode)
                {
                    if (!m_targetSelection.HasSelected(playerIndex))
                    {
                        m_wasSelected.Clear();
                        m_unitSelection.ClearSelection(playerIndex);
                    }
                }
            }
        }