PKHeX/PKHeX.Core/MysteryGifts/WC3.cs

209 lines
7.4 KiB
C#
Raw Normal View History

using System;
namespace PKHeX.Core
{
/// <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>
public class WC3 : MysteryGift, IRibbonSetEvent3, IVersion
{
// Template Properties
/// <summary>
/// Matched <see cref="PIDIV"/> Type
/// </summary>
public PIDType Method;
public override string OT_Name { get; set; }
public int OT_Gender { get; set; } = 3;
public override int TID { get; set; }
public override int SID { get; set; }
public override int Location { get; set; } = 255;
public override int EggLocation { get => 0; set {} }
public GameVersion Version { get; set; }
public int Language { get; set; } = -1;
public override int Species { get; set; }
public override bool IsEgg { get; set; }
public override int[] Moves { get; set; } = new int[0];
public bool NotDistributed { get; set; }
public Shiny Shiny { get; set; } = Shiny.Random;
public bool Fateful { get; set; } // Obedience Flag
// Mystery Gift Properties
public override int Format => 3;
public override int Level { get; set; }
public override int Ball { get; set; } = 4;
public override bool IsShiny => Shiny == Shiny.Always;
// Description
public override string CardTitle { get; set; } = "Generation 3 Event";
public override string CardHeader => CardTitle;
// Unused
public override bool GiftUsed { get; set; }
public override int CardID { get; set; }
public override bool IsItem { get; set; }
public override int ItemID { get; set; }
public override bool IsPokémon { get; set; } = true;
public override bool Empty => false;
public override int Gender { get; set; }
public override int Form { get; set; }
// Synthetic
private int? _metLevel;
public int Met_Level
{
get => _metLevel ?? (IsEgg ? 0 : Level);
set => _metLevel = value;
}
public override PKM ConvertToPKM(ITrainerInfo SAV)
{
PK3 pk = new PK3
{
Species = Species,
Met_Level = Met_Level,
Met_Location = Location,
Ball = 4,
EXP = PKX.GetEXP(Level, Species),
// Ribbons
RibbonCountry = RibbonCountry,
RibbonNational = RibbonNational,
RibbonEarth = RibbonEarth,
RibbonChampionBattle = RibbonChampionBattle,
RibbonChampionRegional = RibbonChampionRegional,
RibbonChampionNational = RibbonChampionNational,
FatefulEncounter = Fateful,
};
var pi = pk.PersonalInfo;
2017-07-16 06:35:32 +00:00
if (Version == 0)
{
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 06:35:32 +00:00
else
{
pk.Version = (int)GetRandomVersion(Version);
2017-07-16 06:35:32 +00:00
}
int lang = GetSafeLanguage(SAV.Language, Language);
bool hatchedEgg = IsEgg && SAV.Generation != 3;
if (hatchedEgg) // ugly workaround for character table interactions
{
pk.Language = (int)LanguageID.English;
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;
}
else
{
2017-07-16 06:35:32 +00:00
if (IsEgg)
{
pk.IsEgg = true;
pk.IsNicknamed = true;
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;
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;
pk.Language = (int)LanguageID.English;
2017-07-16 06:35:32 +00:00
pk.OT_Name = SAV.OT;
pk.Language = (int)LanguageID.Japanese; // as egg is Japanese until hatched
2017-07-16 06:35:32 +00:00
pk.IsEgg = true;
}
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);
if (Version == GameVersion.XD)
pk.FatefulEncounter = true; // pk3 is already converted from xk3
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;
Array.Resize(ref moves, 4);
2017-07-16 06:35:32 +00:00
Moves = moves;
}
pk.Moves = Moves;
pk.SetMaximumPPCurrent(Moves);
pk.HeldItem = 0; // clear, only random for Jirachis(?), no loss
pk.RefreshChecksum();
return pk;
}
2017-07-16 06:35:32 +00:00
private static int GetSafeLanguage(int hatchLang, int supplied)
{
if (supplied >= 1)
return supplied;
if (hatchLang < 0 || hatchLang > 8) // ko
2017-07-16 06:35:32 +00:00
return 2;
return hatchLang;
}
private static GameVersion GetRandomVersion(GameVersion version)
2017-07-16 06:35:32 +00:00
{
if (version <= GameVersion.CXD && version > GameVersion.Unknown) // single game
2017-07-16 06:35:32 +00:00
return version;
int rand = Util.Rand.Next(2); // 0 or 1
2017-07-16 06:35:32 +00:00
switch (version)
{
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}");
}
}
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; }
}
}