Пример #1
0
    public void ItemEnumListTest()
    {
        PKMN.ItemEnumList itemEnumList = new PKMN.ItemEnumList();
        itemEnumList.Add(PKMN.Item.POKE_BALL);
        itemEnumList.Add(PKMN.Item.NET_BALL);
        itemEnumList.Add(PKMN.Item.LUXURY_BALL);
        itemEnumList.Add(PKMN.Item.HEAVY_BALL);
        itemEnumList.Add(PKMN.Item.DREAM_BALL);

        PKMN.ItemEnumList itemEnumListSame = new PKMN.ItemEnumList();
        itemEnumListSame.Add(PKMN.Item.POKE_BALL);
        itemEnumListSame.Add(PKMN.Item.NET_BALL);
        itemEnumListSame.Add(PKMN.Item.LUXURY_BALL);
        itemEnumListSame.Add(PKMN.Item.HEAVY_BALL);
        itemEnumListSame.Add(PKMN.Item.DREAM_BALL);

        PKMN.ItemEnumList itemEnumListReversed = new PKMN.ItemEnumList();
        itemEnumListReversed.Add(PKMN.Item.DREAM_BALL);
        itemEnumListReversed.Add(PKMN.Item.HEAVY_BALL);
        itemEnumListReversed.Add(PKMN.Item.LUXURY_BALL);
        itemEnumListReversed.Add(PKMN.Item.NET_BALL);
        itemEnumListReversed.Add(PKMN.Item.POKE_BALL);

        Assert.AreEqual(itemEnumList, itemEnumList);
        Assert.AreEqual(itemEnumList, itemEnumListSame);
        Assert.AreEqual(itemEnumList.GetHashCode(), itemEnumListSame.GetHashCode());

        Assert.AreNotEqual(itemEnumList, itemEnumListReversed);
        Assert.AreNotEqual(itemEnumList.GetHashCode(), itemEnumListReversed.GetHashCode());
    }
Пример #2
0
        public static void ItemPCTest(
            PKMN.ItemList itemPC,
            PKMN.Game game
            )
        {
            // Check unchanging and initial values.
            Assert.AreEqual(itemPC.Name, "PC");
            Assert.AreEqual(itemPC.Game, game);
            Assert.AreEqual(itemPC.Length, 50);
            Assert.AreEqual(itemPC.NumItems, 0);

            // Make sure item slots start as correctly empty.
            ItemsTestsCommon.TestItemListEmptySlots(itemPC);

            // Confirm exceptions are thrown when expected.
            ItemsTestsCommon.TestItemListIndexOutOfRangeException(
                itemPC,
                PKMN.Item.POTION
                );

            // Confirm items from later generations can't be added.
            ItemsTestsCommon.TestItemListInvalidItems(
                itemPC,
                WrongGenerationAllPocketItems
                );

            // Crystal-specific items.
            if (game == PKMN.Game.CRYSTAL)
            {
                foreach (PKMN.Item crystalItem in CrystalItems)
                {
                    itemPC.Add(crystalItem, 1);
                    itemPC.Remove(crystalItem, 1);
                }

                Assert.AreEqual(itemPC.NumItems, 0);
            }
            else
            {
                ItemsTestsCommon.TestItemListInvalidItems(
                    itemPC,
                    CrystalItems
                    );
            }

            // Start adding and removing stuff, and make sure the numbers are accurate.
            ItemsTestsCommon.TestItemListSettingItems(
                itemPC,
                AllPocketItems
                );
            ItemsTestsCommon.TestItemListAddingAndRemovingItems(
                itemPC,
                AllPocketItems
                );

            PKMN.ItemEnumList fullItemList = PKMN.Database.Lists.ItemList(game);

            Assert.AreEqual(itemPC.ValidItems.Count, itemPC.ValidItemNames.Count);
            Assert.AreEqual(itemPC.ValidItems.Count, fullItemList.Count);
        }
Пример #3
0
        private static void TestLoadingAndSaving(
            PKMN.Game game,
            string extension
            )
        {
            string tmpPath = System.IO.Path.Combine(
                TmpDir,
                String.Format("{0}_{1}.{2}",
                              game,
                              rng.Next(),
                              extension
                              )
                );

            PKMN.ItemEnumList    itemList    = PKMN.Database.Lists.ItemList(game);
            PKMN.MoveEnumList    moveList    = PKMN.Database.Lists.MoveList(game);
            PKMN.SpeciesEnumList pokemonList = PKMN.Database.Lists.PokemonList(
                Util.GameToGeneration(game),
                true
                );

            PKMN.Pokemon randomPokemon = Util.GetRandomPokemon(game, itemList, moveList, pokemonList);
            randomPokemon.ExportToFile(tmpPath);

            PKMN.Pokemon importedPokemon = new PKMN.Pokemon(tmpPath);
            Util.ComparePokemon(randomPokemon, importedPokemon);

            System.IO.File.Delete(tmpPath);
        }
Пример #4
0
        public static void ItemListCommon(
            PKMN.ItemList itemList,
            PKMN.Game game
            )
        {
            // Make sure item slots start as correctly empty.
            ItemsTestsCommon.TestItemListEmptySlots(itemList);

            // Confirm exceptions are thrown when expected.
            ItemsTestsCommon.TestItemListIndexOutOfRangeException(
                itemList,
                PKMN.Item.POTION
                );

            // Confirm items from later generations can't be added.
            ItemsTestsCommon.TestItemListInvalidItems(
                itemList,
                WrongGenerationItems
                );

            // Start adding and removing stuff, and make sure the numbers are accurate.
            ItemsTestsCommon.TestItemListSettingItems(
                itemList,
                Items
                );
            ItemsTestsCommon.TestItemListAddingAndRemovingItems(
                itemList,
                Items
                );

            PKMN.ItemEnumList fullItemList = PKMN.Database.Lists.ItemList(game);

            Assert.AreEqual(itemList.ValidItems.Count, itemList.ValidItemNames.Count);
            Assert.AreEqual(itemList.ValidItems.Count, fullItemList.Count);
        }
Пример #5
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);
                }
            }
        }
Пример #6
0
        public static void ItemPCTest(
            PKMN.ItemList itemPC,
            PKMN.Game game
            )
        {
            // Check unchanging and initial values.
            Assert.AreEqual(itemPC.Name, "PC");
            Assert.AreEqual(itemPC.Game, game);
            Assert.AreEqual(itemPC.Length, 50);
            Assert.AreEqual(itemPC.NumItems, 0);

            // Make sure item slots start as correctly empty.
            ItemsTestsCommon.TestItemListEmptySlots(itemPC);

            // Confirm exceptions are thrown when expected.
            ItemsTestsCommon.TestItemListIndexOutOfRangeException(
                itemPC,
                PKMN.Item.POTION
                );

            // Confirm items from later generations can't be added.
            ItemsTestsCommon.TestItemListInvalidItems(
                itemPC,
                WrongGameAllPocketItems
                );

            // Start adding and removing stuff, and make sure the numbers are accurate.
            ItemsTestsCommon.TestItemListSettingItems(
                itemPC,
                AllPocketItems
                );
            ItemsTestsCommon.TestItemListAddingAndRemovingItems(
                itemPC,
                AllPocketItems
                );

            Assert.AreEqual(itemPC.ValidItems.Count, itemPC.ValidItemNames.Count);

            PKMN.ItemEnumList fullItemList     = PKMN.Database.Lists.ItemList(game);
            PKMN.StringList   fullItemNameList = PKMN.Database.Lists.ItemNameList(game);
            Assert.AreEqual(fullItemList.Count, fullItemNameList.Count);

            if ((game == PKMN.Game.FIRERED) || (game == PKMN.Game.LEAFGREEN))
            {
                Assert.AreEqual(itemPC.ValidItems.Count, fullItemList.Count - 2);

                Assert.IsFalse(itemPC.ValidItems.Contains(PKMN.Item.BERRY_POUCH));
                Assert.IsFalse(itemPC.ValidItems.Contains(PKMN.Item.TM_CASE));

                Assert.IsFalse(itemPC.ValidItemNames.Contains("Berry Pouch"));
                Assert.IsFalse(itemPC.ValidItemNames.Contains("TM Case"));
            }
            else
            {
                Assert.AreEqual(itemPC.ValidItems.Count, fullItemList.Count);
            }
        }
Пример #7
0
        public static void TestGameSave(
            PKMN.GameSaveType type,
            PKMN.Game game,
            string subPath
            )
        {
            string saveFilepath = "";

            if (IsGameGamecube(game))
            {
                saveFilepath = Path.GetFullPath(Path.Combine(LIBPKMN_TEST_FILES, subPath));
            }
            else
            {
                saveFilepath = Path.GetFullPath(Path.Combine(PKSAV_TEST_SAVES, subPath));
            }
            Assert.AreEqual(PKMN.GameSave.DetectType(saveFilepath), type);

            PKMN.GameSave gameSave = new PKMN.GameSave(saveFilepath);
            Assert.AreEqual(gameSave.Filepath, saveFilepath);
            Assert.AreEqual(gameSave.Game, game);

            PKMN.ItemEnumList itemList = PKMN.Database.Lists.ItemList(game);

            TestCommonFields(gameSave);
            TestAttributes(gameSave);

            // TODO: RandomizeItems
            RandomizePokemon(
                gameSave,
                itemList
                );

            string tempSaveFilepath = Path.GetFullPath(
                Path.Combine(
                    PKMN_TMP_DIR,
                    String.Format("{0}_{1}.sav", game, rng.Next())
                    )
                );

            gameSave.SaveAs(tempSaveFilepath);
            PKMN.GameSave gameSave2 = new PKMN.GameSave(tempSaveFilepath);
            Assert.AreEqual(gameSave2.Filepath, tempSaveFilepath);

            CompareGameSaves(
                gameSave,
                gameSave2
                );

            File.Delete(tempSaveFilepath);
        }
Пример #8
0
        public static void ItemPCTest(
            PKMN.ItemList itemPC,
            PKMN.Game game
            )
        {
            bool colosseum = (game == PKMN.Game.COLOSSEUM);

            // Check unchanging and initial values.
            Assert.AreEqual(itemPC.Name, "PC");
            Assert.AreEqual(itemPC.Game, game);
            Assert.AreEqual(itemPC.Length, 235);
            Assert.AreEqual(itemPC.NumItems, 0);

            // Make sure item slots start as correctly empty.
            ItemsTestsCommon.TestItemListEmptySlots(itemPC);

            // Confirm exceptions are thrown when expected.
            ItemsTestsCommon.TestItemListIndexOutOfRangeException(
                itemPC,
                PKMN.Item.POTION
                );

            // Confirm items from later generations can't be added.
            ItemsTestsCommon.TestItemListInvalidItems(
                itemPC,
                colosseum ? ColosseumWrongGameAllPocketItems : XDWrongGameAllPocketItems
                );

            // Start adding and removing stuff, and make sure the numbers are accurate.
            ItemsTestsCommon.TestItemListSettingItems(
                itemPC,
                colosseum ? ColosseumAllPocketItems : XDAllPocketItems
                );
            ItemsTestsCommon.TestItemListAddingAndRemovingItems(
                itemPC,
                colosseum ? ColosseumAllPocketItems : XDAllPocketItems
                );

            PKMN.ItemEnumList fullItemList     = PKMN.Database.Lists.ItemList(game);
            PKMN.StringList   fullItemNameList = PKMN.Database.Lists.ItemNameList(game);

            Assert.AreEqual(itemPC.ValidItems.Count, itemPC.ValidItemNames.Count);
            Assert.AreEqual(itemPC.ValidItems.Count, fullItemList.Count);
            Assert.AreEqual(itemPC.ValidItemNames.Count, fullItemNameList.Count);
        }
Пример #9
0
    public void ItemListTest()
    {
        // Make sure trying to create an invalid list results in an exception
        Assert.Throws <ArgumentOutOfRangeException>(
            delegate
        {
            PKMN.Database.Lists.ItemList(PKMN.Game.NONE);
        }
            );
        Assert.Throws <ArgumentOutOfRangeException>(
            delegate
        {
            PKMN.Database.Lists.ItemNameList(PKMN.Game.NONE);
        }
            );

        PKMN.ItemEnumList itemList = PKMN.Database.Lists.ItemList(PKMN.Game.HEARTGOLD);
        Assert.AreEqual(itemList.Count, 513);
        Assert.AreEqual(itemList[0], PKMN.Item.MASTER_BALL);
        Assert.AreEqual(itemList[512], PKMN.Item.PHOTO_ALBUM);

        PKMN.StringList itemNameList = PKMN.Database.Lists.ItemNameList(PKMN.Game.HEARTGOLD);
        Assert.AreEqual(itemNameList.Count, 513);
        Assert.AreEqual(itemNameList[0], "Master Ball");
        Assert.AreEqual(itemNameList[512], "Photo Album");

        // Make sure lists match. Note that for items, we need to check from
        // name to enum, as there are multiple names for some items but always
        // a single enum.
        Assert.AreEqual(itemList.Count, itemNameList.Count);
        for (int itemIndex = 0; itemIndex < itemList.Count; ++itemIndex)
        {
            PKMN.Item item = PKMN.PKMN.StringToItem(itemNameList[itemIndex]);
            Assert.AreEqual(item, itemList[itemIndex]);
        }
    }
Пример #10
0
        internal static PKMN.Pokemon GetRandomPokemon(
            PKMN.Game game,
            PKMN.ItemEnumList itemList,
            PKMN.MoveEnumList moveList,
            PKMN.SpeciesEnumList pokemonList
            )
        {
            int generation = Util.GameToGeneration(game);

            // Don't deal with Deoxys or Unown issues here.
            PKMN.Species species = PKMN.Species.NONE;
            if (generation == 3)
            {
                do
                {
                    species = pokemonList[rng.Next(0, pokemonList.Count - 1)];
                }while((species == PKMN.Species.DEOXYS) || (species == PKMN.Species.UNOWN));
            }
            else
            {
                species = pokemonList[rng.Next(0, pokemonList.Count - 1)];
            }

            PKMN.Pokemon ret = new PKMN.Pokemon(
                species,
                game,
                "",
                rng.Next(2, 100)
                );

            for (int moveIndex = 0; moveIndex < 4; ++moveIndex)
            {
                PKMN.Move move;
                do
                {
                    move = moveList[rng.Next(0, moveList.Count - 1)];
                }while(move >= PKMN.Move.SHADOW_RUSH);

                ret.Moves[moveIndex].Move = move;
            }

            foreach (PKMN.Stat EV in ret.EVs.Keys)
            {
                ret.EVs[EV] = rng.Next(0, 255);
            }
            foreach (PKMN.Stat IV in ret.IVs.Keys)
            {
                ret.IVs[IV] = rng.Next(0, 15);
            }

            if (generation >= 2)
            {
                // Keep going until one is holdable.
                while (ret.HeldItem == PKMN.Item.NONE)
                {
                    try
                    {
                        ret.HeldItem = itemList[rng.Next(0, itemList.Count - 1)];
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                    }
                }

                ret.PokerusDuration = rng.Next(0, 15);
            }
            if (generation >= 3)
            {
                foreach (PKMN.Marking marking in ret.Markings.Keys)
                {
                    ret.Markings[marking] = Util.RandomBool();
                }
                foreach (string ribbon in ret.Ribbons.Keys)
                {
                    ret.Ribbons[ribbon] = Util.RandomBool();
                }
                foreach (PKMN.ContestStat contestStat in ret.ContestStats.Keys)
                {
                    ret.ContestStats[contestStat] = rng.Next(0, 255);
                }
            }

            return(ret);
        }
Пример #11
0
        public static void ConversionsTest(
            PKMN.Species species,
            string form,
            PKMN.Game originGame,
            PKMN.Game destGame
            )
        {
            PKMN.Pokemon firstPokemon = new PKMN.Pokemon(species, originGame, form, 50);

            int originGeneration = Util.GameToGeneration(originGame);
            int destGeneration   = Util.GameToGeneration(destGame);
            int minGeneration    = System.Math.Min(originGeneration, destGeneration);

            PKMN.Game gameForLists = (minGeneration == originGeneration) ? originGame : destGame;

            PKMN.ItemEnumList items = PKMN.Database.Lists.ItemList(gameForLists);
            PKMN.MoveEnumList moves = PKMN.Database.Lists.MoveList(gameForLists);

            for (int i = 0; i < 4; ++i)
            {
                PKMN.Move move = PKMN.Move.NONE;
                do
                {
                    move = moves[rng.Next(0, moves.Count - 1)];
                }while(move >= PKMN.Move.SHADOW_RUSH);

                firstPokemon.Moves[i].Move = move;
            }

            if (originGeneration >= 3)
            {
                firstPokemon.OriginalTrainerSecretID = (ushort)rng.Next(0, 0xFFFF);

                if (firstPokemon.DatabaseEntry.Abilities.Second != PKMN.Ability.NONE)
                {
                    firstPokemon.Ability = Util.RandomBool() ? firstPokemon.DatabaseEntry.Abilities.First
                                                         : firstPokemon.DatabaseEntry.Abilities.Second;
                }
            }
            firstPokemon.OriginalTrainerPublicID = (ushort)rng.Next(0, 0xFFFF);

            if (minGeneration >= 2)
            {
                PKMN.Item heldItem = PKMN.Item.NONE;
                do
                {
                    heldItem = items[rng.Next(0, items.Count - 1)];
                } while(!(new PKMN.Database.ItemEntry(heldItem, originGame).IsHoldable) ||
                        ((heldItem >= PKMN.Item.JOY_SCENT) && (heldItem <= PKMN.Item.VIVID_SCENT)));

                firstPokemon.HeldItem = heldItem;
            }
            if (originGeneration >= 2)
            {
                firstPokemon.Gender  = Util.RandomBool() ? PKMN.Gender.MALE : PKMN.Gender.FEMALE;
                firstPokemon.IsShiny = Util.RandomBool();
                firstPokemon.CurrentTrainerFriendship = rng.Next(0, 255);

                if ((originGame == PKMN.Game.GOLD) || (originGame == PKMN.Game.CRYSTAL))
                {
                    firstPokemon.OriginalTrainerGender = Util.RandomBool() ? PKMN.Gender.MALE : PKMN.Gender.FEMALE;
                }

                // The max level met value in Generation II is 63.
                firstPokemon.LevelMet = rng.Next(2, (originGeneration == 2) ? 63 : 100);
            }
            if (originGeneration >= 3)
            {
                // Randomize ribbons, markings, and contest stats.
                foreach (PKMN.Marking marking in firstPokemon.Markings.Keys)
                {
                    firstPokemon.Markings[marking] = Util.RandomBool();
                }
                foreach (string ribbon in firstPokemon.Ribbons.Keys)
                {
                    firstPokemon.Ribbons[ribbon] = Util.RandomBool();
                }
                foreach (PKMN.ContestStat contestStat in firstPokemon.ContestStats.Keys)
                {
                    firstPokemon.ContestStats[contestStat] = rng.Next(0, 255);
                }
            }

            firstPokemon.Nickname            = Util.RandomString(10);
            firstPokemon.OriginalTrainerName = Util.RandomString(7);

            // The max level met value in Generation II is 63, which restricts this as well.
            firstPokemon.Level = rng.Next(2, (destGeneration == 2) ? 63 : 100);

            // Convert to the second game and compare.
            PKMN.Pokemon secondPokemon = firstPokemon.ToGame(destGame);

            Assert.AreEqual(firstPokemon.Species, secondPokemon.Species);
            Assert.AreEqual(destGame, secondPokemon.Game);
            Assert.AreEqual(firstPokemon.Form, secondPokemon.Form);
            Assert.AreEqual(firstPokemon.Nickname, secondPokemon.Nickname);
            Assert.AreEqual(firstPokemon.OriginalTrainerName, secondPokemon.OriginalTrainerName);
            Assert.AreEqual(firstPokemon.OriginalTrainerID, secondPokemon.OriginalTrainerID);
            Assert.AreEqual(firstPokemon.OriginalTrainerPublicID, secondPokemon.OriginalTrainerPublicID);
            Assert.AreEqual(firstPokemon.Experience, secondPokemon.Experience);
            Assert.AreEqual(firstPokemon.Level, secondPokemon.Level);

            for (int i = 0; i < 4; ++i)
            {
                Assert.AreEqual(firstPokemon.Moves[i].Move, secondPokemon.Moves[i].Move);
                Assert.AreEqual(firstPokemon.Moves[i].PP, secondPokemon.Moves[i].PP);
            }

            if (minGeneration >= 3)
            {
                Assert.AreEqual(firstPokemon.OriginalTrainerSecretID, secondPokemon.OriginalTrainerSecretID);
                Assert.AreEqual(firstPokemon.Ability, secondPokemon.Ability);
                Assert.AreEqual(firstPokemon.Ball, secondPokemon.Ball);
                Assert.AreEqual(firstPokemon.OriginalGame, secondPokemon.OriginalGame);
                Assert.AreEqual(firstPokemon.Personality, secondPokemon.Personality);

                if (originGeneration == destGeneration)
                {
                    foreach (PKMN.Marking marking in firstPokemon.Markings.Keys)
                    {
                        Assert.AreEqual(firstPokemon.Markings[marking], secondPokemon.Markings[marking]);
                    }
                    foreach (string ribbon in firstPokemon.Ribbons.Keys)
                    {
                        Assert.AreEqual(firstPokemon.Ribbons[ribbon], secondPokemon.Ribbons[ribbon]);
                    }
                    foreach (PKMN.ContestStat contestStat in firstPokemon.ContestStats.Keys)
                    {
                        Assert.AreEqual(firstPokemon.ContestStats[contestStat], secondPokemon.ContestStats[contestStat]);
                    }
                }
            }
            if (minGeneration >= 2)
            {
                Assert.AreEqual(firstPokemon.OriginalTrainerGender, secondPokemon.OriginalTrainerGender);
                Assert.AreEqual(firstPokemon.Gender, secondPokemon.Gender);
                Assert.AreEqual(firstPokemon.IsShiny, secondPokemon.IsShiny);
                Assert.AreEqual(firstPokemon.HeldItem, secondPokemon.HeldItem);
                Assert.AreEqual(firstPokemon.CurrentTrainerFriendship, secondPokemon.CurrentTrainerFriendship);
                Assert.AreEqual(firstPokemon.Level, secondPokemon.LevelMet);
            }
        }