Ejemplo n.º 1
0
        /// <summary>
        /// The player clicked on the Select input button
        /// </summary>
        private async void SelectButtonPressed()
        {
            var  cursorTile = _tileSelector.CursorTile;
            Unit cursorUnit = null;

            if (!ReferenceEquals(cursorTile, null))
            {
                cursorUnit = cursorTile.CurrentUnit;
            }
            //Clicked on a unit
            if (!ReferenceEquals(cursorUnit, null))
            {
                if (cursorUnit.Faction != UnitFaction.Player)
                {
                    return;
                }
                //clicked on a player unit
                await _unitSelector.ChangeSelectedUnitAsync(cursorUnit, _gridManager.TileGrid);

                TileRenderingHelper.RenderUnitAvailablePaths(cursorUnit);
            }
            //Clicked on an empty tile
            else if (!ReferenceEquals(cursorTile, null))
            {
                var selectedUnit = _unitSelector.SelectedUnit;
                _unitMovementHandler.MoveUnitToTile(cursorTile, selectedUnit);
                //to be moved to other class
                selectedUnit.CombatController.AttackableTiles = _gridManager.TileGrid.GetGridTilesOfRange(cursorTile, selectedUnit.CombatController.AttackRanges);
                TileRenderingHelper.RenderUnitAttackTiles(selectedUnit);
            }
        }
Ejemplo n.º 2
0
        private void Update()
        {
            var  cursorTile = _tileSelector.CursorTile;
            Unit cursorUnit = null;

            if (!ReferenceEquals(cursorTile, null))
            {
                cursorUnit = cursorTile.CurrentUnit;
            }

            if (_tileSelector.CursorTileChanged)
            {
                //if the cursor is hovering over a unit, show the profile
                _unitProfile.ShowUnitProfile(cursorUnit);
                //cursor hovered over a tile within the selected units available moves
                if (!ReferenceEquals(_unitSelector.SelectedUnit, null))
                {
                    var selectedUnitPathfindingData = _unitSelector.SelectedUnit.PathfindingData;
                    //If hovering within the selected unit's movement, renders the path, otherwise removes the rendered path
                    var hoveredTilePathData = selectedUnitPathfindingData.FirstOrDefault(x => x.DestinationGridTile == _tileSelector.CursorTile);
                    TileRenderingHelper.RenderPathToTile(hoveredTilePathData, selectedUnitPathfindingData);
                }
                //Hovers over a unit
                if (!ReferenceEquals(cursorUnit, null))
                {
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Deselects the selectedUnit and renders the default grid on its movement path
 /// </summary>
 public void DeselectUnit()
 {
     if (ReferenceEquals(SelectedUnit, null))
     {
         return;
     }
     SelectedUnit.State = UnitState.Idle;
     TileRenderingHelper.UnRenderUnitPaths(SelectedUnit);
     SelectedUnit = null;
 }