public void OnPointerDown(PointerEventData data) { if (this._gameState.selectedCard != null && this._gameState.phaseState.Id() != "AttackPhase") { CardController cardController = this._gameState.selectedCard.GetComponent <CardController>(); UnitController unitController = cardController.GetComponent <UnitController>(); if (cardController.boardLocation == Location.HAND) { this._battlefield.AddCard(this._gameState.selectedCard); } var moveSquares = unitController.SquaresInMoveDistance(); if (this.GetComponent <SquareController>().card == null) { // Move action if (moveSquares.Contains(this.transform)) { if (cardController.ownedBy == Owner.PLAYER && cardController.boardLocation == Location.HAND && cardController.GetComponent <Card>().manaCost <= this._gameState.playerPlayerController.mana) { this._gameState.playerPlayerController.mana -= cardController.GetComponent <Card>().manaCost; } else if (cardController.ownedBy == Owner.ENEMY && cardController.boardLocation == Location.HAND && cardController.GetComponent <Card>().manaCost <= this._gameState.enemyPlayerController.mana) { this._gameState.enemyPlayerController.mana -= cardController.GetComponent <Card>().manaCost; } if (cardController.boardLocation == Location.HAND) { unitController.PlayCard(this.transform); } else { unitController.MoveCard(this.transform); } unitController.transform.SetParent(this.transform); } } // reset all the squares to clear this._battlefield.ResetSquareBorders(); this._gameState.ResetCardColors(); this._gameState.ColorPlayableAndMovableCards(); this._gameState.selectedCard = null; } }
public void Init(List <string> cardList) { this._cards = new List <Transform>(); CardFactory factory = new CardFactory(); if (this.gameObject.name == "PlayerDeck") { foreach (string str in cardList) { CardController card = factory.CreateCard(str).GetComponent <CardController>(); card.GetComponent <UnitController>().Init(Owner.PLAYER); Unit data = card.GetComponent <Unit>(); CanvasGroup canvasGroup = card.GetComponent <CanvasGroup>(); card.GetComponentInChildren <Text>().text = data.name + "\nMana: " + data.manaCost.ToString() + "\nAttack: " + data.attack.ToString() + "\nHealth: " + data.health.ToString(); card.Init(Owner.PLAYER); card.transform.SetParent(GameObject.Find("PlayerDeckPanel/PlayerDeck").transform); canvasGroup.alpha = 0f; canvasGroup.blocksRaycasts = false; this._cards.Add(card.transform); } } else { foreach (string str in cardList) { CardController card = factory.CreateCard(str).GetComponent <CardController>(); card.GetComponent <UnitController>().Init(Owner.ENEMY); Unit data = card.GetComponent <Unit>(); CanvasGroup canvasGroup = card.GetComponent <CanvasGroup>(); card.GetComponentInChildren <Text>().text = data.name + "\nMana: " + data.manaCost.ToString() + "\nAttack: " + data.attack.ToString() + "\nHealth: " + data.health.ToString(); card.Init(Owner.ENEMY); card.transform.SetParent(GameObject.Find("EnemyDeckPanel/EnemyDeck").transform); canvasGroup.alpha = 0f; canvasGroup.blocksRaycasts = false; this._cards.Add(card.transform); } } }
public void SetNewCard(CardController card) { this._cardController = card; this._unitController = card.GetComponent <UnitController>(); }
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); }