Пример #1
0
    private RangePos GetSmallestNearVisitedRay(int x, int y, Vector3 actualPosition)
    {
        //int smallestVisited = Constants.UnlimitedPm;
        float    smallestDistance = 999.0f;
        RangePos tmpRangePos      = new RangePos(-1, -1);

        foreach (var cell in _gridBhv.Cells)
        {
            var   tmpX = cell.GetComponent <CellBhv>().X;
            var   tmpY = cell.GetComponent <CellBhv>().Y;
            float tmpDistance;
            if (Helper.IsPosValid(tmpX, tmpY) &&
                cell.GetComponent <CellBhv>().Type == CellType.On &&
                cell.GetComponent <CellBhv>().Visited > 0
                //&& _gridBhv.Cells[tmpX, tmpY].GetComponent<CellBhv>().Visited < smallestVisited
                && (tmpDistance = Vector3.Distance(_gridBhv.Cells[x, y].transform.position, cell.transform.position)) < smallestDistance)
            {
                //smallestVisited = _gridBhv.Cells[tmpX, tmpY].GetComponent<CellBhv>().Visited;
                smallestDistance = tmpDistance;
                tmpRangePos.X    = tmpX;
                tmpRangePos.Y    = tmpY;
            }
        }
        if (tmpRangePos.X == -1 && tmpRangePos.Y == -1 ||
            Vector3.Distance(_gridBhv.Cells[x, y].transform.position, actualPosition) < Vector3.Distance(_gridBhv.Cells[x, y].transform.position, _gridBhv.Cells[tmpRangePos.X, tmpRangePos.Y].transform.position))
        {
            return(null);
        }
        return(tmpRangePos);
    }
Пример #2
0
    //private void SetPathToOppositeCorner()
    //{
    //    int x = 0;
    //    int y = 0;
    //    if (_opponentBhv.X < 3 ||
    //        (_opponentBhv.X == 3 && _characterBhv.X > 3))
    //        x = Constants.GridMax - 1;
    //    if (_opponentBhv.Y < 3 ||
    //        (_opponentBhv.Y == 3 && _characterBhv.Y > 3))
    //        y = Constants.GridMax - 1;
    //    //if (x != _characterBhv.X && y != _characterBhv.Y)
    //        _gridBhv.ShowPm(_characterBhv, _characterBhv.OpponentBhvs, unlimitedPm: true);
    //    var tmpPos = GetClosestCellVisitedToPlayer(_gridBhv.Cells[x, y].transform.position);
    //    _characterBhv.SetPath(tmpPos.X, tmpPos.Y, usePm: false);
    //}

    private RangePos GetCellVisitedToPlayerBySkill(bool far = false)
    {
        int tmpVisited = 99;

        if (far)
        {
            tmpVisited = 0;
        }
        RangePos tmpPos = new RangePos(-1, -1);

        foreach (var cell in _gridBhv.Cells)
        {
            if (cell.GetComponent <CellBhv>().Visited != Constants.VisitedPmValue &&
                cell.GetComponent <CellBhv>().SkillVisited == Constants.VisitedSkillValue)
            {
                if (far && cell.GetComponent <CellBhv>().Visited > tmpVisited)
                {
                    tmpVisited = cell.GetComponent <CellBhv>().Visited;
                    tmpPos.X   = cell.GetComponent <CellBhv>().X;
                    tmpPos.Y   = cell.GetComponent <CellBhv>().Y;
                }
                else if (!far && cell.GetComponent <CellBhv>().Visited < tmpVisited)
                {
                    tmpVisited = cell.GetComponent <CellBhv>().Visited;
                    tmpPos.X   = cell.GetComponent <CellBhv>().X;
                    tmpPos.Y   = cell.GetComponent <CellBhv>().Y;
                }
            }
        }
        if (tmpPos.X == -1 && tmpPos.Y == -1)
        {
            return(null);
        }
        return(tmpPos);
    }
Пример #3
0
    private int CanIWeaponThePlayer()
    {
        int      canI      = 0;
        RangePos rangeZone = null;

        for (int i = 0; i < 2; ++i)
        {
            if (_characterBhv.Pa >= _characterBhv.Character.Weapons[i].PaNeeded &&
                (rangeZone = _gridBhv.IsOpponentInWeaponRangeAndZone(_characterBhv, i, _characterBhv.OpponentBhvs)) != null)
            {
                _rangeClicked[i]   = rangeZone;
                _weaponsWeight[i] += _characterBhv.Character.Weapons[i].BaseDamage;
                canI += 10;
            }
        }
        return(canI);
    }
Пример #4
0
    private RangePos GetFarestIdCellToPlayer()
    {
        float    maxVisited = 0;
        RangePos tmpPos     = new RangePos(-1, -1);

        foreach (var cell in _gridBhv.Cells)
        {
            if (cell.GetComponent <CellBhv>().Visited > 0 &&
                cell.GetComponent <CellBhv>().Visited > maxVisited)
            {
                maxVisited = cell.GetComponent <CellBhv>().Visited;
                tmpPos.X   = cell.GetComponent <CellBhv>().X;
                tmpPos.Y   = cell.GetComponent <CellBhv>().Y;
            }
        }
        if (tmpPos.X == -1 && tmpPos.Y == -1)
        {
            return(null);
        }
        return(tmpPos);
    }
Пример #5
0
    private RangePos GetSmallestNearVisited(int x, int y, Vector3 actualPosition, bool diagonally = false)
    {
        int      smallestVisited = Constants.UnlimitedPm;
        RangePos tmpRangePos     = new RangePos(-1, -1);
        int      tmpX            = x;
        int      tmpY            = y;

        for (int i = 0; i < 4; ++i)
        {
            if (!diagonally)
            {
                if (i == 0)
                {
                    tmpX = x; tmpY = y + 1;
                }
                else if (i == 1)
                {
                    tmpX = x + 1; tmpY = y;
                }
                else if (i == 2)
                {
                    tmpX = x; tmpY = y - 1;
                }
                else if (i == 3)
                {
                    tmpX = x - 1; tmpY = y;
                }
            }
            else
            {
                if (i == 0)
                {
                    tmpX = x + 1; tmpY = y + 1;
                }
                else if (i == 1)
                {
                    tmpX = x + 1; tmpY = y - 1;
                }
                else if (i == 2)
                {
                    tmpX = x - 1; tmpY = y - 1;
                }
                else if (i == 3)
                {
                    tmpX = x - 1; tmpY = y + 1;
                }
            }

            if (Helper.IsPosValid(tmpX, tmpY) &&
                _gridBhv.Cells[tmpX, tmpY].GetComponent <CellBhv>().Type == CellType.On &&
                _gridBhv.Cells[tmpX, tmpY].GetComponent <CellBhv>().Visited > 0 &&
                _gridBhv.Cells[tmpX, tmpY].GetComponent <CellBhv>().Visited < smallestVisited)
            {
                smallestVisited = _gridBhv.Cells[tmpX, tmpY].GetComponent <CellBhv>().Visited;
                tmpRangePos.X   = tmpX;
                tmpRangePos.Y   = tmpY;
            }
        }
        if (tmpRangePos.X == -1 && tmpRangePos.Y == -1)
        {
            return(GetSmallestNearVisitedRay(x, y, actualPosition));
        }
        if (_gridBhv.Cells[tmpRangePos.X, tmpRangePos.Y].GetComponent <CellBhv>().Visited > _characterBhv.Pm &&
            diagonally == false)    //If too far, go to diagonal
        {
            return(GetSmallestNearVisited(x, y, actualPosition, true));
        }
        return(tmpRangePos);
    }
Пример #6
0
 private bool SetPathToOpponent(RangePos tmpPos)
 {
     _gridBhv.ShowPm(_characterBhv, _characterBhv.OpponentBhvs, unlimitedPm: true);
     return(_characterBhv.SetPath(tmpPos.X, tmpPos.Y, usePm: false));
 }