mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-23 19:03:11 +00:00
1e86fdcea8
## Issue We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got. ## Example: Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots. * We have a Silcoon that we've leveled up a few times. Was our Silcoon originally a Wurmple, or was it caught as a Silcoon? * To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead. * We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range. --- Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves). The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method. --- The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7. --- ## Future Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance. ## Conclusion This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
148 lines
4.7 KiB
C#
148 lines
4.7 KiB
C#
namespace PKHeX.Core
|
|
{
|
|
public abstract record EncounterTrade4 : EncounterTrade
|
|
{
|
|
public sealed override int Generation => 4;
|
|
|
|
protected static readonly string[] RanchOTNames = { string.Empty, "ユカリ", "Hayley", "EULALIE", "GIULIA", "EUKALIA", string.Empty, "Eulalia" };
|
|
|
|
protected EncounterTrade4(GameVersion game) : base(game)
|
|
{
|
|
}
|
|
}
|
|
|
|
public sealed record EncounterTrade4PID : EncounterTrade4, IContestStats
|
|
{
|
|
/// <summary>
|
|
/// Fixed <see cref="PKM.PID"/> value the encounter must have.
|
|
/// </summary>
|
|
public readonly uint PID;
|
|
|
|
public EncounterTrade4PID(GameVersion game, uint pid, int species, int level) : base(game)
|
|
{
|
|
PID = pid;
|
|
Shiny = Shiny.FixedValue;
|
|
Species = species;
|
|
Level = level;
|
|
}
|
|
|
|
public byte CNT_Cool { get; init; }
|
|
public byte CNT_Beauty { get; init; }
|
|
public byte CNT_Cute { get; init; }
|
|
public byte CNT_Smart { get; init; }
|
|
public byte CNT_Tough { get; init; }
|
|
public byte CNT_Sheen { get; init; }
|
|
|
|
public byte Contest
|
|
{
|
|
init
|
|
{
|
|
CNT_Cool = value;
|
|
CNT_Beauty = value;
|
|
CNT_Cute = value;
|
|
CNT_Smart = value;
|
|
CNT_Tough = value;
|
|
//CNT_Sheen = value;
|
|
}
|
|
}
|
|
|
|
public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
|
{
|
|
if (!base.IsMatchExact(pkm, evo))
|
|
return false;
|
|
|
|
if (pkm is IContestStats s && s.IsContestBelow(this))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
{
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
var pkm = (PK4) pk;
|
|
|
|
if (Version == GameVersion.DPPt)
|
|
{
|
|
// Has German Language ID for all except German origin, which is English
|
|
if (Species == (int)Core.Species.Magikarp)
|
|
pkm.Language = (int)(pkm.Language == (int)LanguageID.German ? LanguageID.English : LanguageID.German);
|
|
// All other trades received: English games have a Japanese language ID instead of English.
|
|
else if (pkm.Language == (int)LanguageID.English)
|
|
pkm.Language = (int)LanguageID.Japanese;
|
|
}
|
|
else // HGSS
|
|
{
|
|
// Has English Language ID for all except English origin, which is French
|
|
if (Species == (int)Core.Species.Pikachu)
|
|
pkm.Language = (int)(pkm.Language == (int)LanguageID.English ? LanguageID.French : LanguageID.English);
|
|
}
|
|
|
|
this.CopyContestStatsTo((PK4)pk);
|
|
}
|
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
{
|
|
pk.PID = PID;
|
|
pk.Nature = (int)(PID % 25);
|
|
pk.Gender = Gender;
|
|
pk.RefreshAbility(Ability >> 1);
|
|
SetIVs(pk);
|
|
}
|
|
|
|
protected override bool IsMatchNatureGenderShiny(PKM pkm)
|
|
{
|
|
return PID == pkm.EncryptionConstant;
|
|
}
|
|
}
|
|
|
|
public sealed record EncounterTrade4RanchGift : EncounterTrade4
|
|
{
|
|
/// <summary>
|
|
/// Fixed <see cref="PKM.PID"/> value the encounter must have.
|
|
/// </summary>
|
|
public readonly uint PID;
|
|
|
|
public EncounterTrade4RanchGift(uint pid, int species, int level) : base(GameVersion.D)
|
|
{
|
|
PID = pid;
|
|
Shiny = Shiny.FixedValue;
|
|
Species = species;
|
|
Level = level;
|
|
TrainerNames = RanchOTNames;
|
|
}
|
|
|
|
protected override bool IsMatchNatureGenderShiny(PKM pkm)
|
|
{
|
|
return PID == pkm.EncryptionConstant;
|
|
}
|
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
{
|
|
pk.PID = PID;
|
|
pk.Nature = (int)(PID % 25);
|
|
pk.Gender = Gender;
|
|
pk.RefreshAbility(Ability >> 1);
|
|
SetIVs(pk);
|
|
}
|
|
}
|
|
|
|
public sealed record EncounterTrade4RanchSpecial : EncounterTrade4
|
|
{
|
|
public EncounterTrade4RanchSpecial(int species, int level) : base(GameVersion.D)
|
|
{
|
|
Species = species;
|
|
Level = level;
|
|
Ball = 0x10;
|
|
OTGender = 1;
|
|
Location = 3000;
|
|
TrainerNames = RanchOTNames;
|
|
}
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
{
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
pk.FatefulEncounter = true;
|
|
}
|
|
}
|
|
}
|