2018-11-01 22:38:09 +00:00
|
|
|
using System;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
/// Base class for Pokédex logic operations.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public abstract class ZukanBase
|
|
|
|
{
|
|
|
|
protected readonly SaveFile SAV;
|
|
|
|
public readonly int PokeDex;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected ZukanBase(SaveFile sav, int dex)
|
|
|
|
{
|
|
|
|
SAV = sav;
|
|
|
|
PokeDex = dex;
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region Overall Info
|
|
|
|
/// <summary> Count of unique Species Seen </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public int SeenCount
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
int ctr = 0;
|
|
|
|
for (ushort i = 1; i <= SAV.MaxSpeciesID; i++)
|
|
|
|
{
|
|
|
|
if (GetSeen(i))
|
|
|
|
ctr++;
|
|
|
|
}
|
|
|
|
return ctr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary> Count of unique Species Caught (Owned) </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public int CaughtCount
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
int ctr = 0;
|
|
|
|
for (ushort i = 1; i <= SAV.MaxSpeciesID; i++)
|
|
|
|
{
|
|
|
|
if (GetCaught(i))
|
|
|
|
ctr++;
|
|
|
|
}
|
|
|
|
return ctr;
|
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public decimal PercentSeen => (decimal)SeenCount / SAV.MaxSpeciesID;
|
|
|
|
public decimal PercentCaught => (decimal)CaughtCount / SAV.MaxSpeciesID;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary> Gets if the Species has been Seen by the player. </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract bool GetSeen(ushort species);
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary> Gets if the Species has been Caught (Owned) by the player. </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract bool GetCaught(ushort species);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
/// <summary> Adds the Pokémon's information to the Pokédex. </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract void SetDex(PKM pk);
|
|
|
|
|
|
|
|
#region Overall Manipulation
|
|
|
|
public abstract void SeenNone();
|
|
|
|
public abstract void CaughtNone();
|
|
|
|
|
|
|
|
public abstract void SeenAll(bool shinyToo = false);
|
|
|
|
public abstract void CompleteDex(bool shinyToo = false);
|
|
|
|
public abstract void CaughtAll(bool shinyToo = false);
|
|
|
|
public abstract void SetAllSeen(bool value = true, bool shinyToo = false);
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public abstract void SetDexEntryAll(ushort species, bool shinyToo = false);
|
|
|
|
public abstract void ClearDexEntryAll(ushort species);
|
2022-06-18 18:04:24 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
/// Base class for Pokédex operations, exposing the shared structure features used by Generations 5, 6, and 7.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public abstract class Zukan : ZukanBase
|
|
|
|
{
|
|
|
|
protected readonly int PokeDexLanguageFlags;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected Zukan(SaveFile sav, int dex, int langflag) : base(sav, dex)
|
|
|
|
{
|
|
|
|
PokeDexLanguageFlags = langflag;
|
|
|
|
if (langflag > dex)
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(langflag));
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected abstract int OFS_SEEN { get; }
|
|
|
|
protected abstract int OFS_CAUGHT { get; }
|
|
|
|
protected abstract int BitSeenSize { get; }
|
|
|
|
protected abstract int DexLangFlagByteCount { get; }
|
|
|
|
protected abstract int DexLangIDCount { get; }
|
|
|
|
protected abstract int GetDexLangFlag(int lang);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
protected abstract bool GetSaneFormsToIterate(ushort species, out int formStart, out int formEnd, int formIn);
|
2022-06-18 18:04:24 +00:00
|
|
|
protected virtual void SetSpindaDexData(PKM pk, bool alreadySeen) { }
|
|
|
|
protected abstract void SetAllDexFlagsLanguage(int bit, int lang, bool value = true);
|
2022-08-27 06:43:36 +00:00
|
|
|
protected abstract void SetAllDexSeenFlags(int baseBit, byte b, int gender, bool isShiny, bool value = true);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected bool GetFlag(int ofs, int bitIndex) => SAV.GetFlag(PokeDex + ofs + (bitIndex >> 3), bitIndex);
|
|
|
|
protected void SetFlag(int ofs, int bitIndex, bool value = true) => SAV.SetFlag(PokeDex + ofs + (bitIndex >> 3), bitIndex, value);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override bool GetCaught(ushort species) => GetFlag(OFS_CAUGHT, species - 1);
|
|
|
|
public virtual void SetCaught(ushort species, bool value = true) => SetFlag(OFS_CAUGHT, species - 1, value);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override bool GetSeen(ushort species)
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// check all 4 seen flags (gender/shiny)
|
|
|
|
for (int i = 0; i < 4; i++)
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (GetSeen(species, i))
|
|
|
|
return true;
|
2019-06-22 23:53:25 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-22 23:53:25 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool GetSeen(ushort species, int bitRegion) => GetFlag(OFS_SEEN + (bitRegion * BitSeenSize), species - 1);
|
|
|
|
public void SetSeen(ushort species, int bitRegion, bool value) => SetFlag(OFS_SEEN + (bitRegion * BitSeenSize), species - 1, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool GetDisplayed(int bit, int bitRegion) => GetFlag(OFS_SEEN + ((bitRegion + 4) * BitSeenSize), bit);
|
|
|
|
public void SetDisplayed(int bit, int bitRegion, bool value) => SetFlag(OFS_SEEN + ((bitRegion + 4) * BitSeenSize), bit, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool GetLanguageFlag(int bit, int lang) => GetFlag(PokeDexLanguageFlags, (bit * DexLangIDCount) + lang);
|
|
|
|
public void SetLanguageFlag(int bit, int lang, bool value) => SetFlag(PokeDexLanguageFlags, (bit * DexLangIDCount) + lang, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public virtual void SetSeen(ushort species, bool value = true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (!value)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
ClearSeen(species);
|
|
|
|
return;
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// check all 4 seen flags (gender/shiny)
|
|
|
|
for (int i = 0; i < 4; i++)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (GetFlag(OFS_SEEN + (i * BitSeenSize), species - 1))
|
2018-11-01 22:38:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
var gender = SAV.Personal[species].RandomGender() & 1;
|
|
|
|
SetAllDexSeenFlags(species - 1, 0, gender, false);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private void ClearSeen(ushort species)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetCaught(species, false);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
SetFlag(OFS_SEEN + (i * BitSeenSize), species - 1, false);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetDex(PKM pk)
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
if ((uint)(pk.Species - 1) >= SAV.MaxSpeciesID) // out of range
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
if (pk.IsEgg) // do not add
|
|
|
|
return;
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var species = pk.Species;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (species == (int)Species.Spinda)
|
|
|
|
SetSpindaDexData(pk, GetSeen(species));
|
|
|
|
|
|
|
|
int bit = pk.Species - 1;
|
2022-08-27 06:43:36 +00:00
|
|
|
var form = pk.Form;
|
2022-06-18 18:04:24 +00:00
|
|
|
int gender = pk.Gender & 1;
|
|
|
|
bool shiny = pk.IsShiny;
|
|
|
|
int lang = pk.Language;
|
|
|
|
SetDex(species, bit, form, gender, shiny, lang);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
protected virtual void SetDex(ushort species, int bit, byte form, int gender, bool shiny, int lang)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetCaught(species); // Set the Owned Flag
|
|
|
|
SetAllDexSeenFlags(bit, form, gender, shiny); // genderless -> male
|
|
|
|
SetAllDexFlagsLanguage(bit, lang);
|
|
|
|
}
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected void SetDexFlags(int baseBit, int formBit, int gender, int shiny, bool value = true)
|
|
|
|
{
|
|
|
|
int shift = (gender & 1) | (shiny << 1);
|
|
|
|
|
|
|
|
// Set the [Species/Gender/Shiny] Seen Flag
|
|
|
|
SetFlag(OFS_SEEN + (shift * BitSeenSize), baseBit, value);
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set the Display flag if none are set
|
|
|
|
SetDisplayedFlag(baseBit, formBit, value, shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void SetDisplayedFlag(int baseBit, int formBit, bool value, int shift)
|
|
|
|
{
|
|
|
|
var bit = formBit >= 0 ? formBit : baseBit;
|
|
|
|
if (!value)
|
2018-11-14 03:14:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetDisplayed(bit, shift, false);
|
|
|
|
return;
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool displayed = GetIsSpeciesFormAnyDisplayed(baseBit, formBit);
|
|
|
|
if (displayed)
|
|
|
|
return; // no need to set another bit
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SetDisplayed(bit, shift, true);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool GetIsSpeciesFormAnyDisplayed(int baseBit, int formBit)
|
|
|
|
{
|
|
|
|
// Check Displayed Status for base form
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (GetDisplayed(baseBit, i))
|
|
|
|
return true;
|
2019-07-11 07:13:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (baseBit == formBit)
|
|
|
|
return false;
|
2019-07-11 07:13:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// If form is not base form, check form too
|
|
|
|
for (int i = 0; i < 4; i++)
|
2019-07-11 07:13:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (GetDisplayed(formBit, i))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-20 01:24:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Bulk Manipulation
|
|
|
|
public override void SeenNone() => SetDexEntriesAll(false, shinyToo: true);
|
|
|
|
public override void CaughtNone() => SetAllCaught(false, true);
|
|
|
|
public override void SeenAll(bool shinyToo = false) => SetAllSeen(shinyToo);
|
|
|
|
public override void CompleteDex(bool shinyToo = false) => SetDexEntriesAll(shinyToo: shinyToo);
|
2019-10-20 01:24:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void CaughtAll(bool shinyToo = false)
|
|
|
|
{
|
|
|
|
SetAllSeen(true, shinyToo);
|
|
|
|
SetAllCaught(true, shinyToo);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetAllCaught(bool value = true, bool shinyToo = false)
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
for (ushort i = 1; i <= SAV.MaxSpeciesID; i++)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
SetCaught(i, value); // Set the Owned Flag
|
|
|
|
SetSeenSingle(i, value, shinyToo);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetAllSeen(bool value = true, bool shinyToo = false)
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
for (ushort i = 1; i <= SAV.MaxSpeciesID; i++)
|
|
|
|
SetSeenSingle(i, value, shinyToo);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override void SetDexEntryAll(ushort species, bool shinyToo = false)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetSeenSingle(species, true, shinyToo);
|
|
|
|
SetCaughtSingle(species);
|
|
|
|
}
|
2019-07-06 01:49:43 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override void ClearDexEntryAll(ushort species)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetSeenSingle(species, false);
|
|
|
|
SetCaughtSingle(species, false);
|
|
|
|
}
|
2019-07-06 01:49:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetDexEntriesAll(bool value = true, int max = -1, bool shinyToo = false)
|
|
|
|
{
|
|
|
|
if (max <= 0)
|
|
|
|
max = SAV.MaxSpeciesID;
|
2019-07-06 01:49:43 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
for (ushort i = 1; i <= max; i++)
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetSeenSingle(i, value, shinyToo);
|
|
|
|
SetCaughtSingle(i, value);
|
2019-11-16 01:34:18 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetCaughtSingle(ushort species, bool value = true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetCaught(species, value);
|
|
|
|
int baseBit = species - 1;
|
|
|
|
SetAllDexFlagsLanguage(baseBit, value);
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetSeenSingle(ushort species, bool seen = true, bool shinyToo = false)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
SetSeen(species, seen);
|
2019-07-06 01:49:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var entry = SAV.Personal[species];
|
|
|
|
int baseBit = species - 1;
|
|
|
|
int fc = entry.FormCount;
|
2022-08-27 06:43:36 +00:00
|
|
|
for (byte f = 0; f < fc; f++)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (!entry.OnlyFemale)
|
2019-07-06 01:49:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetAllDexSeenFlags(baseBit, f, 0, false, seen);
|
|
|
|
if (shinyToo)
|
|
|
|
SetAllDexSeenFlags(baseBit, f, 0, true, seen);
|
2019-07-06 01:49:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!entry.OnlyMale && !entry.Genderless)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetAllDexSeenFlags(baseBit, f, 1, false, seen);
|
|
|
|
if (shinyToo)
|
|
|
|
SetAllDexSeenFlags(baseBit, f, 1, true, seen);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected void SetAllDexFlagsLanguage(int bit, bool value = true)
|
|
|
|
{
|
|
|
|
for (int i = 1; i <= DexLangIDCount + 1; i++)
|
|
|
|
SetAllDexFlagsLanguage(bit, i, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|