2017-05-29 07:48:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
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; }
|
2017-09-20 16:04:30 +00:00
|
|
|
|
public override int[] Moves { get; set; } = new int[0];
|
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
|
|
|
|
|
|
|
|
|
// 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;
|
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,
|
|
|
|
|
|
|
|
|
|
EXP = PKX.GetEXP(Level, Species),
|
|
|
|
|
|
|
|
|
|
// 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;
|
2017-07-16 06:35:32 +00:00
|
|
|
|
pk.Met_Location = 32;
|
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
|
|
|
|
|
pk.Language = lang;
|
|
|
|
|
|
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-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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-01 23:50:45 +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
|
|
|
|
}
|
|
|
|
|
}
|