Relocate formargument logic

This commit is contained in:
Kurt
2021-02-08 20:42:19 -08:00
parent ff7817a749
commit 666a1805ba
4 changed files with 36 additions and 34 deletions

View File

@@ -1,4 +1,5 @@
using System;
using static PKHeX.Core.Species;
namespace PKHeX.Core
{
@@ -38,7 +39,7 @@ public interface IFormArgument
/// <summary>
/// Logic for mutating an <see cref="IFormArgument"/> object.
/// </summary>
public static class FormArgumentExtensions
public static class FormArgumentUtil
{
/// <summary>
/// Sets the suggested Form Argument to the <see cref="pkm"/>.
@@ -47,12 +48,12 @@ public static void SetSuggestedFormArgument(this PKM pkm)
{
if (pkm is not IFormArgument)
return;
if (!FormConverter.IsFormArgumentTypeDatePair(pkm.Species, pkm.Form))
if (!IsFormArgumentTypeDatePair(pkm.Species, pkm.Form))
{
pkm.ChangeFormArgument(0);
return;
}
var max = FormConverter.GetFormArgumentMax(pkm.Species, pkm.Form, pkm.Format);
var max = GetFormArgumentMax(pkm.Species, pkm.Form, pkm.Format);
pkm.ChangeFormArgument(max);
}
@@ -76,13 +77,13 @@ public static void ChangeFormArgument(this PKM pkm, uint value)
/// <param name="value">Value to apply</param>
public static void ChangeFormArgument(this IFormArgument f, int species, int form, int generation, uint value)
{
if (!FormConverter.IsFormArgumentTypeDatePair(species, form))
if (!IsFormArgumentTypeDatePair(species, form))
{
f.FormArgument = value;
return;
}
var max = FormConverter.GetFormArgumentMax(species, form, generation);
var max = GetFormArgumentMax(species, form, generation);
f.FormArgumentRemain = (byte)value;
if (value == max)
{
@@ -95,5 +96,32 @@ public static void ChangeFormArgument(this IFormArgument f, int species, int for
if (species == (int)Species.Furfrou)
f.FormArgumentMaximum = Math.Max(f.FormArgumentMaximum, elapsed);
}
public static uint GetFormArgumentMax(int species, int form, int generation)
{
if (generation <= 5)
return 0;
return species switch
{
(int)Furfrou when form != 0 => 5,
(int)Hoopa when form == 1 => 3,
(int)Yamask when form == 1 => 9999,
(int)Runerigus when form == 0 => 9999,
(int)Alcremie => (uint)AlcremieDecoration.Ribbon,
_ => 0,
};
}
public static bool IsFormArgumentTypeDatePair(int species, int form)
{
return species switch
{
(int)Furfrou when form != 0 => true,
(int)Hoopa when form == 1 => true,
_ => false,
};
}
}
}

View File

@@ -732,32 +732,6 @@ public static string[] GetAlcremieFormList(IReadOnlyList<string> forms)
return result;
}
public static uint GetFormArgumentMax(int species, int form, int generation)
{
if (generation <= 5)
return 0;
return species switch
{
(int)Furfrou when form != 0 => 5,
(int)Hoopa when form == 1 => 3,
(int)Yamask when form == 1 => 9999,
(int)Runerigus when form == 0 => 9999,
(int)Alcremie => (uint)AlcremieDecoration.Ribbon,
_ => 0,
};
}
public static bool IsFormArgumentTypeDatePair(int species, int form)
{
return species switch
{
(int)Furfrou when form != 0 => true,
(int)Hoopa when form == 1 => true,
_ => false,
};
}
public static bool GetFormArgumentIsNamedIndex(int species) => species == (int)Alcremie;
public static string[] GetFormArgumentStrings(int species) => species switch

View File

@@ -107,7 +107,7 @@ protected override void SetPKM(PKM pkm, bool isParty = false)
DateTime Date = DateTime.Now;
pk.Trade(this, Date.Day, Date.Month, Date.Year);
if (FormConverter.IsFormArgumentTypeDatePair(pk.Species, pk.Form))
if (FormArgumentUtil.IsFormArgumentTypeDatePair(pk.Species, pk.Form))
{
pk.FormArgumentElapsed = pk.FormArgumentMaximum = 0;
pk.FormArgumentRemain = (byte)GetFormArgument(pkm);

View File

@@ -17,7 +17,7 @@ public partial class FormArgument : UserControl
public void LoadArgument(IFormArgument f, int species, int form, int generation)
{
FieldsLoaded = false;
var max = FormConverter.GetFormArgumentMax(species, form, generation);
var max = FormArgumentUtil.GetFormArgumentMax(species, form, generation);
if (max == 0)
{
CurrentSpecies = species;
@@ -60,7 +60,7 @@ public void LoadArgument(IFormArgument f, int species, int form, int generation)
CurrentForm = form;
CurrentGeneration = generation;
if (FormConverter.IsFormArgumentTypeDatePair(species, form))
if (FormArgumentUtil.IsFormArgumentTypeDatePair(species, form))
CurrentValue = f.FormArgumentRemain;
else
CurrentValue = f.FormArgument;