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); }
public void MoveEnumListTest() { PKMN.MoveEnumList moveEnumList = new PKMN.MoveEnumList(); moveEnumList.Add(PKMN.Move.CUT); moveEnumList.Add(PKMN.Move.FLY); moveEnumList.Add(PKMN.Move.SURF); moveEnumList.Add(PKMN.Move.STRENGTH); moveEnumList.Add(PKMN.Move.FLASH); PKMN.MoveEnumList moveEnumListSame = new PKMN.MoveEnumList(); moveEnumListSame.Add(PKMN.Move.CUT); moveEnumListSame.Add(PKMN.Move.FLY); moveEnumListSame.Add(PKMN.Move.SURF); moveEnumListSame.Add(PKMN.Move.STRENGTH); moveEnumListSame.Add(PKMN.Move.FLASH); PKMN.MoveEnumList moveEnumListReversed = new PKMN.MoveEnumList(); moveEnumListReversed.Add(PKMN.Move.FLASH); moveEnumListReversed.Add(PKMN.Move.STRENGTH); moveEnumListReversed.Add(PKMN.Move.SURF); moveEnumListReversed.Add(PKMN.Move.FLY); moveEnumListReversed.Add(PKMN.Move.CUT); Assert.AreEqual(moveEnumList, moveEnumList); Assert.AreEqual(moveEnumList, moveEnumListSame); Assert.AreEqual(moveEnumList.GetHashCode(), moveEnumListSame.GetHashCode()); Assert.AreNotEqual(moveEnumList, moveEnumListReversed); Assert.AreNotEqual(moveEnumList.GetHashCode(), moveEnumListReversed.GetHashCode()); }
public void TMMoveListTest() { // Make sure trying to create an invalid list results in an exception Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.TMMoveList(PKMN.Game.NONE); } ); Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.TMMoveNameList(PKMN.Game.NONE); } ); PKMN.MoveEnumList tmMoveList = PKMN.Database.Lists.TMMoveList(PKMN.Game.RED); Assert.AreEqual(tmMoveList.Count, 50); Assert.AreEqual(tmMoveList[0], PKMN.Move.MEGA_PUNCH); Assert.AreEqual(tmMoveList[49], PKMN.Move.SUBSTITUTE); PKMN.StringList tmMoveNameList = PKMN.Database.Lists.TMMoveNameList(PKMN.Game.RED); Assert.AreEqual(tmMoveNameList.Count, 50); Assert.AreEqual(tmMoveNameList[0], "Mega Punch"); Assert.AreEqual(tmMoveNameList[49], "Substitute"); // Make sure lists match. Assert.AreEqual(tmMoveList.Count, tmMoveNameList.Count); for (int tmMoveIndex = 0; tmMoveIndex < tmMoveList.Count; ++tmMoveIndex) { string tmMoveName = PKMN.PKMN.MoveToString(tmMoveList[tmMoveIndex]); Assert.AreEqual(tmMoveName, tmMoveNameList[tmMoveIndex]); } }
public void HMMoveListTest() { // Make sure trying to create an invalid list results in an exception Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.HMMoveList(PKMN.Game.NONE); } ); Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.HMMoveNameList(PKMN.Game.NONE); } ); PKMN.MoveEnumList hmMoveList = PKMN.Database.Lists.HMMoveList(PKMN.Game.RED); Assert.AreEqual(hmMoveList.Count, 5); Assert.AreEqual(hmMoveList[0], PKMN.Move.CUT); Assert.AreEqual(hmMoveList[4], PKMN.Move.FLASH); PKMN.StringList hmMoveNameList = PKMN.Database.Lists.HMMoveNameList(PKMN.Game.RED); Assert.AreEqual(hmMoveNameList.Count, 5); Assert.AreEqual(hmMoveNameList[0], "Cut"); Assert.AreEqual(hmMoveNameList[4], "Flash"); // Make sure lists match. Assert.AreEqual(hmMoveList.Count, hmMoveNameList.Count); for (int hmMoveIndex = 0; hmMoveIndex < hmMoveList.Count; ++hmMoveIndex) { string hmMoveName = PKMN.PKMN.MoveToString(hmMoveList[hmMoveIndex]); Assert.AreEqual(hmMoveName, hmMoveNameList[hmMoveIndex]); } }
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); } } }
public void MoveListTest() { // Make sure trying to create an invalid list results in an exception Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.MoveList(PKMN.Game.NONE); } ); Assert.Throws <ArgumentOutOfRangeException>( delegate { PKMN.Database.Lists.MoveNameList(PKMN.Game.NONE); } ); PKMN.MoveEnumList moveList = PKMN.Database.Lists.MoveList(PKMN.Game.RED); Assert.AreEqual(moveList.Count, 165); Assert.AreEqual(moveList[0], PKMN.Move.POUND); Assert.AreEqual(moveList[164], PKMN.Move.STRUGGLE); PKMN.StringList moveNameList = PKMN.Database.Lists.MoveNameList(PKMN.Game.RED); Assert.AreEqual(moveNameList.Count, 165); Assert.AreEqual(moveNameList[0], "Pound"); Assert.AreEqual(moveNameList[164], "Struggle"); // Make sure lists match. Note that for moves, we need to check from // name to enum, as there are multiple names for some moves but always // a single enum. Assert.AreEqual(moveList.Count, moveNameList.Count); for (int moveIndex = 0; moveIndex < moveList.Count; ++moveIndex) { PKMN.Move move = PKMN.PKMN.StringToMove(moveNameList[moveIndex]); Assert.AreEqual(move, moveList[moveIndex]); } }
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); }
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); } }