2022-08-24 04:25:22 +00:00
|
|
|
using System;
|
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;
|
2022-08-24 04:25:22 +00:00
|
|
|
public readonly RibbonValueType Type;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool HasRibbon { get; set; }
|
2022-08-24 04:25:22 +00:00
|
|
|
public byte 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;
|
2022-08-24 04:25:22 +00:00
|
|
|
Type = RibbonValueType.Boolean;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2022-08-24 04:25:22 +00:00
|
|
|
private RibbonInfo(string name, byte count)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
Name = name;
|
2022-08-24 04:25:22 +00:00
|
|
|
Type = RibbonValueType.Byte;
|
2022-06-18 18:04:24 +00:00
|
|
|
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-08-24 04:25:22 +00:00
|
|
|
if (Type is RibbonValueType.Boolean)
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Type));
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return Name switch
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-08-24 04:25:22 +00:00
|
|
|
nameof(IRibbonSetMemory6.RibbonCountMemoryContest) => 40,
|
|
|
|
nameof(IRibbonSetMemory6.RibbonCountMemoryBattle) => 8,
|
|
|
|
_ => 4, // Gen3/4 Contest Ribbons
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
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 bool b)
|
|
|
|
riblist.Add(new RibbonInfo(name, b));
|
2022-08-24 04:25:22 +00:00
|
|
|
else if (RibbonValue is byte x)
|
|
|
|
riblist.Add(new RibbonInfo(name, x));
|
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
|
|
|
}
|
|
|
|
}
|
2022-08-24 04:25:22 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Type of Ribbon Value
|
|
|
|
/// </summary>
|
|
|
|
public enum RibbonValueType
|
|
|
|
{
|
|
|
|
Boolean,
|
|
|
|
Byte,
|
|
|
|
}
|