Пример #1
0
        public static void InitializeGame()
        {
            _playerOnTurn = 0;
            ServerSendData.SendSetTurn(0, 1);
            ServerSendData.SendSetTurn(1, 0);
            CreateHeros();

            //FIXME: Temp code for testing purposes

            AddToGame(Database.GetCard(5, 0), 0);
            AddToGame(Database.GetCard(2, 0), 0);
            AddToGame(Database.GetCard(2, 0), 0);
            AddToGame(Database.GetCard(3, 0), 0);
            AddToGame(Database.GetCard(1, 0), 0);
            AddToGame(Database.GetCard(2, 0), 0);
            AddToGame(Database.GetCard(3, 0), 0);
            AddToGame(Database.GetCard(1, 0), 0);

            AddToGame(Database.GetCard(5, 1), 1);
            AddToGame(Database.GetCard(2, 1), 1);
            AddToGame(Database.GetCard(2, 1), 1);
            AddToGame(Database.GetCard(3, 1), 1);
            AddToGame(Database.GetCard(1, 1), 1);
            AddToGame(Database.GetCard(2, 1), 1);
            AddToGame(Database.GetCard(3, 1), 1);
            AddToGame(Database.GetCard(1, 1), 1);

            DrawCardTo(0, 3);
            DrawCardTo(1, 4);
            SetTotalMana(0, 1);
            SetAvailableMana(0, 1);
            SetTotalMana(1, 0);

            AvailablePlaysVerifier.CheckHandPlays(0, PlayerList[0], CardsOnHand[0]);
        }
Пример #2
0
 public static void CheckBoardPlays(int playerIndex, List <Card> cards)
 {
     foreach (Card card in cards)
     {
         ServerSendData.SendSetCanAttack(playerIndex, card.ServerId, card.CanAttack() ? 1 : 0);
     }
 }
Пример #3
0
        public static void StartAttackEvent(long playerIndex, long sId)
        {
            if (playerIndex != _playerOnTurn)
            {
                throw new IllegalMessageReceivedException("AttackEvent recebido por jogador não permitido.");
            }

            Card attacker = CardsOnBoard[_playerOnTurn].Find(x => x.ServerId == sId);

            if (attacker == null)
            {
                throw new CardNotFoundException();
            }

            if (!attacker.CanAttack())
            {
                throw new IllegalGameEventException("Carta que não pode atacar tentou começar ataque.");
            }

            ServerSendData.SendStartSelectTarget(_playerOnTurn);
            AvailablePlaysVerifier.CheckAttackTargets(_playerOnTurn, CardsOnBoard[_playerOnTurn == 0 ? 1 : 0]);

            _cardSelectCaller       = attacker;
            OnCardSelectedCallback += StartAttackResponse;
        }
Пример #4
0
        public static void CheckAttackTargets(int playerIndex, List <Card> cards)
        {
            // Check for taunts
            bool hasTaunt = false;

            foreach (Card card in cards)
            {
                if (!card.IsTaunt)
                {
                    continue;
                }

                hasTaunt = true;
                break;
            }

            if (hasTaunt)
            {
                foreach (Card card in cards)
                {
                    ServerSendData.SendSetCanTarget(playerIndex, card.ServerId, card.IsTaunt ? 1 : 0);
                }
            }
            else
            {
                foreach (Card card in cards)
                {
                    ServerSendData.SendSetCanTarget(playerIndex, card.ServerId, 1);
                }
            }
        }
Пример #5
0
        public static void CheckHandPlays(int playerIndex, Player player, List <Card> cards)
        {
            foreach (Card card in cards)
            {
                if (card.Mana > player.ManaRemaining)
                {
                    ServerSendData.SendSetCanPlayCard(playerIndex, card.ServerId, 0);
                    continue;
                }

                if (card.CheckRequirement(PlayRequirement.MINIONS_ON_BOARD))
                {
                    if (GameEngine.CardsOnBoard[playerIndex].Count <= 1)   // Have to be 1 because there is a hero card on board.
                    {
                        ServerSendData.SendSetCanPlayCard(playerIndex, card.ServerId, 0);
                        continue;
                    }
                }

                if (card.CheckRequirement(PlayRequirement.ENEMIES_ON_BOARD))   // Have to be 1 because there is a hero card on board.
                {
                    if (GameEngine.CardsOnBoard[playerIndex == 0 ? 1 : 0].Count <= 1)
                    {
                        ServerSendData.SendSetCanPlayCard(playerIndex, card.ServerId, 0);
                        continue;
                    }
                }

                ServerSendData.SendSetCanPlayCard(playerIndex, card.ServerId, 1);
            }
        }
Пример #6
0
        public static void EndGame(int loserIndex)
        {
            Console.WriteLine("Game Ended with loser index value = " + loserIndex);

            ServerSendData.SendEndGame(0, loserIndex == 0 ? 0 : 1);
            ServerSendData.SendEndGame(1, loserIndex == 1 ? 0 : 1);

            NetworkSocket.Instance.EndServer();
        }
Пример #7
0
        private static void StartTurn()
        {
            _playerOnTurn = _playerOnTurn == 0 ? 1 : 0;

            Console.WriteLine("Starting Player " + _playerOnTurn + " turn.");

            SetTotalMana(_playerOnTurn, (PlayerList[_playerOnTurn].Mana + 1));
            SetAvailableMana(_playerOnTurn, PlayerList[_playerOnTurn].Mana);

            AwakeCards();

            ServerSendData.SendSetTurn(0, _playerOnTurn == 0 ? 1 : 0);
            ServerSendData.SendSetTurn(1, _playerOnTurn == 0 ? 0 : 1);

            CheckAvailableMoves();
        }
Пример #8
0
        public static void CardPlayed(long playerIndex, int serverId, int boardIndex)
        {
            if (playerIndex != _playerOnTurn)
            {
                throw new IllegalMessageReceivedException("Carta Jogada por jogador não permitido.");
            }

            Card cardPlayed = CardsOnHand[_playerOnTurn].Find(x => x.ServerId == serverId);

            if (cardPlayed == null)
            {
                throw new CardNotFoundException();
            }

            CardsOnHand[_playerOnTurn].Remove(cardPlayed);
            CardsOnBoard[_playerOnTurn].Add(cardPlayed);

            SetAvailableMana(_playerOnTurn, PlayerList[_playerOnTurn].ManaRemaining - cardPlayed.CurrentMana);
            cardPlayed.PlayCard();
            CheckAvailableMoves();

            if (cardPlayed.IsSpell)
            {
                ServerSendData.SendDisplaySpell(
                    _playerOnTurn == 0 ? 1 : 0,
                    cardPlayed.CardId
                    );
            }
            else
            {
                ServerSendData.SendCreateCard(
                    _playerOnTurn == 0 ? 1 : 0,
                    cardPlayed.CardId,
                    cardPlayed.ServerId,
                    CardPlace.ENEMY_BOARD,
                    boardIndex
                    );
            }

            if (PlayerList[_playerOnTurn].ManaRemaining < 0)
            {
                throw new IllegalGameEventException("Carta jogada sem ter mana suficiente! Jogador Index: " + _playerOnTurn);
            }
        }
Пример #9
0
        private static void CreateHeros()
        {
            Card hero0 = Database.GetCard(0, 0);
            Card hero1 = Database.GetCard(0, 1);

            AddToGame(hero0, 0);
            CardsOnDeck[0].Remove(hero0);
            CardsOnBoard[0].Add(hero0);
            hero0.ChangePlace(CardPlace.BOARD);

            AddToGame(hero1, 1);
            CardsOnDeck[1].Remove(hero1);
            CardsOnBoard[1].Add(hero1);
            hero1.ChangePlace(CardPlace.BOARD);

            ServerSendData.SendHeroPortrait(0, hero0.ServerId);
            ServerSendData.SendEnemyPortrait(0, hero1.ServerId);
            ServerSendData.SendHeroPortrait(1, hero1.ServerId);
            ServerSendData.SendEnemyPortrait(1, hero0.ServerId);
        }
Пример #10
0
        public static void DrawCardTo(long index, long qtd)
        {
            if (CardsOnDeck[index].Count == 0)
            {
                return;
            }

            for (int i = 0; i < qtd; i++)
            {
                Card toDraw = CardsOnDeck[index][0];
                ServerSendData.SendCreateCard(index, toDraw.CardId, toDraw.ServerId, CardPlace.HAND, -1);
                CardsOnDeck[index].Remove(toDraw);
                CardsOnHand[index].Add(toDraw);
                toDraw.ChangePlace(CardPlace.HAND);
            }

            if (index == _playerOnTurn)
            {
                CheckAvailableMoves();
            }
        }
Пример #11
0
        public static void PromptTargets(Dictionary <TargetRequirement, int> reqs)
        {
            ServerSendData.SendStartSelectTarget(_playerOnTurn);

            for (int i = 0; i < 2; i++)
            {
                foreach (Card card in CardsOnBoard[i])
                {
                    bool canTarget = false;

                    if (reqs.TryGetValue(TargetRequirement.ENEMY_MINION, out int extraParam))
                    {
                        canTarget = card.OwnerIndex != _playerOnTurn;
                    }

                    if (reqs.TryGetValue(TargetRequirement.FRIENDLY_MINION, out extraParam))
                    {
                        canTarget = card.OwnerIndex == _playerOnTurn;
                    }

                    ServerSendData.SendSetCanTarget(_playerOnTurn, card.ServerId, canTarget ? 1 : 0);
                }
            }
        }
Пример #12
0
 private static void SetTotalMana(int index, int mana)
 {
     ServerSendData.SendSetTotalMana(index, mana);
     PlayerList[index].Mana = mana;
 }
Пример #13
0
 private static void SetAvailableMana(int index, int mana)
 {
     ServerSendData.SendSetAvailableMana(index, mana);
     PlayerList[index].ManaRemaining = mana;
 }
Пример #14
0
 public static void UpdateCardHealthForAll(int sId, int newHealth)
 {
     ServerSendData.SendUpdateCardHealth(0, sId, newHealth);
     ServerSendData.SendUpdateCardHealth(1, sId, newHealth);
 }
Пример #15
0
 public static void EndTargetEvent(OnCardSelected associatedEvent)
 {
     OnCardSelectedCallback -= associatedEvent;
     ServerSendData.SendEndSelectTarget(_playerOnTurn, 1);
     CheckAvailableMoves();
 }
Пример #16
0
 public static void DestroyCardForAll(int sId)
 {
     ServerSendData.SendDestroyCard(0, sId);
     ServerSendData.SendDestroyCard(1, sId);
 }
Пример #17
0
 public static void DestroyCardTo(int index, int sId)
 {
     ServerSendData.SendDestroyCard(index, sId);
 }