/// <summary>
        /// Overridden from <see cref="PhaseLogic.OnMouseLeftClick(Vector3)"/>.
        /// </summary>
        protected override void OnMouseLeftClick(Vector3 position)
        {
            Coord?fetchCoord = GetSectorAtScreen(position);

            if (!fetchCoord.HasValue) // if the player clicked off-screen, clear selection
            {
                DoUnitSelection(null, s => 0);
            }
            else if (ContainsUnit(fetchCoord.Value, true)) // if player clicked on owned unit, shift selection to that one
            {
                DoUnitSelection(fetchCoord.Value, s =>
                                s.OccupyingUnit.HasAttacked || s.OccupyingUnit.ManaAttackCost > s.OccupyingUnit.Owner.Mana ?
                                0 : s.OccupyingUnit.AttackRange);
                if (SelectedUnit != null) // if the player was able to select the unit
                {                         // this should pass anyway, but it's good to double check
                  // unit just selected
                }
                else
                {
                    Debug.Log("Owned unit selection failed");
                }
            }
            else if (SelectedUnit != null) // if player has clicked a unit before, and has now clicked on a separate space, we need to prepare to move
            {
                SelectSector(fetchCoord);  // try to select the clicked sector
                // only consider an attack selection if it wasn't traversable and if an enemy was on it
                if (SelectedSector != null && SelectedSectorContainsUnit(true))
                {
                    if (SelectedRange.Contains(SelectedSector)) // only attack the unit if it was in range
                    {
                        AttackUnit();
                    }
                }
            }
        }
        protected override void Update()
        {
            base.Update();

            Coord?fetchCoord = GetSectorAtScreen(Input.mousePosition);

            // build unit highlighting
            if (_currentSecondaryHighlightedSectors.Count > 0)
            {
                foreach (Sector sector in _currentSecondaryHighlightedSectors)
                {
                    if (sector.Highlight == HighlightLevel.Bright)
                    {
                        sector.Highlight = HighlightLevel.Dimmed;
                    }
                }
                _currentSecondaryHighlightedSectors.Clear();
            }
            if (SelectedUnit != null && fetchCoord.HasValue && Gc.Map.Grid.IsTraversable(fetchCoord.Value) && SelectedRange.Contains(Gc.Map.Grid[fetchCoord.Value]))
            {
                _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[fetchCoord.Value]);
                Gc.Map.Grid[fetchCoord.Value].Highlight = HighlightLevel.Bright;
            }
        }
Пример #3
0
        /// <summary>
        /// Overridden from <see cref="PhaseLogic.OnMouseLeftClick(Vector3)"/>.
        /// </summary>
        protected override void OnMouseLeftClick(Vector3 position)
        {
            Coord? fetchCoord     = GetSectorAtScreen(position);
            Sector prevUnitSector = SelectedUnit;

            // if we are attempting to build a unit, handle either creation or cancellation
            if (_isBuildingUnit)
            {
                SelectSector(fetchCoord); // we need to know where the player clicked
                if (SelectedSector != null && SelectedRange.Contains(SelectedSector) && SelectedSector.OccupyingUnit == null)
                {                         // if the player clicked a valid build spot, then build the unit
                    IUnit newUnit = Instantiate(Gc.UnitPrefabs[_unitToBuild]).GetComponent <IUnit>();
                    newUnit.Init(Gc.Map.SectorMaterials, SelectedUnit.OccupyingUnit.Owner, SelectedUnit.OccupyingUnit.College);
                    SelectedSector.OccupyingUnit = newUnit;
                    Gc.CurrentPlayer.Mana       -= newUnit.Cost;
                    UpdateMana();
                }
                // we are no longer building
                SetUnitBuildingState(false);
            }
            else
            {
                if (!fetchCoord.HasValue) // if the player clicked off-screen, clear selection
                {
                    DoUnitSelection(null, s => 0);
                }
                else if (ContainsUnit(fetchCoord.Value, true)) // if player clicked on owned unit, shift selection to that one
                {
                    DoUnitSelection(fetchCoord.Value, s => (int)Mathf.Clamp(Mathf.Floor(s.OccupyingUnit.Owner.Mana / s.OccupyingUnit.ManaMoveRatio), 0, s.OccupyingUnit.AvailableMove));
                    if (SelectedUnit != null) // if the player was able to select the unit
                    {                         // this should pass anyway, but it's good to double check
                        _selectedUnitLocation = fetchCoord.Value;
                    }
                    else
                    {
                        Debug.Log("Owned unit selection failed");
                    }
                }
                else if (SelectedUnit != null) // if player has clicked a unit before, and has now clicked on a separate space, we need to prepare to move
                {
                    SelectSector(fetchCoord);  // try to select the clicked sector
                                               // if it wasn't traversable, or it contains an enemy unit, then we won't bother moving
                    if (SelectedSector != null && !SelectedSectorContainsUnit(true) && !BuildMenuState)
                    {                          // only move the unit if we are allowed, and are actually looking to move
                        if (SelectedRange.Contains(SelectedSector))
                        {
                            MoveUnit();
                        }
                    }
                }

                if (SelectedUnit != null && SelectedUnit.OccupyingUnit.BuildRange > 0) // if this is a builder unit
                {
                    // if player selected a new builder unit, make sure the build menu is close and give the option to open it
                    if (!BuildMenuState || prevUnitSector != SelectedUnit)
                    {
                        buildMenuButton.SetActive(true);
                        BuildMenuState = false;
                    }
                }
                else // if not on a builder unit, then make sure the build menu and open button are hidden
                {
                    buildMenuButton.SetActive(false);
                    BuildMenuState = false;
                }
            }
        }
Пример #4
0
        protected override void Update()
        {
            base.Update();

            Coord?fetchCoord = GetSectorAtScreen(Input.mousePosition);

            // build unit highlighting
            if (_currentSecondaryHighlightedSectors.Count > 0)
            {
                foreach (Sector sector in _currentSecondaryHighlightedSectors)
                {
                    if (sector.Highlight == HighlightLevel.Bright)
                    {
                        sector.Highlight = HighlightLevel.Dimmed;
                    }
                }
                _currentSecondaryHighlightedSectors.Clear();
            }
            if (_isBuildingUnit)
            {
                if (fetchCoord.HasValue && Gc.Map.Grid.IsTraversable(fetchCoord.Value) && SelectedRange.Contains(Gc.Map.Grid[fetchCoord.Value]))
                {
                    _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[fetchCoord.Value]);
                    Gc.Map.Grid[fetchCoord.Value].Highlight = HighlightLevel.Bright;
                }
            }
            else if (SelectedUnit != null)
            {
                if (fetchCoord.HasValue && _selectedUnitLocation.DistanceTo(fetchCoord.Value) <= SelectedUnit.OccupyingUnit.AvailableMove &&
                    Gc.Map.Grid.IsTraversable(fetchCoord.Value))
                {
                    Stack <Coord> path = Gc.Map.Grid.PathFind(_selectedUnitLocation, fetchCoord.Value);
                    Coord         item;
                    int           count = 0;
                    while (count < SelectedUnit.OccupyingUnit.AvailableMove && path.Count > 0)
                    {
                        item = path.Pop();
                        Gc.Map.Grid[item].Highlight = HighlightLevel.Bright;
                        _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[item]);
                        count++;
                    }
                }
            }
        }