mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 09:07:52 -05:00
Inject matching dexlevel for form comparison
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.EncounterEvent;
|
||||
|
||||
@@ -30,15 +31,15 @@ public static IEnumerable<MysteryGift> GetValidGifts(PKM pkm)
|
||||
{
|
||||
int gen = pkm.GenNumber;
|
||||
if (pkm.IsEgg && pkm.Format != gen) // transferred
|
||||
return Enumerable.Empty<MysteryGift>();
|
||||
return Array.Empty<MysteryGift>();
|
||||
|
||||
if (gen == 4) // check for manaphy gift
|
||||
if (gen == 4) // check for Manaphy gift
|
||||
return GetMatchingPCD(pkm, MGDB_G4);
|
||||
var table = GetTable(gen, pkm);
|
||||
return GetMatchingGifts(pkm, table);
|
||||
}
|
||||
|
||||
private static IEnumerable<MysteryGift> GetTable(int generation, PKM pkm)
|
||||
private static IReadOnlyList<MysteryGift> GetTable(int generation, PKM pkm)
|
||||
{
|
||||
return generation switch
|
||||
{
|
||||
@@ -46,13 +47,13 @@ private static IEnumerable<MysteryGift> GetTable(int generation, PKM pkm)
|
||||
4 => MGDB_G4,
|
||||
5 => MGDB_G5,
|
||||
6 => MGDB_G6,
|
||||
7 => (pkm.LGPE ? (IEnumerable<MysteryGift>)MGDB_G7GG : MGDB_G7),
|
||||
7 => pkm.LGPE ? (IReadOnlyList<MysteryGift>)MGDB_G7GG : MGDB_G7,
|
||||
8 => MGDB_G8,
|
||||
_ => Enumerable.Empty<MysteryGift>()
|
||||
_ => Array.Empty<MysteryGift>()
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IEnumerable<PCD> DB)
|
||||
private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IReadOnlyList<PCD> DB)
|
||||
{
|
||||
if (PGT.IsRangerManaphy(pkm))
|
||||
{
|
||||
@@ -64,25 +65,28 @@ private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IEnumerable<PCD>
|
||||
yield return g;
|
||||
}
|
||||
|
||||
private static IEnumerable<MysteryGift> GetMatchingGifts(PKM pkm, IEnumerable<MysteryGift> DB)
|
||||
private static IEnumerable<MysteryGift> GetMatchingGifts(PKM pkm, IReadOnlyList<MysteryGift> DB)
|
||||
{
|
||||
var chain = EvolutionChain.GetOriginChain(pkm);
|
||||
return GetMatchingGifts(pkm, DB, chain);
|
||||
}
|
||||
|
||||
private static IEnumerable<MysteryGift> GetMatchingGifts(PKM pkm, IEnumerable<MysteryGift> DB, IReadOnlyList<DexLevel> chain)
|
||||
private static IEnumerable<MysteryGift> GetMatchingGifts(PKM pkm, IReadOnlyList<MysteryGift> DB, IReadOnlyList<DexLevel> chain)
|
||||
{
|
||||
var deferred = new List<MysteryGift>();
|
||||
var gifts = DB.Where(wc => chain.Any(dl => dl.Species == wc.Species));
|
||||
foreach (var mg in gifts)
|
||||
foreach (var mg in DB)
|
||||
{
|
||||
var result = mg.IsMatch(pkm);
|
||||
if (result == EncounterMatchRating.None)
|
||||
continue;
|
||||
if (result == EncounterMatchRating.Match)
|
||||
yield return mg;
|
||||
else if (result == EncounterMatchRating.Deferred)
|
||||
deferred.Add(mg);
|
||||
foreach (var dl in chain)
|
||||
{
|
||||
if (dl.Species != mg.Species)
|
||||
continue;
|
||||
var result = mg.IsMatch(pkm, dl);
|
||||
if (result == EncounterMatchRating.Match)
|
||||
yield return mg;
|
||||
else if (result == EncounterMatchRating.Deferred)
|
||||
deferred.Add(mg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var z in deferred)
|
||||
yield return z;
|
||||
|
||||
@@ -132,12 +132,12 @@ public abstract class MysteryGift : IEncounterable, IMoveset, IRelearn, ILocatio
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
public abstract PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria);
|
||||
|
||||
protected abstract bool IsMatchExact(PKM pkm);
|
||||
protected abstract bool IsMatchExact(PKM pkm, DexLevel evo);
|
||||
protected abstract bool IsMatchDeferred(PKM pkm);
|
||||
|
||||
public EncounterMatchRating IsMatch(PKM pkm)
|
||||
public EncounterMatchRating IsMatch(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (!IsMatchExact(pkm))
|
||||
if (!IsMatchExact(pkm, evo))
|
||||
return EncounterMatchRating.None;
|
||||
if (IsMatchDeferred(pkm))
|
||||
return EncounterMatchRating.Deferred;
|
||||
|
||||
@@ -129,7 +129,7 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
|
||||
public bool CanBeReceivedBy(int pkmVersion) => (CardCompatibility >> pkmVersion & 1) == 1;
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
var wc = Gift.PK;
|
||||
if (!wc.IsEgg)
|
||||
@@ -161,7 +161,7 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wc.AltForm != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, wc.AltForm))
|
||||
if (wc.AltForm != evo.Form && !Legal.IsFormChangeable(pkm, Species, wc.AltForm))
|
||||
return false;
|
||||
|
||||
if (wc.Ball != pkm.Ball) return false;
|
||||
|
||||
@@ -336,7 +336,7 @@ private void SetIVs(PKM pk)
|
||||
pk.IVs = finalIVs;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (!IsEgg)
|
||||
{
|
||||
@@ -369,7 +369,7 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Form != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
if (Form != evo.Form && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
return false;
|
||||
|
||||
if (Level != pkm.Met_Level) return false;
|
||||
|
||||
@@ -254,7 +254,7 @@ public static bool IsRangerManaphy(PKM pkm)
|
||||
return met == Locations.LinkTrade4 || met == 0;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm) => false;
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo) => false;
|
||||
protected override bool IsMatchDeferred(PKM pkm) => false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ private void SetIVs(PKM pk)
|
||||
pk.IVs = finalIVs;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (pkm.Egg_Location == 0) // Not Egg
|
||||
{
|
||||
@@ -474,7 +474,7 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
if (EncryptionConstant != 0 && EncryptionConstant != pkm.EncryptionConstant) return false;
|
||||
}
|
||||
|
||||
if (Form != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
if (Form != evo.Form && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
return false;
|
||||
|
||||
if (IsEgg)
|
||||
|
||||
@@ -211,7 +211,7 @@ private static GameVersion GetRandomVersion(GameVersion version)
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
// Gen3 Version MUST match.
|
||||
if (Version != 0 && !Version.Contains((GameVersion)pkm.Version))
|
||||
@@ -238,6 +238,9 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
}
|
||||
}
|
||||
|
||||
if (Form != evo.Form && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
return false;
|
||||
|
||||
if (Language != -1 && Language != pkm.Language) return false;
|
||||
if (Ball != pkm.Ball) return false;
|
||||
if (Fateful != pkm.FatefulEncounter)
|
||||
|
||||
@@ -457,7 +457,7 @@ private void SetIVs(PKM pk)
|
||||
pk.IVs = finalIVs;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (pkm.Egg_Location == 0) // Not Egg
|
||||
{
|
||||
@@ -478,7 +478,7 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
if (EncryptionConstant != 0 && EncryptionConstant != pkm.EncryptionConstant) return false;
|
||||
if (Language != 0 && Language != pkm.Language) return false;
|
||||
}
|
||||
if (Form != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
if (Form != evo.Form && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
return false;
|
||||
|
||||
if (IsEgg)
|
||||
|
||||
@@ -493,7 +493,7 @@ public bool IsAshGreninjaWC7(PKM pkm)
|
||||
return CardID == 2046 && (pkm.SID << 16 | pkm.TID) == 0x79F57B49;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (pkm.Egg_Location == 0) // Not Egg
|
||||
{
|
||||
@@ -509,17 +509,8 @@ protected override bool IsMatchExact(PKM pkm)
|
||||
if (Language != 0 && Language != pkm.Language) return false;
|
||||
}
|
||||
|
||||
if (Form != pkm.AltForm && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
{
|
||||
if (Species == (int)Core.Species.Rockruff && Form == 1 && pkm.Species == 745 && pkm.AltForm == 2)
|
||||
{
|
||||
// Rockruff gift edge case; has altform 1 then evolves to altform 2
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (Form != evo.Form && !Legal.IsFormChangeable(pkm, Species, Form))
|
||||
return false;
|
||||
|
||||
if (IsEgg)
|
||||
{
|
||||
|
||||
@@ -517,7 +517,7 @@ private void SetIVs(PKM pk)
|
||||
pk.IVs = finalIVs;
|
||||
}
|
||||
|
||||
protected override bool IsMatchExact(PKM pkm)
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
{
|
||||
if (pkm.Egg_Location == 0) // Not Egg
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ public LanguageID LanguageReceived
|
||||
|
||||
// Mystery Gift implementation
|
||||
public override int Format => 7;
|
||||
protected override bool IsMatchExact(PKM pkm) => false;
|
||||
protected override bool IsMatchExact(PKM pkm, DexLevel evo) => false;
|
||||
protected override bool IsMatchDeferred(PKM pkm) => false;
|
||||
public override int Location { get; set; }
|
||||
public override int EggLocation { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user