예제 #1
0
        protected override void setDex(PKM pkm)
        {
            if (PokeDex < 0)
            {
                return;
            }
            if (pkm.Species == 0)
            {
                return;
            }
            if (pkm.Species > MaxSpeciesID)
            {
                return;
            }
            if (Version == GameVersion.Unknown)
            {
                return;
            }

            const int brSize = 0x60;
            int       bit    = pkm.Species - 1;
            int       lang   = pkm.Language - 1; if (lang > 5)
            {
                lang--;                                        // 0-6 language vals
            }
            int origin   = pkm.Version;
            int gender   = pkm.Gender % 2; // genderless -> male
            int shiny    = pkm.IsShiny ? 1 : 0;
            int shiftoff = shiny * brSize * 2 + gender * brSize + brSize;

            // Set the [Species/Gender/Shiny] Owned Flag
            Data[PokeDex + shiftoff + bit / 8 + 0x8] |= (byte)(1 << (bit % 8));

            // Owned quality flag
            if (origin < 0x18 && bit < 649 && !ORAS) // Species: 1-649 for X/Y, and not for ORAS; Set the Foreign Owned Flag
            {
                Data[PokeDex + 0x64C + bit / 8] |= (byte)(1 << (bit % 8));
            }
            else if (origin >= 0x18 || ORAS) // Set Native Owned Flag (should always happen)
            {
                Data[PokeDex + bit / 8 + 0x8] |= (byte)(1 << (bit % 8));
            }

            // Set the Display flag if none are set
            bool Displayed = false;

            Displayed |= (Data[PokeDex + brSize * 5 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + brSize * 6 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + brSize * 7 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + brSize * 8 + bit / 8 + 0x8] & (byte)(1 << (bit % 8))) != 0;
            if (!Displayed) // offset is already biased by brSize, reuse shiftoff but for the display flags.
            {
                Data[PokeDex + shiftoff + brSize * 4 + bit / 8 + 0x8] |= (byte)(1 << (bit % 8));
            }

            // Set the Language
            if (lang < 0)
            {
                lang = 1;
            }
            Data[PokeDexLanguageFlags + (bit * 7 + lang) / 8] |= (byte)(1 << ((bit * 7 + lang) % 8));

            // Set DexNav count (only if not encountered previously)
            if (ORAS && getEncounterCount(pkm.Species - 1) == 0)
            {
                setEncounterCount(pkm.Species - 1, 1);
            }

            // Set Form flags
            int fc = Personal[pkm.Species].FormeCount;
            int f  = ORAS ? SaveUtil.getDexFormIndexORAS(pkm.Species, fc) : SaveUtil.getDexFormIndexXY(pkm.Species, fc);

            if (f < 0)
            {
                return;
            }

            int FormLen = ORAS ? 0x26 : 0x18;
            int FormDex = PokeDex + 0x8 + brSize * 9;

            bit = f + pkm.AltForm;

            // Set Form Seen Flag
            Data[FormDex + FormLen * shiny + bit / 8] |= (byte)(1 << (bit % 8));

            // Set Displayed Flag if necessary, check all flags
            for (int i = 0; i < fc; i++)
            {
                bit = f + i;
                if ((Data[FormDex + FormLen * 2 + bit / 8] & (byte)(1 << (bit % 8))) != 0) // Nonshiny
                {
                    return;                                                                // already set
                }
                if ((Data[FormDex + FormLen * 3 + bit / 8] & (byte)(1 << (bit % 8))) != 0) // Shiny
                {
                    return;                                                                // already set
                }
            }
            bit = f + pkm.AltForm;
            Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8));
        }