Example #1
0
    void ShowCellInformation(BattleboardCell cell, string information, bool achtung = false)
    {
        Color blue = new Color(0f, 0.03f, 0.56f);
        Color red  = new Color(0.56f, 0f, 0.13f);

        var x = cell.transform.position.x;
        var y = cell.transform.position.y;

        if (null == cellInformation)
        {
            cellInformation = Instantiate(CellInfoPrefab);
        }

        cellInformation.transform.position = CellInfoPrefab.transform.position + cell.transform.position;

        // face it straight to the camera w/ animation -- animation effect just irritates
        //StopCoroutine(FaceCellInformationToCamera());
        //StartCoroutine(FaceCellInformationToCamera());
        cellInformation.transform.rotation = camera.transform.rotation;

        var textComp = cellInformation.GetComponentInChildren <Text>();

        textComp.text  = information;
        textComp.color = achtung ? red : blue;
        cellInformation.SetActive(true);
    }
Example #2
0
    List <BattleboardCell> BuildRoute(BattleboardCell start, BattleboardCell target)
    {
        if (start == target)
        {
            return(null);
        }

        // prepare data for the A* algorithm
        var width  = cells.GetLength(0);
        var height = cells.GetLength(1);

        Cell[,] grid = new Cell[width, height];
        Cell gridStart = null, gridTarget = null;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                grid[i, j] = new Cell(new Vector2(i, j), cells[i, j].IsVacant());
                if (cells[i, j] == start)
                {
                    gridStart = grid[i, j];
                }
                if (cells[i, j] == target)
                {
                    gridTarget = grid[i, j];
                }
            }
        }

        if (null == gridStart || null == gridTarget)
        {
            return(null);
        }

        AStar       aStar = new AStar(grid, gridStart, gridTarget);
        List <Cell> route = aStar.Search();

        if (null == route)
        {
            return(null);
        }

        // convert the route to list of battleboard cells
        List <BattleboardCell> resultRoute = new List <BattleboardCell>();

        foreach (var el in route)
        {
            var curCell = cells[Convert.ToInt32(el.Position.x), Convert.ToInt32(el.Position.y)];
            resultRoute.Add(curCell);
        }

        return(resultRoute);
    }
Example #3
0
    private void onCellClicked(object sender, EventArgs e)
    {
        if (!fsm.GetCurrentState().CellClickAllowed())
        {
            Debug.Log("Cell click not allowed in this state");
            return;
        }

        // Battleboard decides, what action to do if cell clicked (bc Battleboard is kinda CellManager)
        BattleboardCell cell = sender as BattleboardCell;

        if (currentRoute != null)
        {
            if (currentCharacter.APEnoughForWalk(currentRoute.Count - 1))
            {
                fsm.GetCurrentState().GoToStateInputDisabled();

                // it's much easier and clearer to make a copy of the route, and correct it,
                // taking into account amount of APs, than setting a bunch of conditions here, in Character,
                // and in Character's Moving State
                var routeCopy = currentRoute.ToList <BattleboardCell>(); // copying using linq
                currentCharacter.MoveByRoute(routeCopy);
                DestroyRoute();                                          // we don't need it anymore; in fact, we could emulate onMouseExit, but it would confuse code reading
            }
            else
            {
                Log.Output(Log.NOT_ENOUGH_AP);
            }
        }

        if (cell.IsOccupiedByCharacterOfParty(cell, enemyParty))
        {
            // attempt to attack
            if (AreCellsAdjacent(cell.transform.position, currentCharacter.transform.position))
            {
                if (currentCharacter.APEnoughForAttack())
                {
                    fsm.GetCurrentState().GoToStateInputDisabled();


                    if (null == charactersInAttack)
                    {
                        charactersInAttack = new List <Character>();
                    }
                    else
                    {
                        charactersInAttack.Clear();
                    }
                    charactersInAttack.Add(currentCharacter);
                    charactersInAttack.Add(cell.Character);


                    currentCharacter.AttackThe(cell.Character);
                    (sender as BattleboardCell).ExternalModificatorColor = Color.clear; // in fact, we could emulate onMouseExit, but it would confuse code reading
                }
                else
                {
                    Log.Output(Log.NOT_ENOUGH_AP);
                }
            }
            else
            {
                Log.Output("Target is too far"); // #localize
            }
        }

        // if cell is occupied by a character from player's party -- don't do anything
    }
Example #4
0
    private void onCellMouseEnter(object sender, EventArgs e)
    {
        if (!fsm.GetCurrentState().CellMouseEnterAllowed())
        {
            Debug.Log("Cell mouse enter not allowed in this state");
            return;
        }

        int    APAmountRequired           = 0;
        string cellInformationText        = "";
        bool   cellInformationTextAchtung = false;

        // Battleboard decides, what action to do if cell clicked (bc Battleboard is kinda CellManager)
        BattleboardCell cell = sender as BattleboardCell;

        if (cell.IsVacant())
        {
            BattleboardCell currentCell = FindCellOfCharacter(currentCharacter);

            currentRoute = BuildRoute(currentCell, cell);

            var routeRealLength = currentRoute.Count - 1;
            APAmountRequired = currentCharacter.WalkCost * routeRealLength;
            if (APAmountRequired > 0) // we need this check here in order not to create cellinfo when mouse is on current character's cell with 0 AP
            {
                // #localize:
                cellInformationText = currentCharacter.APEnoughForWalk(routeRealLength) ?
                                      "Walk here\nfor " + APAmountRequired + " AP" + Utility.GetIntegerEnding(APAmountRequired) :
                                      cellInformationText = String.Format("{0} to walk here\nRequired: {1}", Log.NOT_ENOUGH_AP, APAmountRequired);
                cellInformationTextAchtung = !currentCharacter.APEnoughForWalk(routeRealLength);
            }

            MarkInRouteCells();
        }

        if (cell.IsOccupiedByCharacterOfParty(cell, enemyParty))
        {
            if (AreCellsAdjacent(cell.transform.position, currentCharacter.transform.position))
            {
                APAmountRequired = currentCharacter.AttackCost;

                cell.ExternalModificatorColor = currentCharacter.APEnoughForAttack() ?
                                                BattleboardCell.enoughAPColor :
                                                BattleboardCell.noAPColor;
                // #localize:
                cellInformationText = currentCharacter.APEnoughForAttack() ?
                                      String.Format("Attack {0} {3}\nfor {1} AP{2}", cell.Character.GetHealthStatus(), APAmountRequired, Utility.GetIntegerEnding(APAmountRequired), cell.Character.Name) :
                                      String.Format("{0} for attack {2} {3}\nRequired: {1}", Log.NOT_ENOUGH_AP, APAmountRequired, cell.Character.GetHealthStatus(), cell.Character.Name);
                cellInformationTextAchtung = !currentCharacter.APEnoughForAttack();
            }
            else   // show enemy's name and health status
            {
                // #localize:
                cellInformationText = String.Format("{0}\n{1}", cell.Character.Name, cell.Character.GetHealthStatus());
            }
        }

        // if it's out teammate, show his/her name and exact HP
        if (cell.IsOccupiedByCharacterOfParty(cell, playerParty))
        {
            // #localize:
            cellInformationText = String.Format("{0}\nHP: {1}", cell.Character.Name, cell.Character.HP);
        }

        if (!String.IsNullOrEmpty(cellInformationText))
        {
            ShowCellInformation(cell, cellInformationText, cellInformationTextAchtung);
        }
    }