PKHeX/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade4.cs

172 lines
5.5 KiB
C#
Raw Normal View History

2021-01-01 20:21:46 +00:00
namespace PKHeX.Core
2018-03-09 05:18:32 +00:00
{
/// <summary>
/// Generation 4 Trade Encounter
/// </summary>
/// <inheritdoc cref="EncounterTradeGB"/>
public abstract record EncounterTrade4 : EncounterTrade
2018-03-09 05:18:32 +00:00
{
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)
{
}
}
/// <summary>
/// Generation 4 Trade Encounter with a fixed PID value.
/// </summary>
/// <inheritdoc cref="EncounterTrade4"/>
2021-01-01 20:21:46 +00:00
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)
2020-12-21 22:40:34 +00:00
{
PID = pid;
Shiny = Shiny.FixedValue;
Species = species;
Level = level;
2020-12-21 22:40:34 +00:00
}
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
{
2021-01-01 20:21:46 +00:00
CNT_Cool = value;
CNT_Beauty = value;
CNT_Cute = value;
CNT_Smart = value;
CNT_Tough = value;
//CNT_Sheen = value;
}
}
public int MetLocation { get; init; }
public override int Location => MetLocation == default ? Locations.LinkTrade4NPC : MetLocation;
Fracture the encounter matching checks to allow progressive validation (#3137) ## 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).
2021-01-30 01:55:27 +00:00
public override bool IsMatchExact(PKM pkm, DexLevel evo)
{
Fracture the encounter matching checks to allow progressive validation (#3137) ## 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).
2021-01-30 01:55:27 +00:00
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);
}
2019-11-16 01:34:18 +00:00
protected override bool IsMatchNatureGenderShiny(PKM pkm)
{
return PID == pkm.EncryptionConstant;
2019-11-16 01:34:18 +00:00
}
2018-03-09 05:18:32 +00:00
}
/// <summary>
/// Generation 4 Trade Encounter with a fixed PID value, met location, and version.
/// </summary>
/// <inheritdoc cref="EncounterTradeGB"/>
public sealed record EncounterTrade4RanchGift : EncounterTrade4
{
/// <summary>
/// Fixed <see cref="PKM.PID"/> value the encounter must have.
/// </summary>
public readonly uint PID;
public int MetLocation { private get; init; }
public override int Location => MetLocation;
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);
}
}
/// <summary>
/// Generation 4 Trade Encounter with a fixed location and version, as well as special details.
/// </summary>
/// <inheritdoc cref="EncounterTrade4"/>
public sealed record EncounterTrade4RanchSpecial : EncounterTrade4
{
public override int Location => 3000;
public EncounterTrade4RanchSpecial(int species, int level) : base(GameVersion.D)
{
Species = species;
Level = level;
Ball = 0x10;
OTGender = 1;
TrainerNames = RanchOTNames;
}
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{
base.ApplyDetails(sav, criteria, pk);
pk.FatefulEncounter = true;
}
}
}