2022-06-26 06:08:28 +00:00
|
|
|
using System.Collections.Generic;
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Provides ribbon information about the state of a given ribbon.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class RibbonInfo
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public const string PropertyPrefix = "Ribbon";
|
2020-09-18 23:23:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly string Name;
|
|
|
|
public bool HasRibbon { get; set; }
|
|
|
|
public int RibbonCount { get; set; }
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private RibbonInfo(string name, bool hasRibbon)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
HasRibbon = hasRibbon;
|
|
|
|
RibbonCount = -1;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private RibbonInfo(string name, int count)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
HasRibbon = false;
|
|
|
|
RibbonCount = count;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int MaxCount
|
|
|
|
{
|
|
|
|
get
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (RibbonCount < 0)
|
|
|
|
return -1;
|
|
|
|
return Name switch
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
nameof(IRibbonSetCommon6.RibbonCountMemoryContest) => 40,
|
|
|
|
nameof(IRibbonSetCommon6.RibbonCountMemoryBattle) => 8,
|
|
|
|
_ => 4,
|
|
|
|
};
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-06-26 06:08:28 +00:00
|
|
|
public static List<RibbonInfo> GetRibbonInfo(PKM pk)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Get a list of all Ribbon Attributes in the PKM
|
|
|
|
var riblist = new List<RibbonInfo>();
|
|
|
|
var names = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), PropertyPrefix);
|
|
|
|
foreach (var name in names)
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
object? RibbonValue = ReflectUtil.GetValue(pk, name);
|
|
|
|
if (RibbonValue is int x)
|
|
|
|
riblist.Add(new RibbonInfo(name, x));
|
|
|
|
if (RibbonValue is bool b)
|
|
|
|
riblist.Add(new RibbonInfo(name, b));
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
return riblist;
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
|
|
|
}
|