public void PlaceCard(CardBehaviourScript card) { if (card.team == CardBehaviourScript.Team.My && MyMana - card.mana >= 0 && MyTableCards.Count < 10) { //card.gameObject.transform.position = MyTablePos.position; card.GetComponent <CardBehaviourScript>().newPos = MyTablePos.position; MyHandCards.Remove(card.gameObject); MyTableCards.Add(card.gameObject); card.SetCardStatus(CardBehaviourScript.CardStatus.OnTable); //PlaySound(cardDrop); if (card.cardtype == CardBehaviourScript.CardType.Magic)///Apply Magic Effect { card.canPlay = true; if (card.cardeffect == CardBehaviourScript.CardEffect.ToAll) { card.AddToAll(card, true, delegate { card.Destroy(card); }); } else if (card.cardeffect == CardBehaviourScript.CardEffect.ToEnemies) { card.AddToEnemies(card, AITableCards, true, delegate { card.Destroy(card); }); } } MyMana -= card.mana; } if (card.team == CardBehaviourScript.Team.AI && AIMana - card.mana >= 0 && AITableCards.Count < 10) { //card.gameObject.transform.position = AITablePos.position; card.GetComponent <CardBehaviourScript>().newPos = AITablePos.position; AIHandCards.Remove(card.gameObject); AITableCards.Add(card.gameObject); card.SetCardStatus(CardBehaviourScript.CardStatus.OnTable); //PlaySound(cardDrop); if (card.cardtype == CardBehaviourScript.CardType.Magic)///Apply Magic Effect { card.canPlay = true; if (card.cardeffect == CardBehaviourScript.CardEffect.ToAll) { card.AddToAll(card, true, delegate { card.Destroy(card); }); } else if (card.cardeffect == CardBehaviourScript.CardEffect.ToEnemies) { card.AddToEnemies(card, MyTableCards, true, delegate { card.Destroy(card); }); } } AIMana -= card.mana; } TablePositionUpdate(); HandPositionUpdate(); UpdateGame(); }
public void PlaceCard(CardBehaviourScript temp) { // //Find That Card // CardBehaviourScript card = AIHandCards.Find(item => item._name == temp._name); if (card.team == CardBehaviourScript.Team.AI && AIMana - card.mana >= 0 && AITableCards.Count < 10) { AIHandCards.Remove(card); AITableCards.Add(card); Action a; a.Card1 = card._name; a.Card2 = ""; a.Hero = ""; a.OpCode = 0; Actions.Enqueue(a); card.SetCardStatus(CardBehaviourScript.CardStatus.OnTable); if (card.cardtype == CardBehaviourScript.CardType.Magic)///Apply Magic Effect { card.canPlay = true; if (card.cardeffect == CardBehaviourScript.CardEffect.ToAll) { card.AddToAll(card, false, delegate { card.Destroy(card); }); } else if (card.cardeffect == CardBehaviourScript.CardEffect.ToEnemies) { card.AddToEnemies(card, PlayerTableCards, false, delegate { card.Destroy(card); }); } } AIMana -= card.mana; } }
private void CardMagicCard(CardBehaviourScript _attacker, CardBehaviourScript _target) { CardBehaviourScript attacker = AITableCards.Find(item => item._name == _attacker._name); CardBehaviourScript target = PlayerTableCards.Find(item => item._name == _target._name); { Action a; a.Card1 = attacker._name; a.Card2 = target._name; a.Hero = ""; a.OpCode = 3; Actions.Enqueue(a); attacker.AddToMonster(attacker, target, false, delegate { attacker.Destroy(attacker); }); } }
public void AttackCard(HeroBehaviourScript attacker, CardBehaviourScript target, CustomAction action) { if (attacker.CanAttack) { target.health -= attacker._Attack; attacker.health -= target._Attack; if (target.health <= 0) { target.Destroy(target); } //if (attacker.health <= 0) //{ // BoardBehaviourScript.instance. //} action(); BoardBehaviourScript.instance.AddHistory(attacker, target); } }
public void AttackCard(CardBehaviourScript attacker, CardBehaviourScript target, bool addhistory, CustomAction action) { if (attacker.canPlay) { target.health -= attacker._Attack; attacker.health -= target._Attack; if (target.health <= 0) { Destroy(target); } if (attacker.health <= 0) { attacker.Destroy(attacker); } action(); if (addhistory) { BoardBehaviourScript.instance.AddHistory(attacker, target); } } }//Attack
void AIGetAttacks() { AIGameState InitialState = new AIGameState(/*MyHandCards,*/ MyTableCards, AIHandCards, AITableCards, MyHero, AIHero, maxMana, MyMana, AIMana, turn, null); InitialState.GetAllAttackingActions(AILEVEL); //Find Best Score float MaxScore = float.MinValue; AIGameState BestState = new AIGameState(); foreach (AIGameState item in AIGameState.AllStates) { if (item.State_Score > MaxScore) { MaxScore = item.State_Score; BestState = item; } } //Debug.Log("Best choice Index" + BestState.Index); int count = BestState.Actions.Count; //GetActions for (int i = 0; i < count; i++) { AIGameState.Action a; a = BestState.Actions.Dequeue(); if (a.OpCode == 1) { foreach (var item in AITableCards)//Find Card1 { if (item.GetComponent <CardBehaviourScript>()._name == a.Card1) { currentCard = item.GetComponent <CardBehaviourScript>(); break; } } foreach (var item in MyTableCards)//Find Card2 { if (item.GetComponent <CardBehaviourScript>()._name == a.Card2) { targetCard = item.GetComponent <CardBehaviourScript>(); break; } } if (currentCard != null && targetCard != null)//MakeAction { currentCard.AttackCard(currentCard, targetCard, true, delegate { currentCard.canPlay = false; }); } } else if (a.OpCode == 2) { foreach (var item in AITableCards)//Find Card1 { if (item.GetComponent <CardBehaviourScript>()._name == a.Card1) { currentCard = item.GetComponent <CardBehaviourScript>(); break; } } if (a.Hero == "MyHero") { targetHero = MyHero; } if (currentCard != null && targetHero != null) { currentCard.AttackHero(currentCard, MyHero, true, delegate { currentCard.canPlay = false; }); } } else if (a.OpCode == 3) { foreach (var item in AITableCards)//Find Card1 { if (item.GetComponent <CardBehaviourScript>()._name == a.Card1) { currentCard = item.GetComponent <CardBehaviourScript>(); break; } } foreach (var item in MyTableCards)//Find Card2 { if (item.GetComponent <CardBehaviourScript>()._name == a.Card2) { targetCard = item.GetComponent <CardBehaviourScript>(); break; } } if (currentCard != null && targetCard != null)//MakeAction { currentCard.AddToMonster(currentCard, targetCard, true, delegate { currentCard.Destroy(currentCard); }); } } } //AIGameState.AllStates=new List< AIGameState > (); }
void RendomActions() { #region placing cards //float chanceToPlace = Random.value; if (AIHandCards.Count == 0) { EndTurn(); } else { PlaceRandomCard(CardBehaviourScript.Team.AI); } #endregion #region attacking Hashtable attacks = new Hashtable(); foreach (GameObject Card in AITableCards) { CardBehaviourScript card = Card.GetComponent <CardBehaviourScript>(); if (card.canPlay) { float changeToAttackhero = Random.value; if (changeToAttackhero < 0.50f) { card.AttackHero(card, MyHero, true, delegate { card.canPlay = false; }); } else if (MyTableCards.Count > 0) { int random = Random.Range(0, MyTableCards.Count); GameObject CardToAttack = MyTableCards[random]; attacks.Add(card, CardToAttack.GetComponent <CardBehaviourScript>()); } } } foreach (DictionaryEntry row in attacks) { CardBehaviourScript tempCard = row.Key as CardBehaviourScript; CardBehaviourScript temp2 = row.Value as CardBehaviourScript; if (tempCard.cardtype == CardBehaviourScript.CardType.Monster) { tempCard.AttackCard(tempCard, temp2, true, delegate { tempCard.canPlay = false; }); } else if (tempCard.cardtype == CardBehaviourScript.CardType.Magic) { tempCard.AddToMonster(tempCard, temp2, true, delegate { tempCard.canPlay = false; tempCard.Destroy(tempCard); }); } } #endregion }