diff --git a/PKHeX/MainWindow/MainPK4.cs b/PKHeX/MainWindow/MainPK4.cs index 697193b01..4e27d2d69 100644 --- a/PKHeX/MainWindow/MainPK4.cs +++ b/PKHeX/MainWindow/MainPK4.cs @@ -41,10 +41,14 @@ namespace PKHeX CB_EncounterType.SelectedValue = pk4.Gen4 ? pk4.EncounterType : 0; CB_Ball.SelectedValue = pk4.Ball; - if (pk4.Met_Month == 0) { pk4.Met_Month = 1; } - if (pk4.Met_Day == 0) { pk4.Met_Day = 1; } - try { CAL_MetDate.Value = new DateTime(pk4.Met_Year + 2000, pk4.Met_Month, pk4.Met_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk4.MetDate.HasValue) + { + CAL_MetDate.Value = pk4.MetDate.Value; + } + else + { + CAL_MetDate.Value = new DateTime(2000, 1, 1); + } if (pk4.Egg_Location != 0) { @@ -53,8 +57,14 @@ namespace PKHeX GB_EggConditions.Enabled = true; CB_EggLocation.SelectedValue = pk4.Egg_Location; - try { CAL_EggDate.Value = new DateTime(pk4.Egg_Year + 2000, pk4.Egg_Month, pk4.Egg_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk4.EggMetDate.HasValue) + { + CAL_EggDate.Value = pk4.EggMetDate.Value; + } + else + { + CAL_EggDate.Value = new DateTime(2000, 1, 1); + } } else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } @@ -194,30 +204,22 @@ namespace PKHeX pk4.Language = Util.getIndex(CB_Language); // Default Dates - int egg_year = 2000; - int egg_month = 0; - int egg_day = 0; + DateTime? egg_date = null; int egg_location = 0; if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. { - egg_year = CAL_EggDate.Value.Year; - egg_month = CAL_EggDate.Value.Month; - egg_day = CAL_EggDate.Value.Day; + egg_date = CAL_EggDate.Value; egg_location = Util.getIndex(CB_EggLocation); } // Egg Met Data - pk4.Egg_Year = egg_year - 2000; - pk4.Egg_Month = egg_month; - pk4.Egg_Day = egg_day; + pk4.EggMetDate = egg_date; pk4.Egg_Location = egg_location; // Met Data - pk4.Met_Year = CAL_MetDate.Value.Year - 2000; - pk4.Met_Month = CAL_MetDate.Value.Month; - pk4.Met_Day = CAL_MetDate.Value.Day; + pk4.MetDate = CAL_MetDate.Value; pk4.Met_Location = Util.getIndex(CB_MetLocation); if (pk4.IsEgg && pk4.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! - pk4.Met_Year = pk4.Met_Month = pk4.Met_Day = 0; + pk4.MetDate = null; // Toss in Party Stats Array.Resize(ref pk4.Data, pk4.SIZE_PARTY); diff --git a/PKHeX/MainWindow/MainPK5.cs b/PKHeX/MainWindow/MainPK5.cs index 15f674aab..469fed01d 100644 --- a/PKHeX/MainWindow/MainPK5.cs +++ b/PKHeX/MainWindow/MainPK5.cs @@ -50,10 +50,14 @@ namespace PKHeX CB_EncounterType.SelectedValue = pk5.Gen4 ? pk5.EncounterType : 0; CB_Ball.SelectedValue = pk5.Ball; - if (pk5.Met_Month == 0) { pk5.Met_Month = 1; } - if (pk5.Met_Day == 0) { pk5.Met_Day = 1; } - try { CAL_MetDate.Value = new DateTime(pk5.Met_Year + 2000, pk5.Met_Month, pk5.Met_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk5.MetDate.HasValue) + { + CAL_MetDate.Value = pk5.MetDate.Value; + } + else + { + CAL_MetDate.Value = new DateTime(2000, 1, 1); + } if (pk5.Egg_Location != 0) { @@ -62,8 +66,14 @@ namespace PKHeX GB_EggConditions.Enabled = true; CB_EggLocation.SelectedValue = pk5.Egg_Location; - try { CAL_EggDate.Value = new DateTime(pk5.Egg_Year + 2000, pk5.Egg_Month, pk5.Egg_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk5.EggMetDate.HasValue) + { + CAL_EggDate.Value = pk5.EggMetDate.Value; + } + else + { + CAL_EggDate.Value = new DateTime(2000, 1, 1); + } } else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } @@ -200,30 +210,22 @@ namespace PKHeX pk5.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); // Default Dates - int egg_year = 2000; - int egg_month = 0; - int egg_day = 0; + DateTime? egg_date = null; int egg_location = 0; - if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. + if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. { - egg_year = CAL_EggDate.Value.Year; - egg_month = CAL_EggDate.Value.Month; - egg_day = CAL_EggDate.Value.Day; + egg_date = CAL_EggDate.Value; egg_location = Util.getIndex(CB_EggLocation); } // Egg Met Data - pk5.Egg_Year = egg_year - 2000; - pk5.Egg_Month = egg_month; - pk5.Egg_Day = egg_day; + pk5.EggMetDate = egg_date; pk5.Egg_Location = egg_location; // Met Data - pk5.Met_Year = CAL_MetDate.Value.Year - 2000; - pk5.Met_Month = CAL_MetDate.Value.Month; - pk5.Met_Day = CAL_MetDate.Value.Day; + pk5.MetDate = CAL_MetDate.Value; pk5.Met_Location = Util.getIndex(CB_MetLocation); if (pk5.IsEgg && pk5.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! - pk5.Met_Year = pk5.Met_Month = pk5.Met_Day = 0; + pk5.MetDate = null; pk5.Ball = Util.getIndex(CB_Ball); pk5.Met_Level = Util.ToInt32(TB_MetLevel.Text); diff --git a/PKHeX/MainWindow/MainPK6.cs b/PKHeX/MainWindow/MainPK6.cs index ced541a41..534dbd8db 100644 --- a/PKHeX/MainWindow/MainPK6.cs +++ b/PKHeX/MainWindow/MainPK6.cs @@ -57,10 +57,14 @@ namespace PKHeX CB_EncounterType.SelectedValue = pk6.Gen4 ? pk6.EncounterType : 0; CB_Ball.SelectedValue = pk6.Ball; - if (pk6.Met_Month == 0) { pk6.Met_Month = 1; } - if (pk6.Met_Day == 0) { pk6.Met_Day = 1; } - try { CAL_MetDate.Value = new DateTime(pk6.Met_Year + 2000, pk6.Met_Month, pk6.Met_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk6.MetDate.HasValue) + { + CAL_MetDate.Value = pk6.MetDate.Value; + } + else + { + CAL_MetDate.Value = new DateTime(2000, 1, 1); + } if (pk6.Egg_Location != 0) { @@ -69,8 +73,14 @@ namespace PKHeX GB_EggConditions.Enabled = true; CB_EggLocation.SelectedValue = pk6.Egg_Location; - try { CAL_EggDate.Value = new DateTime(pk6.Egg_Year + 2000, pk6.Egg_Month, pk6.Egg_Day); } - catch { CAL_MetDate.Value = new DateTime(2000, 1, 1); } + if (pk6.EggMetDate.HasValue) + { + CAL_EggDate.Value = pk6.EggMetDate.Value; + } + else + { + CAL_EggDate.Value = new DateTime(2000, 1, 1); + } } else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } @@ -263,30 +273,22 @@ namespace PKHeX pk6.OT_Name = TB_OT.Text; pk6.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); - int egg_year = 2000; // Default Dates - int egg_month = 0; - int egg_day = 0; + DateTime? egg_date = null; int egg_location = 0; if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. { - egg_year = CAL_EggDate.Value.Year; - egg_month = CAL_EggDate.Value.Month; - egg_day = CAL_EggDate.Value.Day; + egg_date = CAL_EggDate.Value; egg_location = Util.getIndex(CB_EggLocation); } // Egg Met Data - pk6.Egg_Year = egg_year - 2000; - pk6.Egg_Month = egg_month; - pk6.Egg_Day = egg_day; + pk6.EggMetDate = egg_date; pk6.Egg_Location = egg_location; // Met Data - pk6.Met_Year = CAL_MetDate.Value.Year - 2000; - pk6.Met_Month = CAL_MetDate.Value.Month; - pk6.Met_Day = CAL_MetDate.Value.Day; + pk6.MetDate = CAL_MetDate.Value; pk6.Met_Location = Util.getIndex(CB_MetLocation); if (pk6.IsEgg && pk6.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! - pk6.Met_Year = pk6.Met_Month = pk6.Met_Day = 0; + pk6.MetDate = null; // 0xD7 Unknown diff --git a/PKHeX/MysteryGifts/PGF.cs b/PKHeX/MysteryGifts/PGF.cs index b4cf94520..24764e7c1 100644 --- a/PKHeX/MysteryGifts/PGF.cs +++ b/PKHeX/MysteryGifts/PGF.cs @@ -90,9 +90,48 @@ namespace PKHeX // Card Attributes public override int Item { get { return BitConverter.ToUInt16(Data, 0x00); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x00); } } - public ushort Year { get { return BitConverter.ToUInt16(Data, 0xAE); } set { BitConverter.GetBytes(value).CopyTo(Data, 0xAE); } } - public byte Month { get { return Data[0xAD]; } set { Data[0xAD] = value; } } - public byte Day { get { return Data[0xAC]; } set { Data[0xAC] = value; } } + private ushort Year { get { return BitConverter.ToUInt16(Data, 0xAE); } set { BitConverter.GetBytes(value).CopyTo(Data, 0xAE); } } + private byte Month { get { return Data[0xAD]; } set { Data[0xAD] = value; } } + private byte Day { get { return Data[0xAC]; } set { Data[0xAC] = value; } } + + /// + /// Gets or sets the date of the card. + /// + public DateTime? Date + { + get + { + // Check to see if date is valid + if (!Util.IsDateValid(Year, Month, Day)) + { + return null; + } + else + { + return new DateTime(2000 + Year, Month, Day); + } + } + set + { + if (value.HasValue) + { + // Only update the properties if a value is provided. + Year = (ushort)value.Value.Year; + Month = (byte)value.Value.Month; + Day = (byte)value.Value.Day; + } + else + { + // Clear the Met Date. + // If code tries to access MetDate again, null will be returned. + Year = 0; + Month = 0; + Day = 0; + } + } + } + + public override int CardID { get { return BitConverter.ToUInt16(Data, 0xB0); } @@ -151,9 +190,7 @@ namespace PKHeX Move3 = Move3, Move4 = Move4, Met_Location = MetLocation, - Met_Day = Day, - Met_Month = Month, - Met_Year = Year - 2000, + MetDate = Date, Egg_Location = EggLocation, CNT_Cool = CNT_Cool, CNT_Beauty = CNT_Beauty, @@ -255,9 +292,7 @@ namespace PKHeX if (IsEgg) { // pk.IsEgg = true; - pk.Egg_Day = Day; - pk.Egg_Month = Month; - pk.Egg_Year = Year - 2000; + pk.EggMetDate = Date; // Force hatch pk.IsEgg = false; pk.Met_Location = 4; // Nuvema Town diff --git a/PKHeX/MysteryGifts/PGT.cs b/PKHeX/MysteryGifts/PGT.cs index 9eeebbfea..911754cf9 100644 --- a/PKHeX/MysteryGifts/PGT.cs +++ b/PKHeX/MysteryGifts/PGT.cs @@ -181,22 +181,17 @@ namespace PKHeX } // Generate Met Info - DateTime dt = DateTime.Now; if (IsPokémon) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; - pk4.Met_Day = dt.Day; - pk4.Met_Month = dt.Month; - pk4.Met_Year = dt.Year - 2000; + pk4.MetDate = DateTime.Now; pk4.IsEgg = false; } else { pk4.Egg_Location = pk4.Egg_Location + 3000; - pk4.Egg_Day = dt.Day; - pk4.Egg_Month = dt.Month; - pk4.Egg_Year = dt.Year - 2000; + pk4.MetDate = DateTime.Now; pk4.IsEgg = false; // Met Location is modified when transferred to pk5; don't worry about it. } diff --git a/PKHeX/MysteryGifts/WC6.cs b/PKHeX/MysteryGifts/WC6.cs index 26f8a186c..254c8f841 100644 --- a/PKHeX/MysteryGifts/WC6.cs +++ b/PKHeX/MysteryGifts/WC6.cs @@ -31,18 +31,56 @@ namespace PKHeX public override string CardTitle { // Max len 36 char, followed by null terminator get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 2, 72)); } set { Encoding.Unicode.GetBytes(value.PadRight(36, '\0')).CopyTo(Data, 2); } } - private uint Date { + private uint RawDate { get { return BitConverter.ToUInt32(Data, 0x4C); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x4C); } } - public uint Year { - get { return Date/10000; } - set { Date = value*10000 + Date%10000; } } - public uint Month { - get { return Date%10000/100; } - set { Date = Year*10000 + value*100 + Date%100; } } - public uint Day { - get { return Date%100; } - set { Date = Year*10000 + Month*100 + value; } } + private uint Year { + get { return RawDate/10000; } + set { RawDate = value*10000 + RawDate%10000; } } + private uint Month { + get { return RawDate%10000/100; } + set { RawDate = Year*10000 + value*100 + RawDate%100; } } + private uint Day { + get { return RawDate%100; } + set { RawDate = Year*10000 + Month*100 + value; } } + + /// + /// Gets or sets the date of the card. + /// + public DateTime? Date + { + get + { + // Check to see if date is valid + if (!Util.IsDateValid(Year, Month, Day)) + { + return null; + } + else + { + return new DateTime(2000 + (int)Year, (int)Month, (int)Day); + } + } + set + { + if (value.HasValue) + { + // Only update the properties if a value is provided. + Year = (ushort)value.Value.Year; + Month = (byte)value.Value.Month; + Day = (byte)value.Value.Day; + } + else + { + // Clear the Met Date. + // If code tries to access MetDate again, null will be returned. + Year = 0; + Month = 0; + Day = 0; + } + } + } + public int CardLocation { get { return Data[0x50]; } set { Data[0x50] = (byte)value; } } public int CardType { get { return Data[0x51]; } set { Data[0x51] = (byte)value; } } @@ -281,18 +319,15 @@ namespace PKHeX pk.Move3_PP = pk.getMovePP(Move3, 0); pk.Move4_PP = pk.getMovePP(Move4, 0); - if (Day + Month + Year == 0) // No datetime set, typical for wc6full + if (Date.HasValue) { - DateTime dt = DateTime.Now; - pk.Met_Day = dt.Day; - pk.Met_Month = dt.Month; - pk.Met_Year = dt.Year - 2000; + pk.MetDate = Date.Value; } else { - pk.Met_Day = (int)Day; - pk.Met_Month = (int)Month; - pk.Met_Year = (int)(Year - 2000); + // No datetime set, typical for wc6full + // Set it to now, instead of zeroing it out. + pk.MetDate = DateTime.Now; } if (pk.CurrentHandler == 0) // OT @@ -375,9 +410,7 @@ namespace PKHeX if (IsEgg) { pk.IsEgg = true; - pk.Egg_Day = (int) Day; - pk.Egg_Month = (int) Month; - pk.Egg_Year = (int) Year; + pk.EggMetDate = Date; } pk.RefreshChecksum(); diff --git a/PKHeX/PKHeX.csproj b/PKHeX/PKHeX.csproj index 14445871e..86daecab2 100644 --- a/PKHeX/PKHeX.csproj +++ b/PKHeX/PKHeX.csproj @@ -298,6 +298,7 @@ + diff --git a/PKHeX/PKM/PK3.cs b/PKHeX/PKM/PK3.cs index a6f20bc4c..7dc83b479 100644 --- a/PKHeX/PKM/PK3.cs +++ b/PKHeX/PKM/PK3.cs @@ -238,9 +238,7 @@ namespace PKHeX PKRS_Strain = PKRS_Strain, PKRS_Days = PKRS_Days, OT_Gender = OT_Gender, - Met_Year = moment.Year - 2000, - Met_Month = moment.Month, - Met_Day = moment.Day, + MetDate = moment, Met_Location = 0x37, // Pal Park RibbonChampionG3Hoenn = RibbonChampionG3Hoenn, diff --git a/PKHeX/PKM/PK4.cs b/PKHeX/PKM/PK4.cs index f5a73b823..535382a52 100644 --- a/PKHeX/PKM/PK4.cs +++ b/PKHeX/PKM/PK4.cs @@ -243,12 +243,12 @@ namespace PKHeX PKX.str2arrayG4(TempNick).CopyTo(Data, 0x68); } } - public override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } - public override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } - public override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } - public override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } - public override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } - public override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } + protected override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } + protected override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } + protected override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } + protected override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } + protected override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } + protected override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } public override int Egg_Location { @@ -411,9 +411,7 @@ namespace PKHeX HeldItem = 0, OT_Friendship = 70, // Apply new met date - Met_Year = moment.Year - 2000, - Met_Month = moment.Month, - Met_Day = moment.Day + MetDate = moment }; // Fix PP diff --git a/PKHeX/PKM/PK5.cs b/PKHeX/PKM/PK5.cs index d8a302b1a..65772c052 100644 --- a/PKHeX/PKM/PK5.cs +++ b/PKHeX/PKM/PK5.cs @@ -248,12 +248,12 @@ namespace PKHeX Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x68); } } - public override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } - public override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } - public override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } - public override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } - public override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } - public override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } + protected override int Egg_Year { get { return Data[0x78]; } set { Data[0x78] = (byte)value; } } + protected override int Egg_Month { get { return Data[0x79]; } set { Data[0x79] = (byte)value; } } + protected override int Egg_Day { get { return Data[0x7A]; } set { Data[0x7A] = (byte)value; } } + protected override int Met_Year { get { return Data[0x7B]; } set { Data[0x7B] = (byte)value; } } + protected override int Met_Month { get { return Data[0x7C]; } set { Data[0x7C] = (byte)value; } } + protected override int Met_Day { get { return Data[0x7D]; } set { Data[0x7D] = (byte)value; } } public override int Egg_Location { get { return BitConverter.ToUInt16(Data, 0x7E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x7E); } } public override int Met_Location { get { return BitConverter.ToUInt16(Data, 0x80); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x80); } } private byte PKRS { get { return Data[0x82]; } set { Data[0x82] = value; } } @@ -403,12 +403,8 @@ namespace PKHeX pk6.OT_Name = OT_Name; // Dates are kept upon transfer - pk6.Met_Year = Met_Year; - pk6.Met_Month = Met_Month; - pk6.Met_Day = Met_Day; - pk6.Egg_Year = Egg_Year; - pk6.Egg_Month = Egg_Month; - pk6.Egg_Day = Egg_Day; + pk6.MetDate = MetDate; + pk6.EggMetDate = EggMetDate; // Locations are kept upon transfer pk6.Met_Location = Met_Location; diff --git a/PKHeX/PKM/PK6.cs b/PKHeX/PKM/PK6.cs index ca81c2eb2..b731d2b26 100644 --- a/PKHeX/PKM/PK6.cs +++ b/PKHeX/PKM/PK6.cs @@ -365,12 +365,12 @@ namespace PKHeX public int OT_Memory { get { return Data[0xCD]; } set { Data[0xCD] = (byte)value; } } public int OT_TextVar { get { return BitConverter.ToUInt16(Data, 0xCE); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xCE); } } public int OT_Feeling { get { return Data[0xD0]; } set { Data[0xD0] = (byte)value; } } - public override int Egg_Year { get { return Data[0xD1]; } set { Data[0xD1] = (byte)value; } } - public override int Egg_Month { get { return Data[0xD2]; } set { Data[0xD2] = (byte)value; } } - public override int Egg_Day { get { return Data[0xD3]; } set { Data[0xD3] = (byte)value; } } - public override int Met_Year { get { return Data[0xD4]; } set { Data[0xD4] = (byte)value; } } - public override int Met_Month { get { return Data[0xD5]; } set { Data[0xD5] = (byte)value; } } - public override int Met_Day { get { return Data[0xD6]; } set { Data[0xD6] = (byte)value; } } + protected override int Egg_Year { get { return Data[0xD1]; } set { Data[0xD1] = (byte)value; } } + protected override int Egg_Month { get { return Data[0xD2]; } set { Data[0xD2] = (byte)value; } } + protected override int Egg_Day { get { return Data[0xD3]; } set { Data[0xD3] = (byte)value; } } + protected override int Met_Year { get { return Data[0xD4]; } set { Data[0xD4] = (byte)value; } } + protected override int Met_Month { get { return Data[0xD5]; } set { Data[0xD5] = (byte)value; } } + protected override int Met_Day { get { return Data[0xD6]; } set { Data[0xD6] = (byte)value; } } public byte _0xD7 { get { return Data[0xD7]; } set { Data[0xD7] = value; } } public override int Egg_Location { get { return BitConverter.ToUInt16(Data, 0xD8); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xD8); } } public override int Met_Location { get { return BitConverter.ToUInt16(Data, 0xDA); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0xDA); } } diff --git a/PKHeX/PKM/PKM.cs b/PKHeX/PKM/PKM.cs index 1d3134d82..590c5fc1f 100644 --- a/PKHeX/PKM/PKM.cs +++ b/PKHeX/PKM/PKM.cs @@ -125,12 +125,96 @@ namespace PKHeX public abstract int OT_Friendship { get; set; } // Future Properties - public virtual int Met_Year { get { return 0; } set { } } - public virtual int Met_Month { get { return 0; } set { } } - public virtual int Met_Day { get { return 0; } set { } } - public virtual int Egg_Year { get { return 0; } set { } } - public virtual int Egg_Month { get { return 0; } set { } } - public virtual int Egg_Day { get { return 0; } set { } } + protected virtual int Met_Year { get { return 0; } set { } } + protected virtual int Met_Month { get { return 0; } set { } } + protected virtual int Met_Day { get { return 0; } set { } } + + /// + /// The date the Pokémon was met. + /// + /// A DateTime representing the date the Pokémon was met, or null if either the format does not support dates or the stored date is invalid. + /// Not all types support the property. In these cases, this property will return null. + /// + /// If null is assigned to this property, it will be cleared. + public virtual DateTime? MetDate + { + get + { + // Check to see if date is valid + if (!Util.IsDateValid(Met_Year, Met_Month, Met_Day)) + { + return null; + } + else + { + return new DateTime(2000 + Met_Year, Met_Month, Met_Day); + } + } + set + { + if (value.HasValue) + { + // Only update the properties if a value is provided. + Met_Year = value.Value.Year; + Met_Month = value.Value.Month; + Met_Day = value.Value.Day; + } + else + { + // Clear the Met Date. + // If code tries to access MetDate again, null will be returned. + Met_Year = 0; + Met_Month = 0; + Met_Day = 0; + } + } + } + + protected virtual int Egg_Year { get { return 0; } set { } } + protected virtual int Egg_Month { get { return 0; } set { } } + protected virtual int Egg_Day { get { return 0; } set { } } + + /// + /// The date a Pokémon was met as an egg. + /// + /// A DateTime representing the date the Pokémon was met as an egg, or null if the format does not support dates. + /// Not all types support the property. In these cases, this property will return null. + /// + /// If null is assigned to this property, it will be cleared. + public virtual DateTime? EggMetDate + { + get + { + // Check to see if date is valid + if (!Util.IsDateValid(Egg_Year, Egg_Month, Egg_Day)) + { + return null; + } + else + { + return new DateTime(2000 + Egg_Year, Egg_Month, Egg_Day); + } + } + set + { + if (value.HasValue) + { + // Only update the properties if a value is provided. + Egg_Year = value.Value.Year; + Egg_Month = value.Value.Month; + Egg_Day = value.Value.Day; + } + else + { + // Clear the Met Date. + // If code tries to access MetDate again, null will be returned. + Egg_Year = 0; + Egg_Month = 0; + Egg_Day = 0; + } + } + } + public virtual int OT_Affection { get { return 0; } set { } } public virtual int RelearnMove1 { get { return 0; } set { } } public virtual int RelearnMove2 { get { return 0; } set { } } diff --git a/PKHeX/Subforms/frmReport.cs b/PKHeX/Subforms/frmReport.cs index 7004595a4..2b0203bc1 100644 --- a/PKHeX/Subforms/frmReport.cs +++ b/PKHeX/Subforms/frmReport.cs @@ -98,12 +98,12 @@ namespace PKHeX public ushort Checksum => pkm.Checksum; public int mFriendship => pkm.OT_Friendship; public int OT_Affection => pkm.OT_Affection; - public int Egg_Year => pkm.Egg_Year; - public int Egg_Month => pkm.Egg_Month; - public int Egg_Day => pkm.Egg_Day; - public int Met_Year => pkm.Met_Year; - public int Met_Month => pkm.Met_Month; - public int Met_Day => pkm.Met_Day; + public int Egg_Year => pkm.EggMetDate.GetValueOrDefault().Year; + public int Egg_Month => pkm.EggMetDate.GetValueOrDefault().Month; + public int Egg_Day => pkm.EggMetDate.GetValueOrDefault().Day; + public int Met_Year => pkm.MetDate.GetValueOrDefault().Year; + public int Met_Month => pkm.MetDate.GetValueOrDefault().Month; + public int Met_Day => pkm.MetDate.GetValueOrDefault().Day; public int Encounter => pkm.EncounterType; #endregion diff --git a/PKHeX/Util/DateUtil.cs b/PKHeX/Util/DateUtil.cs new file mode 100644 index 000000000..3811833a7 --- /dev/null +++ b/PKHeX/Util/DateUtil.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace PKHeX +{ + public static partial class Util + { + /// + /// Determines whether or not the given date components are valid. + /// + /// The year of the date of which to check the validity. + /// The month of the date of which to check the validity. + /// The day of the date of which to check the validity. + /// A boolean indicating whether or not the date is valid. + public static bool IsDateValid(int year, int month, int day) + { + return !(year < 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth(year, day)); + } + + /// + /// Determines whether or not the given date components are valid. + /// + /// The year of the date of which to check the validity. + /// The month of the date of which to check the validity. + /// The day of the date of which to check the validity. + /// A boolean indicating whether or not the date is valid. + public static bool IsDateValid(uint year, uint month, uint day) + { + return !(year < 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth((int)year, (int)day)); + } + } +} diff --git a/PKHeX/Util/ImageUtil.cs b/PKHeX/Util/ImageUtil.cs index cf6db53bf..84a0d29a9 100644 --- a/PKHeX/Util/ImageUtil.cs +++ b/PKHeX/Util/ImageUtil.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; namespace PKHeX { - public partial class Util + public static partial class Util { // Image Layering/Blending Utility internal static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y, double trans) diff --git a/PKHeX/Util/ReflectUtil.cs b/PKHeX/Util/ReflectUtil.cs index f90a32dd2..4ff92d882 100644 --- a/PKHeX/Util/ReflectUtil.cs +++ b/PKHeX/Util/ReflectUtil.cs @@ -5,7 +5,7 @@ using System.Reflection; namespace PKHeX { - public static class ReflectUtil + public static partial class ReflectUtil { internal static bool GetValueEquals(object obj, string propertyName, object value) {