Example #1
0
 void OnMouseDown()
 {
     if (Tile.gameBoard.TurnCounter == 0)
     {
         Unit unit = Tile.gameBoard.SelectedDeploymentUnit;
         Debug.Log("Clicked " + this);
         Debug.Log("Deployed Unit is " + unit);
         if (unit != null)
         {
             Debug.Log("Swap");
             EncounterUtils.SwapUnits(this, unit);
             Tile.gameBoard.SelectedDeploymentUnit = null;
         }
         else
         {
             Tile.gameBoard.SelectedDeploymentUnit = this;
         }
     }
     else if (!HasActed)
     {
         GameObject selectedPiece = Tile.gameBoard.selectedPiece;
         if (selectedPiece == null)
         {
             Tile.gameBoard.selectedPiece = this.gameObject;
             actionMenu.DisplayPanel();
         }
     }
 }
Example #2
0
        void Update()
        {
            CheckMapEndConditions();
            if (Input.GetKeyDown("enter"))
            {
                EndTurn();
                StartTurn();
            }
            if (Input.GetKeyDown("q"))
            {
                Storage.SaveEncounterInfo(Storage.GetCurrentCredits(), -1, Character.GetCurrentCharacters()); // -1 if lvl is failed, 1 if completed successfully
                SceneController.LoadScene("GalaxyMap");
            }

            if (TurnCounter > 5 && EncounterUtils.GetUnitsInArea(playerSpawnArea, Team.Player).Count > 0)
            {
                // Display Button That allows for letting player leave
            }

            if (objective is ReachDestination && !objective.Success)
            {
                ReachDestination rd = objective as ReachDestination;
                EncounterUtils.ToggleHighlightEffect(rd.Destination, true, Color.yellow);
            }
            EncounterUtils.Highlight(playerSpawnArea, Color.yellow);
            if (selectedPiece != null && SelectedPieceState == SelectedPieceState.None)
            {
                Unit unit = selectedPiece.GetComponent <Unit>();
                if (Input.GetKeyDown(KeyCode.M) && !unit.HasMoved)
                {
                    EncounterUtils.Highlight(SelectedPieceMoveRange, Color.blue);
                    SelectedPieceState = SelectedPieceState.Moving;
                }
                if (Input.GetKeyDown(KeyCode.A) && !unit.HasActed)
                {
                    EncounterUtils.Highlight(SelectedPieceAttackRange, Color.red);
                    SelectedPieceState = SelectedPieceState.Attacking;
                }
                if (Input.GetKeyDown(KeyCode.K) && !unit.HasActed)
                {
                    Ability ability = new SunderingBlast(unit);
                    SelectedAbility      = ability;
                    SelectedAbilityRange = EncounterUtils.FindTilesInRange(unit.Tile, 10, (Tile t) => { return(1); });

                    EncounterUtils.Highlight(SelectedAbilityRange, Color.green);
                    SelectedPieceState = SelectedPieceState.Casting;
                }

                /*if (Input.GetKeyDown(KeyCode.P) && !unit.HasActed) {
                 *  PoisonEffect pE = new PoisonEffect(3);
                 *  SelectedAbility = pE;
                 *  //Debug.Log(pE.Range);
                 *  SelectedAbilityRange = EncounterUtils.FindTilesInRange(unit.Tile, 4, (Tile t) => { return 1; });
                 *
                 *  EncounterUtils.Highlight(SelectedAbilityRange, Color.green);
                 *  SelectedPieceState = SelectedPieceState.Casting;
                 * }*/
            }
        }
Example #3
0
        public void OnMouseDown()
        {
            List <Tile> adjacencies = GetNeighbors();

            //Debug.Log("Clicked: " + this.ToString());
            switch (gameBoard.SelectedPieceState)
            {
            case SelectedPieceState.None: {
                gameBoard.selectedPiece = this.BoardPiece;
                break;
            }

            case SelectedPieceState.Attacking: {
                if (gameBoard.SelectedPieceAttackRange.Contains(this) && this.BoardPiece != null)
                {
                    Unit unit = this.BoardPiece.GetComponent <Unit>();
                    gameBoard.selectedPiece.GetComponent <Unit>().AttackUnit(unit);
                }
                gameBoard.selectedPiece      = null;
                gameBoard.SelectedPieceState = SelectedPieceState.None;
                break;
            }

            case SelectedPieceState.Moving: {
                if (gameBoard.SelectedPieceMoveRange.Contains(this))
                {
                    gameBoard.selectedPiece.GetComponent <Unit>().MoveTo(this);
                }

                gameBoard.selectedPiece      = null;
                gameBoard.SelectedPieceState = SelectedPieceState.None;
                break;
            }

            case SelectedPieceState.Casting: {
                if (gameBoard.SelectedAbilityRange.Contains(this))
                {
                    EncounterUtils.ApplyTileEffects(gameBoard.SelectedAbilityZone, (Tile tile) => {
                            Unit unit = null;
                            if (tile.BoardPiece != null)
                            {
                                unit = tile.BoardPiece.GetComponent <Unit>();
                            }
                            if (unit != null)
                            {
                                gameBoard.SelectedAbility.Apply(unit);
                            }
                        }
                                                    );
                    gameBoard.selectedPiece.GetComponent <Unit>().HasActed = true;
                }
                gameBoard.SelectedAbility    = null;
                gameBoard.selectedPiece      = null;
                gameBoard.SelectedPieceState = SelectedPieceState.None;
                break;
            }
            }
        }
Example #4
0
        // Checks if the cursor is hovering on this tile
        private void CheckForCursorHover()
        {
            Vector3 cursorLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            bool    cursorIsOnTile = CursorIsOnTile(cursorLocation.x - xCoordf, cursorLocation.y - yCoordf);

            // If cursor is inside the tile: highlight the tile
            if (cursorIsOnTile && !isWall)
            {
                GetComponent <Renderer>().enabled = true;
                if (gameBoard.SelectedPieceState == SelectedPieceState.Casting && gameBoard.SelectedAbilityRange.Contains(this))
                {
                    gameBoard.SelectedAbilityZone = EncounterUtils.FindTilesInRange(this, gameBoard.SelectedAbility.ZoneRange, (Tile t) => { return(1); });


                    EncounterUtils.Highlight(gameBoard.SelectedAbilityZone, Color.red);
                }
            }
            else
            {
                GetComponent <Renderer>().enabled = false;
            }
        }
Example #5
0
    public List <Tile> PathToClosestPlayerUnit()
    {
        List <Unit> playerUnits = getPlayerUnits();

        int         currentLength = 100;
        Tile        aITile        = gameObject.GetComponent <Unit>().Tile;
        List <Tile> path          = null;

        foreach (Unit player in playerUnits)
        {
            List <Tile> newPath = EncounterUtils.PathFinding(aITile, player.Tile);
            if (newPath == null)
            {
                Debug.Log("No Path");
            }
            if (newPath != null && newPath.Count < currentLength)
            {
                path          = newPath;
                currentLength = path.Count;
            }
        }
        return(path);
    }
Example #6
0
        void Start()
        {
            CreateGrid();
            List <EncounterUtils.Point> playerSpawnPoints = EncounterUtils.GetSpawnPoints(Team.Player, MAP_NAME, EncounterUtils.Difficulty.Easy);
            List <EncounterUtils.Point> enemySpawnPoints  = EncounterUtils.GetSpawnPoints(Team.Enemy, MAP_NAME, EncounterUtils.Difficulty.Easy);

            playerSpawnArea = pointsToTiles(playerSpawnPoints);
            enemySpawnArea  = pointsToTiles(enemySpawnPoints);
            List <Character> playerCharacters = Character.GetCurrentCharacters();
            List <Character> enemyCharacters  = EnemyCharacters.GetEnemies();

            for (int i = 0; i < playerSpawnArea.Count; i++)
            {
                playerSpawnArea[i].SpawnUnit(playerCharacters[i]);
            }
            for (int i = 0; i < playerSpawnArea.Count; i++)
            {
                enemySpawnArea[i].SpawnUnit(enemyCharacters[i]);
            }

            EncounterUtils.Highlight(enemySpawnArea, Color.red);
            turnOnAI = false;
            SetupRandomObjective();
        }