Example #1
0
    public void HandleInput()
    {
        if (_moving)
        {
            if (_cursor.SelectedUnit.isMoving)
            {
                return;
            }

            _battleMovement.UpdateTrackedTiles();
            _overlaysManager.UpdateTrackedOverlays();

            _battleManager.BattleTurnManager.DeactivateUnit(_cursor.SelectedUnit);
            _inputManager.InputState = EInputState.Movement;
            _cursor.DeselectUnit();
            _cursor.SetCursorObjectState(true);
            _cursor.enabled = true;
            _inputManager.ResetCamera();
            _moving = false;
        }
        else if (_inputManager.SelectDown)
        {
            switch (UIManager.ActiveButtonType())
            {
            case EButtonType.Move:
                var movingUnit = _cursor.SelectedUnit;
                movingUnit.MoveToPreviousPosition();
                _inputManager.ExecuteUnitMove();
                UIManager.HideButtons();
                _moving = true;
                break;

            case EButtonType.Attack:
                _inputManager.AddStateToHistory(EInputState.ActionMenu);
                UIManager.HideButtons();
                _inputManager.InputState = EInputState.SelectingUnitToAttack;
                break;

            default:
                Debug.LogError("Unrecognized Button type");
                break;
            }
        }
        else if (_inputManager.CancelDown)
        {
            _cursor.SelectedUnit.MoveToPreviousPosition();
            UIManager.HideButtons();
            _inputManager.InputState = EInputState.Movement;
            _cursor.enabled          = true;
        }
        else if (_inputManager.DownDirection)
        {
            UIManager.NextButton();
        }
        else if (_inputManager.UpDirection)
        {
            UIManager.PreviousButton();
        }
    }
Example #2
0
 public void OnUnitDeath(Unit unit)
 {
     BattleMovement.UntrackEnemyRange(unit);
     BattleMovement.UpdateTrackedTiles();
     OverlaysManager.UpdateTrackedOverlays();
 }
Example #3
0
    public void HandleInput()
    {
        if (_inputManager.ZoomIn)
        {
            _cameraMover.ZoomIn();
        }

        if (_inputManager.ZoomOut)
        {
            _cameraMover.ZoomOut();
        }

        if (_inputManager.RotateLeft)
        {
            _cameraMover.RotateLeft();
        }

        if (_inputManager.RotateRight)
        {
            _cameraMover.RotateRight();
        }

        if (_inputManager.SelectDown)
        {
            if (_cursor.UnitIsSelected)
            {
                if (_cursor.IsInRangeOfSelectedUnit())
                {
                    _inputManager.InputState = EInputState.ActionMenu;
                    _cursor.enabled          = false;
                    var targetTile = BattleMovementUtils.GetDestinationTile();
                    _cursor.SelectedUnit.Move(targetTile);
                    showUnitActions();
                }
            }
            else if (_cursor.HoveredTile.IsOccupied())
            {
                var  hoveredUnit = _cursor.HoveredTile.Occupier;
                bool isUnitFromTheACtiveGroup = hoveredUnit.Group ==
                                                _battleManager.BattleTurnManager.ActiveGroup;
                if (isUnitFromTheACtiveGroup)
                {
                    _cursor.SelectUnit();
                    //_battleManager.BattleMovement.OnNewTile(_cursor.HoveredTile);
                }
                else
                {
                    _overlaysManager.DisableTemporaryOverlays();
                    _battleMovement.ClearUnitTiles();
                    _battleMovement.TrackEnemyRange(hoveredUnit);
                    _battleMovement.UpdateTrackedTiles();
                    _overlaysManager.UpdateTrackedOverlays();
                }
            }
            else
            {
                _inputManager.InputState = EInputState.GeneralMenu;
                _cursor.enabled          = false;
                showGeneralActions();
            }
        }
        else if (_inputManager.CancelDown)
        {
            if (_cursor.UnitIsSelected)
            {
                BattleMovementUtils.HidePath();
                BattleMovementUtils.ResetPath();

                if (_cursor.HoveredTile != _cursor.SelectedUnit.OccupiedTile)
                {
                    _battleManager.OverlaysManager.DisableTemporaryOverlays();
                }

                _cursor.DeselectUnit();
            }
            else if (_cursor.HoveredTile.IsOccupied())
            {
                var  hoveredUnit = _cursor.HoveredTile.Occupier;
                bool isUnitFromTheACtiveGroup = hoveredUnit.Group ==
                                                _battleManager.BattleTurnManager.ActiveGroup;

                if (!isUnitFromTheACtiveGroup)
                {
                    _battleMovement.UntrackEnemyRange(hoveredUnit);
                    _battleMovement.UpdateTrackedTiles();
                    _overlaysManager.UpdateTrackedOverlays();
                }
            }
        }
    }
Example #4
0
    public void HandleInput()
    {
        if (!_setup)
        {
            Setup();
            _setup = true;
        }

        if (_fighting)
        {
            if (_attackingUnit.isFighting)
            {
                return;
            }

            _battleMovement.UpdateTrackedTiles();
            _overlaysManager.UpdateTrackedOverlays();

            _inputManager.ResetHistory();
            _inputManager.InputState = EInputState.Movement;
            _cursor.enabled          = true;
            _cursor.SetCursorObjectState(true);
            _inputManager.ResetCamera();
            _battleManager.BattleTurnManager.DeactivateUnit(_attackingUnit);
            _cursor.DeselectUnit();
            _fighting = false;
            _setup    = false;
        }
        else if (_moving)
        {
            if (_attackingUnit.isMoving)
            {
                return;
            }

            _moving   = false;
            _fighting = true;

            FaceUnitsInBattle(_attackingUnit, _enemiesInRange[_currentEnemy]);
            StartCoroutine(_combatManger.DefaultCombat(_attackingUnit,
                                                       _enemiesInRange[_currentEnemy]));
        }
        else if (_inputManager.SelectDown)
        {
            _cursor.SelectedUnit.MoveToPreviousPosition();
            _inputManager.ExecuteUnitMove();
            _moving = true;
            _combatMenu.gameObject.SetActive(false);
        }
        else if (_inputManager.CancelDown)
        {
            UIManager.ShowPreviousButtons();
            _inputManager.GoToPreviousState();
            _inputManager.ResetCamera();
            _setup = false;
            _combatMenu.gameObject.SetActive(false);
        }
        else if (Input.GetButtonDown("Change Enemy"))
        {
            if (Input.GetAxisRaw("Change Enemy") > 0)
            {
                _currentEnemy = (_currentEnemy + 1) % _enemiesInRange.Count;
            }
            else
            {
                //keeps modulo positive
                _currentEnemy = ((_currentEnemy - 1) % _enemiesInRange.Count
                                 + _enemiesInRange.Count) % _enemiesInRange.Count;
            }

            AdjustWeapon();
            UpdateCombatMenu();
            CenterCameraOnEnemy();
        }
        else if (Input.GetButtonDown("Change Weapon"))
        {
            if (Input.GetAxisRaw("Change Weapon") > 0)
            {
                _attackingUnit.EquipNextWeapon();
                AdjustWeapon();
            }
            else
            {
                _attackingUnit.EquipPreviousWeapon();
                AdjustWeaponBackwards();
            }

            UpdateCombatMenu();
        }
    }