public static void PokemonTest( PKMN.Game game, PKMN.Species species ) { PKMN.Pokemon pokemon = new PKMN.Pokemon(species, game, "", 30); PokemonTestParams testParams = new PokemonTestParams( PKMN.Ball.GREAT_BALL, new PKMN.Ball[] { PKMN.Ball.GREAT_BALL }, PKMN.Item.POTION, new PKMN.Item[] { PKMN.Item.POTION }, "Special", new string[] { "Route 1" }, new string[] { "Route 1" }, new PKMN.Move[] { PKMN.Move.SLASH, PKMN.Move.FLAMETHROWER, PKMN.Move.TAIL_WHIP, PKMN.Move.FIRE_BLAST }, new PKMN.Move[] { PKMN.Move.RETURN }, new PKMN.Game[] { PKMN.Game.RED }, new PKMN.Game[] { PKMN.Game.RED } ); PokemonTestCommon.TestCommon(pokemon, testParams); // Test attributes. Assert.AreEqual(pokemon.NumericAttributes["Catch rate"], 45); }
public void Gen2PokemonTest( PKMN.Game game, PKMN.Species species ) { PKMNTest.Gen2PokemonTests.PokemonTest(game, species); }
public static void PokemonTest( PKMN.Game game, PKMN.Species species ) { PKMN.Pokemon pokemon = new PKMN.Pokemon(species, game, "", 30); PokemonTestParams testParams = new PokemonTestParams( PKMN.Ball.GREAT_BALL, new PKMN.Ball[] { PKMN.Ball.GREAT_BALL }, PKMN.Item.BERRY, new PKMN.Item[] { PKMN.Item.RAZZ_BERRY, PKMN.Item.BICYCLE }, "Special", new string[] { "Sprout Tower", "Tohjo Falls" }, new string[] { "Littleroot Town", "Petalburg Woods" }, new PKMN.Move[] { PKMN.Move.SLASH, PKMN.Move.FLAMETHROWER, PKMN.Move.RETURN, PKMN.Move.FIRE_BLAST }, new PKMN.Move[] { PKMN.Move.FRENZY_PLANT, PKMN.Move.ROOST }, new PKMN.Game[] { PKMN.Game.GOLD }, new PKMN.Game[] { PKMN.Game.GOLD } ); PokemonTestCommon.TestCommon(pokemon, testParams); // Gender is tied to IVs, so make sure the abstraction reflects that. pokemon.Gender = PKMN.Gender.MALE; Assert.AreEqual(pokemon.IVs[PKMN.Stat.ATTACK], 15); pokemon.Gender = PKMN.Gender.FEMALE; Assert.Less(pokemon.IVs[PKMN.Stat.ATTACK], 15); pokemon.IVs[PKMN.Stat.ATTACK] = 0; Assert.AreEqual(pokemon.Gender, PKMN.Gender.FEMALE); pokemon.IVs[PKMN.Stat.ATTACK] = 15; Assert.AreEqual(pokemon.Gender, PKMN.Gender.MALE); // Shininess is tied to IVs, so make sure the abstraction reflects that. pokemon.IsShiny = false; Assert.AreEqual(pokemon.IVs[PKMN.Stat.ATTACK], 13); pokemon.IsShiny = true; Assert.AreEqual(pokemon.IVs[PKMN.Stat.ATTACK], 15); Assert.AreEqual(pokemon.IVs[PKMN.Stat.DEFENSE], 10); Assert.AreEqual(pokemon.IVs[PKMN.Stat.SPEED], 10); Assert.AreEqual(pokemon.IVs[PKMN.Stat.SPECIAL], 10); }
public void PokemonConversionsTest( PKMN.Species species, string form, PKMN.Game originGame, PKMN.Game destGame ) { PKMNTest.PokemonConversionsTest.ConversionsTest( species, form, originGame, destGame ); }
static public void PokemonTest( PKMN.Game game, PKMN.Species species ) { PKMN.Pokemon pokemon = new PKMN.Pokemon(species, game, "", 30); PokemonTestParams testParams; bool isGamecube = (game == PKMN.Game.COLOSSEUM) || (game == PKMN.Game.XD); if (isGamecube) { testParams = new PokemonTestParams( PKMN.Ball.GREAT_BALL, new PKMN.Ball[] { PKMN.Ball.FRIEND_BALL, PKMN.Ball.HEAL_BALL }, PKMN.Item.RAZZ_BERRY, new PKMN.Item[] { PKMN.Item.BERRY, PKMN.Item.MACH_BIKE }, "Distant land", new string[] { "Phenac City", "Orre Colosseum" }, new string[] { "New Bark Town", "Twinleaf Town" }, new PKMN.Move[] { PKMN.Move.SWALLOW, PKMN.Move.FLAMETHROWER, PKMN.Move.RETURN, PKMN.Move.FIRE_BLAST }, new PKMN.Move[] { PKMN.Move.ROOST, PKMN.Move.FLAME_BURST }, new PKMN.Game[] { PKMN.Game.RUBY, PKMN.Game.SAPPHIRE, PKMN.Game.EMERALD, PKMN.Game.FIRERED, PKMN.Game.LEAFGREEN, PKMN.Game.COLOSSEUM, PKMN.Game.XD }, new PKMN.Game[] { PKMN.Game.GOLD, PKMN.Game.HEARTGOLD } ); } else { testParams = new PokemonTestParams( PKMN.Ball.GREAT_BALL, new PKMN.Ball[] { PKMN.Ball.FRIEND_BALL, PKMN.Ball.HEAL_BALL }, PKMN.Item.RAZZ_BERRY, new PKMN.Item[] { PKMN.Item.BERRY, PKMN.Item.MACH_BIKE }, "Fateful encounter", new string[] { "Petalburg Woods", "Viridian Forest" }, new string[] { "New Bark Town", "Twinleaf Town" }, new PKMN.Move[] { PKMN.Move.SWALLOW, PKMN.Move.FLAMETHROWER, PKMN.Move.RETURN, PKMN.Move.FIRE_BLAST }, new PKMN.Move[] { PKMN.Move.SHADOW_SKY, PKMN.Move.ROOST }, new PKMN.Game[] { PKMN.Game.RUBY, PKMN.Game.SAPPHIRE, PKMN.Game.EMERALD, PKMN.Game.FIRERED, PKMN.Game.LEAFGREEN, PKMN.Game.COLOSSEUM, PKMN.Game.XD }, new PKMN.Game[] { PKMN.Game.GOLD, PKMN.Game.HEARTGOLD } ); } PokemonTestCommon.TestCommon(pokemon, testParams); CheckInitialRibbonMap(pokemon); TestContestRibbons(pokemon); TestRibbons(pokemon); // Gender and personality are tied, so make sure they affect each other. pokemon.Gender = PKMN.Gender.FEMALE; Assert.Less((pokemon.Personality & 0xFF), 0xFF); pokemon.Gender = PKMN.Gender.MALE; Assert.AreEqual((pokemon.Personality & 0xFF), 0xFF); pokemon.Personality = 0x1234AB00; Assert.AreEqual(pokemon.Gender, PKMN.Gender.FEMALE); pokemon.Personality = 0xCD5678FF; Assert.AreEqual(pokemon.Gender, PKMN.Gender.MALE); // Setting shininess should affect personality. pokemon.IsShiny = false; uint nonShinyPersonality = pokemon.Personality; pokemon.IsShiny = true; Assert.AreNotEqual(pokemon.Personality, nonShinyPersonality); // Shadow Pokémon should only work in Gamecube games. if (isGamecube) { PKMN.Species shadowSpecies = (game == PKMN.Game.COLOSSEUM) ? PKMN.Species.LEDIAN : PKMN.Species.LEDYBA; PKMN.Pokemon shadowPokemon = new PKMN.Pokemon(shadowSpecies, game, "", 50); Assert.AreEqual(shadowPokemon.Form, "Standard"); shadowPokemon.Form = "Shadow"; Assert.AreEqual(shadowPokemon.Form, "Shadow"); } else { Assert.Throws <ArgumentOutOfRangeException>( delegate { new PKMN.Pokemon(PKMN.Species.LEDYBA, game, "Shadow", 50); } ); } }
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 TestPokedex( PKMN.Pokedex pokedex ) { int generation = Util.GameToGeneration(pokedex.Game); // Test initial values. Assert.AreEqual(0, pokedex.NumSeen); Assert.AreEqual(0, pokedex.AllSeen.Count); Assert.AreEqual(0, pokedex.NumCaught); Assert.AreEqual(0, pokedex.AllCaught.Count); // Set random Pokémon to be seen and caught. PKMN.SpeciesEnumList allPokemon = PKMN.Database.Lists.PokemonList(generation, true); int numSeen = rng.Next(0, allPokemon.Count); int numCaught = rng.Next(0, allPokemon.Count); PKMN.IntList allSeenNums = new PKMN.IntList(); while (allSeenNums.Count < numSeen) { int index = rng.Next(0, allPokemon.Count); if (allSeenNums.IndexOf(index) == -1) { allSeenNums.Add(index); PKMN.Species species = allPokemon[index]; pokedex.SeenPokemonMap[species] = true; Assert.IsTrue(pokedex.SeenPokemonMap[species]); } } Assert.AreEqual(allSeenNums.Count, pokedex.NumSeen); Assert.AreEqual(allSeenNums.Count, pokedex.AllSeen.Count); PKMN.IntList allCaughtNums = new PKMN.IntList(); while (allCaughtNums.Count < numCaught) { int index = rng.Next(0, allPokemon.Count); if (allCaughtNums.IndexOf(index) == -1) { allCaughtNums.Add(index); PKMN.Species species = allPokemon[index]; pokedex.CaughtPokemonMap[species] = true; Assert.IsTrue(pokedex.CaughtPokemonMap[species]); } } Assert.AreEqual(allCaughtNums.Count, pokedex.NumCaught); Assert.AreEqual(allCaughtNums.Count, pokedex.AllCaught.Count); // Remove all entries. foreach (PKMN.Species species in pokedex.AllSeen) { pokedex.SeenPokemonMap[species] = false; Assert.IsFalse(pokedex.SeenPokemonMap[species]); } Assert.AreEqual(0, pokedex.NumSeen); Assert.AreEqual(0, pokedex.AllSeen.Count); foreach (PKMN.Species species in pokedex.AllCaught) { pokedex.CaughtPokemonMap[species] = false; Assert.IsFalse(pokedex.CaughtPokemonMap[species]); } Assert.AreEqual(0, pokedex.NumCaught); Assert.AreEqual(0, pokedex.AllCaught.Count); }
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); } }
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); }