2022-08-21 08:39:16 +00:00
|
|
|
using System;
|
2022-05-03 01:52:43 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using static PKHeX.Core.EncounterServerDateCheck;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides indication that the encounter may or may not have a specific date range to consider.
|
|
|
|
/// </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
public interface IEncounterServerDate
|
|
|
|
{
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// If true, the date range it may be acquired at is restricted to a specific date range.
|
|
|
|
/// </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
bool IsDateRestricted { get; }
|
|
|
|
}
|
|
|
|
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enumeration indicating if a date range check is satisfied.
|
|
|
|
/// </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
public enum EncounterServerDateCheck
|
|
|
|
{
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary> No need to consider date range. </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
None,
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary> Date does fall within the range it was available. </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
Valid,
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary> Date does NOT fall within the range it was available. </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
Invalid,
|
|
|
|
}
|
|
|
|
|
2022-08-21 08:39:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Logic to check if a date obtained is within the date of availability.
|
|
|
|
/// </summary>
|
2022-05-03 01:52:43 +00:00
|
|
|
public static class EncounterServerDate
|
|
|
|
{
|
|
|
|
private static bool IsValidDate(DateTime obtained, DateTime start) => obtained >= start && obtained <= DateTime.UtcNow;
|
|
|
|
private static bool IsValidDate(DateTime obtained, DateTime start, DateTime end) => obtained >= start && obtained <= end;
|
|
|
|
|
2022-06-05 17:56:17 +00:00
|
|
|
private static bool IsValidDate(DateTime obtained, (DateTime Start, DateTime? End) value)
|
2022-05-03 01:52:43 +00:00
|
|
|
{
|
|
|
|
var (start, end) = value;
|
2022-06-05 17:56:17 +00:00
|
|
|
if (end is not { } x)
|
|
|
|
return IsValidDate(obtained, start);
|
|
|
|
return IsValidDate(obtained, start, x);
|
2022-05-03 01:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static EncounterServerDateCheck Result(bool result) => result ? Valid : Invalid;
|
|
|
|
|
|
|
|
public static EncounterServerDateCheck IsValidDate(this IEncounterServerDate enc, DateTime obtained) => enc switch
|
|
|
|
{
|
|
|
|
WC8 wc8 => Result(IsValidDateWC8(wc8.CardID, obtained)),
|
|
|
|
WA8 wa8 => Result(IsValidDateWA8(wa8.CardID, obtained)),
|
2022-05-31 04:43:52 +00:00
|
|
|
WB8 wb8 => Result(IsValidDateWB8(wb8.CardID, obtained)),
|
2022-05-03 01:52:43 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(enc)),
|
|
|
|
};
|
|
|
|
|
|
|
|
public static bool IsValidDateWC8(int cardID, DateTime obtained) => WC8Gifts.TryGetValue(cardID, out var time) && IsValidDate(obtained, time);
|
|
|
|
public static bool IsValidDateWA8(int cardID, DateTime obtained) => WA8Gifts.TryGetValue(cardID, out var time) && IsValidDate(obtained, time);
|
2022-05-31 04:43:52 +00:00
|
|
|
public static bool IsValidDateWB8(int cardID, DateTime obtained) => WB8Gifts.TryGetValue(cardID, out var time) && IsValidDate(obtained, time);
|
2022-05-03 01:52:43 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Minimum date the gift can be received.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly Dictionary<int, DateTime> WC8Gifts = new()
|
|
|
|
{
|
|
|
|
{9000, new DateTime(2020, 02, 12)}, // Bulbasaur
|
|
|
|
{9001, new DateTime(2020, 02, 12)}, // Charmander
|
|
|
|
{9002, new DateTime(2020, 02, 12)}, // Squirtle
|
|
|
|
{9003, new DateTime(2020, 02, 12)}, // Pikachu
|
|
|
|
{9004, new DateTime(2020, 02, 15)}, // Original Color Magearna
|
|
|
|
{9005, new DateTime(2020, 02, 12)}, // Eevee
|
|
|
|
{9006, new DateTime(2020, 02, 12)}, // Rotom
|
|
|
|
{9007, new DateTime(2020, 02, 12)}, // Pichu
|
|
|
|
{9008, new DateTime(2020, 06, 02)}, // Hidden Ability Grookey
|
|
|
|
{9009, new DateTime(2020, 06, 02)}, // Hidden Ability Scorbunny
|
|
|
|
{9010, new DateTime(2020, 06, 02)}, // Hidden Ability Sobble
|
|
|
|
{9011, new DateTime(2020, 06, 30)}, // Shiny Zeraora
|
|
|
|
{9012, new DateTime(2020, 11, 10)}, // Gigantamax Melmetal
|
|
|
|
{9013, new DateTime(2021, 06, 17)}, // Gigantamax Bulbasaur
|
|
|
|
{9014, new DateTime(2021, 06, 17)}, // Gigantamax Squirtle
|
|
|
|
};
|
|
|
|
|
2022-06-05 17:56:17 +00:00
|
|
|
private static readonly DateTime? Never = null;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-05-03 01:52:43 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Minimum date the gift can be received.
|
|
|
|
/// </summary>
|
2022-06-05 17:56:17 +00:00
|
|
|
public static readonly Dictionary<int, (DateTime Start, DateTime? End)> WA8Gifts = new()
|
2022-05-03 01:52:43 +00:00
|
|
|
{
|
2022-05-31 04:43:52 +00:00
|
|
|
{0138, (new(2022, 01, 27), new(2023, 02, 01))}, // Poké Center Happiny
|
2022-06-01 00:21:55 +00:00
|
|
|
{0301, (new(2022, 02, 04), new(2023, 03, 01))}, // プロポチャ Piplup
|
2022-05-03 01:52:43 +00:00
|
|
|
{0801, (new(2022, 02, 25), new(2022, 06, 01))}, // Teresa Roca Hisuian Growlithe
|
2022-05-31 04:43:52 +00:00
|
|
|
{1201, (new(2022, 05, 31), new(2022, 08, 01))}, // 전이마을 Regigigas
|
|
|
|
{1202, (new(2022, 05, 31), new(2022, 08, 01))}, // 빛나's Piplup
|
2022-09-02 07:40:40 +00:00
|
|
|
{1203, (new(2022, 08, 18), new(2022, 10, 31))}, // Arceus Chronicles Hisuian Growlithe
|
2022-05-31 04:43:52 +00:00
|
|
|
|
|
|
|
{9018, (new(2022, 05, 18), Never)}, // Hidden Ability Rowlet
|
|
|
|
{9019, (new(2022, 05, 18), Never)}, // Hidden Ability Cyndaquil
|
|
|
|
{9020, (new(2022, 05, 18), Never)}, // Hidden Ability Oshawott
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Minimum date the gift can be received.
|
|
|
|
/// </summary>
|
2022-06-05 17:56:17 +00:00
|
|
|
public static readonly Dictionary<int, (DateTime Start, DateTime? End)> WB8Gifts = new()
|
2022-05-31 04:43:52 +00:00
|
|
|
{
|
|
|
|
{9015, (new(2022, 05, 18), Never)}, // Hidden Ability Turtwig
|
|
|
|
{9016, (new(2022, 05, 18), Never)}, // Hidden Ability Chimchar
|
|
|
|
{9017, (new(2022, 05, 18), Never)}, // Hidden Ability Piplup
|
2022-05-03 01:52:43 +00:00
|
|
|
};
|
|
|
|
}
|