public Pokemon BaseCreate(string name, int level) { //The code that generates a base Pokemon with no IVs. 2 parameters are needed - a valid name, and a level. //First, two Pokemon objects are declared - one for the "original" Pokemon, as retrieved from the PokemonList class, and one for the "result" Pokemon to be output. //The result Pokemon's parameters are simply copied from the original. Pokemon original = PokemonList.allPokemon.Find(p => p.name == name); Pokemon pokemon = new Pokemon(original.name, original.type, original.type2, original.pokedexSpecies, original.pokedexNumber, original.catchRate, original.baseHP, original.baseAttack, original.baseDefense, original.baseSpecialAttack, original.baseSpecialDefense, original.baseSpeed, original.evolution, original.evolutionLevel); pokemon.availableMoves = MovesList.PokemonAvailableMoves(name); //Then, it acquires its available moves from the MoveList method in the MovesList class. pokemon.level = level; //Its level is set to the given level afterwards so that its moves and stats can be set. foreach (KeyValuePair<Moves, int> move in pokemon.availableMoves) { if (move.Value <= pokemon.level) { //This loop basically adds every move that the Pokemon can learn to its knownMoves list. pokemon.knownMoves.Add(move.Key); } } while (pokemon.knownMoves.Count > 4) { //If the Pokemon knows more than 4 moves, it loses its first move constantly until it knows 4. pokemon.knownMoves.RemoveAt(0); } return pokemon; }
public void Wild(Pokemon e) { //The code for starting a battle with a wild Pokemon. It is virtually identical to the trainer battle method, //except it requires a Pokemon as an input, rather than a trainer. Program.Log("Battle against a wild Pokemon starts.", 1); PokemonSelection(); enemyPokemon = e; encounterType = "wild"; Console.WriteLine("\nA wild level {0} {1} appeared!\n", e.level, e.name); Actions(); }
/// <summary> /// This method is used to start a battle with a trainer or a special Pokemon. The Wild method is used for battles with wild Pokemon. /// </summary> /// <param name="t">The Trainer object for the enemy trainer.</param> /// <param name="type">A special tag to determine several in-battle factors based on the type of battle - i.e. special Pokemon, showcase battle, etc. Default is "trainer".</param> public void Start(Trainer t, string type) { //The code for starting a battle with a trainer. It requires two parameters - an enemy trainer object, //as well as a type of encounter tag that is to be used for special battles. Program.Log("Battle against a trainer starts.", 1); PokemonSelection(); enemyPokemon = t.party.ElementAt(0); enemyTrainer = t; encounterType = type; Console.WriteLine("\n{0} wants to battle!\n{0} sent out a level {1} {2}!\n", t.Name, enemyPokemon.level, enemyPokemon.name); Actions(); }
void AIFaint() { //Code that triggers when the AI's Pokemon faints. //First, experience is awarded to all of the player's Pokemon that participated in the battle. foreach (Pokemon p in participants) { if (p.currentHP > 0 && p.level < 101) Experience(p); } //If the AI has any remaining healthy Pokemon, it sends out its next Pokemon, based on the aiCurrentPokemonIndex index number. if (encounterType == "trainer" && enemyTrainer.party.Exists(pokemon => pokemon.currentHP != 0)) { aiCurrentPokemonIndex++; enemyPokemon = enemyTrainer.party.ElementAt(aiCurrentPokemonIndex); Console.WriteLine("\n{0} sent out a level {1} {2}!\n", enemyTrainer.Name, enemyPokemon.level, enemyPokemon.name); Program.Log("The AI has more Pokemon, so it sends out " + enemyPokemon.name + ". Returning to Actions.", 1); participants.Clear(); AddToParticipants(playerPokemon); Actions(); } //Otherwise, if the AI has no more Pokemon, or if the battle was with a wild Pokemon, the player wins. else Victory(); }
void Faint() { //Code that triggers when the player's Pokemon faints. //First, the game checks if there are any Pokemon in the player's party that are still healthy. if (Overworld.player.party.Exists(pokemon => pokemon.currentHP != 0)) { Program.Log("The player has remaining healthy Pokemon.", 0); Console.WriteLine("\nSend out which Pokemon?\n(Valid input: 1-{0})\n", Overworld.player.party.Count); Pokemon pokemon = Overworld.player.SelectPokemon(true); //If the Pokemon the user selected is alive, it becomes the active Pokemon. if (pokemon.name != "Blank" && pokemon.currentHP > 0) { Program.Log("The player switches " + playerPokemon.name + " out for " + pokemon.name + ". Returning to Actions.", 1); participants.Remove(playerPokemon); playerPokemon = pokemon; AddToParticipants(playerPokemon); Console.WriteLine("\n{0} was sent out!", playerPokemon.name); } else { Program.Log("The player selected a Pokemon that has fainted.", 0); Console.WriteLine("That Pokemon has fainted!"); Faint(); } } //Otherwise, if the player has no remaining healthy Pokemon, he is taken to the defeat screen. else { Program.Log("The player has no remaining healthy Pokemon.", 0); Defeat(); } }
void PokemonSelection() { //This method selects a starting Pokemon for the trainer by looping over //all Pokemon in the player's party until it finds one that's not fainted. for (int i = 0; i < Overworld.player.party.Count; i++) { if (Overworld.player.party.ElementAt(i).currentHP != 0) { playerPokemon = Overworld.player.party.ElementAt(i); AddToParticipants(playerPokemon); break; } } }
void PreBattle(string attacker) { //Quick pre-battle calculations and helpful message adjustments. Program.Log("The " + attacker + " attacks.", 1); if (attacker == "player") { attackingPokemon = playerPokemon; defendingPokemon = enemyPokemon; currentMove = playerMove; attackerName = playerPokemon.name; defenderName = "The enemy " + enemyPokemon.name; //If the selected move does double damage after being used consecutively and was used last turn, sameMoveDamageBonus becomes 2. if (playerMove == previousPlayerMove && playerMove.EffectID == 4) sameMoveDamageBonus = 2; else sameMoveDamageBonus = 1; previousPlayerMove = playerMove; } else if (attacker == "AI") { attackingPokemon = enemyPokemon; defendingPokemon = playerPokemon; currentMove = enemyMove; attackerName = "The enemy " + enemyPokemon.name; defenderName = playerPokemon.name; //If the selected move does double damage after being used consecutively and was used last turn, sameMoveDamageBonus becomes 2. if (enemyMove == previousEnemyMove && enemyMove.EffectID == 4) sameMoveDamageBonus = 2; else sameMoveDamageBonus = 1; previousEnemyMove = enemyMove; } if (attackingPokemon.status == "paralysis" && !Paralyzed() || attackingPokemon.status == "sleep" && !Asleep() || attackingPokemon.status == "" || attackingPokemon.status == "poison") { Console.WriteLine("\n{0} used {1}!", attackerName, currentMove.Name); if (defendingPokemon.protect) Console.WriteLine("{0} was protected from the attack!", defenderName); else { double typeMod = TypeChart.Check(currentMove, defendingPokemon.type, defendingPokemon.type2); if (typeMod == 0.0) { Console.WriteLine("{0} was immune to the attack!", defenderName); } else { //If a player uses a move that locks you into a move, this sets the moveLocked flag to true. if (currentMove.EffectID == 4) { Program.Log(attackingPokemon.name + " used " + currentMove + ", which move-locked it.", 0); attackingPokemon.moveLocked = true; } if (currentMove.Attribute == "Status") { Program.Log("The attack selected by the " + attacker + " does not deal damage, so Effect() will take place.", 0); if (Hit()) Effect(attacker); } else { Program.Log("The attack selected by the " + attacker + " deals damage, so Damage() will take place.", 0); if (Hit()) Damage(attacker, typeMod); } } } } }
void Switch() { //A screen for switching the active Pokemon. Program.Log("The player chooses to switch Pokemon.", 1); Console.WriteLine("Send out which Pokemon?\n(Valid input: 1-{0}, or press Enter to return.)\n", Overworld.player.party.Count); Pokemon pokemon = Overworld.player.SelectPokemon(false); //If the Pokemon the user selected is healthy and is not already the active Pokemon, it becomes the active Pokemon. //The AI also gets to attack once if the player succesfully changes Pokemon. if (pokemon.name != "Blank" && pokemon != playerPokemon && pokemon.currentHP > 0) { Program.Log("The player switches " + playerPokemon.name + " out for " + pokemon.name + ". The AI will now attack.", 1); CancelTemporaryEffects(playerPokemon); playerPokemon = pokemon; AddToParticipants(playerPokemon); Console.WriteLine("\n{0} was sent out!", playerPokemon.name); //The AI will attack once following the player's switch. AIAttack(); } else if (pokemon.name != "Blank" && pokemon.currentHP <= 0) { Program.Log("The player chose to switch to a fainted Pokemon. Returning to Actions.", 0); Console.WriteLine("\nThat Pokemon has fainted!\n"); Actions(); } else if (pokemon.name != "Blank" && pokemon == playerPokemon) { Program.Log("The player chose to switch to the Pokemon that's already active. Returning to Actions.", 0); Console.WriteLine("\nThat Pokemon is already the active Pokemon!\n"); Actions(); } else Actions(); }
void RapidSpin(Pokemon pokemon) { //This method gets called up when Rapid Spin is used, which clears up the field off all hazards. //TODO: Add to this when I add more hazards. if (pokemon.leechSeed) pokemon.leechSeed = false; Console.WriteLine("{0} cleared all effects off the field using Rapid Spin!", attackerName); }
void CancelTemporaryEffects(Pokemon pokemon) { //This method cancels all temporary effects affecting a Pokemon. if (pokemon.moveLocked) pokemon.moveLocked = false; if (pokemon.leechSeed) pokemon.leechSeed = false; if (pokemon.protect) pokemon.protect = false; }
void CancelMoveLock(Pokemon pokemon) { //This cancels a Pokemon's move-lock. if (pokemon.moveLocked) pokemon.moveLocked = false; }
void AddToParticipants(Pokemon p) { if (!participants.Contains(p)) participants.Add(p); }
void Experience(Pokemon p) { //Experience calculation and award code. Right now there's a flat 300 experience threshold per level, soon to change. double multiplier = 1; //This is a band-aid multiplier that simply makes trainer battles give more experience. if (encounterType == "trainer") multiplier = 1.30; /* The amount of experience actually awarded for defeating another Pokemon. * This is actually an expression of percentage for the current level. * I.E., if an enemy Pokemon would yield 1.5 expYield experience, it would award * the current Pokemon 450 exp using the 300 exp / level formula, so 1.5 level. * In a system with incremental experience thresholds per level, it would still be * 450 exp, which would amount to less than 1.5 level this time around. */ double expYield; if (p.level <= enemyPokemon.level) expYield = (((double)enemyPokemon.level - (double)p.level) * 0.33) + 0.45; else expYield = (((double)enemyPokemon.level - (double)p.level) * 0.05) + 0.45; //Program.Log("Exp yield was " + expYield.ToString(), 1); //The above log code helped me test exp yield, keeping it here in case it comes in handy. //If expYield would amount to less than 10% of a level (0.1), it instead becomes 0.1. if (expYield < 0.1) expYield = 0.1; p.experience += Convert.ToInt32(expYield * 300.0 * multiplier / 1.3); Program.Log(p.name + " received " + Convert.ToInt32(expYield * 300.0 * multiplier / 1.4) + " experience.", 1); //This is a while loop to facilitate for the case that a Pokemon gains more than 1 level at a time. while (p.experience >= 300) { Program.Log(p.name + " levelled up.", 0); p.LevelUp(); } }
/// <summary> /// Code for adding a Pokemon to the player's party, or box if his party is full. /// </summary> /// <param name="p">The new Pokemon.</param> /// <param name="method">Method of acquisition. Examples: catch, gift, trade</param> public void AddPokemon(Pokemon p, string method) { //This method handles adding a new Pokemon to the player's lists of Pokemon, depending on how many Pokemon each list already holds. if (!PartyFull()) { //If the player's party is not full, the new Pokemon is added to the party. Console.WriteLine("{0} was added to the party!", p.name); party.Add(p); } else if (!BoxFull()) { //Else, if the player's box is not full, it is sent to the box instead. string extraText = ""; if (method == "catch") extraText = "the caught "; Console.WriteLine("Your party is full, so {0}{1} was sent to the box.", extraText, p.name); box.Add(p); } else { //If both the player's party and box are full, it is instead simply destroyed. string extraText = ""; if (method == "catch") extraText = "the caught "; Console.WriteLine("Both your party and box are full, so {0}{1} had to be released!", extraText, p.name); } }
public void SwitchAround() { Pokemon temp1 = new Pokemon(); Pokemon temp2 = new Pokemon(); if (party.Count > 1) { Console.WriteLine("\nPlease select a Pokemon to be switched with another. (Valid input: 1-{0})\n", party.Count); for (int i = 0; i < party.Count; i++) { Console.WriteLine("{0} - {1}, {2}/{3} HP.", i + 1, party.ElementAt(i).name, party.ElementAt(i).currentHP, party.ElementAt(i).maxHP); } int one; bool validInput = Int32.TryParse(Console.ReadLine(), out one); //Next, input is taken from the player. If the input is a number corresponding to a Pokemon in the player's party, the operation carries on. if (validInput && one > 0 && one < (party.Count + 1)) { temp1 = party.ElementAt(one - 1); party.RemoveAt(one - 1); Console.WriteLine("\nNow please select the Pokemon it will be switched with. (Valid input: 1-{0})\n", party.Count); for (int i = 0; i < party.Count; i++) { Console.WriteLine("{0} - {1}, {2}/{3} HP.", i + 1, party.ElementAt(i).name, party.ElementAt(i).currentHP, party.ElementAt(i).maxHP); } int two; bool validInput2 = Int32.TryParse(Console.ReadLine(), out two); if (validInput2 && two > 0 && two < (party.Count + 1)) { temp2 = party.ElementAt(two - 1); party.RemoveAt(two - 1); party.Insert((two - 1), temp1); party.Insert((one - 1), temp2); Console.WriteLine("\nPokemon succesfully switched."); } else { Console.WriteLine("Incorrect input."); party.Insert((one - 1), temp1); } } else { Console.WriteLine("Incorrect input."); } } else if (party.Count == 1) { Console.WriteLine("You only have one Pokemon!"); } }