Beispiel #1
0
        public void EndTurn()
        {
            if (GameState == GameFieldState.GameOver || GameState == GameFieldState.TurnEnding)
            {
                return;
            }

            GameState = GameFieldState.TurnEnding;

            var abilitiesToRemove = new List <Ability>();

            foreach (var ability in TemporaryPassiveAbilities.OfType <PassiveAbility>())
            {
                ability.TurnsLeft--;

                if (ability.TurnsLeft <= 0 && ability.LimitedByTime)
                {
                    abilitiesToRemove.Add(ability);
                }
            }

            foreach (var ability in abilitiesToRemove)
            {
                TemporaryPassiveAbilities.Remove(ability);
            }

            EnergyRule = new StandardEnergyRule();
            EnergyRule.Reset();
            ActivePlayer.EndTurn(this);
            ActivePlayer.TurnsTaken++;

            foreach (var pokemon in ActivePlayer.GetAllPokemonCards())
            {
                foreach (var attack in pokemon.Attacks)
                {
                    attack.Disabled = false;
                }
            }

            foreach (var pokemon in ActivePlayer.GetAllPokemonCards())
            {
                pokemon.AbilityDisabled = false;
            }

            NonActivePlayer.EndTurn(this);
            CheckDeadPokemon();
            SwapActivePlayer();
            FirstTurn = false;
            StartNextTurn();

            PushGameLogUpdatesToPlayers();
            SendEventToPlayers(new GameSyncEvent {
                Game = this
            });
        }
Beispiel #2
0
        public List <IDamageTakenModifier> GetGlobalDamageTakenModifiers()
        {
            var modifiers = new List <IDamageTakenModifier>();

            foreach (var pokemon in ActivePlayer.GetAllPokemonCards())
            {
                modifiers.AddRange(pokemon.GetAllActiveAbilities(this, ActivePlayer, NonActivePlayer).OfType <DamageTakenModifier>().Where(a => a.IsGlobal));
            }
            foreach (var pokemon in NonActivePlayer.GetAllPokemonCards())
            {
                modifiers.AddRange(pokemon.GetAllActiveAbilities(this, ActivePlayer, NonActivePlayer).OfType <DamageTakenModifier>().Where(a => a.IsGlobal));
            }

            return(modifiers);
        }
Beispiel #3
0
        private void StartNextTurn()
        {
            ActivePlayer.ResetTurn();
            NonActivePlayer.ResetTurn();
            ActivePlayer.DrawCards(1);

            if (ActivePlayer.IsDead)
            {
                GameLog.AddMessage($"{ActivePlayer.NetworkPlayer?.Name} loses because they drew to many cards");
                EndGame(NonActivePlayer.Id);
                return;
            }

            if (ActivePlayer.ActivePokemonCard != null)
            {
                ActivePlayer.ActivePokemonCard.DamageTakenLastTurn = 0;
            }

            GameState = GameFieldState.InTurn;
        }
Beispiel #4
0
        public void PokemonRetreated(PokemonCard replacementCard, List <EnergyCard> payedEnergy)
        {
            if (!ActivePlayer.Id.Equals(replacementCard.Owner.Id))
            {
                return;
            }

            if (!CanRetreat(ActivePlayer.ActivePokemonCard))
            {
                GameLog.AddMessage("Tried to retreat but did not have enough energy");
                return;
            }

            foreach (var pokemon in NonActivePlayer.GetAllPokemonCards())
            {
                TriggerAbilityOfType(TriggerType.OpponentRetreats, pokemon, 0, ActivePlayer.ActivePokemonCard);
            }

            ActivePlayer.RetreatActivePokemon(replacementCard, new List <EnergyCard>(payedEnergy), this);
            CheckDeadPokemon();
        }
Beispiel #5
0
        public List <PassiveAbility> GetAllPassiveAbilities()
        {
            var passiveAbilities = new List <PassiveAbility>();

            if (ActivePlayer != null)
            {
                passiveAbilities.AddRange(ActivePlayer.GetAllPokemonCards().Where(p => p.Ability != null).Select(pokemon => pokemon.Ability).OfType <PassiveAbility>());
            }
            if (NonActivePlayer != null)
            {
                passiveAbilities.AddRange(NonActivePlayer.GetAllPokemonCards().Where(p => p.Ability != null).Select(pokemon => pokemon.Ability).OfType <PassiveAbility>());
            }

            if (StadiumCard != null && StadiumCard.Ability is PassiveAbility)
            {
                passiveAbilities.Add((PassiveAbility)StadiumCard.Ability);
            }

            passiveAbilities.AddRange(TemporaryPassiveAbilities.OfType <PassiveAbility>());

            if (passiveAbilities.Any(ability => ability.ModifierType == PassiveModifierType.NoPokemonPowers))
            {
                return new List <PassiveAbility>()
                       {
                           passiveAbilities.First(ability => ability.ModifierType == PassiveModifierType.NoPokemonPowers)
                       }
            }
            ;

            var idOfStopper = passiveAbilities.FirstOrDefault(x => x.ModifierType == PassiveModifierType.StopAbilities);

            if (idOfStopper != null)
            {
                return(passiveAbilities.Where(x => x.Id.Equals(idOfStopper) || x.IsBuff).ToList());
            }

            return(passiveAbilities.Where(a => a.CanActivate(this, a.GetActivator(ActivePlayer), GetOpponentOf(a.GetActivator(ActivePlayer)))).ToList());
        }
Beispiel #6
0
        private void CheckDeadPokemon()
        {
            if (IsDraw())
            {
                GameLog.AddMessage("It's a draw!");
                EndGame(Id);
                return;
            }

            CheckDeadBenchedPokemon(NonActivePlayer);
            CheckDeadBenchedPokemon(ActivePlayer);

            if (NonActivePlayer.ActivePokemonCard != null && NonActivePlayer.ActivePokemonCard.IsDead())
            {
                GameLog.AddMessage(NonActivePlayer.ActivePokemonCard.GetName() + " Dies");

                NonActivePlayer.ActivePokemonCard.KnockedOutBy = ActivePlayer.ActivePokemonCard;

                SendEventToPlayers(new PokemonDiedEvent
                {
                    Pokemon = NonActivePlayer.ActivePokemonCard
                });

                TriggerAbilityOfType(TriggerType.Dies, NonActivePlayer.ActivePokemonCard);
                TriggerAbilityOfType(TriggerType.Kills, ActivePlayer.ActivePokemonCard);

                NonActivePlayer.ActivePokemonCard.KnockedOutBy = ActivePlayer.ActivePokemonCard;

                PushGameLogUpdatesToPlayers();

                if (ActivePlayer.PrizeCards.Count == 1 && NonActivePlayer.ActivePokemonCard.PrizeCards > 0)
                {
                    GameLog.AddMessage(NonActivePlayer.NetworkPlayer?.Name + $" has no pokémon left, {ActivePlayer.NetworkPlayer?.Name} wins the game");
                    EndGame(ActivePlayer.Id);
                    return;
                }
                else if (NonActivePlayer.BenchedPokemon.Count == 0)
                {
                    GameLog.AddMessage(ActivePlayer.NetworkPlayer?.Name + " wins the game");
                    EndGame(ActivePlayer.Id);
                    return;
                }
                else
                {
                    PushInfoToPlayer("Opponent is selecting a prize card", NonActivePlayer);
                    ActivePlayer.SelectPrizeCard(NonActivePlayer.ActivePokemonCard.PrizeCards, this);
                }

                NonActivePlayer.KillActivePokemon();
                if (NonActivePlayer.BenchedPokemon.Count > 0)
                {
                    PushInfoToPlayer("Opponent is selecting a new active Pokémon", ActivePlayer);
                    NonActivePlayer.SelectActiveFromBench(this);
                }
                else
                {
                    GameLog.AddMessage(NonActivePlayer.NetworkPlayer?.Name + $" has no pokémon left, {ActivePlayer.NetworkPlayer?.Name} wins the game");
                    EndGame(ActivePlayer.Id);
                    return;
                }
            }

            PushGameLogUpdatesToPlayers();

            if (ActivePlayer.ActivePokemonCard != null && ActivePlayer.ActivePokemonCard.IsDead())
            {
                GameLog.AddMessage(ActivePlayer.ActivePokemonCard.GetName() + "Dies");

                SendEventToPlayers(new PokemonDiedEvent
                {
                    Pokemon = ActivePlayer.ActivePokemonCard
                });

                TriggerAbilityOfType(TriggerType.Dies, ActivePlayer.ActivePokemonCard);

                var prizeCardValue = ActivePlayer.ActivePokemonCard.PrizeCards;
                ActivePlayer.ActivePokemonCard.KnockedOutBy = NonActivePlayer.ActivePokemonCard;
                ActivePlayer.KillActivePokemon();

                if (ActivePlayer.BenchedPokemon.Count > 0)
                {
                    PushInfoToPlayer("Opponent is selecting a prize card", ActivePlayer);
                    NonActivePlayer.SelectPrizeCard(prizeCardValue, this);
                    PushInfoToPlayer("Opponent is selecting a new active Pokémon", NonActivePlayer);
                    ActivePlayer.SelectActiveFromBench(this);
                }
                else
                {
                    GameLog.AddMessage(ActivePlayer.NetworkPlayer?.Name + $" has no pokémon left, {NonActivePlayer.NetworkPlayer?.Name} wins the game");
                    EndGame(NonActivePlayer.Id);
                    return;
                }
            }

            PushGameLogUpdatesToPlayers();
        }