public void AttackCard(Card attackingCard, Card attackedCard) { BattleRow attackedCardRow = attackedCard.currentRow; attackedCard.OnCardAttacked(attackingCard); attackingCard.OnCardAttack(); if (attackedCard.ShouldBeDestroyed()) { UnitAttackType attackingUnitAttackType = attackingCard.GetUnitInstance().GetUnit().unitAttackType; if (attackingUnitAttackType == UnitAttackType.Melee) { if (attackedCardRow.GetCardsFromCountryOtherThatArgument(attackingCard.Country).Count <= 0) { MoveCardToRow(attackingCard, attackedCardRow.RowIndex); } } attackedCard.currentRow.RemoveCardFromRow(attackedCard); //Remove card from proper controller (AI or Player) if (attackedCard.Country.isPlayerCountry) { RemovePlayerCard(attackedCard); } else { BattleAI.instance.RemoveCard(attackedCard); } Destroy(attackedCard.gameObject); } }
public bool MoveCardToOtherRow(Card card, int targetRowIndex) { if (HaveCardEnoughStaminaToMove(card, targetRowIndex) && battlefield.IsRoadToRowClear(card, targetRowIndex)) { BattleRow targetRow = battlefield.MoveCardToRow(card, targetRowIndex); currentCardAction = new CardActionMove(card, card.gameObject, new Vector3(targetRow.transform.position.x, card.transform.position.y, targetRow.transform.position.z)); return(true); } return(false); }
void HighlightRowOnProperColor(int i, Card card, int maxMoveDistance, ref bool foundEnemyCard) { BattleRow targetRow = GetBattleRowByIndex(i); if (i != card.currentRow.RowIndex) { if (targetRow.GetCardsFromCountryOtherThatArgument(card.Country).Count > 0) { foundEnemyCard = true; rows[i].SetHighlightActive(true, BattleRow.HighlightType.Attack); } else if (!foundEnemyCard && Mathf.Abs(i - card.currentRow.RowIndex) <= maxMoveDistance) { rows[i].SetHighlightActive(true, BattleRow.HighlightType.Normal); } } }
void GenerateBattlefield(int width) { InitRows(); for (int i = 0; i < width; i++) { Vector3 targetPos = new Vector3((i * rowWidth) - (rowWidth * (width - 1)) / 2f, -0.9f, 0) + battlefieldCenter.position; BattleRow battleRow = Instantiate(rowPrefab, targetPos, Quaternion.Euler(0, 0, 0)); battleRow.transform.localScale = new Vector3(rowWidth, 1, 17.5f); battleRow.transform.SetParent(transform); battleRow.Setup(i); battleRow.GetComponent <BoxCollider>().enabled = false; battleRow.GetComponent <BoxCollider>().enabled = true; rows[i] = battleRow; } }
IEnumerator MakeTurnWait() { List <Card> cards = myCards.GetCards(); for (int i = 0; i < cards.Count; i++) { Card currCard = cards[i]; BattleRow nextRow = GetRowWithOffsetFromCard(currCard, 1); if (nextRow) { //Move(currCard); int maxRowsAvailableToMove = 0; for (int j = 0; j <= currCard.GetUnitInstance().currentStamina; j++) { StartCoroutine(AttackIfCan(currCard)); yield return(new WaitUntil(() => attackFinished)); attackFinished = false; if (nextRow) { if (nextRow.GetCardsFromCountryOtherThatArgument(currCard.Country).Count <= 0) { maxRowsAvailableToMove++; } else { break; } } BattleRow destinationRow = GetRowWithOffsetFromCard(currCard, 1); BattleController.instance.MoveCardToOtherRow(currCard, destinationRow.RowIndex); yield return(new WaitUntil(() => BattleController.instance.IsCardActionFinished())); } } yield return(new WaitUntil(() => BattleController.instance.IsCardActionFinished())); } }
IEnumerator AttackIfCan(Card controlledCard) { int rowOffset = 1; BattleRow nextRow = GetRowWithOffsetFromCard(controlledCard, rowOffset); while (nextRow && controlledCard.GetUnitInstance().currentStamina >= 1 && controlledCard.GetUnitInstance().GetUnit().attackRange >= rowOffset) { List <Card> cardsToAttack = nextRow.GetCardsFromCountryOtherThatArgument(controlledCard.Country); Card cardToAttack = null; if (cardsToAttack.Count > 0) { cardToAttack = cardsToAttack[0]; BattleController.instance.AttackCard(controlledCard, cardToAttack); yield return(new WaitUntil(() => BattleController.instance.IsCardActionFinished())); } else { rowOffset++; nextRow = GetRowWithOffsetFromCard(controlledCard, rowOffset); } } attackFinished = true; }