mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
416f5fe183
Closes #2990 ty @Atrius97 ! Remove the `object Content` accessor only used for Mystery Gifts (used to trickle up the PKM object since the two ribbon interfaces weren't implemented on the IEncounterable). Just make PCD/PGT implement the ribbon interfaces and delegate the get/set to PKM directly. Rewrite the national ribbon check for clarity Optimize invalid/missing ribbon string replace to operate on the final string rather than do linq and replace each input. With this we make 1 temp string only, rather than 1-per-ribbon. Replace hardcoded "Ribbon" strings to use a shared const string in a central spot.
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Provides ribbon information about the state of a given ribbon.
|
|
/// </summary>
|
|
public sealed class RibbonInfo
|
|
{
|
|
public const string PropertyPrefix = "Ribbon";
|
|
|
|
public readonly string Name;
|
|
public bool HasRibbon { get; set; }
|
|
public int RibbonCount { get; set; }
|
|
|
|
private RibbonInfo(string name, bool hasRibbon)
|
|
{
|
|
Name = name;
|
|
HasRibbon = hasRibbon;
|
|
RibbonCount = -1;
|
|
}
|
|
|
|
private RibbonInfo(string name, int count)
|
|
{
|
|
Name = name;
|
|
HasRibbon = false;
|
|
RibbonCount = count;
|
|
}
|
|
|
|
public int MaxCount
|
|
{
|
|
get
|
|
{
|
|
if (RibbonCount < 0)
|
|
return -1;
|
|
return Name switch
|
|
{
|
|
nameof(IRibbonSetCommon6.RibbonCountMemoryContest) => 40,
|
|
nameof(IRibbonSetCommon6.RibbonCountMemoryBattle) => 8,
|
|
_ => 4
|
|
};
|
|
}
|
|
}
|
|
|
|
public static IReadOnlyList<RibbonInfo> GetRibbonInfo(PKM pkm)
|
|
{
|
|
// Get a list of all Ribbon Attributes in the PKM
|
|
var riblist = new List<RibbonInfo>();
|
|
var names = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), PropertyPrefix);
|
|
foreach (var name in names)
|
|
{
|
|
object? RibbonValue = ReflectUtil.GetValue(pkm, name);
|
|
if (RibbonValue is int x)
|
|
riblist.Add(new RibbonInfo(name, x));
|
|
if (RibbonValue is bool b)
|
|
riblist.Add(new RibbonInfo(name, b));
|
|
}
|
|
|
|
return riblist;
|
|
}
|
|
}
|
|
}
|