private void SetFinalPokemon(int index)
        {
            uint       gainedExp = GetGainedExperience(index);
            GBAPokemon original  = originalPokemon[index];
            GBAPokemon output    = (GBAPokemon)original.Clone();

            output.PokeContainer = this;

            output.Experience += gainedExp;
            output.RecalculateStats();

            ushort[] moves = PokemonDatabase.GetMovesLearnedAtLevelRange(original, (byte)(original.Level + 1), output.Level);

            // Teach the Pokemon all the new moves
            // Push the moves up just like the game does it to make room for the new move. Even HMs can be removed.
            foreach (ushort moveID in moves)
            {
                if (!PokemonDatabase.PokemonHasMove(output, moveID))
                {
                    if (output.NumMoves < 4)
                    {
                        output.SetMoveAt(output.NumMoves, new Move(moveID));
                    }
                    else
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            output.SetMoveAt(i, output.GetMoveAt(i + 1));
                        }
                        output.SetMoveAt(3, new Move(moveID));
                    }
                }
            }
            finalPokemon[index] = output;
        }
Example #2
0
        public SharedSecretBase(byte[] data, SecretBaseManager secretBaseManager)
        {
            if (data.Length != 160)
            {
                throw new Exception("Shared Secret Base must be 160 bytes in length");
            }
            this.secretBaseManager = secretBaseManager;
            this.raw = data;
            this.placedDecorations = new List <PlacedDecoration>();
            this.pokemonTeam       = new List <GBAPokemon>();

            for (int i = 0; i < 16; i++)
            {
                byte id = raw[0x12 + i];
                if (id != 0)
                {
                    byte x = ByteHelper.BitsToByte(raw, 0x22 + i, 4, 4);
                    byte y = ByteHelper.BitsToByte(raw, 0x22 + i, 0, 4);
                    placedDecorations.Add(new PlacedDecoration(id, x, y));
                }
            }

            for (int i = 0; i < 6; i++)
            {
                ushort species = LittleEndian.ToUInt16(raw, 0x7C + i * 2);

                if (species != 0 && PokemonDatabase.GetPokemonFromID(species) != null)
                {
                    uint     personality = LittleEndian.ToUInt32(raw, 0x34 + i * 4);
                    ushort[] moves       = new ushort[4];
                    for (int j = 0; j < 4; j++)
                    {
                        moves[j] = LittleEndian.ToUInt16(raw, 0x4C + j * 2 + i * 8);
                    }
                    ushort heldItem = LittleEndian.ToUInt16(raw, 0x88 + i * 2);
                    byte   level    = raw[0x94 + i];
                    byte   unknown  = raw[0x9A + i];

                    GBAPokemon pokemon = new GBAPokemon();
                    pokemon.SpeciesID   = species;
                    pokemon.Personality = personality;
                    pokemon.TrainerID   = TrainerID;
                    pokemon.SecretID    = SecretID;
                    pokemon.Nickname    = pokemon.PokemonData.Name.ToUpper();
                    for (int j = 0; j < 4; j++)
                    {
                        pokemon.SetMoveAt(j, new Move(moves[j]));
                    }
                    pokemon.HeldItemID = heldItem;
                    pokemon.Language   = Languages.English;
                    pokemon.Experience = PokemonDatabase.GetExperienceFromLevel(pokemon.PokemonData.ExperienceGroup, level);
                    pokemon.Level      = level;
                    pokemon.RecalculateStats();
                    pokemonTeam.Add(pokemon);
                }
            }
        }
        public override void GenerateReward(IGameSave gameSave)
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            PokemonData pokemonData = PokemonDatabase.GetPokemonFromDexID(DexID);
            GBAPokemon pkm = new GBAPokemon();

            pkm.DexID = DexID;
            pkm.Personality = (Personality.HasValue ? Personality.Value : (uint)random.Next());
            pkm.Experience = PokemonDatabase.GetExperienceFromLevel(pokemonData.ExperienceGroup, (IsEgg ? (byte)5 : Level));
            pkm.IsSecondAbility2 = (IsSecondAbility.HasValue ? IsSecondAbility.Value : (!pokemonData.CanOnlyHaveFirstAbility && random.Next(2) == 1));
            pkm.Nickname = (Nickname != null ? Nickname : pokemonData.Name.ToUpper());
            pkm.BallCaughtID = 4;
            pkm.MetLocationID = 255;
            if (DexID == 151 || DexID == 386)
                pkm.IsFatefulEncounter = true;
            pkm.LevelMet = (IsEgg ? (byte)0 : Level);
            pkm.Language = Languages.English;
            pkm.Friendship = (byte)(IsEgg ? 10 : 70);

            // Ownership
            pkm.TrainerName = (TrainerName != null ? TrainerName : PokeManager.ManagerGameSave.TrainerName);
            pkm.TrainerGender = (TrainerGender.HasValue ? TrainerGender.Value : PokeManager.ManagerGameSave.TrainerGender);
            pkm.TrainerID = (TrainerID.HasValue ? TrainerID.Value : PokeManager.ManagerGameSave.TrainerID);
            pkm.SecretID = (SecretID.HasValue ? SecretID.Value : PokeManager.ManagerGameSave.SecretID);
            if (TrainerGender.HasValue && TrainerGender.Value == Genders.Genderless)
                pkm.TrainerGender = (random.Next(2) == 1 ? Genders.Female : Genders.Male);

            if (!Personality.HasValue)
                GeneratePID(pkm, random);

            if (HeldItem != null) pkm.HeldItemID = HeldItem[random.Next(HeldItem.Length)];

            if (Conditions != null) {
                pkm.Coolness	= Conditions[0];
                pkm.Beauty		= Conditions[1];
                pkm.Cuteness	= Conditions[2];
                pkm.Smartness	= Conditions[3];
                pkm.Toughness	= Conditions[4];
                pkm.Feel		= Conditions[5];
            }

            pkm.HPIV		= (IVs != null ? IVs[0] : (byte)random.Next(32));
            pkm.AttackIV	= (IVs != null ? IVs[1] : (byte)random.Next(32));
            pkm.DefenseIV	= (IVs != null ? IVs[2] : (byte)random.Next(32));
            pkm.SpAttackIV	= (IVs != null ? IVs[3] : (byte)random.Next(32));
            pkm.SpDefenseIV	= (IVs != null ? IVs[4] : (byte)random.Next(32));
            pkm.SpeedIV		= (IVs != null ? IVs[5] : (byte)random.Next(32));

            if (HiddenPowerDamage.HasValue)	pkm.SetHiddenPowerDamage(HiddenPowerDamage.Value);
            if (HiddenPowerType.HasValue) pkm.SetHiddenPowerType(HiddenPowerType.Value);

            // Teach the Pokemon all of it's default moves
            ushort[] moves = PokemonDatabase.GetMovesLearnedAtLevelRange(pkm, 1, (IsEgg ? (byte)5 : Level));
            foreach (ushort moveID in moves) {
                if (!PokemonDatabase.PokemonHasMove(pkm, moveID)) {
                    if (pkm.NumMoves < 4) {
                        pkm.SetMoveAt(pkm.NumMoves, new Move(moveID));
                    }
                    else {
                        for (int i = 0; i < 3; i++) {
                            pkm.SetMoveAt(i, pkm.GetMoveAt(i + 1));
                        }
                        pkm.SetMoveAt(3, new Move(moveID));
                    }
                }
            }
            if (Move1ID.HasValue) pkm.SetMoveAt(0, new Move(Move1ID.Value));
            if (Move2ID.HasValue) pkm.SetMoveAt(1, new Move(Move2ID.Value));
            if (Move3ID.HasValue) pkm.SetMoveAt(2, new Move(Move3ID.Value));
            if (Move4ID.HasValue) pkm.SetMoveAt(3, new Move(Move4ID.Value));

            GameTypes gameType = gameSave.GameType;
            if (gameType == GameTypes.Ruby)				pkm.GameOrigin = GameOrigins.Ruby;
            else if (gameType == GameTypes.Sapphire)	pkm.GameOrigin = GameOrigins.Sapphire;
            else if (gameType == GameTypes.Emerald)		pkm.GameOrigin = GameOrigins.Emerald;
            else if (gameType == GameTypes.FireRed)		pkm.GameOrigin = GameOrigins.FireRed;
            else if (gameType == GameTypes.LeafGreen)	pkm.GameOrigin = GameOrigins.LeafGreen;
            else if (gameType == GameTypes.Colosseum ||
                     gameType == GameTypes.XD)			pkm.GameOrigin = GameOrigins.ColosseumXD;
            else										pkm.GameOrigin = GameOrigins.Emerald;

            pkm.GameType = gameType;
            pkm.Checksum = pkm.CalculateChecksum();
            pkm.RecalculateStats();
            reward = pkm;
        }
        public override void GenerateReward(IGameSave gameSave)
        {
            Random      random      = new Random((int)DateTime.Now.Ticks);
            PokemonData pokemonData = PokemonDatabase.GetPokemonFromDexID(DexID);
            GBAPokemon  pkm         = new GBAPokemon();

            pkm.DexID            = DexID;
            pkm.Personality      = (Personality.HasValue ? Personality.Value : (uint)random.Next());
            pkm.Experience       = PokemonDatabase.GetExperienceFromLevel(pokemonData.ExperienceGroup, (IsEgg ? (byte)5 : Level));
            pkm.IsSecondAbility2 = (IsSecondAbility.HasValue ? IsSecondAbility.Value : (!pokemonData.CanOnlyHaveFirstAbility && random.Next(2) == 1));
            pkm.Nickname         = (Nickname != null ? Nickname : pokemonData.Name.ToUpper());
            pkm.BallCaughtID     = 4;
            pkm.MetLocationID    = 255;
            if (DexID == 151 || DexID == 386)
            {
                pkm.IsFatefulEncounter = true;
            }
            pkm.LevelMet   = (IsEgg ? (byte)0 : Level);
            pkm.Language   = Languages.English;
            pkm.Friendship = (byte)(IsEgg ? 10 : 70);

            // Ownership
            pkm.TrainerName   = (TrainerName != null ? TrainerName : PokeManager.ManagerGameSave.TrainerName);
            pkm.TrainerGender = (TrainerGender.HasValue ? TrainerGender.Value : PokeManager.ManagerGameSave.TrainerGender);
            pkm.TrainerID     = (TrainerID.HasValue ? TrainerID.Value : PokeManager.ManagerGameSave.TrainerID);
            pkm.SecretID      = (SecretID.HasValue ? SecretID.Value : PokeManager.ManagerGameSave.SecretID);
            if (TrainerGender.HasValue && TrainerGender.Value == Genders.Genderless)
            {
                pkm.TrainerGender = (random.Next(2) == 1 ? Genders.Female : Genders.Male);
            }

            if (!Personality.HasValue)
            {
                GeneratePID(pkm, random);
            }

            if (HeldItem != null)
            {
                pkm.HeldItemID = HeldItem[random.Next(HeldItem.Length)];
            }

            if (Conditions != null)
            {
                pkm.Coolness  = Conditions[0];
                pkm.Beauty    = Conditions[1];
                pkm.Cuteness  = Conditions[2];
                pkm.Smartness = Conditions[3];
                pkm.Toughness = Conditions[4];
                pkm.Feel      = Conditions[5];
            }

            pkm.HPIV        = (IVs != null ? IVs[0] : (byte)random.Next(32));
            pkm.AttackIV    = (IVs != null ? IVs[1] : (byte)random.Next(32));
            pkm.DefenseIV   = (IVs != null ? IVs[2] : (byte)random.Next(32));
            pkm.SpAttackIV  = (IVs != null ? IVs[3] : (byte)random.Next(32));
            pkm.SpDefenseIV = (IVs != null ? IVs[4] : (byte)random.Next(32));
            pkm.SpeedIV     = (IVs != null ? IVs[5] : (byte)random.Next(32));

            if (HiddenPowerDamage.HasValue)
            {
                pkm.SetHiddenPowerDamage(HiddenPowerDamage.Value);
            }
            if (HiddenPowerType.HasValue)
            {
                pkm.SetHiddenPowerType(HiddenPowerType.Value);
            }

            // Teach the Pokemon all of it's default moves
            ushort[] moves = PokemonDatabase.GetMovesLearnedAtLevelRange(pkm, 1, (IsEgg ? (byte)5 : Level));
            foreach (ushort moveID in moves)
            {
                if (!PokemonDatabase.PokemonHasMove(pkm, moveID))
                {
                    if (pkm.NumMoves < 4)
                    {
                        pkm.SetMoveAt(pkm.NumMoves, new Move(moveID));
                    }
                    else
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            pkm.SetMoveAt(i, pkm.GetMoveAt(i + 1));
                        }
                        pkm.SetMoveAt(3, new Move(moveID));
                    }
                }
            }
            if (Move1ID.HasValue)
            {
                pkm.SetMoveAt(0, new Move(Move1ID.Value));
            }
            if (Move2ID.HasValue)
            {
                pkm.SetMoveAt(1, new Move(Move2ID.Value));
            }
            if (Move3ID.HasValue)
            {
                pkm.SetMoveAt(2, new Move(Move3ID.Value));
            }
            if (Move4ID.HasValue)
            {
                pkm.SetMoveAt(3, new Move(Move4ID.Value));
            }

            GameTypes gameType = gameSave.GameType;

            if (gameType == GameTypes.Ruby)
            {
                pkm.GameOrigin = GameOrigins.Ruby;
            }
            else if (gameType == GameTypes.Sapphire)
            {
                pkm.GameOrigin = GameOrigins.Sapphire;
            }
            else if (gameType == GameTypes.Emerald)
            {
                pkm.GameOrigin = GameOrigins.Emerald;
            }
            else if (gameType == GameTypes.FireRed)
            {
                pkm.GameOrigin = GameOrigins.FireRed;
            }
            else if (gameType == GameTypes.LeafGreen)
            {
                pkm.GameOrigin = GameOrigins.LeafGreen;
            }
            else if (gameType == GameTypes.Colosseum ||
                     gameType == GameTypes.XD)
            {
                pkm.GameOrigin = GameOrigins.ColosseumXD;
            }
            else
            {
                pkm.GameOrigin = GameOrigins.Emerald;
            }

            pkm.GameType = gameType;
            pkm.Checksum = pkm.CalculateChecksum();
            pkm.RecalculateStats();
            reward = pkm;
        }
        public GBAPokemon CreateGBAPokemon(GameTypes gameType, bool passFinder = true)
        {
            GBAPokemon pkm = new GBAPokemon();

            if (passFinder)
                pkm.PokemonFinder = PokemonFinder;
            pkm.GameType = gameType;
            pkm.DeoxysForm = DeoxysForm;
            pkm.Language = Language;

            // Pokemon Info
            pkm.Personality = Personality;
            pkm.SpeciesID = SpeciesID;
            pkm.IsSecondAbility2 = IsSecondAbility2;

            // Met Info
            pkm.TrainerName = TrainerName;
            pkm.TrainerGender = TrainerGender;
            pkm.TrainerID = TrainerID;
            pkm.SecretID = SecretID;
            pkm.BallCaughtID = BallCaughtID;
            pkm.LevelMet = LevelMet;
            pkm.MetLocationID = MetLocationID;
            pkm.IsFatefulEncounter = IsFatefulEncounter;
            pkm.GameOrigin = GameOrigin;

            // Personalization Info
            pkm.Nickname = Nickname;
            pkm.HeldItemID = HeldItemID;
            pkm.Markings = Markings;

            // Stats Info
            pkm.Experience = Experience;
            pkm.Friendship = Friendship;

            pkm.HPEV = HPEV;
            pkm.AttackEV = AttackEV;
            pkm.DefenseEV = DefenseEV;
            pkm.SpeedEV = SpeedEV;
            pkm.SpAttackEV = SpAttackEV;
            pkm.SpDefenseEV = SpDefenseEV;

            pkm.HPIV = HPIV;
            pkm.AttackIV = AttackIV;
            pkm.DefenseIV = DefenseIV;
            pkm.SpeedIV = SpeedIV;
            pkm.SpAttackIV = SpAttackIV;
            pkm.SpDefenseIV = SpDefenseIV;

            // Status Info
            pkm.StatusCondition = StatusConditionFlags.None;
            pkm.TurnsOfSleepRemaining = 0;
            pkm.TurnsOfBadPoison = 0;
            pkm.PokerusStrain = PokerusStrain;
            pkm.PokerusDaysRemaining = PokerusDaysRemaining;
            pkm.PokerusRemaining = PokerusRemaining;

            // Contest Info
            pkm.Coolness = Coolness;
            pkm.Beauty = Beauty;
            pkm.Cuteness = Cuteness;
            pkm.Smartness = Smartness;
            pkm.Toughness = Toughness;
            pkm.Feel = Feel;

            pkm.CoolRibbonCount = CoolRibbonCount;
            pkm.BeautyRibbonCount = BeautyRibbonCount;
            pkm.CuteRibbonCount = CuteRibbonCount;
            pkm.SmartRibbonCount = SmartRibbonCount;
            pkm.ToughRibbonCount = ToughRibbonCount;
            pkm.HasChampionRibbon = HasChampionRibbon;
            pkm.HasWinningRibbon = HasWinningRibbon;
            pkm.HasVictoryRibbon = HasVictoryRibbon;
            pkm.HasArtistRibbon = HasArtistRibbon;
            pkm.HasEffortRibbon = HasEffortRibbon;
            pkm.HasMarineRibbon = HasMarineRibbon;
            pkm.HasLandRibbon = HasLandRibbon;
            pkm.HasSkyRibbon = HasSkyRibbon;
            pkm.HasCountryRibbon = HasCountryRibbon;
            pkm.HasNationalRibbon = HasNationalRibbon;
            pkm.HasEarthRibbon = HasEarthRibbon;
            pkm.HasWorldRibbon = HasWorldRibbon;

            // Move Info
            pkm.SetMoveAt(0, GetMoveAt(0));
            pkm.SetMoveAt(1, GetMoveAt(1));
            pkm.SetMoveAt(2, GetMoveAt(2));
            pkm.SetMoveAt(3, GetMoveAt(3));

            pkm.Checksum = pkm.CalculateChecksum();

            // Recalculate Stats to make sure they're accurate
            pkm.RecalculateStats();

            return pkm;
        }