Implement Gender/Ability criteria

This commit is contained in:
Kurt 2015-12-25 17:06:56 -08:00
parent 1c257c0a24
commit c91512dc15
2 changed files with 37 additions and 11 deletions

View file

@ -223,20 +223,31 @@ namespace PKHeX
pk.HiddenAbility = true;
pk.Ability = PKX.Personal[PKX.Personal[Species].FormeIndex(Species, pk.AltForm)].Abilities[av];
switch (PIDType)
if (PID != 0) pk.PID = PID;
else switch (PIDType)
{
case 00: // Specified
if (PID == 0)
do { pk.PID = Util.rnd32(); } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 8) + (pk.PID & 0xFFFF)) < 8);
else
pk.PID = PID;
case 00: // Not Shiny
do { pk.PID = Util.rnd32();
// Ensure Ability
if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
} while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 8) + (pk.PID & 0xFFFF)) < 8 || !pk.getGenderIsValid());
break;
case 01: // Random
pk.PID = PID == 0 ? Util.rnd32() : PID;
case 01: // Can Be Shiny
pk.PID = Util.rnd32();
// Ensure Ability
if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
// Ensure Gender
do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
break;
case 02: // Random Shiny
// This is not the actual Shiny PID generation routine.
pk.PID = Util.rnd32();
pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 8) + (pk.PID & 0xFFFF));
// Ensure Ability
if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
// Ensure Gender
do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
// Ensure Shiny
pk.PID = (uint)(pk.PID & 0x0001FFFF | ((TID ^ SID ^ (pk.PID & 0xFFFF)) & 0xFFFE) << 8);
break;
}

View file

@ -279,8 +279,8 @@ namespace PKHeX
}
public int[] EVs { get { return new[] { EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD }; } }
public int[] Moves { get { return new[] { Move1, Move2, Move3, Move4 }; } }
public int PSV { get { return (int)(((PID >> 16) ^ (PID & 0xFFFF)) >> 4); } }
public int TSV { get { return (TID ^ SID) >> 4; } }
public int PSV { get { return (int)(((PID >> 16) ^ (PID & 0xFFFF)) >> 3); } }
public int TSV { get { return (TID ^ SID) >> 3; } }
public bool IsShiny { get { return TSV == PSV; } }
public bool PKRS_Infected { get { return PKRS_Strain > 0; } }
public bool PKRS_Cured { get { return PKRS_Days == 0 && PKRS_Strain > 0; } }
@ -339,5 +339,20 @@ namespace PKHeX
RefreshChecksum();
return Data;
}
public bool getGenderIsValid()
{
int gv = PKX.Personal[Species].Gender;
if (gv == 255 && Gender == 2)
return true;
if (gv == 0 && Gender == 1)
return true;
if (gv == 254 && Gender == 0)
return true;
if (gv <= (PID & 0xFF) && Gender == 0)
return true;
if (gv > (PID & 0xFF) && Gender == 1)
return true;
return false;
}
}
}