public void DrawOneCard() { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)] }; GameObject gc = GameObject.FindGameObjectWithTag("GameController"); gc.GetComponent <V_GameManager> ().DrawACard(picks); }
public void AttackPlayer(V_Card card) { gm.aiCurSelected = card; gm.AI_AttackEnemyPlayer(); Debug.Log("AI is attacking our base!"); i = 0; }
public void DestroyThisCard() { //send to graveyard instead V_Card thisCard = card; if (thisCard.health <= 0 || card.isDestroyed) { Instantiate(thisCard.deathEffect, thisCard.transform); if (gameObject.tag == "PlayerOwned") { gameObject.tag = "InGrave"; transform.SetParent(V_GameManager.graveZone.transform); V_GameManager.graveZone.GetComponent <V_Graveyard>().AddToGraveyard(gameObject); curParent = V_GameManager.graveZone.transform; } else { if (gm.ActiveCards.Find(x => gameObject) != null) { gameObject.tag = "InGrave"; } else { Destroy(gameObject, 1f); } } } }
public void AttackPlayer(V_Card card) { gm.GetComponent <V_GameManager> ().aiCurSelected = card; gm.GetComponent <V_GameManager> ().AI_AttackEnemyPlayer(); Debug.Log("AI is attacking our base!"); i = 0; }
public void DestroyThisCard(){ V_Card thisCard = this.GetComponent<V_Card> (); if (thisCard.health <= 0) { Instantiate (thisCard.deathEffect, thisCard.transform); Destroy (gameObject, 1f); } }
public void LoseACard(V_Card[] cards) { foreach (V_Card card in cards) { V_Card curCard = Instantiate(card, graveZone.transform); curCard.cActions.isInGame = true; } }
/*public void AISelect(){ * if (!isUsed && gameObject.tag == "AIOwned") { * if (isSelected) { * gm.aiCurSelected = null; * isSelected = false; * } else { * isSelected = true; * gm.aiCurSelected = card; * * Debug.Log ("AI has selected a card!"); * } * } * * }*/ //USE THIS FOR ATTACKING/USING ACTIONS public void Use(V_Card target) { V_Card thisCard = card; thisCard.isAttacking = true; Debug.Log("Player attacked!"); if (target.gameObject.tag == "AIOwned" && this.tag == "PlayerOwned") { if (thisCard.type == V_Card.cardType.Creature && V_GameManager.CardGameState == V_GameManager.currentState.war) { AttackEffect(target, null); // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // We damaged effect: Text us = Instantiate(V_GameManager.sdamageEffect, thisCard.transform) as Text; us.text = "-" + target.attackDamage; // target.health -= thisCard.attackDamage + card.PowerAttack - target.Armor; thisCard.health -= target.attackDamage - target.Armor; target.cardHealthHandler.text = target.health.ToString(); thisCard.cardHealthHandler.text = thisCard.health.ToString(); thisCard.DoEffect(); //AHA THERE IT IS. COMBAT EFFECTS thisCard.actions--; target.actions--; DestroyThisCard(); target.cActions.DestroyThisCard(); isUsed = true; } } if (target.gameObject.tag == "PlayerOwned" && this.tag == "AIOwned") { if (thisCard.type == V_Card.cardType.Creature && V_GameManager.CardGameState == V_GameManager.currentState.war) { Debug.Log("AI attacked!"); AttackEffect(target, null); // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // We damaged effect: Text us = Instantiate(V_GameManager.sdamageEffect, thisCard.transform) as Text; us.text = "-" + target.attackDamage; // target.health -= thisCard.attackDamage + card.PowerAttack - target.Armor; thisCard.health -= target.attackDamage - target.Armor; target.cardHealthHandler.text = target.health.ToString(); thisCard.cardHealthHandler.text = thisCard.health.ToString(); thisCard.DoEffect(); //here thisCard.actions--; target.actions--; DestroyThisCard(); target.cActions.DestroyThisCard(); isUsed = true; } } thisCard.isAttacking = false; }
// Use this for initialization void Start() { // References: gm = GameObject.FindObjectOfType <V_GameManager>(); card = gameObject.GetComponent <V_Card> (); if (isInGame) { curParent = V_GameManager.handZone.transform; Brendrr = V_GameManager.battleZone.GetComponent <Image> (); Srendrr = V_GameManager.spellZone.GetComponent <Image> (); } }
//public void UniqueEffectActivate()//we may not need this... we'll see... //{ // switch (SpecialEffect) // { // case UniqueEffect.None: // break; // case UniqueEffect.WebCrawler_OnAttack: // // WebCrawler(); // break; // default: // break; // } //} public void WebCrawler(V_Card target) { if (target != null) { if (target.speed == 0) { this.PowerAttack = 50; } else { this.PowerAttack = 0; } } }
public void StartDraw() { if (V_GameManager.playerTurn == V_GameManager.playerTypes.Us) { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)] }; GameObject gc = GameObject.FindGameObjectWithTag("GameController"); gc.GetComponent <V_GameManager> ().Redraw(picks); } }
public void AttackPlayer(V_Card card, playerTypes who) { if (who == playerTypes.Player) { GameObject targetPlayer = GameObject.FindGameObjectWithTag("Player"); card.cActions.UseToPlayer(targetPlayer); } if (who == playerTypes.AI) { GameObject targetPlayer = GameObject.FindGameObjectWithTag("AIPlayer"); card.cActions.UseToPlayer(targetPlayer); } }
public void StartDraw() { if (V_GameManager.playerTurn == V_GameManager.playerTypes.Player) { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)] }; gm.Redraw(picks); } V_GameManager.initialsetup = false; }
//add all unique attack effects here. public void AttackEffect(V_Card target, GameObject targetplayer) { if (card.SpecialTiming == V_Card.UniqueEffectType.Attack) { switch (card.SpecialEffect) { case V_Card.UniqueEffect.WebCrawler_OnAttack: card.WebCrawler(target); break; default: break; } } }
// This is called by the Player: public void AttackEnemyPlayer() { if (curSelected != null) { if (curSelected.canBeUsedTo == V_Card.usage.All || curSelected.canBeUsedTo == V_Card.usage.BaseOnly) { AttackPlayer(curSelected, playerTypes.AI); curSelected = null; } else { // Display error if the selected card is not usable to a player base: DisplayError(cantBeUsedToBase); } } }
///This will be for once we add gewnerators to the game. //public void UsetoGenerator(V_Card target) //{ // V_Card thisCard = card; // Debug.Log("AI attacked!"); // if (target.gameObject.tag == "AIOwned" && this.tag == "PlayerOwned") // { // if (thisCard.type == V_Card.cardType.Creature) // { // // We damaged effect: // Text us = Instantiate(V_GameManager.sdamageEffect, thisCard.transform) as Text; // us.text = "-" + target.attackDamage; // // // target.health -= thisCard.attackDamage; // thisCard.health -= target.attackDamage; // target.cardHealthHandler.text = target.health.ToString(); // thisCard.cardHealthHandler.text = thisCard.health.ToString(); // thisCard.DoEffect(); // DestroyThisCard(); // target.cActions.DestroyThisCard(); // isUsed = true; // } // } // if (target.gameObject.tag == "PlayerOwned" && this.tag == "AIOwned") // { // if (thisCard.type == V_Card.cardType.Creature) // { // Debug.Log("AI attacked!"); // // Enemy damaged effect: // Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; // enemy.text = "-" + thisCard.attackDamage; // // // target.health -= thisCard.attackDamage; // thisCard.health -= target.attackDamage; // target.cardHealthHandler.text = target.health.ToString(); // thisCard.cardHealthHandler.text = thisCard.health.ToString(); // thisCard.DoEffect(); // DestroyThisCard(); // target.cActions.DestroyThisCard(); // isUsed = true; // } // } //} public void UseToPlayer(GameObject target) //for attacking players. { V_Card thisCard = card; thisCard.isAttacking = true; Debug.Log("AI attacked!"); if (target.tag == "Player") { V_GameManager.CardGameState = V_GameManager.currentState.war; //testing if (thisCard.type == V_Card.cardType.Creature && V_GameManager.CardGameState == V_GameManager.currentState.war) { AttackEffect(null, target); // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.energyCost; // V_PlayerHandler.health -= thisCard.energyCost; //this can be changed to make people discard from the deck instead. for (int i = thisCard.energyCost; i > 0; i--) { if (V_PlayerHandler.health > 0) { target.GetComponent <V_PlayerHandler>().TakeDamage();//returns null after a player has lost. } } thisCard.DoEffect(); thisCard.actions--; isUsed = true; } } if (target.tag == "AIPlayer") { if (thisCard.type == V_Card.cardType.Creature && V_GameManager.CardGameState == V_GameManager.currentState.war) { AttackEffect(null, target); // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.energyCost; // V_AI.health -= thisCard.energyCost; //same here thisCard.DoEffect(); thisCard.actions--; isUsed = true; } } thisCard.isAttacking = false; }
// Called by the Redraw() function in the V_PlayerHandler script: public void Redraw(V_Card[] cards) { RectTransform[] childCards = handZone.transform.GetComponentsInChildren <RectTransform> (); foreach (RectTransform t in childCards) { if (t.gameObject.tag == "InHand" && t.gameObject != this.gameObject) { Destroy(t.gameObject); } } foreach (V_Card card in cards) { V_Card curCard = Instantiate(card, handZone.transform); curCard.cActions.isInGame = true; } }
// This is called by the AI: public void AI_AttackEnemyPlayer() { if (aiCurSelected != null) { // if the card is usable to enemy bases then attack... if (aiCurSelected.canBeUsedTo == V_Card.usage.All || aiCurSelected.canBeUsedTo == V_Card.usage.BaseOnly) { AttackPlayer(aiCurSelected, playerTypes.Player); aiCurSelected = null; // ...else, restart the action: } else { V_AI ai = GameObject.Find("_AI").GetComponent <V_AI> (); ai.AITurn(); } } }
// This function allows the AI to deploy cards: public void PlaceCard(V_Card card) { // If the card is a CREATURE card... if (card.type == V_Card.cardType.Creature) { GameObject obj = Instantiate(card.gameObject, V_GameManager.aiBattleZone.transform) as GameObject; obj.tag = "AIOwned"; } // ... but if it's a SPELL card: if (card.type == V_Card.cardType.Event) { GameObject obj = Instantiate(card.gameObject, V_GameManager.aiSpellZone.transform) as GameObject; obj.tag = "AIOwned"; // and because it's a spell card, do it's effect: obj.GetComponent <V_Card> ().DoEffectAI(); } }
public void UseToPlayer(GameObject target){ V_Card thisCard = this.GetComponent<V_Card> (); Debug.Log ("AI attacked!"); if (target.tag == "Player") { if (thisCard.type == V_Card.cardType.Close_Rage_Creature) { // Enemy damaged effect: Text enemy = Instantiate (V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // V_PlayerHandler.health -= thisCard.attackDamage; isUsed = true; } else if (thisCard.type == V_Card.cardType.Long_Rage_Creature) { // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // V_PlayerHandler.health -= thisCard.attackDamage; isUsed = true; } } if (target.tag == "AIPlayer") { if (thisCard.type == V_Card.cardType.Close_Rage_Creature) { // Enemy damaged effect: Text enemy = Instantiate (V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // V_AI.health -= thisCard.attackDamage; isUsed = true; } if (thisCard.type == V_Card.cardType.Long_Rage_Creature) { // Enemy damaged effect: Text enemy = Instantiate(V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // V_AI.health -= thisCard.attackDamage; isUsed = true; } } }
public void ReDraw() { if (energy >= gm.drawCost && V_GameManager.playerTurn == V_GameManager.playerTypes.Player) { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)] }; gm.Redraw(picks); energy -= gm.drawCost; } else { // Display error: gm.DisplayError(gm.noEnergy); } }
public void ReDraw() { gm = GameObject.FindGameObjectWithTag("GameController"); if (energy >= gm.GetComponent <V_GameManager> ().drawCost&& V_GameManager.playerTurn == V_GameManager.playerTypes.Us) { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)], myDeck [Random.Range(0, myDeck.Length)] }; GameObject gc = GameObject.FindGameObjectWithTag("GameController"); gc.GetComponent <V_GameManager> ().Redraw(picks); energy -= gm.GetComponent <V_GameManager> ().drawCost; } else { // Display error: gm.GetComponent <V_GameManager> ().DisplayError(gm.GetComponent <V_GameManager> ().noEnergy); } }
/*public void AISelect(){ if (!isUsed && gameObject.tag == "AIOwned") { if (isSelected) { gm.GetComponent<V_GameManager> ().aiCurSelected = null; isSelected = false; } else { isSelected = true; gm.GetComponent<V_GameManager> ().aiCurSelected = gameObject.GetComponent<V_Card> (); Debug.Log ("AI has selected a card!"); } } }*/ public void Use(V_Card target){ V_Card thisCard = this.GetComponent<V_Card> (); Debug.Log ("AI attacked!"); if (target.gameObject.tag == "AIOwned" && this.tag == "PlayerOwned") { if (thisCard.type == V_Card.cardType.Close_Rage_Creature) { // Enemy damaged effect: Text enemy = Instantiate (V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // We damaged effect: Text us = Instantiate (V_GameManager.sdamageEffect, thisCard.transform) as Text; us.text = "-" + target.attackDamage; // target.health -= thisCard.attackDamage; thisCard.health -= target.attackDamage; thisCard.DoEffect (); DestroyThisCard (); target.GetComponent<V_CardActions> ().DestroyThisCard (); isUsed = true; } } if (target.gameObject.tag == "PlayerOwned" && this.tag == "AIOwned") { if (thisCard.type == V_Card.cardType.Close_Rage_Creature) { Debug.Log ("AI attacked!"); // Enemy damaged effect: Text enemy = Instantiate (V_GameManager.sdamageEffect, target.transform) as Text; enemy.text = "-" + thisCard.attackDamage; // We damaged effect: Text us = Instantiate (V_GameManager.sdamageEffect, thisCard.transform) as Text; us.text = "-" + target.attackDamage; // target.health -= thisCard.attackDamage; thisCard.health -= target.attackDamage; thisCard.DoEffect (); DestroyThisCard (); target.GetComponent<V_CardActions> ().DestroyThisCard (); isUsed = true; } } }
public void ViewCard(V_Card card) { // Dispose any viewed card first (if there's any): foreach (Transform t in container) { Destroy(t.gameObject); } // ...then instantiate a new one: V_Card c = null; if (card.tag == "AIOwned") { for (int i = 0; i < ai.aiCards.Length; i++) { if (card.cardName == ai.aiCards [i].cardName) { c = Instantiate(ai.aiCards [i], container); print("Found it!"); break; } } } else { for (int i = 0; i < player.myDeck.Length; i++) { if (card.cardName == player.myDeck [i].cardName) { c = Instantiate(player.myDeck [i], container); print("Found it!"); break; } } } c.cActions.enabled = false; c.enabled = false; c.tag = "Untagged"; closed = false; }
/// <summary> /// AITurn Function: The main BRAIN /// This function is where the AI's decisions are made. It holds the logics /// which make the AI decide its next move. This is tailored to the current setup /// so if something's changed, it might affect the AI's performance... /// "Modify at your own RISK!" /// </summary> public void AITurn() { if (!gm.isGameOver) { //Set all the variables needed: bool attack = Random.Range(0, 6) < 2? true : false; V_Card chosenCard = aiCards [Random.Range(0, aiCards.Length)]; GameObject[] card = GameObject.FindGameObjectsWithTag("AIOwned"); GameObject[] target = GameObject.FindGameObjectsWithTag("PlayerOwned"); // Logics! if (energy <= 0) { Debug.Log("AI plans to attack our base!"); if (card.Length >= 1) { if (card.Length > 0) { Debug.Log("AI will find some enemies..."); for (int n = 0; n < card.Length; n++) { if (card [n].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.All || card [n].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.BaseOnly) { if (card [n].GetComponent <V_CardActions> ().isUsed == false) { Debug.Log("Can't find enemies so " + card [n].name + " will attack the player base."); AttackPlayer(card [n].GetComponent <V_Card> ()); return; } } else { if (target.Length >= 1) { Debug.Log("AI found some enemies so " + card [n].name + " will attack one of player's cards!"); UseACard(card [n].GetComponent <V_CardActions> (), target [Random.Range(0, target.Length)].GetComponent <V_Card> ()); return; } else { if (n >= card.Length) { Debug.Log("Finished!"); AIEndTurn(); } else { } } } } AIEndTurn(); } } else { Debug.Log("2"); AIEndTurn(); } } else { // If the AI chose to deploy a card than to attack: if (!attack) { // ... and when the AI has enough energy to place the card and the Battle Zone still has slot, do: if (V_GameManager.aiBattleZone.transform.childCount < 6 && chosenCard.energyCost <= energy) { PlaceCard(chosenCard); energy -= chosenCard.energyCost; return; } /// But if there's no more room for cards then check if our Battle Zone is /// not empty and if there are cards in the player's Battle Zone: else { // If we have any cards in our battleground that we can use then do the following... if (card.Length > 0) { // if there are cards on the opponent's battleground, attack one of them... int index = Random.Range(0, card.Length); if (target.Length > 0 && card [index].GetComponent <V_CardActions> ().isUsed == false) { if (card [index].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.All || card [index].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.CardsOnly) { UseACard(card [index].GetComponent <V_CardActions> (), target [Random.Range(0, target.Length)].GetComponent <V_Card> ()); } Debug.Log("AI is attacking one of our cards!"); return; } //...but if there is none, then attack the opponent's base instead: else { if (i <= card.Length) { i += 1; GameObject cc = card [Random.Range(0, card.Length)]; if (cc.GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.All || cc.GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.BaseOnly) { if (cc.GetComponent <V_CardActions> ().isUsed == false) { AttackPlayer(cc.GetComponent <V_Card> ()); return; } else { AIEndTurn(); } } else { Debug.Log("The AI is attempting to find a card to be used against us..."); AITurn(); } } else { // ...else, end the turn: AIEndTurn(); } } } // ...but if we don't have one then just end our turn, or deploy a card if we still have some energy: else { //checking if we still have some energy... if (energy <= 0) { AIEndTurn(); } else { AITurn(); } } } } // ...but if it's the empty slot, use random deployed card: else { // Check if we already have cards deployed in our Battle Zone, proceed if we have, restart move if we don't: if (card.Length > 0) { int index = Random.Range(0, card.Length); if (target.Length > 0 && card [index].GetComponent <V_CardActions> ().isUsed == false) { if (card [index].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.All || card [index].GetComponent <V_Card> ().canBeUsedTo == V_Card.usage.CardsOnly) { UseACard(card [index].GetComponent <V_CardActions> (), target [Random.Range(0, target.Length)].GetComponent <V_Card> ()); } Debug.Log("AI is attacking one of our cards!"); return; } else { AITurn(); } } else { AITurn(); } } } } }
public void DrawOneCard() { V_Card[] picks = new V_Card[] { myDeck [Random.Range(0, myDeck.Length)] }; gm.DrawACard(picks); }
public void UseACard(V_CardActions card, V_Card target) { card.Use(target); }
public void TakeDamage() { V_Card[] picks = new V_Card[] { myDeck[Random.Range(0, myDeck.Length)] }; gm.LoseACard(picks); }