Misc legality fixes & improvements

Recognize gen4/5 events
check ability mismatch
check nature mismatch
This commit is contained in:
Kurt 2017-03-23 21:42:33 -07:00
parent a922bda342
commit b6c4eab36b
6 changed files with 25 additions and 10 deletions

View File

@ -121,7 +121,8 @@ private void parsePK4(PKM pk)
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
verifyPreRelearn();
updateEncounterChain();
updateMoveLegality();
updateEncounterInfo();
@ -133,7 +134,8 @@ private void parsePK5(PKM pk)
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
verifyPreRelearn();
updateEncounterChain();
updateMoveLegality();
updateEncounterInfo();

View File

@ -241,7 +241,7 @@ private void verifyNickname()
{
// Can't have another language name if it hasn't evolved or wasn't a language-traded egg.
bool match = PKX.getSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format) == nickname;
match |= (pkm.WasTradedEgg || Legal.getHasEvolved(pkm)) && PKX.getIsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format);
match |= (pkm.WasTradedEgg || Legal.getHasEvolved(pkm)) && !PKX.getIsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format);
if (!match)
{
@ -1107,7 +1107,7 @@ private void verifyAbility()
if (3 <= pkm.Format && pkm.Format <= 5) // 3-5
{
if (pkm.Version != (int) GameVersion.CXD && abilities[0] != abilities[1] && pkm.PIDAbility != abilval)
if (pkm.Version != (int) GameVersion.CXD && abilities[0] != abilities[1] && pkm.AbilityNumber != 1 << abilval)
{
AddLine(Severity.Invalid, V113, CheckIdentifier.Ability);
return;
@ -2149,6 +2149,16 @@ private static CheckResult[] parseMoves(int[] moves, int[] learn, int[] relearn,
return res;
}
private void verifyPreRelearn()
{
// For origins prior to relearn moves, need to try to match a mystery gift if applicable.
if (pkm.WasEvent || pkm.WasEventEgg)
{
EventGiftMatch = new List<MysteryGift>(Legal.getValidGifts(pkm));
EncounterMatch = EventGiftMatch.FirstOrDefault();
}
}
private CheckResult[] verifyRelearn()
{
RelearnBase = null;

View File

@ -1064,13 +1064,13 @@ private static IEnumerable<MysteryGift> getMatchingPGF(PKM pkm, IEnumerable<Myst
{
if (pkm.Egg_Location == 0) // Not Egg
{
if (wc.CardID != pkm.SID) continue;
if (wc.SID != pkm.SID) continue;
if (wc.TID != pkm.TID) continue;
if (wc.OT != pkm.OT_Name) continue;
if (wc.OTGender != pkm.OT_Gender) continue;
if (wc.PIDType == 0 && pkm.PID != wc.PID) continue;
if (wc.PID != 0 && pkm.PID != wc.PID) continue;
if (wc.PIDType == 0 && pkm.IsShiny) continue;
if (wc.PIDType == 2 && !pkm.IsShiny) continue;
if (wc.PIDType == 3 && pkm.IsShiny) continue;
if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) continue;
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}

View File

@ -29,6 +29,7 @@ public PK4(byte[] decryptedData = null, string ident = null)
public override int Nature { get { return (int)(PID%25); } set { } }
public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } }
public override int CurrentHandler { get { return 0; } set { } }
public override int AbilityNumber { get { return 1 << PIDAbility; } set { } }
// Structure
public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } }

View File

@ -29,6 +29,7 @@ public PK5(byte[] decryptedData = null, string ident = null)
public override uint EncryptionConstant { get { return PID; } set { } }
public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } }
public override int CurrentHandler { get { return 0; } set { } }
public override int AbilityNumber { get { return HiddenAbility ? 4 : 1 << PIDAbility; } set { } }
// Structure
public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } }

View File

@ -360,9 +360,10 @@ public int PIDAbility
{
if (GenNumber > 5 || Format > 5)
return -1;
if (GenNumber == 5)
return (int)((PID >> 16) & 1);
return (int)(PID & 1);
if (Version == (int) GameVersion.CXD)
return Array.IndexOf(PersonalInfo.Abilities, Ability);
return (int)((GenNumber == 5 ? PID >> 16 : PID) & 1);
}
}