Example #1
0
        public void Camouflage_Fails()
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Staryu, 0, 100, PBEMove.Camouflage);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"), battleTerrain: PBEBattleTerrain.Water);
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon staryu   = t0.Party[0];
            PBEBattlePokemon magikarp = t1.Party[0];
            #endregion

            #region Use Camouflage and check
            Assert.True(PBEBattle.SelectActionsIfValid(t0, new PBETurnAction(staryu, PBEMove.Camouflage, PBETurnTarget.AllyCenter)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1, new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(battle.VerifyMoveResultHappened(staryu, staryu, PBEResult.InvalidConditions));
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #2
0
        public void Intimidate_Does_Not_Announce_If_No_Foes()
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Shuckle, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Luxray, 0, 100, PBEMove.Splash)
            {
                Ability = PBEAbility.Intimidate
            };
            p1[1] = new TestPokemon(settings, PBESpecies.Skitty, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Triple, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0      = battle.Trainers[0];
            PBETrainer       t1      = battle.Trainers[1];
            PBEBattlePokemon shuckle = t0.Party[0];
            PBEBattlePokemon luxray  = t1.Party[0];
            PBEBattlePokemon skitty  = t1.Party[1];
            #endregion

            #region Check
            Assert.True(!battle.VerifyAbilityHappened(luxray, luxray, PBEAbility.Intimidate, PBEAbilityAction.Stats)); // Did not activate
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("----- Pokémon Battle Engine Test -----");

            PBESettings settings = PBESettings.DefaultSettings;

            PBEPokemonShell[] team0Party = PBECompetitivePokemonShells.CreateRandomTeam(settings.MaxPartySize).ToArray();
            PBEPokemonShell[] team1Party = PBECompetitivePokemonShells.CreateRandomTeam(settings.MaxPartySize).ToArray();
            PBEBattle         battle     = new PBEBattle(PBEBattleFormat.Triple, settings, team0Party, team1Party);

            battle.Teams[0].TrainerName = "Team 1";
            battle.Teams[1].TrainerName = "Team 2";
            battle.OnNewEvent          += PBEBattle.ConsoleBattleEventHandler;
            battle.OnStateChanged      += Battle_OnStateChanged;
            try
            {
                writer = new StreamWriter(new FileStream(logFile, FileMode.Create, FileAccess.Write));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Cannot open \"{logFile}\" for writing.");
                Console.WriteLine(e.Message);
                return;
            }
            oldWriter = Console.Out;
            Console.SetOut(writer);
            battle.Begin();
        }
        public void TeamProtection_Works(PBEMove move, PBEMove move2, PBETeamStatus teamStatus)
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Mienshao, 0, 100, move);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Lucario, 0, 100, move2);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon mienshao = t0.Party[0];
            PBEBattlePokemon lucario  = t1.Party[0];
            #endregion

            #region Use move and check
            Assert.True(PBEBattle.SelectActionsIfValid(t0, new PBETurnAction(mienshao, move, PBETurnTarget.AllyCenter)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1, new PBETurnAction(lucario, move2, PBETurnTarget.FoeCenter)));

            battle.RunTurn();

            Assert.True(battle.VerifyTeamStatusHappened(t0.Team, teamStatus, PBETeamStatusAction.Damage, damageVictim: mienshao) && !t0.Team.TeamStatus.HasFlag(teamStatus));
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Illusion_Does_Copy_Active_Trainer_Teammate()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Zoroark, 0, 100, PBEMove.Splash)
            {
                Ability = PBEAbility.Illusion
            };
            p1[1] = p0[0];

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t1      = battle.Trainers[1];
            PBEBattlePokemon zoroark = t1.Party[0];

            battle.Begin();
            #endregion

            #region Check
            Assert.True(zoroark.Status2.HasFlag(PBEStatus2.Disguised));
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #6
0
        public void Camouflage_Works(PBEBattleTerrain battleTerrain, PBEType expectedType, PBESpecies species)
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, species, 0, 100, PBEMove.Camouflage);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"), battleTerrain: battleTerrain);
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0          = battle.Trainers[0];
            PBETrainer       t1          = battle.Trainers[1];
            PBEBattlePokemon camouflager = t0.Party[0];
            PBEBattlePokemon magikarp    = t1.Party[0];
            #endregion

            #region Use Camouflage and check
            Assert.True(PBEBattle.SelectActionsIfValid(t0, new PBETurnAction(camouflager, PBEMove.Camouflage, PBETurnTarget.AllyCenter)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1, new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(camouflager.Type1 == expectedType && camouflager.Type2 == PBEType.None);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Illusion_Does_Not_Copy_Same_Species()
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = p1[1] = new TestPokemon(settings, PBESpecies.Zoroark, 0, 100, PBEMove.Splash)
            {
                Ability = PBEAbility.Illusion
            };

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon zoroark1 = t1.Party[0];
            #endregion

            #region Check
            Assert.True(zoroark1.DisguisedAsPokemon == null);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #8
0
        void BattleStateHandler(PBEBattle battle)
        {
            Console.WriteLine("Battle state changed: {0}", battle.BattleState);
            switch (battle.BattleState)
            {
            case PBEBattleState.ReadyToBegin:
            {
                foreach (Player player in battlers)
                {
                    foreach (PBEPokemonShell shell in player.Party)
                    {
                        try
                        {
                            shell.ValidateShell(battle.Settings);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Invalid team data received from {player.PlayerName}:");
                            Console.WriteLine(e.Message);
                            CancelMatch();
                            return;
                        }
                    }
                }
                state = ServerState.StartingMatch;
                Console.WriteLine("Battle starting!");
                battlers[0].Send(new PBESetPartyPacket(battle.Teams[0]));
                battlers[1].Send(new PBESetPartyPacket(battle.Teams[1]));
                battlers[0].ResetEvent.WaitOne();
                battlers[1].ResetEvent.WaitOne();
                battle.Begin();
                break;
            }

            case PBEBattleState.Processing:
            {
                state = ServerState.BattleProcessing;
                break;
            }

            case PBEBattleState.ReadyToRunTurn:
            {
                battle.RunTurn();
                break;
            }

            case PBEBattleState.WaitingForActions:
            {
                state = ServerState.WaitingForActions;
                break;
            }

            case PBEBattleState.WaitingForSwitchIns:
            {
                state = ServerState.WaitingForSwitchIns;
                break;
            }
            }
        }
Example #9
0
        public void Basic_Actions()
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Koffing, 0, 100, PBEMove.Selfdestruct);
            p0[1] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Darkrai, 0, 100, PBEMove.Protect);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon koffing  = t0.Party[0];
            PBEBattlePokemon magikarp = t0.Party[1];
            PBEBattlePokemon darkrai  = t1.Party[0];
            #endregion

            #region Darkrai uses Protect, Koffing uses Selfdestruct and faints
            var a = new PBETurnAction(koffing, PBEMove.Selfdestruct, PBETurnTarget.FoeCenter);
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectActionsIfValid(null, a));                                   // Throw for null team
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectActionsIfValid(t0, (IReadOnlyList <PBETurnAction>)null));   // Throw for null collection
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectActionsIfValid(t0, new PBETurnAction[] { null }));          // Throw for null elements
            Assert.False(PBEBattle.SelectActionsIfValid(t0, a, a));                                                                 // False for too many actions
            Assert.True(PBEBattle.SelectActionsIfValid(t0, a));                                                                     // True for good actions
                                                                                                                                    // TODO: bad field position to switch into, bad move, bad targets, bad targets with templockedmove, battle status, bad pkmn id, wrong team pkmn id, duplicate pkmn id, can't switch out but tried, invalid switch mon (null hp pos), duplicate switch mon
            Assert.False(PBEBattle.SelectActionsIfValid(t0, a));                                                                    // False because actions were already submitted
            Assert.False(PBEBattle.SelectActionsIfValid(t0, Array.Empty <PBETurnAction>()));                                        // False for 0 despite us now needing 0 additional actions

            Assert.True(PBEBattle.SelectActionsIfValid(t1, new PBETurnAction(darkrai, PBEMove.Protect, PBETurnTarget.AllyCenter))); // True for good actions

            battle.RunTurn();
            #endregion

            #region More checks
            var s = new PBESwitchIn(magikarp, PBEFieldPosition.Center);
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectSwitchesIfValid(null, s));                               // Throw for null team
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectSwitchesIfValid(t0, (IReadOnlyList <PBESwitchIn>)null)); // Throw for null collection
            Assert.Throws <ArgumentNullException>(() => PBEBattle.SelectSwitchesIfValid(t0, new PBESwitchIn[] { null }));        // Throw for null elements
            Assert.False(PBEBattle.SelectSwitchesIfValid(t0, s, s));                                                             // False for too many
            Assert.True(PBEBattle.SelectSwitchesIfValid(t0, s));                                                                 // True for good switches

            // Below two wouldn't work because of battle status lol
            //Assert.False(PBEBattle.SelectSwitchesIfValid(t0, s)); // False because switches were already submitted
            //Assert.False(PBEBattle.SelectSwitchesIfValid(t0, Array.Empty<PBESwitchIn>())); // False for 0 despite us now needing 0 additional actions

            //battle.RunSwitches();
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #10
0
        public void CastformCherrim_Interacts_With_AirLock(PBESpecies species, PBEAbility ability, PBEForm form)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);
            p0[1] = new TestPokemon(settings, PBESpecies.Rayquaza, 0, 100, PBEMove.Splash)
            {
                Ability = PBEAbility.AirLock
            };

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, species, 0, 100, PBEMove.Splash)
            {
                Ability = ability
            };

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"),
                                       weather: PBEWeather.HarshSunlight);
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0              = battle.Trainers[0];
            PBETrainer       t1              = battle.Trainers[1];
            PBEBattlePokemon magikarp        = t0.Party[0];
            PBEBattlePokemon rayquaza        = t0.Party[1];
            PBEBattlePokemon castformCherrim = t1.Party[0];

            battle.Begin();
            #endregion

            #region Check Castform/Cherrim for correct form
            Assert.True(battle.Weather == PBEWeather.HarshSunlight && castformCherrim.Form == form);
            #endregion

            #region Swap Magikarp for Rayquaza and check for no form
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(magikarp, rayquaza)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(castformCherrim, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(battle.Weather == PBEWeather.HarshSunlight && castformCherrim.Form == 0);
            #endregion

            #region Swap Rayquaza for Magikarp and check for correct form
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(rayquaza, magikarp)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(castformCherrim, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(battle.Weather == PBEWeather.HarshSunlight && castformCherrim.Form == form);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Basic_Actions()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Koffing, 0, 100, PBEMove.Selfdestruct);
            p0[1] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Darkrai, 0, 100, PBEMove.Protect);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon koffing  = t0.Party[0];
            PBEBattlePokemon magikarp = t0.Party[1];
            PBEBattlePokemon darkrai  = t1.Party[0];

            battle.Begin();
            #endregion

            #region Darkrai uses Protect, Koffing uses Selfdestruct and faints
            var a = new PBETurnAction(koffing, PBEMove.Selfdestruct, PBETurnTarget.FoeCenter);
            Assert.Throws <ArgumentNullException>(() => t0.SelectActionsIfValid((IReadOnlyList <PBETurnAction>)null));   // Throw for null collection
            Assert.Throws <ArgumentNullException>(() => t0.SelectActionsIfValid(new PBETurnAction[] { null }));          // Throw for null elements
            Assert.NotNull(t0.SelectActionsIfValid(a, a));                                                               // Too many actions
            Assert.Null(t0.SelectActionsIfValid(a));                                                                     // Good actions
            Assert.NotNull(t0.SelectActionsIfValid(a));                                                                  // Actions were already submitted
            Assert.NotNull(t0.SelectActionsIfValid(Array.Empty <PBETurnAction>()));                                      // 0 despite us now needing 0 additional actions

            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(darkrai, PBEMove.Protect, PBETurnTarget.AllyCenter))); // True for good actions

            battle.RunTurn();
            #endregion

            #region More checks
            var s = new PBESwitchIn(magikarp, PBEFieldPosition.Center);
            Assert.Throws <ArgumentNullException>(() => t0.SelectSwitchesIfValid((IReadOnlyList <PBESwitchIn>)null)); // Throw for null collection
            Assert.Throws <ArgumentNullException>(() => t0.SelectSwitchesIfValid(new PBESwitchIn[] { null }));        // Throw for null elements
            Assert.NotNull(t0.SelectSwitchesIfValid(s, s));                                                           // Too many
            Assert.Null(t0.SelectSwitchesIfValid(s));                                                                 // Good switches

            // Below two wouldn't work because of battle status lol
            //Assert.NotNull(t0.SelectSwitchesIfValid(s)); // Switches were already submitted
            //Assert.NotNull(t0.SelectSwitchesIfValid(Array.Empty<PBESwitchIn>())); // 0 despite us now needing 0 additional switches

            //battle.RunSwitches();
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Illusion_Works_Wild()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Tackle);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Zoroark, 0, 100, PBEMove.Splash)
            {
                Ability    = PBEAbility.Illusion,
                CaughtBall = PBEItem.None
            };

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBEWildInfo(p1));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon magikarp = t0.Party[0];
            PBEBattlePokemon zoroark  = t1.Party[0];

            zoroark.Status2        |= PBEStatus2.Disguised;
            zoroark.KnownGender     = PBEGender.Genderless;
            zoroark.KnownCaughtBall = PBEItem.None;
            zoroark.KnownShiny      = false;
            zoroark.KnownSpecies    = PBESpecies.Entei;
            zoroark.KnownForm       = 0;
            zoroark.KnownNickname   = zoroark.KnownSpecies.ToString();
            IPBEPokemonData pData = PBEDataProvider.Instance.GetPokemonData(zoroark.KnownSpecies, zoroark.KnownForm);
            zoroark.KnownType1 = pData.Type1;
            zoroark.KnownType2 = pData.Type2;

            battle.Begin();
            #endregion

            #region Check that the disguise works
            Assert.True(zoroark.Status2.HasFlag(PBEStatus2.Disguised) &&
                        ((PBEWildPkmnAppearedPacket)battle.Events.Single(p => p is PBEWildPkmnAppearedPacket)).Pokemon[0].IsDisguised);
            #endregion

            #region Break the disguise and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(magikarp, PBEMove.Tackle, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(zoroark, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(!zoroark.Status2.HasFlag(PBEStatus2.Disguised) &&
                        zoroark.KnownSpecies == PBESpecies.Zoroark);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #13
0
        public void Gem_Does_Not_Activate__Effectiveness()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Excadrill, 0, 100, PBEMove.Earthquake)
            {
                Item = PBEItem.GroundGem
            };
            p0[1] = new TestPokemon(settings, PBESpecies.Starly, 0, 1, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Rotom, 0, 1, PBEMove.Splash)
            {
                Ability = PBEAbility.Levitate
            };
            p1[1] = new TestPokemon(settings, PBESpecies.Shedinja, 0, 1, PBEMove.Splash)
            {
                Ability = PBEAbility.WonderGuard
            };

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0        = battle.Trainers[0];
            PBETrainer       t1        = battle.Trainers[1];
            PBEBattlePokemon excadrill = t0.Party[0];
            PBEBattlePokemon starly    = t0.Party[1];
            PBEBattlePokemon rotom     = t1.Party[0];
            PBEBattlePokemon shedinja  = t1.Party[1];

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(excadrill, PBEMove.Earthquake, PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeRight),
                            new PBETurnAction(starly, PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(rotom, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(shedinja, PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True(battle.VerifyMoveResultHappened(excadrill, starly, PBEResult.Ineffective_Type) && starly.HPPercentage == 1 && // Doesn't affect Flying
                        battle.VerifyMoveResultHappened(excadrill, rotom, PBEResult.Ineffective_Ability) && rotom.HPPercentage == 1 && // Doesn't affect Levitate
                        battle.VerifyMoveResultHappened(excadrill, shedinja, PBEResult.Ineffective_Ability) && shedinja.HPPercentage == 1 && // Doesn't affect WonderGuard
                        excadrill.Item == PBEItem.GroundGem); // Gem not consumed
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public static void Test()
        {
            Console.WriteLine("----- Pokémon Battle Engine Test -----");

            var settings = new PBESettings {
                NumMoves = 12
            };

            PBEPokemonShell[] team0Party, team1Party;

            // Completely Randomized Pokémon
            team0Party = PBEUtils.CreateCompletelyRandomTeam(settings, true);
            team1Party = PBEUtils.CreateCompletelyRandomTeam(settings, true);

            // Predefined Pokémon

            /*team0Party = new PBEPokemonShell[]
             * {
             *  PBECompetitivePokemonShells.Zoroark_VGC,
             *  PBECompetitivePokemonShells.Volcarona_VGC,
             *  PBECompetitivePokemonShells.Vaporeon_VGC,
             *  PBECompetitivePokemonShells.Thundurus_VGC,
             *  PBECompetitivePokemonShells.Vanilluxe_VGC,
             *  PBECompetitivePokemonShells.Chandelure_VGC
             * };
             * team1Party = new PBEPokemonShell[]
             * {
             *  PBECompetitivePokemonShells.Arceus_Uber,
             *  PBECompetitivePokemonShells.Darkrai_Uber,
             *  PBECompetitivePokemonShells.Kyurem_White_Uber,
             *  PBECompetitivePokemonShells.Latias_VGC,
             *  PBECompetitivePokemonShells.Metagross_VGC,
             *  PBECompetitivePokemonShells.Victini_Uber
             * };*/

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, team0Party, team1Party);

            battle.Teams[0].TrainerName = "Team 1";
            battle.Teams[1].TrainerName = "Team 2";
            battle.OnNewEvent          += PBEBattle.ConsoleBattleEventHandler;
            battle.OnStateChanged      += Battle_OnStateChanged;
            try
            {
                writer = new StreamWriter(new FileStream(LogFile, FileMode.Create, FileAccess.Write));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Cannot open \"{LogFile}\" for writing.");
                Console.WriteLine(e.Message);
                return;
            }
            oldWriter = Console.Out;
            Console.SetOut(writer);
            battle.Begin();
        }
        [InlineData(PBESpecies.Gyarados, false)]                    // Flying dual-type-secondary
        public void Roost_Works(PBESpecies species, bool swapTypes) // Swap types around since there's no primary flying-type
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Lucario, 0, 50, PBEMove.Earthquake, PBEMove.VacuumWave);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, species, 0, 100, PBEMove.Roost, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0      = battle.Trainers[0];
            PBETrainer       t1      = battle.Trainers[1];
            PBEBattlePokemon lucario = t0.Party[0];
            PBEBattlePokemon rooster = t1.Party[0];
            PBEType          type1   = rooster.Type1;
            PBEType          type2   = rooster.Type2;
            if (swapTypes)
            {
                rooster.Type1      = type2;
                rooster.Type2      = type1;
                rooster.KnownType1 = type2;
                rooster.KnownType2 = type1;
            }

            battle.Begin();
            #endregion

            #region Use VacuumWave to lower HP
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(lucario, PBEMove.VacuumWave, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(rooster, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();
            #endregion

            #region Use Roost and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(lucario, PBEMove.Earthquake, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(rooster, PBEMove.Roost, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(!battle.VerifyMoveResultHappened(lucario, rooster, PBEResult.Ineffective_Type) && // Earthquake hit
                        !rooster.Status2.HasFlag(PBEStatus2.Roost) && // Roost ended properly
                        rooster.Type1 == type1 && rooster.Type2 == type2 && // Types restored properly
                        rooster.KnownType1 == type1 && rooster.KnownType2 == type2);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #16
0
        public void Gem_Does_Not_Activate__Miss()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 1; // Seed ensures all miss
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Corsola, 0, 100, PBEMove.Earthquake)
            {
                Ability = PBEAbility.Hustle,
                Item    = PBEItem.GroundGem
            };
            p0[1] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Splash);
            p1[1] = new TestPokemon(settings, PBESpecies.Qwilfish, 0, 1, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon corsola  = t0.Party[0];
            PBEBattlePokemon magikarp = t0.Party[1];
            PBEBattlePokemon happiny  = t1.Party[0];
            PBEBattlePokemon qwilfish = t1.Party[1];
            corsola.AccuracyChange = (sbyte)-settings.MaxStatChange;
            magikarp.EvasionChange = settings.MaxStatChange;
            happiny.EvasionChange  = settings.MaxStatChange;
            qwilfish.EvasionChange = settings.MaxStatChange;

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(corsola, PBEMove.Earthquake, PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeRight),
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(qwilfish, PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True(battle.VerifyMoveResultHappened(corsola, magikarp, PBEResult.Missed) && magikarp.HPPercentage == 1 && // Miss everyone
                        battle.VerifyMoveResultHappened(corsola, happiny, PBEResult.Missed) && happiny.HPPercentage == 1 &&
                        battle.VerifyMoveResultHappened(corsola, qwilfish, PBEResult.Missed) && qwilfish.HPPercentage == 1 &&
                        corsola.Item == PBEItem.GroundGem); // Gem not consumed
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Whirlwind_Succeeds_WildDoubleBattle()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(3);
            p0[0] = new TestPokemon(settings, PBESpecies.Diglett, 0, 1, PBEMove.Splash);
            p0[1] = new TestPokemon(settings, PBESpecies.Geodude, 0, 1, PBEMove.Splash);
            p0[2] = new TestPokemon(settings, PBESpecies.Trubbish, 0, 1, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Starly, 0, 100, PBEMove.Whirlwind)
            {
                CaughtBall = PBEItem.None
            };
            p1[1] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash)
            {
                CaughtBall = PBEItem.None
            };

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBEWildInfo(p1));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon diglett  = t0.Party[0];
            PBEBattlePokemon geodude  = t0.Party[1];
            PBEBattlePokemon trubbish = t0.Party[2];
            PBEBattlePokemon starly   = t1.Party[0];
            PBEBattlePokemon magikarp = t1.Party[1];

            battle.Begin();
            #endregion

            #region Use Whirlwind and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(diglett, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(geodude, PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(starly, PBEMove.Whirlwind, PBETurnTarget.FoeLeft),
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True(!battle.VerifyMoveResultHappened(starly, diglett, PBEResult.InvalidConditions) && // No fail
                        diglett.FieldPosition == PBEFieldPosition.None && trubbish.FieldPosition == PBEFieldPosition.Left && // Properly swapped
                        !battle.BattleResult.HasValue); // Did not flee
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #18
0
        //[InlineData(PBEMove.SkyDrop, PBEStatus2.Airborne)]
        public void HelpingHand_HitsSemiInvulnerable(PBEMove move, PBEStatus2 status2)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(2);
            p0[0] = new TestPokemon(settings, PBESpecies.Minun, 0, 100, PBEMove.HelpingHand, PBEMove.Splash);
            p0[1] = new TestPokemon(settings, PBESpecies.Giratina, 0, 1, move);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon minun    = t0.Party[0];
            PBEBattlePokemon giratina = t0.Party[1];
            PBEBattlePokemon magikarp = t1.Party[0];

            battle.Begin();
            #endregion

            #region Use Shadow Force
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(minun, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(giratina, move, PBETurnTarget.FoeLeft)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyLeft)));

            battle.RunTurn();

            Assert.True(giratina.Status2.HasFlag(status2));
            #endregion

            #region Use Helping Hand and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(minun, PBEMove.HelpingHand, PBETurnTarget.AllyRight),
                            new PBETurnAction(giratina, move, PBETurnTarget.FoeLeft)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyLeft)));

            battle.RunTurn();

            Assert.True(battle.VerifyStatus2Happened(giratina, minun, PBEStatus2.HelpingHand, PBEStatusAction.Added));
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #19
0
        public void Confusion_Heal__Bug(bool bugFix)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 40703; // Seed ensures Swagger does not miss and Deoxys hurts itself
            var settings = new PBESettings {
                BugFix = bugFix
            };
            settings.MakeReadOnly();

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Deoxys, PBEForm.Deoxys, 50, PBEMove.Splash)
            {
                Item = PBEItem.SitrusBerry
            };

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Accelgor, 0, 100, PBEMove.Swagger);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon deoxys   = t0.Party[0];
            PBEBattlePokemon accelgor = t1.Party[0];

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(deoxys, PBEMove.Splash, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(accelgor, PBEMove.Swagger, PBETurnTarget.FoeCenter)));

            battle.RunTurn();

            Assert.True(battle.VerifyStatus2Happened(deoxys, accelgor, PBEStatus2.Confused, PBEStatusAction.Added) &&
                        battle.VerifyStatus2Happened(deoxys, deoxys, PBEStatus2.Confused, PBEStatusAction.Damage));
            if (settings.BugFix)
            {
                Assert.True(battle.VerifyItemHappened(deoxys, deoxys, PBEItem.SitrusBerry, PBEItemAction.Consumed) &&
                            deoxys.Item == PBEItem.None); // Healed
            }
            else
            {
                Assert.True(!battle.VerifyItemHappened(deoxys, deoxys, PBEItem.SitrusBerry, PBEItemAction.Consumed) &&
                            deoxys.Item == PBEItem.SitrusBerry); // Buggy
            }
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #20
0
        public AIBattleDemo()
        {
            Console.WriteLine("----- Pokémon Battle Engine - AI Battle Demo -----");
            try
            {
                _writer = new StreamWriter(new FileStream(LogFile, FileMode.Create, FileAccess.Write));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Cannot open \"{LogFile}\" for writing.");
                Console.WriteLine(e.Message);
                _battle    = null !;
                _ai0       = null !;
                _ai1       = null !;
                _writer    = null !;
                _oldWriter = null !;
                return;
            }

            PBESettings settings = PBESettings.DefaultSettings;
            //var settings = new PBESettings { NumMoves = 8, MaxPartySize = 10 };
            //settings.MakeReadOnly();
            PBELegalPokemonCollection p0, p1;

            // Competitively Randomized Pokémon
            p0 = PBEDDRandomTeamGenerator.CreateRandomTeam(settings.MaxPartySize);
            p1 = PBEDDRandomTeamGenerator.CreateRandomTeam(settings.MaxPartySize);

            _battle = PBEBattle.CreateTrainerBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0", false), new PBETrainerInfo(p1, "Trainer 1", false),
                                                    battleTerrain: PBEDataProvider.GlobalRandom.RandomBattleTerrain());
            _battle.OnNewEvent     += PBEBattle.ConsoleBattleEventHandler;
            _battle.OnNewEvent     += Battle_OnNewEvent;
            _battle.OnStateChanged += Battle_OnStateChanged;
            _ai0       = new PBEDDAI(_battle.Trainers[0]);
            _ai1       = new PBEDDAI(_battle.Trainers[1]);
            _oldWriter = Console.Out;
            Console.SetOut(_writer);
            new Thread(() =>
            {
                try
                {
                    _battle.Begin();
                }
                catch (Exception e)
                {
                    CatchException(e);
                }
            })
            {
                Name = "Battle Thread"
            }.Start();
        }
        public void BellyDrum_Contrary__Bug(bool bugFix)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            var settings = new PBESettings {
                BugFix = bugFix
            };
            settings.MakeReadOnly();

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Hariyama, 0, 100, PBEMove.BellyDrum)
            {
                Ability = PBEAbility.Contrary
            };

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon hariyama = t0.Party[0];
            PBEBattlePokemon magikarp = t1.Party[0];
            hariyama.AttackChange = settings.MaxStatChange;

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(hariyama, PBEMove.BellyDrum, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            if (settings.BugFix)
            {
                Assert.True(!battle.VerifyMoveResultHappened(hariyama, hariyama, PBEResult.InvalidConditions) &&
                            hariyama.AttackChange == -settings.MaxStatChange); // Stat minimized because of Contrary
            }
            else
            {
                Assert.True(battle.VerifyMoveResultHappened(hariyama, hariyama, PBEResult.InvalidConditions) &&
                            hariyama.AttackChange == settings.MaxStatChange); // Buggy
            }
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void SecretPower_SereneGrace__Bug(bool bugFix)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 473; // Seed ensures SecretPower does not freeze without the bugfix
            var settings = new PBESettings {
                BugFix = bugFix
            };
            settings.MakeReadOnly();

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Makuhita, 0, 1, PBEMove.SecretPower)
            {
                Ability = PBEAbility.SereneGrace
            };

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"),
                                       battleTerrain: PBEBattleTerrain.Snow);
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon makuhita = t0.Party[0];
            PBEBattlePokemon magikarp = t1.Party[0];

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(makuhita, PBEMove.SecretPower, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            if (settings.BugFix)
            {
                Assert.True(battle.VerifyStatus1Happened(magikarp, makuhita, PBEStatus1.Frozen, PBEStatusAction.Added) &&
                            magikarp.Status1 == PBEStatus1.Frozen); // Frozen because of Serene Grace
            }
            else
            {
                Assert.True(!battle.VerifyStatus1Happened(magikarp, makuhita, PBEStatus1.Frozen, PBEStatusAction.Added) &&
                            magikarp.Status1 == PBEStatus1.None); // Buggy
            }
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #23
0
        public void Gem_Activates__FixedDamage__Bug(bool bugFix)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            var settings = new PBESettings {
                BugFix = bugFix
            };
            settings.MakeReadOnly();

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Swellow, 0, 1, PBEMove.Endeavor)
            {
                Item = PBEItem.NormalGem
            };

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon swellow  = t0.Party[0];
            PBEBattlePokemon magikarp = t1.Party[0];

            battle.Begin();
            #endregion

            #region Use and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(swellow, PBEMove.Endeavor, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            if (settings.BugFix)
            {
                Assert.True(!battle.VerifyItemHappened(swellow, swellow, PBEItem.NormalGem, PBEItemAction.Consumed) &&
                            swellow.Item == PBEItem.NormalGem); // Not consumed
            }
            else
            {
                Assert.True(battle.VerifyItemHappened(swellow, swellow, PBEItem.NormalGem, PBEItemAction.Consumed) &&
                            swellow.Item == PBEItem.None); // Buggy
            }
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Explosion_User_Loses_Multiple()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(3);
            p0[0] = new TestPokemon(settings, PBESpecies.Qwilfish, 0, 1, PBEMove.Splash);
            p0[1] = new TestPokemon(settings, PBESpecies.Golem, 0, 100, PBEMove.Explosion);
            p0[2] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Splash);

            var p1 = new TestPokemonCollection(3);
            p1[0] = new TestPokemon(settings, PBESpecies.Patrat, 0, 1, PBEMove.Splash);
            p1[1] = new TestPokemon(settings, PBESpecies.Lickilicky, 0, 1, PBEMove.Splash);
            p1[2] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Triple, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0         = battle.Trainers[0];
            PBETrainer       t1         = battle.Trainers[1];
            PBEBattlePokemon qwilfish   = t0.Party[0];
            PBEBattlePokemon golem      = t0.Party[1];
            PBEBattlePokemon magikarp   = t0.Party[2];
            PBEBattlePokemon patrat     = t1.Party[0];
            PBEBattlePokemon lickilicky = t1.Party[1];
            PBEBattlePokemon happiny    = t1.Party[2];

            battle.Begin();
            #endregion

            #region Use move and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(qwilfish, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(golem, PBEMove.Explosion, PBETurnTarget.AllyLeft | PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeCenter | PBETurnTarget.FoeRight),
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(patrat, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(lickilicky, PBEMove.Splash, PBETurnTarget.AllyCenter),
                            new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True(qwilfish.HP == 0 && golem.HP == 0 && magikarp.HP == 0 && patrat.HP == 0 && lickilicky.HP == 0 && happiny.HP == 0 && // All faint
                        battle.BattleResult == PBEBattleResult.Team1Win); // Golem's team loses
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #25
0
        public void Intimidate_Does_Not_Hit_Through_Substitute()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Shuckle, 0, 100, PBEMove.Substitute, PBEMove.Splash);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Skitty, 0, 100, PBEMove.Splash);
            p1[1] = new TestPokemon(settings, PBESpecies.Luxray, 0, 100, PBEMove.Splash)
            {
                Ability = PBEAbility.Intimidate
            };

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0      = battle.Trainers[0];
            PBETrainer       t1      = battle.Trainers[1];
            PBEBattlePokemon shuckle = t0.Party[0];
            PBEBattlePokemon skitty  = t1.Party[0];
            PBEBattlePokemon luxray  = t1.Party[1];

            battle.Begin();
            #endregion

            #region Use Substitute
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(shuckle, PBEMove.Substitute, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(skitty, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(shuckle.Status2.HasFlag(PBEStatus2.Substitute));
            #endregion

            #region Switch in Luxray and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(shuckle, PBEMove.Splash, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(skitty, luxray)));

            battle.RunTurn();

            Assert.True(battle.VerifyAbilityHappened(luxray, luxray, PBEAbility.Intimidate, PBEAbilityAction.Stats) && // Activated
                        battle.VerifyMoveResultHappened(luxray, shuckle, PBEResult.Ineffective_Substitute) && shuckle.AttackChange == 0); // Did not affect
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #26
0
        public void Shaymin_Reverts_To_Normal_Form_Forever()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 40703; // Seed ensures SecretPower freezes
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Happiny, 0, 100, PBEMove.SecretPower, PBEMove.Splash)
            {
                Ability = PBEAbility.SereneGrace
            };

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Shaymin, PBEForm.Shaymin_Sky, 100, PBEMove.Splash);
            p1[1] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"),
                                       battleTerrain: PBEBattleTerrain.Snow);
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon happiny  = t0.Party[0];
            PBEBattlePokemon shaymin  = t1.Party[0];
            PBEBattlePokemon magikarp = t1.Party[1];

            battle.Begin();
            #endregion

            #region Freeze Shaymin
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(happiny, PBEMove.SecretPower, PBETurnTarget.FoeCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(shaymin, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(shaymin.Status1 == PBEStatus1.Frozen && shaymin.Form == PBEForm.Shaymin);
            #endregion

            #region Swap Shaymin for Magikarp and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(shaymin, magikarp)));

            battle.RunTurn();

            Assert.True(shaymin.Form == PBEForm.Shaymin);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void NaturalCure_Works_On_Battle_Ending()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Splash);

            var p1 = new TestPokemonCollection(1);
            p1[0] = new TestPokemon(settings, PBESpecies.Shaymin, PBEForm.Shaymin, 100, PBEMove.Splash, PBEMove.QuickAttack)
            {
                Ability = PBEAbility.NaturalCure,
                Item    = PBEItem.FlameOrb
            };

            var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1"));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0      = battle.Trainers[0];
            PBETrainer       t1      = battle.Trainers[1];
            PBEBattlePokemon happiny = t0.Party[0];
            PBEBattlePokemon shaymin = t1.Party[0];

            battle.Begin();
            #endregion

            #region Burn Shaymin
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(shaymin, PBEMove.Splash, PBETurnTarget.AllyCenter)));

            battle.RunTurn();

            Assert.True(shaymin.Status1 == PBEStatus1.Burned);
            #endregion

            #region End battle and check
            Assert.Null(t0.SelectActionsIfValid(new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyCenter)));
            Assert.Null(t1.SelectActionsIfValid(new PBETurnAction(shaymin, PBEMove.QuickAttack, PBETurnTarget.FoeCenter)));

            battle.RunTurn();

            Assert.True(battle.BattleResult == PBEBattleResult.Team1Win &&
                        battle.BattleState == PBEBattleState.Ended &&
                        shaymin.Status1 == PBEStatus1.None);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void AutoCenter_Works_MultiBattle(bool faintLeft)
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var pL = new TestPokemonCollection(1);
            pL[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Protect, PBEMove.Splash);
            var pC = new TestPokemonCollection(1);
            pC[0] = new TestPokemon(settings, PBESpecies.Golem, 0, 100, PBEMove.Explosion);
            var pR = new TestPokemonCollection(1);
            pR[0] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Protect, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Triple, settings,
                                       new[] { new PBETrainerInfo(pL, "Trainer 0"), new PBETrainerInfo(pC, "Trainer 1"), new PBETrainerInfo(pR, "Trainer 2") },
                                       new[] { new PBETrainerInfo(pL, "Trainer 3"), new PBETrainerInfo(pC, "Trainer 4"), new PBETrainerInfo(pR, "Trainer 5") });
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0L       = battle.Trainers[0];
            PBETrainer       t0C       = battle.Trainers[1];
            PBETrainer       t0R       = battle.Trainers[2];
            PBETrainer       t1L       = battle.Trainers[3];
            PBETrainer       t1C       = battle.Trainers[4];
            PBETrainer       t1R       = battle.Trainers[5];
            PBEBattlePokemon magikarp0 = t0L.Party[0];
            PBEBattlePokemon golem0    = t0C.Party[0];
            PBEBattlePokemon happiny0  = t0R.Party[0];
            PBEBattlePokemon magikarp1 = t1L.Party[0];
            PBEBattlePokemon golem1    = t1C.Party[0];
            PBEBattlePokemon happiny1  = t1R.Party[0];

            battle.Begin();
            #endregion

            #region Force auto-center and check
            Assert.Null(t0L.SelectActionsIfValid(new PBETurnAction(magikarp0, faintLeft ? PBEMove.Splash : PBEMove.Protect, PBETurnTarget.AllyLeft)));
            Assert.Null(t0C.SelectActionsIfValid(new PBETurnAction(golem0, PBEMove.Explosion, PBETurnTarget.AllyLeft | PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeCenter | PBETurnTarget.FoeRight)));
            Assert.Null(t0R.SelectActionsIfValid(new PBETurnAction(happiny0, faintLeft ? PBEMove.Protect : PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.Null(t1L.SelectActionsIfValid(new PBETurnAction(magikarp1, faintLeft ? PBEMove.Splash : PBEMove.Protect, PBETurnTarget.AllyLeft)));
            Assert.Null(t1C.SelectActionsIfValid(new PBETurnAction(golem1, PBEMove.Explosion, PBETurnTarget.AllyLeft | PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeCenter | PBETurnTarget.FoeRight)));
            Assert.Null(t1R.SelectActionsIfValid(new PBETurnAction(happiny1, faintLeft ? PBEMove.Protect : PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True((faintLeft ? happiny0 : magikarp0).FieldPosition == PBEFieldPosition.Center && (faintLeft ? happiny1 : magikarp1).FieldPosition == PBEFieldPosition.Center);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
Example #29
0
        public void AutoCenter_Works_MultiBattle(bool left)
        {
            #region Setup
            PBERandom.SetSeed(0);
            PBESettings settings = PBESettings.DefaultSettings;

            var pM = new TestPokemonCollection(1);
            pM[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Protect, PBEMove.Splash);
            var pG = new TestPokemonCollection(1);
            pG[0] = new TestPokemon(settings, PBESpecies.Golem, 0, 100, PBEMove.Explosion);
            var pH = new TestPokemonCollection(1);
            pH[0] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Protect, PBEMove.Splash);

            var battle = new PBEBattle(PBEBattleFormat.Triple, settings,
                                       new[] { new PBETrainerInfo(pM, "Trainer 0"), new PBETrainerInfo(pG, "Trainer 1"), new PBETrainerInfo(pH, "Trainer 3") },
                                       new[] { new PBETrainerInfo(pM, "Trainer 3"), new PBETrainerInfo(pG, "Trainer 4"), new PBETrainerInfo(pH, "Trainer 5") });
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;
            battle.Begin();

            PBETrainer       t0M       = battle.Trainers[0];
            PBETrainer       t0G       = battle.Trainers[1];
            PBETrainer       t0H       = battle.Trainers[2];
            PBETrainer       t1M       = battle.Trainers[3];
            PBETrainer       t1G       = battle.Trainers[4];
            PBETrainer       t1H       = battle.Trainers[5];
            PBEBattlePokemon magikarp0 = t0M.Party[0];
            PBEBattlePokemon golem0    = t0G.Party[0];
            PBEBattlePokemon happiny0  = t0H.Party[0];
            PBEBattlePokemon magikarp1 = t1M.Party[0];
            PBEBattlePokemon golem1    = t1G.Party[0];
            PBEBattlePokemon happiny1  = t1H.Party[0];
            #endregion

            #region Force auto-center and check
            Assert.True(PBEBattle.SelectActionsIfValid(t0M, new PBETurnAction(magikarp0, left ? PBEMove.Splash : PBEMove.Protect, PBETurnTarget.AllyLeft)));
            Assert.True(PBEBattle.SelectActionsIfValid(t0G, new PBETurnAction(golem0, PBEMove.Explosion, PBETurnTarget.AllyLeft | PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeCenter | PBETurnTarget.FoeRight)));
            Assert.True(PBEBattle.SelectActionsIfValid(t0H, new PBETurnAction(happiny0, left ? PBEMove.Protect : PBEMove.Splash, PBETurnTarget.AllyRight)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1M, new PBETurnAction(magikarp1, left ? PBEMove.Splash : PBEMove.Protect, PBETurnTarget.AllyLeft)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1G, new PBETurnAction(golem1, PBEMove.Explosion, PBETurnTarget.AllyLeft | PBETurnTarget.AllyRight | PBETurnTarget.FoeLeft | PBETurnTarget.FoeCenter | PBETurnTarget.FoeRight)));
            Assert.True(PBEBattle.SelectActionsIfValid(t1H, new PBETurnAction(happiny1, left ? PBEMove.Protect : PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True((left ? happiny0 : magikarp0).FieldPosition == PBEFieldPosition.Center && (left ? happiny1 : magikarp1).FieldPosition == PBEFieldPosition.Center);
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }
        public void Whirlwind_Fails_WildDoubleBattle()
        {
            #region Setup
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Tropius, 0, 100, PBEMove.Whirlwind);

            var p1 = new TestPokemonCollection(2);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 1, PBEMove.Splash)
            {
                CaughtBall = PBEItem.None
            };
            p1[1] = new TestPokemon(settings, PBESpecies.Happiny, 0, 1, PBEMove.Splash)
            {
                CaughtBall = PBEItem.None
            };

            var battle = new PBEBattle(PBEBattleFormat.Double, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBEWildInfo(p1));
            battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler;

            PBETrainer       t0       = battle.Trainers[0];
            PBETrainer       t1       = battle.Trainers[1];
            PBEBattlePokemon tropius  = t0.Party[0];
            PBEBattlePokemon magikarp = t1.Party[0];
            PBEBattlePokemon happiny  = t1.Party[1];

            battle.Begin();
            #endregion

            #region Use Whirlwind and check
            Assert.Null(t0.SelectActionsIfValid(
                            new PBETurnAction(tropius, PBEMove.Whirlwind, PBETurnTarget.FoeLeft)));
            Assert.Null(t1.SelectActionsIfValid(
                            new PBETurnAction(magikarp, PBEMove.Splash, PBETurnTarget.AllyLeft),
                            new PBETurnAction(happiny, PBEMove.Splash, PBETurnTarget.AllyRight)));

            battle.RunTurn();

            Assert.True(battle.VerifyMoveResultHappened(tropius, magikarp, PBEResult.InvalidConditions) && // Fail
                        !battle.BattleResult.HasValue); // Did not flee
            #endregion

            #region Cleanup
            battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler;
            #endregion
        }