public object Clone() { HeroBehaviourScript temp = new HeroBehaviourScript(); temp._name = _name; temp.health = health; temp.CanAttack = CanAttack; temp._Attack = _Attack; return(temp); }
public void AddHistory(CardGameBase a, CardGameBase b) { Hashtable hash = new Hashtable(); hash.Add(a, b); boardHistory.Add(hash); currentCard = null; targetCard = null; currentHero = null; targetHero = null; }
}//Attack public void AttackHero(CardBehaviourScript attacker, HeroBehaviourScript target, bool addhistory, CustomAction action) { if (attacker.canPlay) { target.health -= attacker._Attack; attacker.health -= target._Attack; action(); if (addhistory) { BoardBehaviourScript.instance.AddHistory(attacker, target); } } }//Attack
public void CardAttackHero(CardBehaviourScript _attacker, HeroBehaviourScript _target) { CardBehaviourScript attacker = AITableCards.Find(item => item._name == _attacker._name); Action a; a.Card1 = attacker._name; a.Card2 = ""; a.Hero = _target._name; a.OpCode = 2; Actions.Enqueue(a); attacker.AttackHero(attacker, PlayerHero, false, delegate { attacker.canPlay = false; }); }
public void AttackHero(HeroBehaviourScript attacker, HeroBehaviourScript target, CustomAction action) { if (attacker.CanAttack) { target.health -= attacker._Attack; attacker.health -= target._Attack; if (target.health <= 0) { Destroy(target.gameObject); BoardBehaviourScript.instance.EndGame(attacker); } action(); BoardBehaviourScript.instance.AddHistory(attacker, target); } }
public void AddToHero(CardBehaviourScript magic, HeroBehaviourScript target, CustomAction action) { if (magic.canPlay) { target._Attack += magic.AddedAttack; if (target.health + magic.AddedHealth <= 30) { target.health += magic.AddedHealth; } else { target.health = 30; } action(); BoardBehaviourScript.instance.AddHistory(magic, target); } }//Magic
public void EndGame(HeroBehaviourScript winner) { if (winner == MyHero) { Debug.Log("MyHero"); Time.timeScale = 0; winnertext.text = "You Won"; //Destroy(this); } if (winner == AIHero) { Time.timeScale = 0; Debug.Log("AIHero"); winnertext.text = "You Losse"; //Destroy(this); } }
public AIGameState( //List<CardBehaviourScript> PlayerHand, List <CardBehaviourScript> PlayerTable, List <CardBehaviourScript> AIHand, List <CardBehaviourScript> AITable, HeroBehaviourScript _PlayerHero, HeroBehaviourScript _AIHero, int _MaxMana, int _PlayerMana, int _AIMana, BoardBehaviourScript.Turn _Turn, AIGameState Parent ) { ParentState = Parent; if (ParentState == null) { Index = 0; } else { Index = ParentState.Index + 1; Actions = new Queue <Action>(ParentState.Actions); } //PlayerHandCards = CardListCopier.DeepCopy(PlayerHand); PlayerTableCards = CardListCopier.DeepCopy(PlayerTable); PlayerHero = _PlayerHero.Clone() as HeroBehaviourScript; AIHandCards = CardListCopier.DeepCopy(AIHand); AITableCards = CardListCopier.DeepCopy(AITable); AIHero = _AIHero.Clone() as HeroBehaviourScript; maxMana = _MaxMana; PlayerMana = _PlayerMana; AIMana = _AIMana; turn = _Turn; Calculate_State_Score(); //if (Index <= BoardBehaviourScript.instance.AILEVEL) //{ // GetAllPlacingAction(); // GetAllAttackingActions(); //} AllStates.Add(this); }
void EndTurn() { maxMana += (turnNumber - 1) % 2; if (maxMana >= 10) { maxMana = 10; } MyMana = maxMana; AIMana = maxMana; turnNumber += 1; currentCard = new CardBehaviourScript(); targetCard = new CardBehaviourScript(); currentHero = new HeroBehaviourScript(); targetHero = new HeroBehaviourScript(); foreach (GameObject card in MyTableCards) { card.GetComponent <CardBehaviourScript>().canPlay = true; } foreach (GameObject card in AITableCards) { card.GetComponent <CardBehaviourScript>().canPlay = true; } MyHero.CanAttack = true; AIHero.CanAttack = true; if (turn == Turn.AITurn) { DrawCardFromDeck(CardBehaviourScript.Team.My); turn = Turn.MyTurn; } else if (turn == Turn.MyTurn) { DrawCardFromDeck(CardBehaviourScript.Team.AI); turn = Turn.AITurn; } HandPositionUpdate(); TablePositionUpdate(); OnNewTurn(); }
void Update() { if (Input.GetMouseButtonDown(1)) { currentCard = null; targetCard = null; currentHero = null; targetHero = null; Debug.Log("Action Revet"); } //if(BoardBehaviourScript.instance.currentCard&&BoardBehaviourScript.instance.targetCard) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 250, layer)) { if (hit.transform.CompareTag("Board")) { //do whatever...... //Debug.Log(hit.point); if (BoardBehaviourScript.instance.currentHero) { drawMyLine(BoardBehaviourScript.instance.currentHero.transform.position, hit.point, Color.blue, 0.1f); } if (BoardBehaviourScript.instance.currentCard) { drawMyLine(BoardBehaviourScript.instance.currentCard.transform.position, hit.point, Color.blue, 0.1f); } } } } if (MyHero.health <= 0) { EndGame(AIHero); } if (AIHero.health <= 0) { EndGame(MyHero); } }
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 AIGameState( //List<GameObject> PlayerHand, List <GameObject> PlayerTable, List <GameObject> AIHand, List <GameObject> AITable, HeroBehaviourScript _PlayerHero, HeroBehaviourScript _AIHero, int _MaxMana, int _PlayerMana, int _AIMana, BoardBehaviourScript.Turn _Turn, AIGameState Parent ) { ParentState = Parent; if (ParentState == null) { Index = 0; } else { Index = ParentState.Index + 1; Actions = new Queue <Action>(ParentState.Actions); } //List<CardBehaviourScript> _tempPlayerHand = new List<CardBehaviourScript>(); //foreach (var item in PlayerHand)_tempPlayerHand.Add( item.GetComponent<CardBehaviourScript>()); //PlayerHandCards = CardListCopier<List<CardBehaviourScript>>.DeepCopy(_tempPlayerHand); List <CardBehaviourScript> _tempPlayerTable = new List <CardBehaviourScript>(); foreach (var item in PlayerTable) { _tempPlayerTable.Add(item.GetComponent <CardBehaviourScript>()); } PlayerTableCards = CardListCopier.DeepCopy(_tempPlayerTable); PlayerHero = _PlayerHero.Clone() as HeroBehaviourScript; List <CardBehaviourScript> _tempAIHand = new List <CardBehaviourScript>(); foreach (var item in AIHand) { _tempAIHand.Add(item.GetComponent <CardBehaviourScript>()); } AIHandCards = CardListCopier.DeepCopy(_tempAIHand); List <CardBehaviourScript> _tempAITable = new List <CardBehaviourScript>(); foreach (var item in AITable) { _tempAITable.Add(item.GetComponent <CardBehaviourScript>()); } AITableCards = CardListCopier.DeepCopy(_tempAITable); AIHero = _AIHero.Clone() as HeroBehaviourScript; maxMana = _MaxMana; PlayerMana = _PlayerMana; AIMana = _AIMana; turn = _Turn; Calculate_State_Score(); //if (Index<=BoardBehaviourScript.instance.AILEVEL) //{ // GetAllPlacingAction(); // GetAllAttackingActions(); //} AllStates.Add(this); }
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 > (); }