Beispiel #1
0
        private static void RandomizePokemon(
            PKMN.GameSave gameSave,
            PKMN.ItemEnumList itemList
            )
        {
            PKMN.Game game = gameSave.Game;

            PKMN.MoveEnumList    moveList    = PKMN.Database.Lists.MoveList(game);
            PKMN.SpeciesEnumList pokemonList = PKMN.Database.Lists.PokemonList(1, true);

            PKMN.PokemonParty party = gameSave.PokemonParty;
            for (int i = 0; i < 6; ++i)
            {
                party[i] = Util.GetRandomPokemon(game, itemList, moveList, pokemonList);
            }

            PKMN.PokemonPC PC = gameSave.PokemonPC;
            for (int i = 0; i < PC.Length; ++i)
            {
                PKMN.PokemonBox box = PC[i];
                for (int j = 0; j < box.Length; ++j)
                {
                    box[j] = Util.GetRandomPokemon(game, itemList, moveList, pokemonList);
                }
            }
        }
Beispiel #2
0
        private static void TestEmptyPokemonParty(
            PKMN.PokemonParty party
            )
        {
            Assert.AreEqual(6, party.Length);

            for (int i = 0; i < party.Length; ++i)
            {
                Assert.AreEqual(PKMN.Species.NONE, party[i].Species);
                Assert.AreEqual(party.Game, party[i].Game);

                for (int j = 0; j < party[i].Moves.Count; ++j)
                {
                    Assert.AreEqual(PKMN.Move.NONE, party[i].Moves[j].Move);
                    Assert.AreEqual(0, party[i].Moves[j].PP);
                }
            }

            // Make sure trying to get a Pokémon at an invalid index fails.
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                PKMN.Pokemon pokemon = party[-1];
            }
                );
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                PKMN.Pokemon pokemon = party[party.Length];
            }
                );
        }
Beispiel #3
0
 public static void TestPokemonParty(
     PKMN.PokemonParty party,
     PKMN.Game[] validOtherGames,
     PKMN.Game invalidOtherGame
     )
 {
     TestEmptyPokemonParty(party);
     TestSettingPokemon(party, validOtherGames, invalidOtherGame);
 }
Beispiel #4
0
        private static void TestCommonFields(
            PKMN.GameSave gameSave
            )
        {
            PKMN.Game game = gameSave.Game;

            // Trainer name
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                gameSave.TrainerName = "";
            }
                );
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                gameSave.TrainerName = "LibPKMNLibPKMN";
            }
                );
            gameSave.TrainerName = "LibPKMN";
            Assert.AreEqual(gameSave.TrainerName, "LibPKMN");

            // Trainer ID
            gameSave.TrainerID = IsGBGame(game) ? DEFAULT_TRAINER_PID : PKMN.Pokemon.DefaultTrainerID;
            TestTrainerID(gameSave);
            gameSave.TrainerPublicID = DEFAULT_TRAINER_PID;
            TestTrainerID(gameSave);
            if (IsGBGame(game))
            {
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerSecretID = DEFAULT_TRAINER_SID;
                }
                    );
            }
            else
            {
                gameSave.TrainerSecretID = DEFAULT_TRAINER_SID;
                TestTrainerID(gameSave);
            }

            // Rival Name
            if (IsRivalNameSet(game))
            {
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.RivalName = PKMN.Pokemon.DefaultTrainerName;
                }
                    );
            }
            else
            {
                gameSave.RivalName = PKMN.Pokemon.DefaultTrainerName;
                Assert.AreEqual(gameSave.RivalName, PKMN.Pokemon.DefaultTrainerName);
            }

            // Trainer Gender
            if (IsMaleOnly(game))
            {
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.MALE);
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.MALE;
                }
                    );
                Assert.Throws <ApplicationException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.FEMALE;
                }
                    );
            }
            else
            {
                gameSave.TrainerGender = PKMN.Gender.MALE;
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.MALE);
                gameSave.TrainerGender = PKMN.Gender.FEMALE;
                Assert.AreEqual(gameSave.TrainerGender, PKMN.Gender.FEMALE);
                Assert.Throws <ArgumentOutOfRangeException>(
                    delegate
                {
                    gameSave.TrainerGender = PKMN.Gender.GENDERLESS;
                }
                    );
            }

            // Money
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                gameSave.Money = -1;
            }
                );
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                gameSave.Money = MONEY_MAX + 1;
            }
                );
            gameSave.Money = 123456;
            Assert.AreEqual(gameSave.Money, 123456);

            // Pokémon Party
            PKMN.PokemonParty party = gameSave.PokemonParty;
            int numPokemon          = party.NumPokemon;

            Assert.AreEqual(party.Length, 6);

            Assert.Greater(numPokemon, 0);
            Assert.LessOrEqual(numPokemon, 6);
            for (int i = 0; i < 6; ++i)
            {
                if (i < numPokemon)
                {
                    Assert.AreNotEqual(party[i].Species, PKMN.Species.NONE);
                }
                else
                {
                    Assert.AreEqual(party[i].Species, PKMN.Species.NONE);
                }
            }

            // Pokémon PC
            PKMN.PokemonPC pokemonPC = gameSave.PokemonPC;
            for (int i = 0; i < pokemonPC.Length; ++i)
            {
                PKMN.PokemonBox box = pokemonPC[i];

                Assert.LessOrEqual(box.NumPokemon, box.Length);

                // Boxes are only contiguous in Game Boy games.
                if (IsGBGame(game))
                {
                    numPokemon = box.NumPokemon;
                    for (int j = 0; j < box.Length; ++j)
                    {
                        if (j < numPokemon)
                        {
                            Assert.AreNotEqual(box[j].Species, PKMN.Species.NONE);
                        }
                        else
                        {
                            Assert.AreEqual(box[j].Species, PKMN.Species.NONE);
                        }
                    }
                }
            }

            // Pokédex
            if (!IsGameGamecube(game))
            {
                PKMN.Pokedex pokedex = gameSave.Pokedex;
                Assert.GreaterOrEqual(pokedex.NumSeen, pokedex.NumCaught);

                for (int partyIndex = 0; partyIndex < party.Length; ++partyIndex)
                {
                    PKMN.Species species = party[partyIndex].Species;
                    if ((species != PKMN.Species.NONE) && !party[partyIndex].IsEgg)
                    {
                        Assert.IsTrue(pokedex.SeenPokemonMap[species]);
                        Assert.IsTrue(pokedex.CaughtPokemonMap[species]);
                    }
                }

                for (int PCIndex = 0; PCIndex < pokemonPC.Length; ++PCIndex)
                {
                    PKMN.PokemonBox box = pokemonPC[PCIndex];
                    for (int boxIndex = 0; boxIndex < box.Length; ++boxIndex)
                    {
                        PKMN.Species species = box[boxIndex].Species;
                        if ((species != PKMN.Species.NONE) && !box[boxIndex].IsEgg)
                        {
                            Assert.IsTrue(pokedex.SeenPokemonMap[species]);
                            Assert.IsTrue(pokedex.CaughtPokemonMap[species]);
                        }
                    }
                }

                // Make sure that when a Pokémon is added to the party or PC, it's
                // added to the Pokédex. Manually remove the test species from the
                // Pokédex to confirm this behavior.

                PKMN.Species testSpecies1 = PKMN.Species.BULBASAUR;
                PKMN.Species testSpecies2 = PKMN.Species.CHARMANDER;

                pokedex.SeenPokemonMap[testSpecies1] = false;
                Assert.IsFalse(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsFalse(pokedex.CaughtPokemonMap[testSpecies1]);

                pokedex.SeenPokemonMap[testSpecies2] = false;
                Assert.IsFalse(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsFalse(pokedex.CaughtPokemonMap[testSpecies1]);

                PKMN.Pokemon testPokemon1 = new PKMN.Pokemon(
                    testSpecies1,
                    game,
                    "",
                    5
                    );
                PKMN.Pokemon testPokemon2 = new PKMN.Pokemon(
                    testSpecies2,
                    game,
                    "",
                    5
                    );


                party[0] = testPokemon1;
                Assert.IsTrue(pokedex.SeenPokemonMap[testSpecies1]);
                Assert.IsTrue(pokedex.CaughtPokemonMap[testSpecies1]);

                pokemonPC[0][0] = testPokemon2;
                Assert.IsTrue(pokedex.SeenPokemonMap[testSpecies2]);
                Assert.IsTrue(pokedex.CaughtPokemonMap[testSpecies2]);
            }

            TestTimePlayed(gameSave);
        }
Beispiel #5
0
        private static void TestSettingPokemon(
            PKMN.PokemonParty party,
            PKMN.Game[] validOtherGames,
            PKMN.Game invalidOtherGame
            )
        {
            PKMN.Pokemon originalFirst  = party[0];
            PKMN.Pokemon originalSecond = party[1];

            // Make sure we can't set Pokémon at invalid indices.
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                party[-1] = originalFirst;
            }
                );
            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                party[party.Length] = originalSecond;
            }
                );

            // Create Pokémon and place in party. The original variables should
            // still have the same underlying Pokémon.
            PKMN.Pokemon bulbasaur  = new PKMN.Pokemon(PKMN.Species.BULBASAUR, party.Game, "", 5);
            PKMN.Pokemon charmander = new PKMN.Pokemon(PKMN.Species.CHARMANDER, party.Game, "", 5);
            PKMN.Pokemon squirtle   = new PKMN.Pokemon(PKMN.Species.SQUIRTLE, party.Game, "", 5);

            party[0] = bulbasaur;
            Assert.AreEqual(1, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.BULBASAUR, party[0].Species);
            party[1] = charmander;
            Assert.AreEqual(2, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species);

            // Replace one of the new ones.
            party[0] = squirtle;
            Assert.AreEqual(2, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.SQUIRTLE, party[0].Species);

            // Copy a Pokémon already part of the party.
            party[2] = party[1];
            Assert.AreEqual(3, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species);

            // We should be able to clear the last contiguous Pokémon.
            party[2] = originalFirst;
            Assert.AreEqual(2, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.NONE, party[2].Species);

            // Put it back.
            party[2] = party[1];
            Assert.AreEqual(3, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species);

            // Check that Pokémon cannot be placed non-contiguously.
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                party[1] = originalFirst;
            }
                );
            Assert.AreEqual(3, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species);

            Assert.Throws <IndexOutOfRangeException>(
                delegate
            {
                party[4] = bulbasaur;
            }
                );
            Assert.AreEqual(3, party.NumPokemon);
            Assert.AreEqual(PKMN.Species.NONE, party[4].Species);

            // Now check everything we've created. Each variable should have
            // the same underlying Pokémon.
            Assert.AreEqual(PKMN.Species.SQUIRTLE, party[0].Species);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[1].Species);
            Assert.AreEqual(PKMN.Species.CHARMANDER, party[2].Species);
            Assert.AreEqual(PKMN.Species.NONE, originalFirst.Species);
            Assert.AreEqual(PKMN.Species.NONE, originalSecond.Species);
            Assert.AreEqual(PKMN.Species.BULBASAUR, bulbasaur.Species);
            Assert.AreEqual(PKMN.Species.CHARMANDER, charmander.Species);
            Assert.AreEqual(PKMN.Species.SQUIRTLE, squirtle.Species);

            // Make sure converting Pokémon before putting them in the party works (or doesn't)
            // as expected.
            foreach (PKMN.Game validGame in validOtherGames)
            {
                PKMN.Pokemon pikachu = new PKMN.Pokemon(
                    PKMN.Species.PIKACHU,
                    validGame,
                    "",
                    50
                    );
                Assert.AreEqual(validGame, pikachu.Game);

                party[3] = pikachu;
                Assert.AreEqual(PKMN.Species.PIKACHU, party[3].Species);
                Assert.AreEqual(party.Game, party[3].Game);
                Assert.AreEqual(50, party[3].Level);
            }

            PKMN.Pokemon invalidPikachu = new PKMN.Pokemon(
                PKMN.Species.PIKACHU,
                invalidOtherGame,
                "",
                50
                );
            Assert.Throws <ArgumentOutOfRangeException>(
                delegate
            {
                party[3] = invalidPikachu;
            }
                );
        }