public void RemoveCard() { this._unitController = null; this._cardController = null; }
public void SetNewCard(CardController card) { this._cardController = card; this._unitController = card.GetComponent <UnitController>(); }
public void SetNewUnit(UnitController unit) { this._unitController = unit; this._cardController = unit.GetComponent <CardController>(); }
public List <Transform> SquaresInAttackDistance() { List <Transform> squares = new List <Transform>(); List <Transform> possibleSquaresInAttackDistance = new List <Transform>(); List <List <int> > coordinates = new List <List <int> >(); if (this._cardController.boardLocation == Location.HAND) { return(squares); } if (this._cardController.boardLocation != Location.BATTLEFIELD) { Debug.LogWarning("Card is not on the battlefield!"); return(null); } // Card is on the battlefield var currentLocation = this.square.GetComponent <SquareController>().battlefieldLocation; // Add the coordinates of squares in the attack distance for (int i = 1; i <= this._unit.attackDistance; i++) { coordinates.Add(new List <int> { currentLocation[0] - i, currentLocation[1] }); coordinates.Add(new List <int> { currentLocation[0] + i, currentLocation[1] }); coordinates.Add(new List <int> { currentLocation[0], currentLocation[1] - i }); coordinates.Add(new List <int> { currentLocation[0], currentLocation[1] + i }); } for (int i = 1; i <= this._unit.diagonalAttackDistance; i++) { coordinates.Add(new List <int> { currentLocation[0] - i, currentLocation[1] - i }); coordinates.Add(new List <int> { currentLocation[0] - i, currentLocation[1] + i }); coordinates.Add(new List <int> { currentLocation[0] + i, currentLocation[1] - i }); coordinates.Add(new List <int> { currentLocation[0] + i, currentLocation[1] + i }); } // Get rid of the coordinates that are not on the battlefield foreach (List <int> coor in coordinates) { if (coor[0] >= 0 && coor[0] < this._battlefield.width && coor[1] >= 0 && coor[1] < this._battlefield.height) { possibleSquaresInAttackDistance.Add(this._battlefield.GetSquareAt(coor[0], coor[1])); } } // Get rid of the squares with no units or friendly units on them foreach (Transform sq in possibleSquaresInAttackDistance) { CardController card = sq.GetComponent <SquareController>().card; if (card != null && card.GetComponent <UnitController>().ownedBy != this.ownedBy) { squares.Add(sq); } } return(squares); }