2021-01-01 20:21:46 +00:00
|
|
|
|
namespace PKHeX.Core
|
2018-03-09 05:18:32 +00:00
|
|
|
|
{
|
2021-09-16 01:13:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Trade Encounter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterTradeGB"/>
|
2021-12-09 09:08:46 +00:00
|
|
|
|
public abstract record EncounterTrade4(GameVersion Version) : EncounterTrade(Version)
|
2018-03-09 05:18:32 +00:00
|
|
|
|
{
|
2020-12-24 23:23:26 +00:00
|
|
|
|
public sealed override int Generation => 4;
|
2021-01-04 00:49:49 +00:00
|
|
|
|
|
|
|
|
|
protected static readonly string[] RanchOTNames = { string.Empty, "ユカリ", "Hayley", "EULALIE", "GIULIA", "EUKALIA", string.Empty, "Eulalia" };
|
2020-12-24 23:23:26 +00:00
|
|
|
|
}
|
2020-08-30 22:35:59 +00:00
|
|
|
|
|
2021-09-16 01:13:17 +00:00
|
|
|
|
/// <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
|
2020-12-24 23:23:26 +00:00
|
|
|
|
{
|
2019-09-10 07:21:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fixed <see cref="PKM.PID"/> value the encounter must have.
|
|
|
|
|
/// </summary>
|
2020-03-14 04:39:35 +00:00
|
|
|
|
public readonly uint PID;
|
|
|
|
|
|
2022-03-06 05:04:18 +00:00
|
|
|
|
public override Shiny Shiny => Shiny.FixedValue;
|
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
|
public EncounterTrade4PID(GameVersion game, uint pid, ushort species, byte level) : base(game)
|
2020-12-21 22:40:34 +00:00
|
|
|
|
{
|
|
|
|
|
PID = pid;
|
2020-12-24 23:23:26 +00:00
|
|
|
|
Species = species;
|
|
|
|
|
Level = level;
|
2020-12-21 22:40:34 +00:00
|
|
|
|
}
|
2019-09-10 07:21:51 +00:00
|
|
|
|
|
2021-01-01 21:39:08 +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; }
|
2020-12-24 08:06:40 +00:00
|
|
|
|
|
2021-01-01 21:39:08 +00:00
|
|
|
|
public byte Contest
|
2020-12-24 08:06:40 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2020-12-24 08:06:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-30 22:35:59 +00:00
|
|
|
|
|
2021-05-19 00:14:17 +00:00
|
|
|
|
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)
|
2020-08-30 22:35:59 +00:00
|
|
|
|
{
|
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))
|
2020-08-30 22:35:59 +00:00
|
|
|
|
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);
|
2020-12-28 22:42:48 +00:00
|
|
|
|
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);
|
2021-12-26 07:59:18 +00:00
|
|
|
|
// All other trades received (DP only): English games have a Japanese language ID instead of English.
|
|
|
|
|
else if (pkm.Version is not (int)GameVersion.Pt && pkm.Language == (int)LanguageID.English)
|
2020-12-28 22:42:48 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 22:35:59 +00:00
|
|
|
|
this.CopyContestStatsTo((PK4)pk);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 19:37:20 +00:00
|
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
|
{
|
|
|
|
|
pk.PID = PID;
|
2020-12-24 23:23:26 +00:00
|
|
|
|
pk.Nature = (int)(PID % 25);
|
|
|
|
|
pk.Gender = Gender;
|
2022-01-09 06:34:04 +00:00
|
|
|
|
pk.RefreshAbility(Ability.GetSingleValue());
|
2019-02-09 19:37:20 +00:00
|
|
|
|
SetIVs(pk);
|
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
|
|
|
|
protected override bool IsMatchNatureGenderShiny(PKM pkm)
|
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
return PID == pkm.EncryptionConstant;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
}
|
2018-03-09 05:18:32 +00:00
|
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
|
|
2021-09-16 01:13:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Trade Encounter with a fixed PID value, met location, and version.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterTradeGB"/>
|
2020-12-24 23:23:26 +00:00
|
|
|
|
public sealed record EncounterTrade4RanchGift : EncounterTrade4
|
2020-08-21 23:35:49 +00:00
|
|
|
|
{
|
2020-12-24 23:23:26 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fixed <see cref="PKM.PID"/> value the encounter must have.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly uint PID;
|
|
|
|
|
|
2021-05-19 00:14:17 +00:00
|
|
|
|
public int MetLocation { private get; init; }
|
|
|
|
|
public override int Location => MetLocation;
|
2022-03-06 05:04:18 +00:00
|
|
|
|
public override Shiny Shiny => Shiny.FixedValue;
|
2021-05-19 00:14:17 +00:00
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
|
public EncounterTrade4RanchGift(uint pid, ushort species, byte level) : base(GameVersion.D)
|
2020-12-24 23:23:26 +00:00
|
|
|
|
{
|
|
|
|
|
PID = pid;
|
|
|
|
|
Species = species;
|
|
|
|
|
Level = level;
|
2021-01-04 00:49:49 +00:00
|
|
|
|
TrainerNames = RanchOTNames;
|
2020-12-24 23:23:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchNatureGenderShiny(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
return PID == pkm.EncryptionConstant;
|
|
|
|
|
}
|
2020-09-13 21:40:10 +00:00
|
|
|
|
|
2020-12-24 23:23:26 +00:00
|
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
|
|
|
{
|
|
|
|
|
pk.PID = PID;
|
|
|
|
|
pk.Nature = (int)(PID % 25);
|
|
|
|
|
pk.Gender = Gender;
|
2022-01-09 06:34:04 +00:00
|
|
|
|
pk.RefreshAbility(Ability.GetSingleValue());
|
2020-12-24 23:23:26 +00:00
|
|
|
|
SetIVs(pk);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 01:13:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Trade Encounter with a fixed location and version, as well as special details.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterTrade4"/>
|
2020-12-24 23:23:26 +00:00
|
|
|
|
public sealed record EncounterTrade4RanchSpecial : EncounterTrade4
|
|
|
|
|
{
|
2021-05-19 00:14:17 +00:00
|
|
|
|
public override int Location => 3000;
|
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
|
public EncounterTrade4RanchSpecial(ushort species, byte level) : base(GameVersion.D)
|
2020-09-13 21:40:10 +00:00
|
|
|
|
{
|
|
|
|
|
Species = species;
|
|
|
|
|
Level = level;
|
|
|
|
|
Ball = 0x10;
|
2020-12-24 23:23:26 +00:00
|
|
|
|
OTGender = 1;
|
2021-01-04 00:49:49 +00:00
|
|
|
|
TrainerNames = RanchOTNames;
|
2020-09-13 21:40:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
|
{
|
|
|
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
|
|
|
pk.FatefulEncounter = true;
|
|
|
|
|
}
|
2020-08-21 23:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|