2017-05-29 07:48:25 +00:00
|
|
|
|
using System;
|
2018-12-27 09:00:08 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-29 07:48:25 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 3 Mystery Gift Template File
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is fabricated data built to emulate the future generation Mystery Gift objects.
|
|
|
|
|
/// Data here is not stored in any save file and cannot be naturally exported.
|
|
|
|
|
/// </remarks>
|
2018-05-27 17:11:01 +00:00
|
|
|
|
public class WC3 : MysteryGift, IRibbonSetEvent3, IVersion
|
2017-05-29 07:48:25 +00:00
|
|
|
|
{
|
|
|
|
|
// Template Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Matched <see cref="PIDIV"/> Type
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PIDType Method;
|
|
|
|
|
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override string OT_Name { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int OT_Gender { get; set; } = 3;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int TID { get; set; }
|
|
|
|
|
public override int SID { get; set; }
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public override int Location { get; set; } = 255;
|
|
|
|
|
public override int EggLocation { get => 0; set {} }
|
2018-05-27 17:11:01 +00:00
|
|
|
|
public GameVersion Version { get; set; }
|
2017-06-30 02:32:29 +00:00
|
|
|
|
public int Language { get; set; } = -1;
|
2017-05-29 07:48:25 +00:00
|
|
|
|
public override int Species { get; set; }
|
|
|
|
|
public override bool IsEgg { get; set; }
|
2018-08-02 01:30:51 +00:00
|
|
|
|
public override int[] Moves { get; set; } = Array.Empty<int>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool NotDistributed { get; set; }
|
2018-03-17 02:35:55 +00:00
|
|
|
|
public Shiny Shiny { get; set; } = Shiny.Random;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool Fateful { get; set; } // Obedience Flag
|
2017-05-29 07:48:25 +00:00
|
|
|
|
|
|
|
|
|
// Mystery Gift Properties
|
|
|
|
|
public override int Format => 3;
|
|
|
|
|
public override int Level { get; set; }
|
|
|
|
|
public override int Ball { get; set; } = 4;
|
2018-04-04 16:53:48 +00:00
|
|
|
|
public override bool IsShiny => Shiny == Shiny.Always;
|
2017-05-29 07:48:25 +00:00
|
|
|
|
|
2018-12-27 09:00:08 +00:00
|
|
|
|
public bool RibbonEarth { get; set; }
|
|
|
|
|
public bool RibbonNational { get; set; }
|
|
|
|
|
public bool RibbonCountry { get; set; }
|
|
|
|
|
public bool RibbonChampionBattle { get; set; }
|
|
|
|
|
public bool RibbonChampionRegional { get; set; }
|
|
|
|
|
public bool RibbonChampionNational { get; set; }
|
|
|
|
|
|
2017-05-29 07:48:25 +00:00
|
|
|
|
// Description
|
|
|
|
|
public override string CardTitle { get; set; } = "Generation 3 Event";
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string CardHeader => CardTitle;
|
2017-05-29 07:48:25 +00:00
|
|
|
|
|
|
|
|
|
// Unused
|
|
|
|
|
public override bool GiftUsed { get; set; }
|
|
|
|
|
public override int CardID { get; set; }
|
|
|
|
|
public override bool IsItem { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int ItemID { get; set; }
|
2017-07-16 01:36:55 +00:00
|
|
|
|
public override bool IsPokémon { get; set; } = true;
|
|
|
|
|
public override bool Empty => false;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int Gender { get; set; }
|
|
|
|
|
public override int Form { get; set; }
|
2017-05-29 07:48:25 +00:00
|
|
|
|
|
2017-06-30 02:32:29 +00:00
|
|
|
|
// Synthetic
|
2017-07-06 06:22:06 +00:00
|
|
|
|
private int? _metLevel;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2017-06-30 02:32:29 +00:00
|
|
|
|
public int Met_Level
|
|
|
|
|
{
|
2017-07-06 06:22:06 +00:00
|
|
|
|
get => _metLevel ?? (IsEgg ? 0 : Level);
|
2017-06-30 02:32:29 +00:00
|
|
|
|
set => _metLevel = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-28 22:55:19 +00:00
|
|
|
|
public override PKM ConvertToPKM(ITrainerInfo SAV)
|
2017-05-29 07:48:25 +00:00
|
|
|
|
{
|
2017-07-16 01:36:55 +00:00
|
|
|
|
PK3 pk = new PK3
|
|
|
|
|
{
|
|
|
|
|
Species = Species,
|
|
|
|
|
Met_Level = Met_Level,
|
2018-01-02 20:00:41 +00:00
|
|
|
|
Met_Location = Location,
|
2017-07-16 01:36:55 +00:00
|
|
|
|
Ball = 4,
|
|
|
|
|
|
2018-11-27 00:55:16 +00:00
|
|
|
|
EXP = Experience.GetEXP(Level, Species, 0),
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
|
|
|
|
// Ribbons
|
|
|
|
|
RibbonCountry = RibbonCountry,
|
|
|
|
|
RibbonNational = RibbonNational,
|
|
|
|
|
RibbonEarth = RibbonEarth,
|
|
|
|
|
RibbonChampionBattle = RibbonChampionBattle,
|
|
|
|
|
RibbonChampionRegional = RibbonChampionRegional,
|
|
|
|
|
RibbonChampionNational = RibbonChampionNational,
|
|
|
|
|
|
|
|
|
|
FatefulEncounter = Fateful,
|
|
|
|
|
};
|
2018-03-28 22:55:19 +00:00
|
|
|
|
var pi = pk.PersonalInfo;
|
2017-07-16 06:35:32 +00:00
|
|
|
|
|
|
|
|
|
if (Version == 0)
|
2017-07-16 01:36:55 +00:00
|
|
|
|
{
|
2017-07-16 06:35:32 +00:00
|
|
|
|
bool gen3 = SAV.Game <= 15 && GameVersion.Gen3.Contains((GameVersion)SAV.Game);
|
|
|
|
|
pk.Version = gen3 ? SAV.Game : (int)GameVersion.R;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
}
|
2017-07-16 06:35:32 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-27 21:16:56 +00:00
|
|
|
|
pk.Version = (int)GetRandomVersion(Version);
|
2017-07-16 06:35:32 +00:00
|
|
|
|
}
|
|
|
|
|
int lang = GetSafeLanguage(SAV.Language, Language);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
bool hatchedEgg = IsEgg && SAV.Generation != 3;
|
|
|
|
|
if (hatchedEgg) // ugly workaround for character table interactions
|
|
|
|
|
{
|
2017-10-23 04:01:08 +00:00
|
|
|
|
pk.Language = (int)LanguageID.English;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.OT_Name = "PKHeX";
|
|
|
|
|
pk.OT_Gender = SAV.Gender;
|
|
|
|
|
pk.TID = SAV.TID;
|
|
|
|
|
pk.SID = SAV.SID;
|
|
|
|
|
pk.OT_Friendship = pi.BaseFriendship;
|
2018-06-16 05:00:51 +00:00
|
|
|
|
pk.Met_Location = pk.FRLG ? 146 /* Four Island */ : 32; // Route 117
|
|
|
|
|
pk.FatefulEncounter &= pk.FRLG; // clear flag for RSE
|
|
|
|
|
pk.Met_Level = 0; // hatched
|
2017-07-16 01:36:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-16 06:35:32 +00:00
|
|
|
|
if (IsEgg)
|
|
|
|
|
{
|
|
|
|
|
pk.IsEgg = true;
|
|
|
|
|
pk.IsNicknamed = true;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
pk.Language = (int)LanguageID.Japanese; // JPN
|
2017-07-16 06:35:32 +00:00
|
|
|
|
if (SID >= 0)
|
|
|
|
|
pk.SID = SID;
|
|
|
|
|
if (TID >= 0)
|
|
|
|
|
pk.SID = TID;
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-08-10 04:53:39 +00:00
|
|
|
|
{
|
2017-07-16 06:35:32 +00:00
|
|
|
|
pk.Language = lang;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
}
|
2017-07-16 06:35:32 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.OT_Name = OT_Name ?? SAV.OT;
|
2017-07-16 06:35:32 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(pk.OT_Name))
|
|
|
|
|
{
|
|
|
|
|
// Try again (only happens for eggs)
|
|
|
|
|
pk.IsEgg = false;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
pk.Language = (int)LanguageID.English;
|
2017-07-16 06:35:32 +00:00
|
|
|
|
pk.OT_Name = SAV.OT;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
pk.Language = (int)LanguageID.Japanese; // as egg is Japanese until hatched
|
2017-07-16 06:35:32 +00:00
|
|
|
|
pk.IsEgg = true;
|
|
|
|
|
}
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.OT_Gender = OT_Gender != 3 ? OT_Gender & 1 : SAV.Gender;
|
|
|
|
|
pk.TID = TID;
|
|
|
|
|
pk.SID = SID;
|
|
|
|
|
pk.OT_Friendship = IsEgg ? pi.HatchCycles : pi.BaseFriendship;
|
|
|
|
|
}
|
|
|
|
|
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, pk.Language, 3); // will be set to Egg nickname if appropriate by PK3 setter
|
|
|
|
|
|
|
|
|
|
// Generate PIDIV
|
|
|
|
|
var seed = Util.Rand32();
|
|
|
|
|
switch (Method)
|
|
|
|
|
{
|
|
|
|
|
case PIDType.BACD_R:
|
|
|
|
|
seed &= 0xFFFF;
|
|
|
|
|
break;
|
|
|
|
|
case PIDType.BACD_R_S:
|
|
|
|
|
seed &= 0xFF;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
PIDGenerator.SetValuesFromSeed(pk, Method, seed);
|
|
|
|
|
|
2018-05-27 17:11:01 +00:00
|
|
|
|
if (Version == GameVersion.XD)
|
2018-05-27 22:04:21 +00:00
|
|
|
|
pk.FatefulEncounter = true; // pk3 is already converted from xk3
|
2018-05-27 17:11:01 +00:00
|
|
|
|
|
2017-10-03 23:44:12 +00:00
|
|
|
|
if (Moves == null || Moves.Length == 0) // not completely defined
|
2017-07-16 06:35:32 +00:00
|
|
|
|
Moves = Legal.GetBaseEggMoves(pk, Species, (GameVersion)pk.Version, Level);
|
|
|
|
|
if (Moves.Length != 4)
|
|
|
|
|
{
|
|
|
|
|
var moves = Moves;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
Array.Resize(ref moves, 4);
|
2017-07-16 06:35:32 +00:00
|
|
|
|
Moves = moves;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pk.Moves = Moves;
|
2018-04-07 18:40:01 +00:00
|
|
|
|
pk.SetMaximumPPCurrent(Moves);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.HeldItem = 0; // clear, only random for Jirachis(?), no loss
|
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
return pk;
|
2017-05-29 07:48:25 +00:00
|
|
|
|
}
|
2017-07-01 23:50:45 +00:00
|
|
|
|
|
2017-07-16 06:35:32 +00:00
|
|
|
|
private static int GetSafeLanguage(int hatchLang, int supplied)
|
|
|
|
|
{
|
|
|
|
|
if (supplied >= 1)
|
|
|
|
|
return supplied;
|
2018-04-07 18:40:01 +00:00
|
|
|
|
if (hatchLang < 0 || hatchLang > 8) // ko
|
2017-07-16 06:35:32 +00:00
|
|
|
|
return 2;
|
|
|
|
|
return hatchLang;
|
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
|
2018-05-27 21:16:56 +00:00
|
|
|
|
private static GameVersion GetRandomVersion(GameVersion version)
|
2017-07-16 06:35:32 +00:00
|
|
|
|
{
|
2018-05-27 21:16:56 +00:00
|
|
|
|
if (version <= GameVersion.CXD && version > GameVersion.Unknown) // single game
|
2017-07-16 06:35:32 +00:00
|
|
|
|
return version;
|
|
|
|
|
|
2017-12-15 04:58:55 +00:00
|
|
|
|
int rand = Util.Rand.Next(2); // 0 or 1
|
2017-07-16 06:35:32 +00:00
|
|
|
|
switch (version)
|
|
|
|
|
{
|
2018-05-27 21:16:56 +00:00
|
|
|
|
case GameVersion.FRLG:
|
|
|
|
|
return GameVersion.FR + rand; // or LG
|
|
|
|
|
case GameVersion.RS:
|
|
|
|
|
return GameVersion.S + rand; // or R
|
|
|
|
|
|
|
|
|
|
case GameVersion.COLO:
|
|
|
|
|
case GameVersion.XD:
|
|
|
|
|
return GameVersion.CXD;
|
2017-07-16 06:35:32 +00:00
|
|
|
|
default:
|
|
|
|
|
throw new Exception($"Unknown GameVersion: {version}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 09:00:08 +00:00
|
|
|
|
protected override bool IsMatchExact(PKM pkm, IEnumerable<DexLevel> vs)
|
|
|
|
|
{
|
|
|
|
|
// Gen3 Version MUST match.
|
|
|
|
|
if (Version != 0 && !(Version).Contains((GameVersion)pkm.Version))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool hatchedEgg = IsEgg && !pkm.IsEgg;
|
|
|
|
|
if (!hatchedEgg)
|
|
|
|
|
{
|
|
|
|
|
if (SID != -1 && SID != pkm.SID) return false;
|
|
|
|
|
if (TID != -1 && TID != pkm.TID) return false;
|
|
|
|
|
if (OT_Gender < 3 && OT_Gender != pkm.OT_Gender) return false;
|
|
|
|
|
var wcOT = OT_Name;
|
|
|
|
|
if (wcOT != null)
|
|
|
|
|
{
|
|
|
|
|
if (wcOT.Length > 7) // Colosseum Mattle Ho-Oh
|
|
|
|
|
{
|
|
|
|
|
if (!GetIsValidOTMattleHoOh(wcOT, pkm.OT_Name, pkm is CK3))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (wcOT != pkm.OT_Name)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Language != -1 && Language != pkm.Language) return false;
|
|
|
|
|
if (Ball != pkm.Ball) return false;
|
|
|
|
|
if (Fateful != pkm.FatefulEncounter)
|
|
|
|
|
{
|
|
|
|
|
// XD Gifts only at level 20 get flagged after transfer
|
|
|
|
|
if (Version == GameVersion.XD != pkm is XK3)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsNative)
|
|
|
|
|
{
|
|
|
|
|
if (hatchedEgg)
|
|
|
|
|
return true; // defer egg specific checks to later.
|
|
|
|
|
if (Met_Level != pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
if (Location != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
return false;
|
|
|
|
|
if (Level > pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool GetIsValidOTMattleHoOh(string wc, string ot, bool ck3)
|
|
|
|
|
{
|
|
|
|
|
if (ck3 && ot.Length == 10)
|
|
|
|
|
return wc == ot;
|
|
|
|
|
return ot.Length == 7 && wc.StartsWith(ot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMatchDeferred(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
return Species != pkm.Species;
|
|
|
|
|
}
|
2017-05-29 07:48:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|