private bool MoveToNextCell() { bool isAdjacent = _gridBhv.IsAdjacentOpponent(_characterBhv.X, _characterBhv.Y, _characterBhv.OpponentBhvs); if (_characterBhv.Pm <= 0 || (isAdjacent && _characterBhv.Pm <= 1)) { return(false); } var lostPm = isAdjacent ? 2 : 1; _characterBhv.LosePm(lostPm); _characterBhv.MoveToFirstPathStep(); return(true); }
public bool SetPath(int xToReach, int yToReach, bool usePm = true) { PathfindingSteps.Clear(); PathfindingPos.Clear(); if (_gridBhv.Cells[xToReach, yToReach].GetComponent <CellBhv>().Visited <= 0) { return(false); } PathfindingSteps.Add(_gridBhv.Cells[xToReach, yToReach].transform.position); PathfindingPos.Add(new RangePos(xToReach, yToReach)); var visitedIndex = _gridBhv.Cells[xToReach, yToReach].GetComponent <CellBhv>().Visited; if (usePm) { LosePm(visitedIndex); } int x = xToReach; int y = yToReach; while (visitedIndex > 0) { var tmpX = x; var tmpY = y; //Check if can get around the opponent if (LookForLowerIndex(x, y + 1, visitedIndex - 1) && !_gridBhv.IsAdjacentOpponent(x, y + 1, OpponentBhvs)) { ++y; } else if (LookForLowerIndex(x + 1, y, visitedIndex - 1) && !_gridBhv.IsAdjacentOpponent(x + 1, y, OpponentBhvs)) { ++x; } else if (LookForLowerIndex(x, y - 1, visitedIndex - 1) && !_gridBhv.IsAdjacentOpponent(x, y - 1, OpponentBhvs)) { --y; } else if (LookForLowerIndex(x - 1, y, visitedIndex - 1) && !_gridBhv.IsAdjacentOpponent(x - 1, y, OpponentBhvs)) { --x; } if (tmpX == x && tmpY == y) //Can't get around { if (LookForLowerIndex(x, y + 1, visitedIndex - 1)) { ++y; } else if (LookForLowerIndex(x + 1, y, visitedIndex - 1)) { ++x; } else if (LookForLowerIndex(x, y - 1, visitedIndex - 1)) { --y; } else if (LookForLowerIndex(x - 1, y, visitedIndex - 1)) { --x; } } PathfindingSteps.Insert(0, _gridBhv.Cells[x, y].transform.position); PathfindingPos.Insert(0, new RangePos(x, y)); --visitedIndex; } if (PathfindingPos.Count > 0) { SkinContainer.OrientToTarget(X - PathfindingPos[0].X); } return(true); }