private void SetAiTypeByDeck() { OpponentDeck deck = _dataManager.CachedOpponentDecksData.Decks.First(d => d.Id == _gameplayManager.OpponentDeckId); SetAiType((Enumerators.AiType)Enum.Parse(typeof(Enumerators.AiType), deck.Type)); }
private async Task PayCasualty() { if (Deck.Count > 0) { Deck[0].FaceUP = true; Casualties.Add(Deck[0]); Log += $"You lost {Deck[0].GetValueStringLog()} as a casualty\n"; Deck.RemoveAt(0); OnPropertyChanged("CasualtyCard"); } await Task.Delay(2000); if (OpponentDeck.Count > 0) { OpponentDeck[0].FaceUP = true; Casualties.Add(OpponentDeck[0]); Log += $"Opponent lost {OpponentDeck[0].GetValueStringLog()} as a casualty\n"; OpponentDeck.RemoveAt(0); OnPropertyChanged("CasualtyCard"); } OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
public void ReturnBattlefields(List <Card> BattleCards, List <Card> OpponentBattleCards) { foreach (Card c in BattleCards) { c.FaceUP = false; Deck.Add(c); } foreach (Card c in OpponentBattleCards) { c.FaceUP = false; OpponentDeck.Add(c); } }
/// <summary> /// Initializes this agent's estimation of the opponent /// </summary> /// <param name="opponent"></param> /// <returns></returns> void SetupOpponent(Game game) { BlindGame = game.Clone(); Opponent = BlindGame.CurrentOpponent; Opponent.Game = BlindGame; OpponentDeck = DeckQuery.GetMostPopular(Opponent.HeroClass); OpponentDeckZone = new DeckZone(Opponent) { Controller = Opponent }; Opponent.Deck = OpponentDeck.Clone(); Opponent.DeckZone = OpponentDeckZone; OpponentGraveyardZone = new GraveyardZone(Opponent); OpponentSecretZone = new SecretZone(Opponent); OpponentSet = true; }
/// <summary> /// Updates this agent's estimation of the opponent /// </summary> void UpdateOpponent(int handSize) { Opponent.Game = BlindGame; Opponent.Deck = OpponentDeck.Clone(); Opponent.DeckZone = OpponentDeckZone.Clone(Opponent); //OpponentDeckZone.Controller = Opponent; OpponentHandZone = new HandZone(Opponent); //{ // Controller = Opponent //}; foreach (Card card in OpponentDeck) { Entity.FromCard(Opponent, card, null, OpponentDeckZone); } foreach (Card card in PlayedSoFar) { if (OpponentDeckZone.Contains(card)) { OpponentDeckZone.Remove(card); } } for (int i = 0; i < handSize; ++i) { IPlayable rnd = OpponentDeckZone.Random; OpponentDeckZone.Remove(rnd); rnd.Controller = OpponentHandZone.Controller; OpponentHandZone.Add(rnd); } Opponent.HandZone = OpponentHandZone.Clone(Opponent); OpponentGraveyardZone = BlindGame.CurrentOpponent.GraveyardZone.Clone(Opponent); if (BlindGame.CurrentOpponent.SecretZone.Count == 0) { OpponentSecretZone = new SecretZone(Opponent); } else if (BlindGame.CurrentOpponent.SecretZone.Count == 1 && BlindGame.CurrentOpponent.SecretZone.Contains(s => s.IsQuest)) { OpponentSecretZone = BlindGame.CurrentOpponent.SecretZone.Clone(Opponent); } else { OpponentSecretZone = new SecretZone(Opponent); if (!OpponentDeck.Contains(c => c.IsSecret)) { AddBlindSecrets(); } else { var secretsPlayed = OpponentGraveyardZone.Where(p => p.Card.IsSecret).ToList(); if (secretsPlayed != null) { List <string> secrets = GetSecrets(Opponent.HeroClass); foreach (Spell s in secretsPlayed) { if (secretsPlayed.Count(s) > 2) { secrets.Remove(s.Card.Name); } } if (secrets.Count != 0) { AddBlindSecrets(secrets); } else { AddBlindSecrets(GetSecrets(Opponent.HeroClass)); } } } } BlindGame.Player2 = Opponent; BlindGame.CurrentPlayer.Game = BlindGame; BlindGame.CurrentOpponent.Game = BlindGame; }
private void SetBattleField() { //start laying out normal for player if (Deck.Count >= 6) { for (int i = 0; i < 6; i++) { BattlefieldLayout[i] = Deck[0]; Deck.RemoveAt(0); } OnPropertyChanged("BattlefieldLayout"); } else { //near end of game for (int i = 0; i < 3; i++) { if (Deck.Count > 0) { BattlefieldLayout[i + 3] = Deck[0]; Deck.RemoveAt(0); } else { BattlefieldLayout[i + 3] = null; } if (Deck.Count > 0) { BattlefieldLayout[i] = Deck[0]; Deck.RemoveAt(0); } else { BattlefieldLayout[i] = null; } } OnPropertyChanged("BattlefieldLayout"); } //Layout battlefield of oppenent if (OpponentDeck.Count >= 6) { for (int i = 0; i < 6; i++) { OpponentBattlefield[i] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } OnPropertyChanged("OpponentBattlefield"); } else { //near end of game for (int i = 0; i < 3; i++) { if (OpponentDeck.Count > 0) { OpponentBattlefield[i + 3] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } else { OpponentBattlefield[i + 3] = null; } if (OpponentDeck.Count > 0) { OpponentBattlefield[i] = OpponentDeck[0]; OpponentDeck.RemoveAt(0); } else { OpponentBattlefield[i] = null; } } OnPropertyChanged("OpponentBattlefield"); } Log += "Battlefields have been laid down.\n"; OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
private void TakeSpoils(bool playerWon, int column, bool playerAttack, bool opponentAttack, List <Card> BattleCards, List <Card> OpponentBattleCards, int aceCount) { if (playerWon) { foreach (Card c in BattleCards) { c.FaceUP = false; Deck.Add(c); } foreach (Card c in OpponentBattleCards) { c.FaceUP = false; Deck.Add(c); } BattleCards.Clear(); OpponentBattleCards.Clear(); if (Pot.Count > 0) { foreach (Card c in Pot) { c.FaceUP = false; Deck.Add(c); } if (BattlefieldLayout.Contains(Pot[0])) { BattlefieldLayout[PotColumn] = null; BattlefieldLayout[PotColumn + 3] = null; OpponentBattlefield[PotColumn] = null; OpponentBattlefield[PotColumn + 3] = null; } Pot.Clear(); } BattlefieldLayout[column] = null; BattlefieldLayout[column + 3] = null; OpponentBattlefield[column] = null; OpponentBattlefield[column + 3] = null; Reinforcement = null; OpponentReinforcement = null; OnPropertyChanged("BattleFieldLayout"); OnPropertyChanged("OpponentBattlefield"); int spoils = 0; spoils += (playerAttack ? 1 : 0) + (opponentAttack ? 1 : 0); if (aceCount > 0) { Log += $"Additional {aceCount} spoils for Aces\n"; spoils += aceCount; } if (playerAttack) { for (int i = 0; i < spoils; i++) { if (OpponentDeck.Count > 0) { Deck.Add(OpponentDeck[0]); Log += $"Oppenent lost {OpponentDeck[0].GetValueStringLog()} as a spoil\n"; OpponentDeck.RemoveAt(0); } } } } else { foreach (Card c in BattleCards) { c.FaceUP = false; OpponentDeck.Add(c); } foreach (Card c in OpponentBattleCards) { c.FaceUP = false; OpponentDeck.Add(c); } BattleCards.Clear(); OpponentBattleCards.Clear(); if (Pot.Count > 0) { foreach (Card c in Pot) { c.FaceUP = false; OpponentDeck.Add(c); } if (BattlefieldLayout.Contains(Pot[0])) { BattlefieldLayout[PotColumn] = null; BattlefieldLayout[PotColumn + 3] = null; OpponentBattlefield[PotColumn] = null; OpponentBattlefield[PotColumn + 3] = null; } Pot.Clear(); } BattlefieldLayout[column] = null; BattlefieldLayout[column + 3] = null; OpponentBattlefield[column] = null; OpponentBattlefield[column + 3] = null; Reinforcement = null; OpponentReinforcement = null; //OnPropertyChanged("Reinforcement"); //OnPropertyChanged("OpponentReinforcement"); OnPropertyChanged("BattlefieldLayout"); OnPropertyChanged("OpponentBattlefield"); int spoils = 0; spoils += (playerAttack ? 1 : 0) + (opponentAttack ? 1 : 0); if (aceCount > 0) { Log += $"Additional {aceCount} spoils for Aces\n"; spoils += aceCount; } if (opponentAttack) { for (int i = 0; i < spoils; i++) { if (Deck.Count > 0) { OpponentDeck.Add(Deck[0]); Log += $"You lost {Deck[0].GetValueStringLog()} as a spoil\n"; Deck.RemoveAt(0); } } } } OnPropertyChanged("DeckCount"); OnPropertyChanged("OpponentDeckCount"); }
private async Task DoBattle(bool playerAttack, bool opponentAttack, int column) { List <Card> BattleCards = new List <Card>(); List <Card> OpponentBattleCards = new List <Card>(); int aceCount = 0; string order = playerAttack ? "attack" : "defend"; Log += $"You order to {order}\n"; order = opponentAttack ? "attack" : "defend"; Log += $"Opponent orders to {order}\n"; if (!playerAttack && !opponentAttack) { //no battle, cards go into pot Log += "Both defend so current cards go into spoils\n"; //Pot.Clear(); await FlipCards(column); Pot.Add(BattlefieldLayout[column]); Pot.Add(BattlefieldLayout[column + 3]); Pot.Add(OpponentBattlefield[column]); Pot.Add(OpponentBattlefield[column + 3]); PotColumn = column; } else { await FlipCards(column); int PlayerTotal = 0; int OpponentTotal = 0; //manage reinforcements and jokers with the battlecards if (BattlefieldLayout[column] != null) { BattleCards.Add(BattlefieldLayout[column]); } if (BattlefieldLayout[column + 3] != null) { BattleCards.Add(BattlefieldLayout[column + 3]); } if (OpponentBattlefield[column] != null) { OpponentBattleCards.Add(OpponentBattlefield[column]); } if (OpponentBattlefield[column + 3] != null) { OpponentBattleCards.Add(OpponentBattlefield[column + 3]); } EvaluateJoker(BattleCards, OpponentBattleCards, out PlayerTotal, out OpponentTotal, out aceCount); Log += $"{PlayerTotal} vs {OpponentTotal}\n"; if (PlayerTotal > OpponentTotal) { //player win Log += "You won the Battle!\n"; TakeSpoils(true, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else if (OpponentTotal > PlayerTotal) { //Opponent win Log += "Opponent won the Battle!\n"; TakeSpoils(false, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else { //Ties will result in reinforcement while (PlayerTotal == OpponentTotal) { Log += "Tie\n"; if (Deck.Count > 0) { Reinforcement = Deck[0]; Deck.RemoveAt(0); Reinforcement.FaceUP = true; BattleCards.Add(Reinforcement); PlayerTotal += Reinforcement.GetValue(); Log += $"You reinforced with {Reinforcement.GetValueStringLog()}\n"; await Task.Delay(1000); } if (OpponentDeck.Count > 0) { OpponentReinforcement = OpponentDeck[0]; OpponentDeck.RemoveAt(0); OpponentReinforcement.FaceUP = true; OpponentBattleCards.Add(OpponentReinforcement); OpponentTotal += OpponentReinforcement.GetValue(); Log += $"Opponent reinforced with {OpponentReinforcement.GetValueStringLog()}\n"; await Task.Delay(1000); } EvaluateJoker(BattleCards, OpponentBattleCards, out PlayerTotal, out OpponentTotal, out aceCount); } if (PlayerTotal > OpponentTotal) { Log += "You won with the reinforcement!\n"; TakeSpoils(true, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } else { Log += "Opponent won with the reinforcement!\n"; TakeSpoils(false, column, playerAttack, opponentAttack, BattleCards, OpponentBattleCards, aceCount); } OpponentReinforcement = null; Reinforcement = null; } } }
public void DealCards() { List <Card> AllCards = new List <Card>(); CardSuit[] Suits = (CardSuit[])Enum.GetValues(typeof(CardSuit)); CardValue[] Vals = (CardValue[])Enum.GetValues(typeof(CardValue)); Deck.Clear(); OpponentDeck.Clear(); Casualties.Clear(); //create cards foreach (var suit in Suits) { foreach (var v in Vals) { Card c = new Card(); c.Suit = suit; c.Value = v; c.FaceUP = false; if (c.Value != CardValue.Joker) { AllCards.Add(c); } } } //Add 2 Jokers Card c3 = new Card(); c3.Value = CardValue.Joker; c3.FaceUP = false; Card c2 = new Card(); c2.Value = CardValue.Joker; c2.FaceUP = false; AllCards.Add(c3); AllCards.Add(c2); //Shuffle the deck int n = AllCards.Count; while (n > 1) { n--; int k = rng.Next(n + 1); Card c = AllCards[k]; AllCards[k] = AllCards[n]; AllCards[n] = c; } //Deal int i = 0; foreach (Card c in AllCards) { if (i % 2 == 0) { Deck.Add(c); } else { OpponentDeck.Add(c); } i++; } Log += "Cards have been dealt.\n"; }
public void StartGame() { if (_battlegroundController == null) { _battlegroundController = _gameplayManager.GetController <BattlegroundController>(); _battlegroundController.PlayerGraveyardUpdated += PlayerGraveyardUpdatedHandler; _battlegroundController.OpponentGraveyardUpdated += OpponentGraveyardUpdatedHandler; } _gameplayManager.PlayerDeckId = CurrentDeckId; OpponentDeck randomOpponentDeck = _dataManager.CachedOpponentDecksData.Decks[ Random.Range(0, _dataManager.CachedOpponentDecksData.Decks.Count)]; _gameplayManager.OpponentDeckId = randomOpponentDeck.Id; //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo); //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo); //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo.HeroId); int heroId = 0; //Constants.TutorialPlayerHeroId; // TUTORIAL int opponentHeroId = 0; if (!_gameplayManager.IsTutorial) { heroId = _dataManager.CachedDecksData.Decks.First(o => o.Id == CurrentDeckId).HeroId; opponentHeroId = randomOpponentDeck.HeroId; } else { heroId = _tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.PlayerInfo.HeroId; opponentHeroId = _tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo.HeroId; } Hero currentPlayerHero = _dataManager.CachedHeroesData.HeroesParsed[heroId]; Hero currentOpponentHero = _dataManager.CachedHeroesData.HeroesParsed[opponentHeroId]; _playerDeckStatusTexture = GameObject.Find("Player/Deck_Illustration/Deck").GetComponent <SpriteRenderer>(); _opponentDeckStatusTexture = GameObject.Find("Opponent/Deck_Illustration/Deck").GetComponent <SpriteRenderer>(); _playerGraveyardStatusTexture = GameObject.Find("Player/Graveyard_Illustration/Graveyard") .GetComponent <SpriteRenderer>(); _opponentGraveyardStatusTexture = GameObject.Find("Opponent/Graveyard_Illustration/Graveyard") .GetComponent <SpriteRenderer>(); _playerHealthText = GameObject.Find("Player/Avatar/LivesCircle/DefenceText").GetComponent <TextMeshPro>(); _opponentHealthText = GameObject.Find("Opponent/Avatar/LivesCircle/DefenceText").GetComponent <TextMeshPro>(); _playerManaBar = new PlayerManaBarItem(GameObject.Find("PlayerManaBar"), "GooOverflowPlayer", new Vector3(-3.55f, 0, -6.07f)); _opponentManaBar = new PlayerManaBarItem(GameObject.Find("OpponentManaBar"), "GooOverflowOpponent", new Vector3(9.77f, 0, 4.75f)); // improve find to get it from OBJECTS ON BOARD!! _playerNameText = GameObject.Find("Player/NameBoard/NameText").GetComponent <TextMeshPro>(); _opponentNameText = GameObject.Find("Opponent/NameBoard/NameText").GetComponent <TextMeshPro>(); _playerCardDeckCountText = GameObject.Find("Player/CardDeckText").GetComponent <TextMeshPro>(); _opponentCardDeckCountText = GameObject.Find("Opponent/CardDeckText").GetComponent <TextMeshPro>(); _endTurnButton = GameObject.Find("EndTurnButton"); PlayerPrimarySkillHandler = GameObject.Find("Player").transform.Find("Object_SpellPrimary").GetComponent <OnBehaviourHandler>(); PlayerSecondarySkillHandler = GameObject.Find("Player").transform.Find("Object_SpellSecondary").GetComponent <OnBehaviourHandler>(); OpponentPrimarySkillHandler = GameObject.Find("Opponent").transform.Find("Object_SpellPrimary").GetComponent <OnBehaviourHandler>(); OpponentSecondarySkillHandler = GameObject.Find("Opponent").transform.Find("Object_SpellSecondary").GetComponent <OnBehaviourHandler>(); if (currentPlayerHero != null) { SetHeroInfo(currentPlayerHero, "Player", PlayerPrimarySkillHandler.gameObject, PlayerSecondarySkillHandler.gameObject); string playerNameText = currentPlayerHero.FullName; if (_backendDataControlMediator.LoadUserDataModel()) { playerNameText = _backendDataControlMediator.UserDataModel.UserId; } _playerNameText.text = playerNameText; } if (currentOpponentHero != null) { SetHeroInfo(currentOpponentHero, "Opponent", OpponentPrimarySkillHandler.gameObject, OpponentSecondarySkillHandler.gameObject); _opponentNameText.text = currentOpponentHero.FullName; } _isPlayerInited = true; }